| 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
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
$lib ||= "File::Spec"->curdir
$lib
"File::Spec"->curdir
Truth table33%1/3
A ||= B
A= $libB= "File::Spec"->curdir
| |||||||||||||||||||||||||||||
| 34 | 6 | ($mod_file = $module) =~ s,::,/,g; | |||||||||||||||||||||||||||
| 35 | 6 | ▶ | $mod_file =~ tr|/|:| if $^O eq 'MacOS'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 43 | 6 | local $/ = "\n"; | |||||||||||||||||||||||||||
| 44 | 6 | ▶ | while(defined ($line = <$fh>) and $line !~ m/^__DATA__/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined($line = readline $fh) and not $line =~ /^__DATA__/
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__/
| |||||||||||||||||||||||||||||
| 45 | 28 | push(@BEFORE_DATA,$line); | |||||||||||||||||||||||||||
| 46 | 28 | ▶ | $line =~ /use\s+SelfLoader/ && $found_selfloader++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 6 | ▶ | (defined ($line) && $line =~ m/^__DATA__/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $line and $line =~ /^__DATA__/
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__/
| |||||||||||||||||||||||||||||
| 49 | || die "$mod_file doesn't contain a __DATA__ token"; | ||||||||||||||||||||||||||||
| 50 | 6 | ▶ | $found_selfloader || | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | print 'die "\'use SelfLoader;\' statement NOT FOUND!!\n"',"\n"; | ||||||||||||||||||||||||||||
| 52 | 6 | ▶ | if ($JUST_STUBS) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 58 | 3 | $end_data = 1; | |||||||||||||||||||||||||||
| 59 | 3 | ▶ | while(defined($line = <$fh>)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 1 | push(@AFTER_DATA,$line); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 6 | close($fh); | |||||||||||||||||||||||||||
| 64 | 6 | ▶ | unless ($JUST_STUBS) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 3 | print @BEFORE_DATA; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 6 | print @STUBS; | |||||||||||||||||||||||||||
| 68 | 6 | ▶ | unless ($JUST_STUBS) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 3 | print "1;\n__DATA__\n",@DATA; | |||||||||||||||||||||||||||
| 70 | 3 | ▶ | if($end_data) { print "__END__ DATA\n",@AFTER_DATA; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 3 | ▶ | if(@AFTER_END) { print "__END__\n",@AFTER_END; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | 1; | |||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||