| 1 | ######################################################################## | ||||||||||||||
| 2 | # housekeeping | ||||||||||||||
| 3 | ######################################################################## | ||||||||||||||
| 4 | |||||||||||||||
| 5 | package Exporter::Proxy v1.8.1; | ||||||||||||||
| 6 | |||||||||||||||
| 7 | 6 | ▶ | use v5.20; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 6 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 6 | ▶ | use List::Util qw( first ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 6 | ▶ | use Symbol qw( qualify_to_ref ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | ######################################################################## | ||||||||||||||
| 15 | # package variables | ||||||||||||||
| 16 | ######################################################################## | ||||||||||||||
| 17 | |||||||||||||||
| 18 | 6 | my $disp_list = 'DISPATCH_OK'; | |||||||||||||
| 19 | |||||||||||||||
| 20 | ######################################################################## | ||||||||||||||
| 21 | # utility functions | ||||||||||||||
| 22 | ######################################################################## | ||||||||||||||
| 23 | |||||||||||||||
| 24 | ######################################################################## | ||||||||||||||
| 25 | # methods (public interface) | ||||||||||||||
| 26 | ######################################################################## | ||||||||||||||
| 27 | |||||||||||||||
| 28 | sub import | ||||||||||||||
| 29 | 5 | ▶ | { | ||||||||||||
|
Subroutine
import: called CC=13 SCAR=29.5
| |||||||||||||||
| 30 | 5 | ▶ | state $stub = sub{}; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 31 | |||||||||||||||
| 32 | # discard this package. | ||||||||||||||
| 33 | # left on the stack are assignment operators and | ||||||||||||||
| 34 | # exported names. | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 5 | shift; | |||||||||||||
| 37 | |||||||||||||||
| 38 | # use "$source" avoid colliding with '$caller' in the | ||||||||||||||
| 39 | # exported subs. | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 5 | my $source = caller; | |||||||||||||
| 42 | 5 | my @exportz = grep { ! /=/ } @_; | |||||||||||||
| 43 | my %argz | ||||||||||||||
| 44 | = map | ||||||||||||||
| 45 | { | ||||||||||||||
| 46 | 5 | split /=/, $_, 2 | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | grep /=/, @_; | ||||||||||||||
| 49 | |||||||||||||||
| 50 | # maybe carp about extraneous arguments here? | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 5 | ▶ | my $disp = delete $argz{ dispatch } || ''; | ||||||||||||
|
Condition100%2/2
delete $argz{'dispatch'} || ''
MC/DC100%1/1
delete $argz{'dispatch'} || ''
delete $argz{'dispatch'}
Truth table100%2/2
A
A= delete $argz{'dispatch'}
| |||||||||||||||
| 53 | 5 | ▶ | my $preproc = delete $argz{ prefilter } || ''; | ||||||||||||
|
Condition50%1/2
delete $argz{'prefilter'} || ''
MC/DC0%0/1
delete $argz{'prefilter'} || ''
delete $argz{'prefilter'}
Truth table50%1/2
A
A= delete $argz{'prefilter'}
| |||||||||||||||
| 54 | 5 | ▶ | my $postproc = delete $argz{ postfilter } || ''; | ||||||||||||
|
Condition50%1/2
delete $argz{'postfilter'} || ''
MC/DC0%0/1
delete $argz{'postfilter'} || ''
delete $argz{'postfilter'}
Truth table50%1/2
A
A= delete $argz{'postfilter'}
| |||||||||||||||
| 55 | 5 | ▶ | my $inst_import = delete $argz{ import } // 1; | ||||||||||||
|
Condition50%1/2
delete $argz{"import"} // 1
MC/DC0%0/1
delete $argz{"import"} // 1
delete $argz{"import"}
Truth table50%1/2
A
A= delete $argz{"import"}
| |||||||||||||||
| 56 | |||||||||||||||
| 57 | # if a dispatcher is being used then it must | ||||||||||||||
| 58 | # be exported. in most cases this will be the | ||||||||||||||
| 59 | # only thing exported. | ||||||||||||||
| 60 | |||||||||||||||
| 61 | 5 | ▶ | if( $disp ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | { | ||||||||||||||
| 63 | 2 | my $list = qualify_to_ref $disp_list, $source; | |||||||||||||
| 64 | |||||||||||||||
| 65 | 2 | ▶ | first { $disp eq $_ } @exportz | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 66 | 2 | ▶ | or push @exportz, $disp; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | |||||||||||||||
| 68 | 2 | ▶ | unless( $source->can( $disp ) ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 69 | { | ||||||||||||||
| 70 | 2 | my $sub = qualify_to_ref $disp, $source; | |||||||||||||
| 71 | 2 | my $can = qualify_to_ref $disp_list, $source; | |||||||||||||
| 72 | |||||||||||||||
| 73 | 2 | ▶ | if( my $sanity = *{ $can }{ ARRAY } ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 74 | { | ||||||||||||||
| 75 | *$sub | ||||||||||||||
| 76 | = sub | ||||||||||||||
| 77 | 0 | ▶ | { | ||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||
| 78 | 0 | my $op = splice @_, 1, 1; | |||||||||||||
| 79 | |||||||||||||||
| 80 | 0 | ▶ | first { $op eq $_ } @$sanity | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 81 | or do | ||||||||||||||
| 82 | 0 | ▶ | { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 83 | 0 | local $" = ' '; | |||||||||||||
| 84 | |||||||||||||||
| 85 | 0 | confess "Bogus $disp: '$op' not in @$sanity" | |||||||||||||
| 86 | }; | ||||||||||||||
| 87 | |||||||||||||||
| 88 | # this could happen if someone plays with | ||||||||||||||
| 89 | # the symbol table after installing the sub. | ||||||||||||||
| 90 | |||||||||||||||
| 91 | 0 | ▶ | my $handler = $source->can( $op ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 92 | or croak "Bogus $disp: $source cannot '$op'"; | ||||||||||||||
| 93 | |||||||||||||||
| 94 | 0 | goto &$handler | |||||||||||||
| 95 | 0 | }; | |||||||||||||
| 96 | } | ||||||||||||||
| 97 | else | ||||||||||||||
| 98 | { | ||||||||||||||
| 99 | *$sub | ||||||||||||||
| 100 | = sub | ||||||||||||||
| 101 | 4 | ▶ | { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||
| 102 | 4 | my $op = splice @_, 1, 1; | |||||||||||||
| 103 | |||||||||||||||
| 104 | 4 | ▶ | my $handler = $source->can( $op ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 105 | or croak "Bogus $disp: $source cannot '$op'"; | ||||||||||||||
| 106 | |||||||||||||||
| 107 | 4 | goto &$handler | |||||||||||||
| 108 | 2 | }; | |||||||||||||
| 109 | } | ||||||||||||||
| 110 | } | ||||||||||||||
| 111 | } | ||||||||||||||
| 112 | |||||||||||||||
| 113 | @exportz | ||||||||||||||
| 114 | 5 | ▶ | or carp "Oddity: nothing requested for export!"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 115 | |||||||||||||||
| 116 | 5 | my $exports = qualify_to_ref 'exports', $source; | |||||||||||||
| 117 | |||||||||||||||
| 118 | 5 | undef &$exports; | |||||||||||||
| 119 | |||||||||||||||
| 120 | *$exports | ||||||||||||||
| 121 | = sub | ||||||||||||||
| 122 | 4 | ▶ | { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||
| 123 | # avoid giving away ref's to the closed-over | ||||||||||||||
| 124 | # variable. | ||||||||||||||
| 125 | |||||||||||||||
| 126 | wantarray | ||||||||||||||
| 127 | ? @exportz | ||||||||||||||
| 128 | 4 | ▶ | : [ @exportz ] | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 129 | 5 | }; | |||||||||||||
| 130 | |||||||||||||||
| 131 | $inst_import | ||||||||||||||
| 132 | and | ||||||||||||||
| 133 | do | ||||||||||||||
| 134 | 5 | ▶ | { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 135 | 5 | my $import = qualify_to_ref 'import', $source; | |||||||||||||
| 136 | |||||||||||||||
| 137 | 5 | undef &$import; | |||||||||||||
| 138 | |||||||||||||||
| 139 | my $find_pre | ||||||||||||||
| 140 | = $preproc | ||||||||||||||
| 141 | ? sub | ||||||||||||||
| 142 | 0 | ▶ | { | ||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||
| 143 | 0 | ▶ | $source->can( $preproc ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 144 | or die "Unusable $source: cannot '$preproc'"; | ||||||||||||||
| 145 | } | ||||||||||||||
| 146 | 5 | ▶ | : $stub | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 147 | ; | ||||||||||||||
| 148 | |||||||||||||||
| 149 | my $find_post | ||||||||||||||
| 150 | = $postproc | ||||||||||||||
| 151 | ? sub | ||||||||||||||
| 152 | 0 | ▶ | { | ||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||
| 153 | 0 | ▶ | $source->can( $postproc ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 154 | or die "Unusable $source: cannot '$postproc'"; | ||||||||||||||
| 155 | } | ||||||||||||||
| 156 | 5 | ▶ | : $stub | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 157 | ; | ||||||||||||||
| 158 | |||||||||||||||
| 159 | *$import | ||||||||||||||
| 160 | = sub | ||||||||||||||
| 161 | 4 | ▶ | { | ||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.8
| |||||||||||||||
| 162 | # these are delayed since the "use E::P" is | ||||||||||||||
| 163 | # usually dealt with before the subs are defined | ||||||||||||||
| 164 | # in the caller. | ||||||||||||||
| 165 | |||||||||||||||
| 166 | 4 | state $pre_handler = $find_pre->(); | |||||||||||||
| 167 | 4 | state $post_handler = $find_post->(); | |||||||||||||
| 168 | |||||||||||||||
| 169 | # discard the package as first argument: | ||||||||||||||
| 170 | # $pkg->import | ||||||||||||||
| 171 | |||||||||||||||
| 172 | 4 | shift; | |||||||||||||
| 173 | |||||||||||||||
| 174 | 4 | my $caller = caller; | |||||||||||||
| 175 | |||||||||||||||
| 176 | # allow the caller to pre-process the arguments. | ||||||||||||||
| 177 | # notice this happens *before* ":noexport" is | ||||||||||||||
| 178 | # processed. | ||||||||||||||
| 179 | |||||||||||||||
| 180 | 4 | ▶ | &$pre_handler | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 181 | if $pre_handler; | ||||||||||||||
| 182 | |||||||||||||||
| 183 | # empty list => use @exportz. | ||||||||||||||
| 184 | # :noexport => use empty list. | ||||||||||||||
| 185 | |||||||||||||||
| 186 | 4 | ▶ | if( first { ':noexport' eq $_ } @_ ) | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
| |||||||||||||||
| 187 | { | ||||||||||||||
| 188 | 0 | @_ = (); | |||||||||||||
| 189 | } | ||||||||||||||
| 190 | elsif( @_ ) | ||||||||||||||
| 191 | { | ||||||||||||||
| 192 | # nothing more for the moment. | ||||||||||||||
| 193 | } | ||||||||||||||
| 194 | else | ||||||||||||||
| 195 | { | ||||||||||||||
| 196 | 2 | @_ = @exportz; | |||||||||||||
| 197 | } | ||||||||||||||
| 198 | |||||||||||||||
| 199 | # resolve these at runtime to account for | ||||||||||||||
| 200 | # possible autoloading, etc. | ||||||||||||||
| 201 | |||||||||||||||
| 202 | 4 | for my $arg ( @_ ) | |||||||||||||
| 203 | { | ||||||||||||||
| 204 | 5 | ▶ | index $arg, ':' | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 205 | or next; | ||||||||||||||
| 206 | |||||||||||||||
| 207 | 5 | ▶ | if( first { $arg eq $_ } @exportz ) | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||
| 208 | { | ||||||||||||||
| 209 | 5 | my $source = qualify_to_ref $arg, $source; | |||||||||||||
| 210 | 5 | my $install = qualify_to_ref $arg, $caller; | |||||||||||||
| 211 | |||||||||||||||
| 212 | 5 | *$install = *$source; | |||||||||||||
| 213 | } | ||||||||||||||
| 214 | else | ||||||||||||||
| 215 | { | ||||||||||||||
| 216 | 0 | die "Bogus $source: '$arg' not exported"; | |||||||||||||
| 217 | } | ||||||||||||||
| 218 | } | ||||||||||||||
| 219 | |||||||||||||||
| 220 | 4 | ▶ | goto &$post_handler | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 221 | if $post_handler; | ||||||||||||||
| 222 | 5 | }; | |||||||||||||
| 223 | }; | ||||||||||||||
| 224 | |||||||||||||||
| 225 | return | ||||||||||||||
| 226 | 5 | } | |||||||||||||
| 227 | |||||||||||||||
| 228 | # keep require happy | ||||||||||||||
| 229 | |||||||||||||||
| 230 | 6 | 1 | |||||||||||||
| 231 | |||||||||||||||
| 232 | __END__ | ||||||||||||||