| 1 | package Module::Stubber::Stub; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 7 | 1 | our %Retvals; | |||||||||||||||||||||||||||
| 8 | 1 | our @EXPORT; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | our $MSG_FMT = <<EOS; | |||||||||||||||||||||||||||
| 11 | *** '%s' requested at %s:%d | ||||||||||||||||||||||||||||
| 12 | *** This symbol does not really exist, and has been | ||||||||||||||||||||||||||||
| 13 | *** implemented as a stub by Module::Stubber. | ||||||||||||||||||||||||||||
| 14 | *** Depending on how important | ||||||||||||||||||||||||||||
| 15 | *** this function is, this program may not function | ||||||||||||||||||||||||||||
| 16 | *** correctly. This message will only display once. | ||||||||||||||||||||||||||||
| 17 | EOS | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | our %Warncache; | |||||||||||||||||||||||||||
| 20 | 4 | ▶ | sub _can_warn($) { | ||||||||||||||||||||||||||
|
Subroutine
_can_warn: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 21 | 4 | my $key = shift; | |||||||||||||||||||||||||||
| 22 | 4 | (my $cls = $key) =~ s/::[^:]+$//g; | |||||||||||||||||||||||||||
| 23 | 4 | ▶ | return !(exists $Warncache{$cls} || exists $Warncache{$key}); | ||||||||||||||||||||||||||
|
Condition33%1/3
exists $Module::Stubber::Stub::Warncache{$cls} || exists $Module::Stubber::Stub::Warncache{$key}
MC/DC0%0/2
exists $Module::Stubber::Stub::Warncache{$cls} || exists $Module::Stubber::Stub::Warncache{$key}
exists $Module::Stubber::Stub::Warncache{$cls}
exists $Module::Stubber::Stub::Warncache{$key}
Truth table33%1/3
A || B
A= exists $Module::Stubber::Stub::Warncache{$cls}B= exists $Module::Stubber::Stub::Warncache{$key}
| |||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 3 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||
| 27 | 3 | my $arg = shift; | |||||||||||||||||||||||||||
| 28 | 3 | my $fn = $AUTOLOAD; | |||||||||||||||||||||||||||
| 29 | 3 | my @callinfo = caller(0); | |||||||||||||||||||||||||||
| 30 | 3 | my ($pkg,$fname,$line,$subname) = @callinfo[0..3]; | |||||||||||||||||||||||||||
| 31 | 3 | ▶ | if(_can_warn($fn)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | printf STDERR ($MSG_FMT, $fn, $fname, $line); | |||||||||||||||||||||||||||
| 33 | 0 | $Warncache{$fn} = 1; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 3 | ▶ | if(!exists $Retvals{$fn}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 3 | ▶ | return $arg if ref $arg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 1 | return 1; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | return $Retvals{$fn}; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 45 | 1 | my $cls = shift; | |||||||||||||||||||||||||||
| 46 | 1 | my $s = "Dummy Object"; | |||||||||||||||||||||||||||
| 47 | 1 | my ($pkg,$file,$line) = caller(); | |||||||||||||||||||||||||||
| 48 | 1 | ▶ | printf STDERR $MSG_FMT, $cls . "::new", $file, $line if _can_warn($cls . "::new"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 1 | bless \$s, $cls; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 4 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 53 | 4 | my ($cls,@options) = @_; | |||||||||||||||||||||||||||
| 54 | 4 | ▶ | my @esyms = grep { !ref $_ && $_ =~ m/^[a-zA-Z_\$\@\%\&]/ } @options; | ||||||||||||||||||||||||||
|
Condition33%1/3
!ref($_) && $_ =~ /^[a-zA-Z_\$\@\%\&]/
MC/DC0%0/2
!ref($_) && $_ =~ /^[a-zA-Z_\$\@\%\&]/
!ref($_)
$_ =~ /^[a-zA-Z_\$\@\%\&]/
Truth table33%1/3
not(A) && B
A= !ref($_)B= $_ =~ /^[a-zA-Z_\$\@\%\&]/
| |||||||||||||||||||||||||||||
| 55 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 4 | @{$cls.'::EXPORT'} = @esyms; | |||||||||||||||||||||||||||
| 58 | 4 | *{$cls.'::AUTOLOAD'} = \&AUTOLOAD; | |||||||||||||||||||||||||||
| 59 | 4 | @_ = ($cls,@esyms); | |||||||||||||||||||||||||||
| 60 | 4 | goto &Exporter::import; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | package Module::Stubber; | ||||||||||||||||||||||||||||
| 64 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 1 | our %Status; | |||||||||||||||||||||||||||
| 67 | 1 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | my $USAGE_ERR = sprintf("Usage: use %s ". | |||||||||||||||||||||||||||
| 70 | "Pkg::Name => [ 'import', 'options' ], extra => 'options'", | ||||||||||||||||||||||||||||
| 71 | __PACKAGE__); | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 4 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=9 SCAR=22.5
| |||||||||||||||||||||||||||||
| 74 | 4 | my ($cls,$wanted_pkg,$import_params,%options) = @_; | |||||||||||||||||||||||||||
| 75 | 4 | my ($caller,$ifname,$ifline) = caller(); | |||||||||||||||||||||||||||
| 76 | 4 | ▶ | if(!$wanted_pkg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | die $USAGE_ERR; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 4 | my $pkg_s = $wanted_pkg; | |||||||||||||||||||||||||||
| 81 | 4 | $pkg_s =~ s,::,/,g; | |||||||||||||||||||||||||||
| 82 | 4 | $pkg_s .= ".pm"; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 4 | @_ = ($wanted_pkg, @$import_params); | |||||||||||||||||||||||||||
| 85 | 4 | ▶ | if(eval { require $pkg_s } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
eval {
do {
require $pkg_s
}
} and not $wanted_pkg->isa("Module::Stubber::Stub")
MC/DC50%1/2
eval {
do {
require $pkg_s
}
} and not $wanted_pkg->isa("Module::Stubber::Stub")
eval {
do {
require $pkg_s
}
}
not $wanted_pkg->isa("Module::Stubber::Stub")
Truth table66%2/3
A and not(B)
A= eval {
do {
require $pkg_s
}
}B= not $wanted_pkg->isa("Module::Stubber::Stub")
| |||||||||||||||||||||||||||||
| 86 | && !$wanted_pkg->isa('Module::Stubber::Stub') ) { | ||||||||||||||||||||||||||||
| 87 | 2 | $Status{$wanted_pkg} = 1; | |||||||||||||||||||||||||||
| 88 | 2 | ▶ | goto &{$wanted_pkg->can('import') || sub () { } }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.6
Condition33%1/3
$wanted_pkg->can('import') || sub () {
}
MC/DC0%0/2
$wanted_pkg->can('import') || sub () {
}
$wanted_pkg->can('import')
sub () {
}
Truth table33%1/3
A || B
A= $wanted_pkg->can('import')B= sub () {
}
| |||||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||||
| 90 | 2 | warn(__PACKAGE__ . ": ".$@); | |||||||||||||||||||||||||||
| 91 | 2 | $Status{$wanted_pkg} = 0; | |||||||||||||||||||||||||||
| 92 | 2 | $INC{$pkg_s} = 1; | |||||||||||||||||||||||||||
| 93 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | 2 | @{$wanted_pkg . '::ISA'} = 'Module::Stubber::Stub'; | |||||||||||||||||||||||||||
| 95 | 2 | my $more_syms = $options{will_use}; | |||||||||||||||||||||||||||
| 96 | 2 | ▶ | if(ref $more_syms eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | push @_, @$more_syms; | |||||||||||||||||||||||||||
| 98 | } else { | ||||||||||||||||||||||||||||
| 99 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 100 | 2 | ▶ | while (my ($sym,$symspec) = each %$more_syms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 10 | ▶ | if(ref $symspec eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 10 | *{$wanted_pkg."::$sym"} = $symspec; | |||||||||||||||||||||||||||
| 103 | } else { | ||||||||||||||||||||||||||||
| 104 | 0 | $Module::Stubber::Stub::Retvals{$wanted_pkg."::$sym"} = $symspec; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 10 | push @_, $sym; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 2 | ▶ | if($options{silent}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 2 | $Module::Stubber::Stub::Warncache{$wanted_pkg} = 1; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 2 | goto &Module::Stubber::Stub::import; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | 1; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||||||