blib/lib/methods/import.pm

filter: Statementstmt 76.3% 97 / 127 Branchbran 57.4% 31 / 54 Conditioncond 68.4% 13 / 19 MC/DCmcdc 27.2% 3 / 11 Subroutinesub 84.2% 16 / 19 Podpod 0.0% 0 / 6 totaltotal 67.8% 160 / 236 CC 35 SCAR 19.0
CC
35
Cov
70%
__ANON__
13.5
using
13.5
_hashify
12.0
CRAP 6.7
↑ Summary
1 5 ▶use 5.008006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package methods::import;
6  
7 5 our $AUTHORITY = 'cpan:TOBYINK';
8 5 our $VERSION = '0.001';
9  
10 5 ▶use namespace::clean qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Sub::Util qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
14 6 my $caller = caller;
15 6 my $class = shift;
16 6 return $class->import_into($caller, @_);
17 }
18  
19 0 ▶sub method_list {
Subroutine method_list: not called CC=1 SCAR=6.9
Pod undocumented
20 0 require Carp;
21 0 Carp::croak("No methods listed to import");
22 }
23  
24 {
25 5 my %bools = (-keep => 1);
26 26 ▶ sub _get_opt {
Subroutine _get_opt: called CC=6 SCAR=18.0
27 26 my $class = shift;
28 26 my ($list) = @_;
29 26 ▶ my $opts =
Branch: 2 branches
BranchTrueFalseTotal
ref $list->[0] eq 'HASH' ? : 4 22 26
ref $list->[0] eq 'ARRAY' ? : 0 22 22
30 ref($list->[0]) eq 'HASH' ? shift @$list :
31 ref($list->[0]) eq 'ARRAY' ? $class->_hashify(shift @$list) :
32 {};
33 26 ▶ while (@$list and !ref($list->[0]) and exists($bools{$list->[0]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$list and not ref $list->[0] and exists $bools{$list->[0]}) 1 26 27
Condition83%5/6
@$list and not ref $list->[0] and exists $bools{$list->[0]}
!ll&&!rl&&r
6201
@$list and not ref $list->[0]
!ll&&!rl&&r
6021
MC/DC66%2/3
@$list and not ref $list->[0] and exists $bools{$list->[0]}
@$list not ref $list->[0] exists $bools{$list->[0]}
Truth table75%3/4
A and not(B) and C
A= @$listB= not ref $list->[0]C= exists $bools{$list->[0]}
ABCresult
0XX0
10X0
1100
1111
34 1 my $thing = shift @$list;
35 1 $opts->{$thing} = $bools{$thing};
36 }
37 26 return $opts;
38 }
39 0 ▶ sub _hashify {
Subroutine _hashify: not called CC=3 SCAR=24.8
40 0 shift;
41 0 @_ = @{+shift};
42 0 my %r;
43 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
44 0 my $thing = shift;
45 0 ▶ $r{$thing} = exists($bools{$thing}) ? 1 : shift;
Branch: 1 branch
BranchTrueFalseTotal
exists $bools{$thing} ? : 0 0 0
46 }
47 0 \%r;
48 }
49 }
50  
51 5 ▶sub import_into {
Subroutine import_into: called CC=7 SCAR=19.6
Pod undocumented
52 6 my $class = shift;
53 6 my $caller = shift;
54 6 my $using;
55
56 6 ▶ @_ = $class->method_list unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 6 6
57 6 my $default_opts = $class->_get_opt(\@_);
58
59 6 ▶ push @_, 'using' unless grep !ref && /^using$/, @_;
Branch: 1 branch
BranchTrueFalseTotal
unless grep((!ref($_) && /^using$/), @_) 6 0 6
Condition66%2/3
!ref($_) && /^using$/
!ll&&!rl&&r
4140
MC/DC0%0/2
!ref($_) && /^using$/
!ref($_) /^using$/
Truth table66%2/3
not(A) && B
A= !ref($_)B= /^using$/
ABresult
0X0
100
111
60
61 6 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 20 6 26
62 20 my $method = shift;
63 20 my $opts = $class->_get_opt(\@_);
64 20 ▶ if ($method =~ /=/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method =~ /=/) 6 14 20
65 6 ($method, $opts->{-as}, $opts->{-prototype}) = split /=/, $method;
66 }
67 20 $opts = { %$default_opts, %$opts };
68 20 ▶ $opts->{'-using'} ||= \$using;
Condition50%1/2
$opts->{"-using"} ||= \$using
l!l
020
MC/DC0%0/1
$opts->{"-using"} ||= \$using
$opts->{"-using"}
Truth table50%1/2
A
A= $opts->{"-using"}
Aresult
11
00
69 20 $class->import_method($caller, $method, $opts);
70 }
71 6 return;
72 }
73  
74 20 ▶sub import_method {
Subroutine import_method: called CC=1 SCAR=0.0
Pod undocumented
75 20 my $class = shift;
76 20 my ($caller, $method, $opts) = @_;
77 20 my $coderef = $class->make_coderef($method, $opts);
78 20 $class->install_coderef($caller, $coderef, $method, $opts);
79 }
80  
81 20 ▶sub make_coderef {
Subroutine make_coderef: called CC=4 SCAR=16.3
Pod undocumented
82 20 my $class = shift;
83 20 my ($method, $opts) = @_;
84 20 ▶ my $curry = $opts->{'-curry'} || [];
Condition100%2/2
$opts->{'-curry'} || []
l!l
416
MC/DC100%1/1
$opts->{'-curry'} || []
$opts->{'-curry'}
Truth table100%2/2
A
A= $opts->{'-curry'}
Aresult
11
00
85 20 my $coderef;
86 20 ▶ if ($method eq 'using') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq 'using') { } 6 14 20
87 5 ▶ $coderef = sub {
Subroutine __ANON__: called CC=6 SCAR=26.0
Subroutine using: not called CC=6 SCAR=26.0
88 0 ▶ return ${$opts->{'-using'}} unless @_;
Branch: 2 branches
BranchTrueFalseTotal
unless @_ 2 3 5
unless @_ 0 0 0
89 0 my ($object, $coderef) = @_;
90 0 my $old = ${$opts->{'-using'}};
91 0 ${$opts->{'-using'}} = $object;
92 0 ▶ return $old unless $coderef;
Branch: 2 branches
BranchTrueFalseTotal
unless $coderef 2 1 3
unless $coderef 0 0 0
93 0 my @r;
94 0 ▶ if (wantarray) {
Branch: 4 branches
BranchTrueFalseTotal
if (wantarray) { } 0 1 1
elsif (defined wantarray) { } 0 1 1
if (wantarray) { } 0 0 0
elsif (defined wantarray) { } 0 0 0
95 0 @r = $coderef->();
96 }
97 elsif (defined wantarray) {
98 0 $r[0] = $coderef->();
99 }
100 else {
101 0 $coderef->(); 1;
102 }
103 0 ${$opts->{'-using'}} = $old;
104 0 ▶ wantarray ? @r : $r[0];
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 1 1
wantarray ? : 0 0 0
105 6 };
106 }
107 else {
108 11 ▶ $coderef = sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
Subroutine bar1: called CC=3 SCAR=11.2
109 0 ▶ defined(my $object = defined(${$opts->{'-using'}}) ? ${$opts->{'-using'}} : $_)
Branch: 4 branches
BranchTrueFalseTotal
defined(my $object = defined ${$$opts{"-using"};} ? ${$opts->{"-using"};} : $_) or $class->croak_undefined($method, $opts) 10 1 11
defined ${$$opts{'-using'};} ? : 6 5 11
defined(my $object = defined ${$$opts{"-using"};} ? ${$opts->{"-using"};} : $_) or $class->croak_undefined($method, $opts) 3 0 3
defined ${$$opts{'-using'};} ? : 0 3 3
110 or $class->croak_undefined($method, $opts);
111 10 $object->$method(@$curry, @_);
112 14 };
113 }
114 20 ▶ if (defined $opts->{-prototype}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"-prototype"}) 1 19 20
115 1 $coderef = Sub::Util::set_prototype($opts->{-prototype}, $coderef);
116 }
117 20 return $coderef;
118 }
119  
120 20 ▶sub install_coderef {
Subroutine install_coderef: called CC=4 SCAR=13.9
Pod undocumented
121 20 my $class = shift;
122 20 my ($caller, $coderef, $method, $opts) = @_;
123 20 ▶ my $as = $opts->{'-as'} || $method;
Condition66%2/3
$opts->{'-as'} || $method
l!l&&r!l&&!r
5150
MC/DC0%0/2
$opts->{'-as'} || $method
$opts->{'-as'} $method
Truth table66%2/3
A || B
A= $opts->{'-as'}B= $method
ABresult
1X1
011
000
124 20 ▶ return if $as eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $as eq "-" 0 20 20
125 20 $coderef = Sub::Util::set_subname("$caller\::$as", $coderef);
126 20 do {
127 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
128 20 *{"$caller\::$as"} = $coderef;
129 };
130 'namespace::clean'->import(-cleanee => $caller, $as)
131 20 ▶ unless $opts->{'-keep'};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"-keep"} 16 4 20
132 }
133  
134 1 ▶sub croak_undefined {
Subroutine croak_undefined: called CC=2 SCAR=7.2
Pod undocumented
135 1 my $class = shift;
136 1 my ($method, $opts) = @_;
137 1 ▶ my $as = $opts->{'-as'} || $method;
Condition33%1/3
$opts->{'-as'} || $method
l!l&&r!l&&!r
100
MC/DC0%0/2
$opts->{'-as'} || $method
$opts->{'-as'} $method
Truth table33%1/3
A || B
A= $opts->{'-as'}B= $method
ABresult
1X1
011
000
138 1 require Carp;
139 1 Carp::croak("Can't call method \"$method\" (via imported sub \"$as\") because \$_ is not defined");
140 }
141  
142 5 1;
143  
144 __END__
↑ Summary