File Coverage

blib/lib/Role/Commons/Tap.pm
Criterion Covered Total %
statement 38 39 97.4
branch 12 14 85.7
condition 3 3 100.0
subroutine 8 8 100.0
pod 1 1 100.0
total 62 65 95.3


line stmt bran cond sub pod time code
1             package Role::Commons::Tap;
2              
3 4     4   1088 use strict;
  4         9  
  4         126  
4 4     4   41 use warnings;
  4         8  
  4         106  
5 4     4   20 use Moo::Role;
  4         5  
  4         38  
6 4     4   1779 use Carp qw[croak];
  4         6  
  4         272  
7 4     4   3303 use Scalar::Does qw[ does blessed CODE ARRAY HASH REGEXP STRING SCALAR ];
  4         396092  
  4         69  
8              
9             BEGIN {
10 4     4   4901 $Role::Commons::Tap::AUTHORITY = 'cpan:TOBYINK';
11 4         1454 $Role::Commons::Tap::VERSION = '0.102';
12             }
13              
14             our $setup_for_class = sub {
15             my ($role, $package, %args) = @_;
16             return 0;
17             };
18              
19             sub tap
20             {
21 8     8 1 1136 my $self = shift;
22 8         13 my %flags;
23            
24 8         24 PARAM: while (@_)
25             {
26 15         21 my $next = shift;
27            
28 15 100 100     44 if (does($next, CODE) or not ref $next)
29             {
30 12 100       1440 my $args = does($_[0], 'ARRAY') ? shift : [];
31 12 100   7   1159 my $code = ref $next ? $next : sub { $self->$next(@_) };
  7         30  
32            
33 12 100       31 if ($flags{ EVAL })
34             {
35 2         3 local $_ = $self;
36 2         4 eval { $code->(@$args) }
  2         7  
37             }
38             else
39             {
40 10         17 local $_ = $self;
41 10         12 do { $code->(@$args) }
  10         23  
42             }
43 11         1035 next PARAM;
44             }
45            
46 3 50       86 if (does($next, SCALAR))
47             {
48 3 50       1087 if ($$next =~ m{^(no_?)?(.+)$}i)
49             {
50 3 100       17 $flags{ uc $2 } = $1 ? 0 : 1;
51 3         14 next PARAM;
52             }
53             }
54            
55 0         0 croak qq/Unsupported parameter to tap: $next/;
56             }
57            
58 7         37 return $self;
59             }
60              
61             1;
62              
63             __END__