blib/lib/Exporter/Proxy.pm

filter: Statementstmt 84.4% 65 / 77 Branchbran 45.0% 18 / 40 Conditioncond 62.5% 5 / 8 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 75.0% 12 / 16 Podpod n/a totaltotal 69.6% 101 / 145 CC 26 SCAR 22.7
CC
26
Cov
70%
import
19.1
__ANON__
12.0
__ANON__
8.8
CRAP 9.7
↑ Summary
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'} || ''
l!l
23
MC/DC100%1/1
delete $argz{'dispatch'} || ''
delete $argz{'dispatch'}
Truth table100%2/2
A
A= delete $argz{'dispatch'}
Aresult
11
00
53 5 ▶ my $preproc = delete $argz{ prefilter } || '';
Condition50%1/2
delete $argz{'prefilter'} || ''
l!l
05
MC/DC0%0/1
delete $argz{'prefilter'} || ''
delete $argz{'prefilter'}
Truth table50%1/2
A
A= delete $argz{'prefilter'}
Aresult
11
00
54 5 ▶ my $postproc = delete $argz{ postfilter } || '';
Condition50%1/2
delete $argz{'postfilter'} || ''
l!l
05
MC/DC0%0/1
delete $argz{'postfilter'} || ''
delete $argz{'postfilter'}
Truth table50%1/2
A
A= delete $argz{'postfilter'}
Aresult
11
00
55 5 ▶ my $inst_import = delete $argz{ import } // 1;
Condition50%1/2
delete $argz{"import"} // 1
l!l
05
MC/DC0%0/1
delete $argz{"import"} // 1
delete $argz{"import"}
Truth table50%1/2
A
A= delete $argz{"import"}
Aresult
11
00
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
BranchTrueFalseTotal
if ($disp) 2 3 5
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
BranchTrueFalseTotal
&first(sub { $disp eq $_; } , @exportz) or push @exportz, $disp 0 2 2
67  
68 2 ▶ unless( $source->can( $disp ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($source->can($disp)) 2 0 2
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
BranchTrueFalseTotal
if (my $sanity = *{$can;}{'ARRAY'}) { } 0 2 2
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
BranchTrueFalseTotal
&first(sub { $op eq $_; } , @$sanity) or do { local $" = " "; confess("Bogus ${disp}: '${op}' not in @$sanity") } 0 0 0
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
BranchTrueFalseTotal
my $handler = $source->can($op) or croak("Bogus ${disp}: $source cannot '${op}'") 0 0 0
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
BranchTrueFalseTotal
my $handler = $source->can($op) or croak("Bogus ${disp}: $source cannot '${op}'") 4 0 4
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
BranchTrueFalseTotal
@exportz or carp("Oddity: nothing requested for export!") 5 0 5
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
BranchTrueFalseTotal
wantarray ? : 4 0 4
129 5 };
130  
131 $inst_import
132 and
133 do
134 5 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
$inst_import and do { my $import = &qualify_to_ref("import", $source); undef &$import; my $find_pre = $preproc ? sub { $source->can($preproc) or die "Unusable ${source}: cannot '${preproc}'"; } : $stub; my $find_post = $postproc ? sub { $source->can($postproc) or die "Unusable ${source}: cannot '${postproc}'"; } : $stub; *$import = sub { state $pre_handler = &$find_pre(); state $post_handler = &$find_post(); shift(); my $caller = caller; &$pre_handler if $pre_handler; if (&first(sub { ":noexport" eq $_; } , @_)) { @_ = (); } elsif (@_) { (); } else { @_ = @exportz; } ; foreach my $arg (@_) { index $arg, ":" or next; if (&first(sub { $arg eq $_; } , @exportz)) { my $source = &qualify_to_ref($arg, $source); my $install = &qualify_to_ref($arg, $caller); *$install = *$source; } else { die "Bogus ${source}: '${arg}' not exported"; } ; } ; goto \&$post_handler if $post_handler; } } 5 0 5
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
BranchTrueFalseTotal
$source->can($preproc) or die "Unusable ${source}: cannot '${preproc}'" 0 0 0
144 or die "Unusable $source: cannot '$preproc'";
145 }
146 5 ▶ : $stub
Branch: 1 branch
BranchTrueFalseTotal
$preproc ? : 0 5 5
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
BranchTrueFalseTotal
$source->can($postproc) or die "Unusable ${source}: cannot '${postproc}'" 0 0 0
154 or die "Unusable $source: cannot '$postproc'";
155 }
156 5 ▶ : $stub
Branch: 1 branch
BranchTrueFalseTotal
$postproc ? : 0 5 5
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
BranchTrueFalseTotal
if $pre_handler 0 4 4
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
BranchTrueFalseTotal
if (&first(sub { ':noexport' eq $_; } , @_)) { } 0 4 4
elsif (@_) { } 2 2 4
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
BranchTrueFalseTotal
index $arg, ":" or next 5 0 5
205 or next;
206  
207 5 ▶ if( first { $arg eq $_ } @exportz )
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (&first(sub { $arg eq $_; } , @exportz)) { } 5 0 5
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
BranchTrueFalseTotal
if $post_handler 0 4 4
221 if $post_handler;
222 5 };
223 };
224  
225 return
226 5 }
227  
228 # keep require happy
229  
230 6 1
231  
232 __END__
↑ Summary