| 1 | package autouse; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | #use strict; # debugging only | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use 5.006; # use warnings | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | $autouse::VERSION = '1.11'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | $autouse::DEBUG ||= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$DEBUG ||= 0
MC/DC0%0/1
$DEBUG ||= 0
$DEBUG
Truth table50%1/2
A
A= $DEBUG
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | sub vet_import ($); | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | sub croak { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
croak: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | Carp::croak(@_); | |||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=11 SCAR=29.3
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | ▶ | my $class = @_ ? shift : 'autouse'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 8 | ▶ | croak "usage: use $class MODULE [,SUBS...]" unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | my $module = shift; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 8 | (my $pm = $module) =~ s{::}{/}g; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 8 | $pm .= '.pm'; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | if (exists $INC{$pm}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | vet_import $module; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | local $Exporter::ExportLevel = $Exporter::ExportLevel + 1; | |||||||||||||||||||||||||||||||||||||||||
| 27 | # $Exporter::Verbose = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | return $module->import(map { (my $f = $_) =~ s/\(.*?\)$//; $f } @_); | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # It is not loaded: need to do real work. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | my $callpkg = caller(0); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | ▶ | print "autouse called from $callpkg\n" if $autouse::DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | my $index; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | for my $f (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | my $proto; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | ▶ | $proto = $1 if (my $func = $f) =~ s/\((.*)\)$//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | my $closure_import_func = $func; # Full name | |||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | my $closure_func = $func; # Name inside package | |||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | my $index = rindex($func, '::'); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | ▶ | if ($index == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | $closure_import_func = "${callpkg}::$func"; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $closure_func = substr $func, $index + 2; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | croak "autouse into different package attempted" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | unless substr($func, 0, $index) eq $module; | ||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $load_sub = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=20.0
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | unless ($INC{$pm}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | require $pm; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | vet_import $module; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | no warnings qw(redefine prototype); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | *$closure_import_func = \&{"${module}::$closure_func"}; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | print "autousing $module; " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | ."imported $closure_func as $closure_import_func\n" | ||||||||||||||||||||||||||||||||||||||||||
| 60 | if $autouse::DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | goto &$closure_import_func; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | ▶ | if (defined $proto) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | *$closure_import_func = eval "sub ($proto) { goto &\$load_sub }" | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval "sub ($proto) { goto &\$load_sub }" || die()
MC/DC0%0/1
eval "sub ($proto) { goto &\$load_sub }" || die()
eval "sub ($proto) { goto &\$load_sub }"
Truth table0%0/2
A
A= eval "sub ($proto) { goto &\$load_sub }"
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | || die; | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | *$closure_import_func = $load_sub; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | ▶ | sub vet_import ($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
vet_import: called CC=5 SCAR=16.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | my $module = shift; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 5 | ▶ | if (my $import = $module->can('import')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | ▶ | croak "autoused module $module has unique import() method" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined &Exporter::import and $import == \&Exporter::import || $import == \&UNIVERSAL::import
$import == \&Exporter::import or $import == \&UNIVERSAL::import
MC/DC33%1/3
defined &Exporter::import and $import == \&Exporter::import || $import == \&UNIVERSAL::import
defined &Exporter::import
$import == \&Exporter::import
$import == \&UNIVERSAL::import
Truth table50%2/4
A and B or C
A= defined &Exporter::importB= $import == \&Exporter::importC= $import == \&UNIVERSAL::import
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | unless defined(&Exporter::import) | ||||||||||||||||||||||||||||||||||||||||||
| 78 | && ($import == \&Exporter::import || | ||||||||||||||||||||||||||||||||||||||||||
| 79 | $import == \&UNIVERSAL::import) | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||||||||||||||||