blib/lib/package/compute.pm

filter: Statementstmt 96.4% 55 / 57 Branchbran 75.0% 18 / 24 Conditioncond 72.7% 8 / 11 MC/DCmcdc 57.1% 4 / 7 Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 87.0% 94 / 108 CC 19 SCAR 21.0
CC
19
Cov
88%
__RPACKAGE__
11.2
import
10.0
BEGIN
1.0
CRAP 8.1
↑ Summary
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
BranchTrueFalseTotal
if (not defined $name) { } 1 4 5
elsif (not ref $name and $name eq '-anon') { } 1 3 4
elsif (not ref $name and $name eq '-filename') { } 1 2 3
25 {
26 1 $pkg = $caller;
27 }
28 ▶ elsif (!ref $name and $name eq '-anon')
Condition66%2/3
not ref $name and $name eq "-anon"
!ll&&!rl&&r
031
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"
ABresult
0X0
100
111
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"
!ll&&!rl&&r
021
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($INC{$k} eq $filename) 1 64 65
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
BranchTrueFalseTotal
unless defined $pkg 0 5 5
55 unless defined $pkg;
56
57 5 ▶ B::Hooks::Parser::inject("; package $pkg;")
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg eq $caller 4 1 5
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
l!l
91
MC/DC100%1/1
$caller ||= scalar caller
$caller
Truth table100%2/2
A
A= $caller
Aresult
11
00
68 10 ▶ return $caller unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 10 10
69
70 10 my $count;
71 10 ▶ while (ref $name eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $name eq "CODE") 0 10 10
72 0 ▶ { $name = $name->($caller); die "too deep" if ++$count > 7 }
Branch: 1 branch
BranchTrueFalseTotal
if ++$count > 7 0 0 0
73 10 ▶ if ($name =~ /^[.]+(?:::|'|\/)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ m[^[.]+(?:::|'|/)]) 10 0 10
74 10 { $name = "$caller\::$name" }
75
76 10 ▶ my @pkg = grep { length and $_ ne '.' } split /(?:::|'|\/)/, $name;
Condition66%2/3
length $_ && $_ ne '.'
!ll&&!rl&&r
0341
MC/DC50%1/2
length $_ && $_ ne '.'
length $_ $_ ne '.'
Truth table66%2/3
A && B
A= length $_B= $_ ne '.'
ABresult
0X0
100
111
77 10 my @final;
78 10 foreach (@pkg)
79 {
80 40 push @final, $_;
81 40 ▶ next unless /^([.]+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^([.]+)/ 33 7 40
82 7 ▶ confess "invalid relative package path" if length $1 > @final;
Branch: 1 branch
BranchTrueFalseTotal
if length $1 > @final 1 6 7
83 6 splice(@final, -(length $1));
84 }
85
86 9 return join q/::/, @final;
87 }
88  
89 4 1;
90  
91 __END__
↑ Summary