| 1 | package package::compute; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 4 | ▶ | use 5.008; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 4 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 4 | $package::compute::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||
| 9 | 4 | $package::compute::VERSION = '0.005'; | |||||||||||||||||||
| 10 | } | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 4 | ▶ | use B::Hooks::Parser 0.08 qw(); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 4 | ▶ | use Carp qw(confess); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 4 | my $count = 0; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | sub import | ||||||||||||||||||||
| 18 | 5 | ▶ | { | ||||||||||||||||||
|
Subroutine
import: called CC=10 SCAR=23.1
| |||||||||||||||||||||
| 19 | 5 | my ($class, $name) = @_; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 5 | my $caller = caller; | |||||||||||||||||||
| 22 | 5 | my $pkg; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 5 | ▶ | if (not defined $name) | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 25 | { | ||||||||||||||||||||
| 26 | 1 | $pkg = $caller; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | ▶ | elsif (!ref $name and $name eq '-anon') | |||||||||||||||||||
|
Condition66%2/3
not ref $name and $name eq "-anon"
MC/DC50%1/2
not ref $name and $name eq "-anon"
not ref $name
$name eq "-anon"
Truth table66%2/3
not(A) and B
A= not ref $nameB= $name eq "-anon"
| |||||||||||||||||||||
| 29 | { | ||||||||||||||||||||
| 30 | 1 | $pkg = sprintf('%s::__ANON__::%s', $class, ++$count); | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | ▶ | elsif (!ref $name and $name eq '-filename') | |||||||||||||||||||
|
Condition66%2/3
not ref $name and $name eq "-filename"
MC/DC50%1/2
not ref $name and $name eq "-filename"
not ref $name
$name eq "-filename"
Truth table66%2/3
not(A) and B
A= not ref $nameB= $name eq "-filename"
| |||||||||||||||||||||
| 33 | { | ||||||||||||||||||||
| 34 | # figure out where we're called from | ||||||||||||||||||||
| 35 | 1 | my (undef, $filename) = caller; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | # figure out where it got loaded via %INC. | ||||||||||||||||||||
| 38 | 1 | for my $k (sort keys %INC) | |||||||||||||||||||
| 39 | { | ||||||||||||||||||||
| 40 | 65 | ▶ | if ($INC{$k} eq $filename) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | { | ||||||||||||||||||||
| 42 | 1 | $pkg = $k; | |||||||||||||||||||
| 43 | 1 | $pkg =~ s<[/\\]><::>g; | |||||||||||||||||||
| 44 | 1 | $pkg =~ s<\.pm$><>i; # can this be uppercase on some platforms? | |||||||||||||||||||
| 45 | 1 | last; | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | else | ||||||||||||||||||||
| 50 | { | ||||||||||||||||||||
| 51 | 2 | $pkg = __RPACKAGE__($name, $caller); | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 5 | ▶ | confess("package::compute could not determine package name, died") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | unless defined $pkg; | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 5 | ▶ | B::Hooks::Parser::inject("; package $pkg;") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | unless $pkg eq $caller; | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 61 | 5 | *{"$pkg\::__RPACKAGE__"} = \&__RPACKAGE__; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | sub __RPACKAGE__ | ||||||||||||||||||||
| 65 | 10 | ▶ | { | ||||||||||||||||||
|
Subroutine
__RPACKAGE__: called CC=10 SCAR=24.2
| |||||||||||||||||||||
| 66 | 10 | my ($name, $caller) = @_; | |||||||||||||||||||
| 67 | 10 | ▶ | $caller ||= scalar caller; | ||||||||||||||||||
|
Condition100%2/2
$caller ||= scalar caller
MC/DC100%1/1
$caller ||= scalar caller
$caller
Truth table100%2/2
A
A= $caller
| |||||||||||||||||||||
| 68 | 10 | ▶ | return $caller unless defined $name; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 10 | my $count; | |||||||||||||||||||
| 71 | 10 | ▶ | while (ref $name eq 'CODE') | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 0 | ▶ | { $name = $name->($caller); die "too deep" if ++$count > 7 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 10 | ▶ | if ($name =~ /^[.]+(?:::|'|\/)/) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 10 | { $name = "$caller\::$name" } | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 10 | ▶ | my @pkg = grep { length and $_ ne '.' } split /(?:::|'|\/)/, $name; | ||||||||||||||||||
|
Condition66%2/3
length $_ && $_ ne '.'
MC/DC50%1/2
length $_ && $_ ne '.'
length $_
$_ ne '.'
Truth table66%2/3
A && B
A= length $_B= $_ ne '.'
| |||||||||||||||||||||
| 77 | 10 | my @final; | |||||||||||||||||||
| 78 | 10 | foreach (@pkg) | |||||||||||||||||||
| 79 | { | ||||||||||||||||||||
| 80 | 40 | push @final, $_; | |||||||||||||||||||
| 81 | 40 | ▶ | next unless /^([.]+)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | 7 | ▶ | confess "invalid relative package path" if length $1 > @final; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 6 | splice(@final, -(length $1)); | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 9 | return join q/::/, @final; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 4 | 1; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||