| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition83%5/6
@$list and not ref $list->[0] and exists $bools{$list->[0]}
@$list and not ref $list->[0]
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]}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $thing = shift; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | $r{$thing} = exists($bools{$thing}) ? 1 : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | my $default_opts = $class->_get_opt(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | ▶ | push @_, 'using' unless grep !ref && /^using$/, @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
!ref($_) && /^using$/
MC/DC0%0/2
!ref($_) && /^using$/
!ref($_)
/^using$/
Truth table66%2/3
not(A) && B
A= !ref($_)B= /^using$/
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 6 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 20 | my $method = shift; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 20 | my $opts = $class->_get_opt(\@_); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 20 | ▶ | if ($method =~ /=/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$opts->{"-using"} ||= \$using
$opts->{"-using"}
Truth table50%1/2
A
A= $opts->{"-using"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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'} || []
MC/DC100%1/1
$opts->{'-curry'} || []
$opts->{'-curry'}
Truth table100%2/2
A
A= $opts->{'-curry'}
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 20 | my $coderef; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 20 | ▶ | if ($method eq 'using') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my @r; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | or $class->croak_undefined($method, $opts); | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 10 | $object->$method(@$curry, @_); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 14 | }; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 20 | ▶ | if (defined $opts->{-prototype}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
$opts->{'-as'} || $method
$opts->{'-as'}
$method
Truth table66%2/3
A || B
A= $opts->{'-as'}B= $method
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 20 | ▶ | return if $as eq '-'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
$opts->{'-as'} || $method
$opts->{'-as'}
$method
Truth table33%1/3
A || B
A= $opts->{'-as'}B= $method
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||