blib/lib/Devel/SelfStubber.pm

filter: Statementstmt 94.1% 48 / 51 Branchbran 85.7% 24 / 28 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 60.0% 3 / 5 Podpod 0.0% 0 / 2 totaltotal 79.2% 80 / 101 CC 18 SCAR 26.4
CC
18
Cov
86%
stub
17.7
Version
2.0
_add_to_cache
2.0
CRAP 14.1
↑ Summary
1 package Devel::SelfStubber;
2 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 require SelfLoader;
4 1 @ISA = qw(SelfLoader);
5 1 @EXPORT = 'AUTOLOAD';
6 1 $JUST_STUBS = 1;
7 1 $VERSION = 1.05;
8 0 ▶sub Version {$VERSION}
Subroutine Version: not called CC=1 SCAR=6.9
Pod undocumented
9  
10 # Use as
11 # perl -e 'use Devel::SelfStubber;Devel::SelfStubber->stub(MODULE_NAME,LIB)'
12 # (LIB defaults to '.') e.g.
13 # perl -e 'use Devel::SelfStubber;Devel::SelfStubber->stub('Math::BigInt')'
14 # would print out stubs needed if you added a __DATA__ before the subs.
15 # Setting $Devel::SelfStubber::JUST_STUBS to 0 will print out the whole
16 # module with the stubs entered just before the __DATA__
17  
18 13 ▶sub _add_to_cache {
Subroutine _add_to_cache: called CC=2 SCAR=6.9
19 13 my($self,$fullname,$pack,$lines, $prototype) = @_;
20 13 push(@DATA,@{$lines});
21 13 ▶ if($fullname){push(@STUBS,"sub $fullname $prototype;\n")}; # stubs
Branch: 1 branch
BranchTrueFalseTotal
if ($fullname) 7 6 13
22 13 '1;';
23 }
24  
25 0 ▶sub _package_defined {
Subroutine _package_defined: not called CC=1 SCAR=6.9
26 0 my($self,$line) = @_;
27 0 push(@DATA,$line);
28 }
29  
30 6 ▶sub stub {
Subroutine stub: called CC=17 SCAR=28.7
Pod undocumented
31 6 my($self,$module,$lib) = @_;
32 6 my($line,$end_data,$fh,$mod_file,$found_selfloader);
33 6 ▶ $lib ||= File::Spec->curdir();
Condition33%1/3
$lib ||= "File::Spec"->curdir
l!l&&r!l&&!r
600
MC/DC0%0/2
$lib ||= "File::Spec"->curdir
$lib "File::Spec"->curdir
Truth table33%1/3
A ||= B
A= $libB= "File::Spec"->curdir
ABresult
1X1
011
000
34 6 ($mod_file = $module) =~ s,::,/,g;
35 6 ▶ $mod_file =~ tr|/|:| if $^O eq 'MacOS';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MacOS" 0 6 6
36  
37 6 $mod_file = File::Spec->catfile($lib, "$mod_file.pm");
38 6 $fh = "${module}::DATA";
39 6 my (@BEFORE_DATA, @AFTER_DATA, @AFTER_END);
40 6 @DATA = @STUBS = ();
41  
42 6 ▶ open($fh,$mod_file) || die "Unable to open $mod_file";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, $mod_file or die "Unable to open $mod_file" 6 0 6
43 6 local $/ = "\n";
44 6 ▶ while(defined ($line = <$fh>) and $line !~ m/^__DATA__/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $fh) and not $line =~ /^__DATA__/) 28 6 34
Condition66%2/3
defined($line = readline $fh) and not $line =~ /^__DATA__/
!ll&&!rl&&r
0628
MC/DC50%1/2
defined($line = readline $fh) and not $line =~ /^__DATA__/
defined($line = readline $fh) not $line =~ /^__DATA__/
Truth table66%2/3
A and not(B)
A= defined($line = readline $fh)B= not $line =~ /^__DATA__/
ABresult
0X0
100
111
45 28 push(@BEFORE_DATA,$line);
46 28 ▶ $line =~ /use\s+SelfLoader/ && $found_selfloader++;
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /use\s+SelfLoader/ and ++$found_selfloader 6 22 28
47 }
48 6 ▶ (defined ($line) && $line =~ m/^__DATA__/)
Branch: 1 branch
BranchTrueFalseTotal
defined $line and $line =~ /^__DATA__/ or die "$mod_file doesn't contain a __DATA__ token" 6 0 6
Condition33%1/3
defined $line and $line =~ /^__DATA__/
!ll&&!rl&&r
006
MC/DC0%0/2
defined $line and $line =~ /^__DATA__/
defined $line $line =~ /^__DATA__/
Truth table33%1/3
A and B
A= defined $lineB= $line =~ /^__DATA__/
ABresult
0X0
100
111
49 || die "$mod_file doesn't contain a __DATA__ token";
50 6 ▶ $found_selfloader ||
Branch: 1 branch
BranchTrueFalseTotal
$found_selfloader or print "die \"'use SelfLoader;' statement NOT FOUND!!\\n\"", "\n" 6 0 6
51 print 'die "\'use SelfLoader;\' statement NOT FOUND!!\n"',"\n";
52 6 ▶ if ($JUST_STUBS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($JUST_STUBS) { } 3 3 6
53 3 $self->_load_stubs($module);
54 } else {
55 3 $self->_load_stubs($module, \@AFTER_END);
56 }
57 6 ▶ if ( fileno($fh) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (fileno $fh) 3 3 6
58 3 $end_data = 1;
59 3 ▶ while(defined($line = <$fh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $fh)) 1 3 4
60 1 push(@AFTER_DATA,$line);
61 }
62 }
63 6 close($fh);
64 6 ▶ unless ($JUST_STUBS) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($JUST_STUBS) 3 3 6
65 3 print @BEFORE_DATA;
66 }
67 6 print @STUBS;
68 6 ▶ unless ($JUST_STUBS) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($JUST_STUBS) 3 3 6
69 3 print "1;\n__DATA__\n",@DATA;
70 3 ▶ if($end_data) { print "__END__ DATA\n",@AFTER_DATA; }
Branch: 1 branch
BranchTrueFalseTotal
if ($end_data) 1 2 3
71 3 ▶ if(@AFTER_END) { print "__END__\n",@AFTER_END; }
Branch: 1 branch
BranchTrueFalseTotal
if (@AFTER_END) 1 2 3
72 }
73 }
74  
75 1 1;
76 __END__
↑ Summary