blib/lib/CXC/Exporter/Util.pm

filter: Statementstmt 98.9% 184 / 186 Branchbran 81.2% 39 / 48 Conditioncond 68.1% 45 / 66 MC/DCmcdc 34.2% 13 / 38 Subroutinesub 100% 38 / 38 Podpod 100% 4 / 4 totaltotal 85.0% 323 / 380 CC 67 SCAR 20.5
CC
67
Cov
89%
install_EXPORTS
19.1
install_constant_tag
12.5
ui_entry
10.8
CRAP 7.8
↑ Summary Build »
1 package CXC::Exporter::Util;
2  
3 # ABSTRACT: Tagged Based Exporting
4  
5 9 ▶use v5.22;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #<<<
11 9 our $VERSION = '0.12';
12 #>>>
13  
14 9 ▶use Scalar::Util 'reftype';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 9 ▶use List::Util 1.45 'uniqstr';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 9 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 ▶use experimental 'signatures', 'postderef', 'lexical_subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 9 ▶use constant HAVE_EXPORTER_TINY => eval { require Exporter::Tiny; 1; }; ## no critic ( ReturnValueOfEval )
Subroutine BEGIN: called CC=1 SCAR=0.0
20 9 ▶use if HAVE_EXPORTER_TINY, parent => 'Exporter::Tiny';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 9 ▶use if !HAVE_EXPORTER_TINY, Exporter => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 9 ▶use constant UI_HELPERS => 'ui_helpers';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 9 our %EXPORT_TAGS;
26  
27 BEGIN {
28  
29 9 ▶ %EXPORT_TAGS = (
Subroutine BEGIN: called CC=1 SCAR=0.0
30 default => [qw( install_EXPORTS )],
31 exports => [qw( install_EXPORTS )],
32 constants => [qw( install_EXPORTS install_CONSTANTS )],
33 utils => [qw( install_constant_tag install_constant_func )],
34 );
35  
36 9 if ( HAVE_EXPORTER_TINY ) {
37 9 $EXPORT_TAGS{ +UI_HELPERS }
38 = [qw( ui_list_constants ui_coerce_constant ui_assert_coerce_constant )];
39 }
40  
41 }
42  
43 9 my %REGISTRY = (
44 HOOK => {},
45 CONSTANTS_TAGS => {},
46 UI => {},
47 );
48  
49 9 install_EXPORTS();
50  
51 my sub _croak {
52 1 ▶ require Carp;
Subroutine _croak: called CC=1 SCAR=0.0
53 1 goto \&Carp::croak;
54 }
55  
56  
57 93 ▶my sub _EXPORT_TAGS ( $caller = scalar caller ) {
Subroutine _EXPORT_TAGS: called CC=3 SCAR=11.0
58 9 ▶ no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNostrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
59 93 ▶ *${ \"${caller}::EXPORT_TAGS" }{HASH} // \%{ *${ \"${caller}::EXPORT_TAGS" } = {} };
Condition100%2/2
*${\("${caller}::EXPORT_TAGS");}{"HASH"} // \%{*${\("${caller}::EXPORT_TAGS");} = {};}
l!l
8211
MC/DC100%1/1
*${\("${caller}::EXPORT_TAGS");}{"HASH"} // \%{*${\("${caller}::EXPORT_TAGS");} = {};}
*${\("${caller}::EXPORT_TAGS");}{"HASH"}
Truth table100%2/2
A
A= *${\("${caller}::EXPORT_TAGS");}{"HASH"}
Aresult
11
00
60 }
61  
62 24 ▶my sub _EXPORT_OK ( $caller = scalar caller ) {
Subroutine _EXPORT_OK: called CC=3 SCAR=11.0
63 9 ▶ no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNostrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
64 24 ▶ *${ \"${caller}::EXPORT_OK" }{ARRAY} // \@{ *${ \"${caller}::EXPORT_OK" } = [] };
Condition100%2/2
*${\("${caller}::EXPORT_OK");}{"ARRAY"} // \@{*${\("${caller}::EXPORT_OK");} = [];}
l!l
123
MC/DC100%1/1
*${\("${caller}::EXPORT_OK");}{"ARRAY"} // \@{*${\("${caller}::EXPORT_OK");} = [];}
*${\("${caller}::EXPORT_OK");}{"ARRAY"}
Truth table100%2/2
A
A= *${\("${caller}::EXPORT_OK");}{"ARRAY"}
Aresult
11
00
65 }
66  
67 24 ▶my sub _EXPORT ( $caller = scalar caller ) {
Subroutine _EXPORT: called CC=3 SCAR=11.0
68 9 ▶ no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNostrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
69 24 ▶ *${ \"${caller}::EXPORT" }{ARRAY} // \@{ *${ \"${caller}::EXPORT" } = [] };
Condition50%1/2
*${\("${caller}::EXPORT");}{"ARRAY"} // \@{*${\("${caller}::EXPORT");} = [];}
l!l
024
MC/DC0%0/1
*${\("${caller}::EXPORT");}{"ARRAY"} // \@{*${\("${caller}::EXPORT");} = [];}
*${\("${caller}::EXPORT");}{"ARRAY"}
Truth table50%1/2
A
A= *${\("${caller}::EXPORT");}{"ARRAY"}
Aresult
11
00
70 }
71  
72 my sub add_constant_to_tag;
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143 sub install_EXPORTS {
144  
145 24 ▶ my $export_tags = ( reftype( $_[0] ) // q{} ) eq 'HASH' ? shift : undef;
Subroutine install_EXPORTS: called CC=19 SCAR=29.5
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
(builtin::reftype($_[0]) // '') eq 'HASH' ? : 10 14 24
Condition100%2/2
builtin::reftype($_[0]) // ""
l!l
1014
MC/DC100%1/1
builtin::reftype($_[0]) // ""
builtin::reftype($_[0])
Truth table100%2/2
A
A= builtin::reftype($_[0])
Aresult
11
00
146 24 ▶ my $u_opts = ( reftype( $_[-1] ) // q{} ) eq 'HASH' ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
(builtin::reftype($_[-1]) // '') eq 'HASH' ? : 4 20 24
Condition100%2/2
builtin::reftype($_[-1]) // ""
l!l
420
MC/DC100%1/1
builtin::reftype($_[-1]) // ""
builtin::reftype($_[-1])
Truth table100%2/2
A
A= builtin::reftype($_[-1])
Aresult
11
00
147  
148 24 ▶ my %options = (
Condition50%1/2
shift() // scalar caller
l!l
024
MC/DC0%0/1
shift() // scalar caller
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
149 overwrite => 0,
150 all => 'auto',
151 package => shift // scalar caller,
152 %$u_opts,
153 );
154  
155 24 ▶ _croak( 'too many arguments to INSTALL_EXPORTS' ) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 24 24
156  
157 24 my $package = delete $options{package};
158 24 my $install_all = delete $options{all};
159  
160 # run hooks.
161 24 ▶ if ( defined( my $hooks = delete $REGISTRY{HOOK}{$package}{pre} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $hooks = delete $REGISTRY{"HOOK"}{$package}{"pre"})) 4 20 24
162 4 $_->() for values $hooks->%*;
163 }
164  
165 24 my $EXPORT_TAGS = _EXPORT_TAGS( $package );
166  
167 24 ▶ if ( defined $export_tags ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $export_tags) 10 14 24
168  
169 10 ▶ if ( delete $options{overwrite} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $options{'overwrite'}) { } 1 9 10
170 1 $EXPORT_TAGS->%* = $export_tags->%*;
171 }
172  
173 else {
174 # cheap one layer deep hash merge
175 9 for my $tag ( keys $export_tags->%* ) {
176 13 ▶ push( ( $EXPORT_TAGS->{$tag} //= [] )->@*, $export_tags->{$tag}->@* );
Condition50%1/2
$EXPORT_TAGS->{$tag} //= []
l!l
013
MC/DC0%0/1
$EXPORT_TAGS->{$tag} //= []
$EXPORT_TAGS->{$tag}
Truth table50%1/2
A
A= $EXPORT_TAGS->{$tag}
Aresult
11
00
177 }
178 }
179 }
180  
181 24 ▶ if ( defined( my $hooks = delete $REGISTRY{HOOK}{$package}{post} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $hooks = delete $REGISTRY{"HOOK"}{$package}{"post"})) 4 20 24
182 4 $_->() for values $hooks->%*;
183 }
184  
185 # Exporter::Tiny handles the 'all' tag, as does Sub::Exporter, but
186 # I don't know how to detect when the latter is being used.
187 24 ▶ $install_all = !$package->isa( 'Exporter::Tiny' )
Branch: 1 branch
BranchTrueFalseTotal
if $install_all eq "auto" 21 3 24
188 if $install_all eq 'auto';
189  
190 24 ▶ if ( $install_all ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($install_all) 8 16 24
191 # Assign the all tag in two steps to avoid the situation
192 # where $EXPORT_TAGS->{all} is created with an undefined value
193 # before running values on $EXPORT_TAGS->%*;
194  
195 8 my @all = map { $_->@* } values $EXPORT_TAGS->%*;
196 8 ▶ $EXPORT_TAGS->{all} //= \@all;
Condition50%1/2
$EXPORT_TAGS->{"all"} //= \@all
l!l
08
MC/DC0%0/1
$EXPORT_TAGS->{"all"} //= \@all
$EXPORT_TAGS->{"all"}
Truth table50%1/2
A
A= $EXPORT_TAGS->{"all"}
Aresult
11
00
197 }
198  
199 24 ▶ _EXPORT( $package )->@* = ( $EXPORT_TAGS->{default} // [] )->@*;
Condition100%2/2
$EXPORT_TAGS->{"default"} // []
l!l
168
MC/DC100%1/1
$EXPORT_TAGS->{"default"} // []
$EXPORT_TAGS->{"default"}
Truth table100%2/2
A
A= $EXPORT_TAGS->{"default"}
Aresult
11
00
200 24 _EXPORT_OK( $package )->@* = uniqstr map { $_->@* } values $EXPORT_TAGS->%*;
201  
202 24 delete $REGISTRY{HOOK}{$package};
203 }
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265 sub install_CONSTANTS {
266 8 ▶ my $package = !defined reftype( $_[-1] ) ? pop : scalar caller;
Subroutine install_CONSTANTS: called CC=8 SCAR=21.3
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
!defined(builtin::reftype($_[-1])) ? : 0 8 8
267  
268 8 for my $spec ( @_ ) {
269 11 my $type = reftype( $spec );
270  
271 11 ▶ if ( 'HASH' eq $type ) {
Branch: 2 branches
BranchTrueFalseTotal
if ('HASH' eq $type) { } 6 5 11
elsif ('ARRAY' eq $type) { } 5 0 5
272 6 install_constant_tag( $_, $spec->{$_}, $package ) for keys $spec->%*;
273 }
274  
275 elsif ( 'ARRAY' eq $type ) {
276 5 my $idx = $spec->@*;
277 5 ▶ _croak( 'constant spec passed as array has an odd number of elements' )
Branch: 1 branch
BranchTrueFalseTotal
unless 0 == $idx % 2 0 5 5
278 unless 0 == $idx % 2;
279  
280 5 ▶ while ( $idx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx) 5 5 10
281 5 my $hash = $spec->[ --$idx ];
282 5 my $id = $spec->[ --$idx ];
283 5 install_constant_tag( $id, $hash, $package );
284 }
285 }
286  
287 else {
288 0 _croak( 'expect a HashRef or an ArrayRef' );
289 }
290 }
291 }
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  
320  
321  
322  
323  
324  
325  
326  
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
349  
350  
351  
352  
353  
354  
355  
356  
357  
358  
359  
360  
361  
362  
363  
364  
365  
366  
367  
368  
369  
370  
371  
372  
373  
374  
375  
376  
377  
378  
379  
380  
381  
382  
383  
384  
385  
386  
387  
388  
389  
390  
391  
392  
393  
394  
395  
396  
397  
398  
399  
400  
401  
402  
403  
404  
405  
406  
407  
408  
409  
410  
411  
412  
413  
414  
415  
416  
417  
418  
419  
420  
421  
422  
423  
424  
425  
426  
427  
428  
429  
430  
431  
432  
433  
434  
435  
436  
437  
438  
439  
440  
441  
442  
443  
444  
445  
446  
447  
448  
449  
450  
451  
452  
453  
454  
455  
456  
457  
458  
459  
460  
461  
462  
463  
464  
465  
466  
467  
468  
469  
470  
471  
472  
473  
474  
475  
476  
477  
478  
479  
480  
481  
482  
483  
484  
485  
486  
487 11 ▶sub install_constant_tag ( $id, $constants, $package = scalar caller ) {
Subroutine install_constant_tag: called CC=12 SCAR=25.2
Pod documented
488  
489 # caller may specify distinct tag and enumeration function names.
490 11 ▶ my ( $tag, $fn_values, $fn_names )
Branch: 1 branch
BranchTrueFalseTotal
'ARRAY' eq (builtin::reftype($id) // '') ? : 5 6 11
Condition100%2/2
builtin::reftype($id) // ""
l!l
56
MC/DC100%1/1
builtin::reftype($id) // ""
builtin::reftype($id)
Truth table100%2/2
A
A= builtin::reftype($id)
Aresult
11
00
491 = 'ARRAY' eq ( reftype( $id ) // q{} )
492 ? ( $id->@* )
493 : ( lc( $id ), $id );
494  
495 11 ▶ $fn_values //= uc( $tag );
Condition33%1/3
$fn_values //= uc $tag
l!l&&r!l&&!r
1100
MC/DC0%0/2
$fn_values //= uc $tag
$fn_values uc $tag
Truth table33%1/3
A //= B
A= $fn_valuesB= uc $tag
ABresult
1X1
011
000
496 11 ▶ $fn_names //= $fn_values . '_NAMES';
Condition100%2/2
$fn_names //= $fn_values . '_NAMES'
l!l
38
MC/DC100%1/1
$fn_names //= $fn_values . '_NAMES'
$fn_names
Truth table100%2/2
A
A= $fn_names
Aresult
11
00
497  
498 11 my ( @names );
499 11 ▶ if ( reftype( $constants ) eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::reftype($constants) eq 'HASH') { } 5 6 11
elsif (builtin::reftype($constants) eq 'ARRAY') { } 6 0 6
500 5 @names = keys $constants->%*;
501 }
502 elsif ( reftype( $constants ) eq 'ARRAY' ) {
503 # the list of names must be returned in the order specified,
504 # hence this bizzarity
505 6 @names = $constants->@[ map { $_ * 2 } 0 .. $constants->$#* / 2 ];
506 6 $constants = { $constants->@* };
507 }
508 else {
509 0 _croak( '$constants argument should be either a hashref or an arrayref' );
510 }
511  
512 11 constant->import::into( $package, $constants );
513  
514 11 ▶ push( ( _EXPORT_TAGS( $package )->{$tag} //= [] )->@*, @names );
Condition100%2/2
_EXPORT_TAGS($package)->{$tag} //= []
l!l
47
MC/DC100%1/1
_EXPORT_TAGS($package)->{$tag} //= []
_EXPORT_TAGS($package)->{$tag}
Truth table100%2/2
A
A= _EXPORT_TAGS($package)->{$tag}
Aresult
11
00
515  
516 $REGISTRY{HOOK}{$package}{pre}{$fn_values} //= sub {
517 9 ▶ my $fqdn = join q{::}, $package, $fn_values;
Subroutine __ANON__: called CC=2 SCAR=6.9
518 _croak( "Error: attempt to redefine enumerating function $fqdn" )
519 9 ▶ if exists &{$fqdn};
Branch: 1 branch
BranchTrueFalseTotal
if exists &{$fqdn;} 0 9 9
520 9 ▶ no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNostrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
521 my @values
522 9 = map { &{"${package}::${_}"} } _EXPORT_TAGS( $package )->{$tag}->@*;
523 9 install_constant_func( $fn_values, \@values, $package );
524 11 ▶ };
Condition66%2/3
$REGISTRY{"HOOK"}{$package}{"pre"}{$fn_values} //= sub { my $fqdn = join("::", $package, $fn_values); _croak "Error: attempt to redefine enumerating function $fqdn" if exists &{$fqdn;}; no strict 'refs'; my(@values) = map({&{"${package}::$_";};} @{_EXPORT_TAGS($package)->{$tag}}); install_constant_func($fn_values, \@values, $package); }
l!l&&r!l&&!r
290
MC/DC0%0/2
$REGISTRY{"HOOK"}{$package}{"pre"}{$fn_values} //= sub { my $fqdn = join("::", $package, $fn_values); _croak "Error: attempt to redefine enumerating function $fqdn" if exists &{$fqdn;}; no strict 'refs'; my(@values) = map({&{"${package}::$_";};} @{_EXPORT_TAGS($package)->{$tag}}); install_constant_func($fn_values, \@values, $package); }
$REGISTRY{"HOOK"}{$package}{"pre"}{$fn_values} sub { my $fqdn = join("::", $package, $fn_values); _croak "Error: attempt to redefine enumerating function $fqdn" if exists &{$fqdn;}; no strict 'refs'; my(@values) = map({&{"${package}::$_";};} @{_EXPORT_TAGS($package)->{$tag}}); install_constant_func($fn_values, \@values, $package); }
Truth table66%2/3
A //= B
A= $REGISTRY{"HOOK"}{$package}{"pre"}{$fn_values}B= sub { my $fqdn = join("::", $package, $fn_values); _croak "Error: attempt to redefine enumerating function $fqdn" if exists &{$fqdn;}; no strict 'refs'; my(@values) = map({&{"${package}::$_";};} @{_EXPORT_TAGS($package)->{$tag}}); install_constant_func($fn_values, \@values, $package); }
ABresult
1X1
011
000
525  
526 $REGISTRY{HOOK}{$package}{pre}{$fn_names} //= sub {
527 9 ▶ my $fqdn = join q{::}, $package, $fn_names;
Subroutine __ANON__: called CC=2 SCAR=7.0
528 _croak( "Error: attempt to redefine enumerating function $fqdn" )
529 9 ▶ if exists &{$fqdn};
Branch: 1 branch
BranchTrueFalseTotal
if exists &{$fqdn;} 0 9 9
530 add_constant_to_tag( 'constant_name_funcs', $fn_names,
531 9 [ _EXPORT_TAGS( $package )->{$tag}->@* ], $package );
532  
533 11 ▶ };
Condition66%2/3
$REGISTRY{"HOOK"}{$package}{"pre"}{$fn_names} //= sub { my $fqdn = join("::", $package, $fn_names); _croak "Error: attempt to redefine enumerating function $fqdn" if exists &{$fqdn;}; add_constant_to_tag "constant_name_funcs", $fn_names, [@{_EXPORT_TAGS($package)->{$tag}}], $package; }
l!l&&r!l&&!r
290
MC/DC0%0/2
$REGISTRY{"HOOK"}{$package}{"pre"}{$fn_names} //= sub { my $fqdn = join("::", $package, $fn_names); _croak "Error: attempt to redefine enumerating function $fqdn" if exists &{$fqdn;}; add_constant_to_tag "constant_name_funcs", $fn_names, [@{_EXPORT_TAGS($package)->{$tag}}], $package; }
$REGISTRY{"HOOK"}{$package}{"pre"}{$fn_names} sub { my $fqdn = join("::", $package, $fn_names); _croak "Error: attempt to redefine enumerating function $fqdn" if exists &{$fqdn;}; add_constant_to_tag "constant_name_funcs", $fn_names, [@{_EXPORT_TAGS($package)->{$tag}}], $package; }
Truth table66%2/3
A //= B
A= $REGISTRY{"HOOK"}{$package}{"pre"}{$fn_names}B= sub { my $fqdn = join("::", $package, $fn_names); _croak "Error: attempt to redefine enumerating function $fqdn" if exists &{$fqdn;}; add_constant_to_tag "constant_name_funcs", $fn_names, [@{_EXPORT_TAGS($package)->{$tag}}], $package; }
ABresult
1X1
011
000
534  
535 $REGISTRY{HOOK}{$package}{pre}{"register_tag:$tag"} //= sub {
536 7 ▶ ( $REGISTRY{CONSTANTS_TAGS}{$package} //= {} )->{$tag} = $fn_names;
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$REGISTRY{"CONSTANTS_TAGS"}{$package} //= {}
l!l
34
MC/DC100%1/1
$REGISTRY{"CONSTANTS_TAGS"}{$package} //= {}
$REGISTRY{"CONSTANTS_TAGS"}{$package}
Truth table100%2/2
A
A= $REGISTRY{"CONSTANTS_TAGS"}{$package}
Aresult
11
00
537 11 ▶ };
Condition66%2/3
$REGISTRY{"HOOK"}{$package}{"pre"}{"register_tag:$tag"} //= sub { +($REGISTRY{"CONSTANTS_TAGS"}{$package} //= {})->{$tag} = $fn_names; }
l!l&&r!l&&!r
470
MC/DC0%0/2
$REGISTRY{"HOOK"}{$package}{"pre"}{"register_tag:$tag"} //= sub { +($REGISTRY{"CONSTANTS_TAGS"}{$package} //= {})->{$tag} = $fn_names; }
$REGISTRY{"HOOK"}{$package}{"pre"}{"register_tag:$tag"} sub { +($REGISTRY{"CONSTANTS_TAGS"}{$package} //= {})->{$tag} = $fn_names; }
Truth table66%2/3
A //= B
A= $REGISTRY{"HOOK"}{$package}{"pre"}{"register_tag:$tag"}B= sub { +($REGISTRY{"CONSTANTS_TAGS"}{$package} //= {})->{$tag} = $fn_names; }
ABresult
1X1
011
000
538  
539 }
540  
541  
542  
543  
544  
545  
546  
547  
548  
549  
550  
551  
552  
553  
554  
555  
556  
557  
558  
559  
560  
561  
562  
563  
564  
565  
566  
567  
568  
569  
570  
571  
572  
573  
574  
575  
576  
577  
578  
579  
580  
581  
582  
583  
584 9 ▶sub install_constant_func ( $tag, $values, $caller = scalar caller ) {
Subroutine install_constant_func: called CC=2 SCAR=6.9
Pod documented
585 9 add_constant_to_tag( 'constant_funcs', $tag, $values, $caller );
586 # for backwards compatibility
587 9 _EXPORT_TAGS( $caller )->{constants_funcs} = _EXPORT_TAGS( $caller )->{constant_funcs};
588 }
589  
590  
591  
592  
593  
594  
595  
596  
597  
598  
599  
600  
601  
602  
603  
604  
605  
606  
607  
608  
609  
610  
611  
612  
613  
614  
615  
616  
617  
618  
619  
620  
621  
622  
623  
624  
625  
626  
627  
628  
629  
630  
631  
632  
633  
634  
635  
636 18 ▶sub add_constant_to_tag ( $tag, $name, $values, $caller = scalar caller ) {
Subroutine add_constant_to_tag: called CC=3 SCAR=11.0
637 18 constant->import::into( $caller, $name => $values->@* );
638 18 ▶ push( ( _EXPORT_TAGS( $caller )->{$tag} //= [] )->@*, $name );
Condition100%2/2
_EXPORT_TAGS($caller)->{$tag} //= []
l!l
108
MC/DC100%1/1
_EXPORT_TAGS($caller)->{$tag} //= []
_EXPORT_TAGS($caller)->{$tag}
Truth table100%2/2
A
A= _EXPORT_TAGS($caller)->{$tag}
Aresult
11
00
639 }
640  
641 ▶my sub ui_entry ( $target, $tag, $pfx ) {
Subroutine ui_entry: called CC=10 SCAR=23.8
642  
643 11 ▶ my $tags = $REGISTRY{CONSTANTS_TAGS}{$target}
Condition33%1/3
$REGISTRY{"CONSTANTS_TAGS"}{$target} // _croak("Can't find any constant tags associated with '${target}'")
l!l&&r!l&&!r
1100
MC/DC0%0/2
$REGISTRY{"CONSTANTS_TAGS"}{$target} // _croak("Can't find any constant tags associated with '${target}'")
$REGISTRY{"CONSTANTS_TAGS"}{$target} _croak("Can't find any constant tags associated with '${target}'")
Truth table33%1/3
A // B
A= $REGISTRY{"CONSTANTS_TAGS"}{$target}B= _croak("Can't find any constant tags associated with '${target}'")
ABresult
1X1
011
000
644 // _croak( "Can't find any constant tags associated with '$target'" );
645  
646 11 ▶ my $names = $tags->{$tag} // _croak( "unknown constant tag '$tag'" );
Condition33%1/3
$tags->{$tag} // _croak("unknown constant tag '${tag}'")
l!l&&r!l&&!r
1100
MC/DC0%0/2
$tags->{$tag} // _croak("unknown constant tag '${tag}'")
$tags->{$tag} _croak("unknown constant tag '${tag}'")
Truth table33%1/3
A // B
A= $tags->{$tag}B= _croak("unknown constant tag '${tag}'")
ABresult
1X1
011
000
647  
648 exists $REGISTRY{UI}{$target}{$tag}{$pfx}
649 11 ▶ and return $REGISTRY{UI}{$target}{$tag}{$pfx};
Branch: 1 branch
BranchTrueFalseTotal
exists $REGISTRY{"UI"}{$target}{$tag}{$pfx} and return $REGISTRY{"UI"}{$target}{$tag}{$pfx} 7 4 11
650  
651 4 my $entry = $REGISTRY{UI}{$target}{$tag}{$pfx} = {};
652  
653 4 ▶ my $sub = $target->can( $names )
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $target->can($names) or die "internal error: Can't find subroutine ${target}::$names" 0 4 4
654 or die( "internal error: Can't find subroutine ${target}::$names" )
655 ; # yes, die. so error points to this line.
656  
657 4 my %values;
658 my %valsubs;
659 4 my @names;
660  
661 # Copy each returned name before mutation; $sub is generated by
662 # the 'constant' pragma, and may return aliases to the actual
663 # constants, which cannot be mutated.
664 4 for my $const_name ( $sub->() ) {
665 31 my $name = $const_name;
666  
667 31 ▶ my $valsub = $valsubs{$name} //= do {
Condition33%1/3
$valsubs{$name} //= do { my $coderef = $target->can($name) or die "internal error: Can't find subroutine ${target}::$name"; sub { &$coderef(); } }
l!l&&r!l&&!r
0310
MC/DC0%0/2
$valsubs{$name} //= do { my $coderef = $target->can($name) or die "internal error: Can't find subroutine ${target}::$name"; sub { &$coderef(); } }
$valsubs{$name} do { my $coderef = $target->can($name) or die "internal error: Can't find subroutine ${target}::$name"; sub { &$coderef(); } }
Truth table33%1/3
A //= B
A= $valsubs{$name}B= do { my $coderef = $target->can($name) or die "internal error: Can't find subroutine ${target}::$name"; sub { &$coderef(); } }
ABresult
1X1
011
000
668 31 ▶ my $coderef = $target->can( $name )
Branch: 1 branch
BranchTrueFalseTotal
my $coderef = $target->can($name) or die "internal error: Can't find subroutine ${target}::$name" 0 31 31
669 or die( "internal error: Can't find subroutine ${target}::$name" );
670 31 ▶ sub { $coderef->() };
Subroutine __ANON__: called CC=1 SCAR=0.0
671 };
672  
673 31 ▶ defined $pfx
Branch: 1 branch
BranchTrueFalseTotal
defined $pfx and length $pfx and $name =~ s/^\Q$pfx\E_?//u 13 18 31
Condition66%2/3
defined $pfx and length $pfx
!ll&&!rl&&r
01813
MC/DC50%1/2
defined $pfx and length $pfx
defined $pfx length $pfx
Truth table66%2/3
A and B
A= defined $pfxB= length $pfx
ABresult
0X0
100
111
674 and length $pfx
675 and $name =~ s/^\Q${pfx}\E_?//;
676  
677 31 my %names;
678 31 $name = lc $name;
679 31 @names{$name} = ();
680 31 $name =~ s/_/-/g;
681 31 @names{$name} = ();
682 31 my @lnames = keys %names;
683 31 push @names, @lnames;
684 31 @values{@lnames} = ( $valsub ) x @lnames;
685 }
686 4 $entry->{names} = [ sort @names ];
687 4 $entry->{values} = \%values;
688  
689 4 return $entry;
690 }
691  
692 ▶sub _exporter_expand_tag ( $class, $name, $value, $globals ) {
Subroutine _exporter_expand_tag: called CC=5 SCAR=16.8
693  
694 7 my $target = $globals->{into};
695  
696 7 ▶ if ( $name eq UI_HELPERS
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "ui_helpers" or $name eq "all" and $class ne __PACKAGE__) 4 3 7
Condition66%4/6
$name eq "ui_helpers" or $name eq "all" and $class ne __PACKAGE__
l!l&&r!l&&!r
403
$name eq "all" and $class ne __PACKAGE__
!ll&&!rl&&r
120
MC/DC33%1/3
$name eq "ui_helpers" or $name eq "all" and $class ne __PACKAGE__
$name eq "ui_helpers" $name eq "all" $class ne __PACKAGE__
Truth table50%2/4
A or B and C
A= $name eq "ui_helpers"B= $name eq "all"C= $class ne __PACKAGE__
ABCresult
1XX1
0111
00X0
0100
697 || ( $name eq 'all' && $class ne __PACKAGE__ ) )
698 {
699 $REGISTRY{HOOK}{$target}{post}{add_helpers} //= sub {
700 4 ▶ _EXPORT_TAGS( $target )->{ +UI_HELPERS } = [ $EXPORT_TAGS{ +UI_HELPERS }->@* ];
Subroutine __ANON__: called CC=1 SCAR=0.0
701 4 ▶ };
Condition33%1/3
$REGISTRY{"HOOK"}{$target}{"post"}{"add_helpers"} //= sub { _EXPORT_TAGS($target)->{"ui_helpers"} = [@{$EXPORT_TAGS{"ui_helpers"}}]; }
l!l&&r!l&&!r
040
MC/DC0%0/2
$REGISTRY{"HOOK"}{$target}{"post"}{"add_helpers"} //= sub { _EXPORT_TAGS($target)->{"ui_helpers"} = [@{$EXPORT_TAGS{"ui_helpers"}}]; }
$REGISTRY{"HOOK"}{$target}{"post"}{"add_helpers"} sub { _EXPORT_TAGS($target)->{"ui_helpers"} = [@{$EXPORT_TAGS{"ui_helpers"}}]; }
Truth table33%1/3
A //= B
A= $REGISTRY{"HOOK"}{$target}{"post"}{"add_helpers"}B= sub { _EXPORT_TAGS($target)->{"ui_helpers"} = [@{$EXPORT_TAGS{"ui_helpers"}}]; }
ABresult
1X1
011
000
702 }
703  
704 7 $class->SUPER::_exporter_expand_tag( $name, $value, $globals );
705 }
706  
707  
708  
709  
710  
711  
712  
713  
714  
715  
716  
717  
718  
719 ▶sub _generate_ui_list_constants ( $class, $name, $args, $globals ) {
Subroutine _generate_ui_list_constants: called CC=1 SCAR=0.0
720 6 my $target = $globals->{into};
721 3 ▶ sub ( $tag, $pfx = q{} ) {
Subroutine __ANON__: called CC=2 SCAR=6.9
722 3 return ui_entry( $target, $tag, $pfx )->{names}->@*;
723 6 };
724 }
725  
726  
727  
728  
729  
730  
731  
732  
733  
734  
735 ▶sub _generate_ui_coerce_constant ( $class, $name, $args, $globals ) {
Subroutine _generate_ui_coerce_constant: called CC=1 SCAR=0.0
736 6 my $target = $globals->{into};
737 6 ▶ sub ( $name, $tag, $pfx = q{} ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
738 6 ▶ my $valsub = ui_entry( $target, $tag, $pfx )->{values}{$name} // return $name;
Condition100%2/2
ui_entry($target, $tag, $pfx)->{"values"}{$name} // (return $name)
l!l
42
MC/DC100%1/1
ui_entry($target, $tag, $pfx)->{"values"}{$name} // (return $name)
ui_entry($target, $tag, $pfx)->{"values"}{$name}
Truth table100%2/2
A
A= ui_entry($target, $tag, $pfx)->{"values"}{$name}
Aresult
11
00
739 4 return $valsub->();
740 6 };
741 }
742  
743  
744  
745  
746  
747  
748  
749  
750  
751  
752 ▶sub _generate_ui_assert_coerce_constant ( $class, $name, $args, $globals ) {
Subroutine _generate_ui_assert_coerce_constant: called CC=1 SCAR=0.0
753 6 my $target = $globals->{into};
754 2 ▶ sub ( $name, $tag, $pfx = q{} ) {
Subroutine __ANON__: called CC=3 SCAR=11.1
755 2 ▶ my $valsub = ui_entry( $target, $tag, $pfx )->{values}{$name}
Condition66%2/3
ui_entry($target, $tag, $pfx)->{"values"}{$name} // _croak("unknown constant ${tag}: $name")
l!l&&r!l&&!r
101
MC/DC0%0/2
ui_entry($target, $tag, $pfx)->{"values"}{$name} // _croak("unknown constant ${tag}: $name")
ui_entry($target, $tag, $pfx)->{"values"}{$name} _croak("unknown constant ${tag}: $name")
Truth table33%1/3
A // B
A= ui_entry($target, $tag, $pfx)->{"values"}{$name}B= _croak("unknown constant ${tag}: $name")
ABresult
1X1
011
000
756 // _croak( "unknown constant $tag: $name" );
757 1 return $valsub->();
758 6 };
759 }
760  
761 9 1;
762  
763 #
764 # This file is part of CXC-Exporter-Util
765 #
766 # This software is Copyright (c) 2022 by Smithsonian Astrophysical Observatory.
767 #
768 # This is free software, licensed under:
769 #
770 # The GNU General Public License, Version 3, June 2007
771 #
772  
773 __END__
↑ Summary Build »