blib/lib/CXC/Exporter/Util.pm

filter: Statementstmt 98.9% 184 / 186 Branchbran 79.1% 38 / 48 Conditioncond 68.2% 43 / 63 MC/DCmcdc 32.4% 12 / 37 Subroutinesub 100% 38 / 38 Podpod 100% 4 / 4 totaltotal 84.8% 319 / 376 CC 66 SCAR 20.5
CC
66
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 8 ▶use v5.22;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #<<<
11 8 our $VERSION = '0.11';
12 #>>>
13  
14 8 ▶use Scalar::Util 'reftype';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use List::Util 1.45 'uniqstr';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 8 ▶use experimental 'signatures', 'postderef', 'lexical_subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 8 ▶use constant HAVE_EXPORTER_TINY => eval { require Exporter::Tiny; 1; }; ## no critic ( ReturnValueOfEval )
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use if HAVE_EXPORTER_TINY, parent => 'Exporter::Tiny';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 ▶use if !HAVE_EXPORTER_TINY, Exporter => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 8 ▶use constant UI_HELPERS => 'ui_helpers';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 8 our %EXPORT_TAGS;
26  
27 BEGIN {
28  
29 8 ▶ %EXPORT_TAGS = (
Subroutine BEGIN: called CC=1 SCAR=0.0
30 default => [qw( install_EXPORTS )],
31 constants => [qw( install_CONSTANTS )],
32 utils => [qw( install_constant_tag install_constant_func )],
33 );
34  
35 8 if ( HAVE_EXPORTER_TINY ) {
36 8 $EXPORT_TAGS{ +UI_HELPERS }
37 = [qw( ui_list_constants ui_coerce_constant ui_assert_coerce_constant )];
38 }
39  
40 }
41  
42 8 my %REGISTRY = (
43 HOOK => {},
44 CONSTANTS_TAGS => {},
45 UI => {},
46 );
47  
48 8 install_EXPORTS();
49  
50 my sub _croak {
51 1 ▶ require Carp;
Subroutine _croak: called CC=1 SCAR=0.0
52 1 goto \&Carp::croak;
53 }
54  
55  
56 88 ▶my sub _EXPORT_TAGS ( $caller = scalar caller ) {
Subroutine _EXPORT_TAGS: called CC=3 SCAR=11.0
57 8 ▶ no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNostrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
58 88 ▶ *${ \"${caller}::EXPORT_TAGS" }{HASH} // \%{ *${ \"${caller}::EXPORT_TAGS" } = {} };
Condition100%2/2
*${\("${caller}::EXPORT_TAGS");}{"HASH"} // \%{*${\("${caller}::EXPORT_TAGS");} = {};}
l!l
808
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
59 }
60  
61 20 ▶my sub _EXPORT_OK ( $caller = scalar caller ) {
Subroutine _EXPORT_OK: called CC=3 SCAR=11.0
62 8 ▶ no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNostrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
63 20 ▶ *${ \"${caller}::EXPORT_OK" }{ARRAY} // \@{ *${ \"${caller}::EXPORT_OK" } = [] };
Condition100%2/2
*${\("${caller}::EXPORT_OK");}{"ARRAY"} // \@{*${\("${caller}::EXPORT_OK");} = [];}
l!l
119
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
64 }
65  
66 20 ▶my sub _EXPORT ( $caller = scalar caller ) {
Subroutine _EXPORT: called CC=3 SCAR=11.0
67 8 ▶ no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNostrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
68 20 ▶ *${ \"${caller}::EXPORT" }{ARRAY} // \@{ *${ \"${caller}::EXPORT" } = [] };
Condition50%1/2
*${\("${caller}::EXPORT");}{"ARRAY"} // \@{*${\("${caller}::EXPORT");} = [];}
l!l
020
MC/DC0%0/1
*${\("${caller}::EXPORT");}{"ARRAY"} // \@{*${\("${caller}::EXPORT");} = [];}
*${\("${caller}::EXPORT");}{"ARRAY"}
Truth table50%1/2
A
A= *${\("${caller}::EXPORT");}{"ARRAY"}
Aresult
11
00
69 }
70  
71 my sub add_constant_to_tag;
72  
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 sub install_EXPORTS {
134  
135 20 ▶ 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' ? : 7 13 20
Condition100%2/2
builtin::reftype($_[0]) // ""
l!l
713
MC/DC100%1/1
builtin::reftype($_[0]) // ""
builtin::reftype($_[0])
Truth table100%2/2
A
A= builtin::reftype($_[0])
Aresult
11
00
136 20 ▶ my $u_opts = ( reftype( $_[-1] ) // q{} ) eq 'HASH' ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
(builtin::reftype($_[-1]) // '') eq 'HASH' ? : 3 17 20
Condition100%2/2
builtin::reftype($_[-1]) // ""
l!l
317
MC/DC100%1/1
builtin::reftype($_[-1]) // ""
builtin::reftype($_[-1])
Truth table100%2/2
A
A= builtin::reftype($_[-1])
Aresult
11
00
137  
138 20 ▶ my %options = (
Condition50%1/2
shift() // scalar caller
l!l
020
MC/DC0%0/1
shift() // scalar caller
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
139 overwrite => 0,
140 all => 'auto',
141 package => shift // scalar caller,
142 %$u_opts,
143 );
144  
145 20 ▶ _croak( 'too many arguments to INSTALL_EXPORTS' ) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 20 20
146  
147 20 my $package = delete $options{package};
148 20 my $install_all = delete $options{all};
149  
150 # run hooks.
151 20 ▶ if ( defined( my $hooks = delete $REGISTRY{HOOK}{$package}{pre} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $hooks = delete $REGISTRY{"HOOK"}{$package}{"pre"})) 4 16 20
152 4 $_->() for values $hooks->%*;
153 }
154  
155 20 my $EXPORT_TAGS = _EXPORT_TAGS( $package );
156  
157 20 ▶ if ( defined $export_tags ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $export_tags) 7 13 20
158  
159 7 ▶ if ( delete $options{overwrite} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $options{'overwrite'}) { } 1 6 7
160 1 $EXPORT_TAGS->%* = $export_tags->%*;
161 }
162  
163 else {
164 # cheap one layer deep hash merge
165 6 for my $tag ( keys $export_tags->%* ) {
166 10 ▶ push( ( $EXPORT_TAGS->{$tag} //= [] )->@*, $export_tags->{$tag}->@* );
Condition50%1/2
$EXPORT_TAGS->{$tag} //= []
l!l
010
MC/DC0%0/1
$EXPORT_TAGS->{$tag} //= []
$EXPORT_TAGS->{$tag}
Truth table50%1/2
A
A= $EXPORT_TAGS->{$tag}
Aresult
11
00
167 }
168 }
169 }
170  
171 20 ▶ if ( defined( my $hooks = delete $REGISTRY{HOOK}{$package}{post} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $hooks = delete $REGISTRY{"HOOK"}{$package}{"post"})) 3 17 20
172 3 $_->() for values $hooks->%*;
173 }
174  
175 # Exporter::Tiny handles the 'all' tag, as does Sub::Exporter, but
176 # I don't know how to detect when the latter is being used.
177 20 ▶ $install_all = !$package->isa( 'Exporter::Tiny' )
Branch: 1 branch
BranchTrueFalseTotal
if $install_all eq "auto" 18 2 20
178 if $install_all eq 'auto';
179  
180 20 ▶ if ( $install_all ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($install_all) 7 13 20
181 # Assign the all tag in two steps to avoid the situation
182 # where $EXPORT_TAGS->{all} is created with an undefined value
183 # before running values on $EXPORT_TAGS->%*;
184  
185 7 my @all = map { $_->@* } values $EXPORT_TAGS->%*;
186 7 ▶ $EXPORT_TAGS->{all} //= \@all;
Condition50%1/2
$EXPORT_TAGS->{"all"} //= \@all
l!l
07
MC/DC0%0/1
$EXPORT_TAGS->{"all"} //= \@all
$EXPORT_TAGS->{"all"}
Truth table50%1/2
A
A= $EXPORT_TAGS->{"all"}
Aresult
11
00
187 }
188  
189 20 ▶ _EXPORT( $package )->@* = ( $EXPORT_TAGS->{default} // [] )->@*;
Condition100%2/2
$EXPORT_TAGS->{"default"} // []
l!l
155
MC/DC100%1/1
$EXPORT_TAGS->{"default"} // []
$EXPORT_TAGS->{"default"}
Truth table100%2/2
A
A= $EXPORT_TAGS->{"default"}
Aresult
11
00
190 20 _EXPORT_OK( $package )->@* = uniqstr map { $_->@* } values $EXPORT_TAGS->%*;
191  
192 20 delete $REGISTRY{HOOK}{$package};
193 }
194  
195  
196  
197  
198  
199  
200  
201  
202  
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 sub install_CONSTANTS {
256 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
257  
258 8 for my $spec ( @_ ) {
259 11 my $type = reftype( $spec );
260  
261 11 ▶ if ( 'HASH' eq $type ) {
Branch: 2 branches
BranchTrueFalseTotal
if ('HASH' eq $type) { } 6 5 11
elsif ('ARRAY' eq $type) { } 5 0 5
262 6 install_constant_tag( $_, $spec->{$_}, $package ) for keys $spec->%*;
263 }
264  
265 elsif ( 'ARRAY' eq $type ) {
266 5 my $idx = $spec->@*;
267 5 ▶ _croak( 'constant spec passed as array has an odd number of elements' )
Branch: 1 branch
BranchTrueFalseTotal
unless 0 == $idx % 2 0 5 5
268 unless 0 == $idx % 2;
269  
270 5 ▶ while ( $idx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx) 5 5 10
271 5 my $hash = $spec->[ --$idx ];
272 5 my $id = $spec->[ --$idx ];
273 5 install_constant_tag( $id, $hash, $package );
274 }
275 }
276  
277 else {
278 0 _croak( 'expect a HashRef or an ArrayRef' );
279 }
280 }
281 }
282  
283  
284  
285  
286  
287  
288  
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 11 ▶sub install_constant_tag ( $id, $constants, $package = scalar caller ) {
Subroutine install_constant_tag: called CC=12 SCAR=25.2
Pod documented
478  
479 # caller may specify distinct tag and enumeration function names.
480 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
481 = 'ARRAY' eq ( reftype( $id ) // q{} )
482 ? ( $id->@* )
483 : ( lc( $id ), $id );
484  
485 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
486 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
487  
488 11 my ( @names );
489 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
490 5 @names = keys $constants->%*;
491 }
492 elsif ( reftype( $constants ) eq 'ARRAY' ) {
493 # the list of names must be returned in the order specified,
494 # hence this bizzarity
495 6 @names = $constants->@[ map { $_ * 2 } 0 .. $constants->$#* / 2 ];
496 6 $constants = { $constants->@* };
497 }
498 else {
499 0 _croak( '$constants argument should be either a hashref or an arrayref' );
500 }
501  
502 11 constant->import::into( $package, $constants );
503  
504 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
505  
506 $REGISTRY{HOOK}{$package}{pre}{$fn_values} //= sub {
507 9 ▶ my $fqdn = join q{::}, $package, $fn_values;
Subroutine __ANON__: called CC=2 SCAR=6.9
508 _croak( "Error: attempt to redefine enumerating function $fqdn" )
509 9 ▶ if exists &{$fqdn};
Branch: 1 branch
BranchTrueFalseTotal
if exists &{$fqdn;} 0 9 9
510 8 ▶ no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNostrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
511 my @values
512 9 = map { &{"${package}::${_}"} } _EXPORT_TAGS( $package )->{$tag}->@*;
513 9 install_constant_func( $fn_values, \@values, $package );
514 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
515  
516 $REGISTRY{HOOK}{$package}{pre}{$fn_names} //= sub {
517 9 ▶ my $fqdn = join q{::}, $package, $fn_names;
Subroutine __ANON__: called CC=2 SCAR=7.0
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 add_constant_to_tag( 'constant_name_funcs', $fn_names,
521 9 [ _EXPORT_TAGS( $package )->{$tag}->@* ], $package );
522  
523 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
524  
525 $REGISTRY{HOOK}{$package}{pre}{"register_tag:$tag"} //= sub {
526 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
527 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
528  
529 }
530  
531  
532  
533  
534  
535  
536  
537  
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 9 ▶sub install_constant_func ( $tag, $values, $caller = scalar caller ) {
Subroutine install_constant_func: called CC=2 SCAR=6.9
Pod documented
575 9 add_constant_to_tag( 'constant_funcs', $tag, $values, $caller );
576 # for backwards compatibility
577 9 _EXPORT_TAGS( $caller )->{constants_funcs} = _EXPORT_TAGS( $caller )->{constant_funcs};
578 }
579  
580  
581  
582  
583  
584  
585  
586  
587  
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 18 ▶sub add_constant_to_tag ( $tag, $name, $values, $caller = scalar caller ) {
Subroutine add_constant_to_tag: called CC=3 SCAR=11.0
627 18 constant->import::into( $caller, $name => $values->@* );
628 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
629 }
630  
631 ▶my sub ui_entry ( $target, $tag, $pfx ) {
Subroutine ui_entry: called CC=10 SCAR=23.8
632  
633 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
634 // _croak( "Can't find any constant tags associated with '$target'" );
635  
636 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
637  
638 exists $REGISTRY{UI}{$target}{$tag}{$pfx}
639 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
640  
641 4 my $entry = $REGISTRY{UI}{$target}{$tag}{$pfx} = {};
642  
643 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
644 or die( "internal error: Can't find subroutine ${target}::$names" )
645 ; # yes, die. so error points to this line.
646  
647 4 my %values;
648 my %valsubs;
649 4 my @names;
650  
651 # Copy each returned name before mutation; $sub is generated by
652 # the 'constant' pragma, and may return aliases to the actual
653 # constants, which cannot be mutated.
654 4 for my $const_name ( $sub->() ) {
655 31 my $name = $const_name;
656  
657 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
658 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
659 or die( "internal error: Can't find subroutine ${target}::$name" );
660 31 ▶ sub { $coderef->() };
Subroutine __ANON__: called CC=1 SCAR=0.0
661 };
662  
663 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
664 and length $pfx
665 and $name =~ s/^\Q${pfx}\E_?//;
666  
667 31 my %names;
668 31 $name = lc $name;
669 31 @names{$name} = ();
670 31 $name =~ s/_/-/g;
671 31 @names{$name} = ();
672 31 my @lnames = keys %names;
673 31 push @names, @lnames;
674 31 @values{@lnames} = ( $valsub ) x @lnames;
675 }
676 4 $entry->{names} = [ sort @names ];
677 4 $entry->{values} = \%values;
678  
679 4 return $entry;
680 }
681  
682 ▶sub _exporter_expand_tag ( $class, $name, $value, $globals ) {
Subroutine _exporter_expand_tag: called CC=4 SCAR=15.0
683  
684 3 ▶ if ( $name eq UI_HELPERS or $name eq 'all' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "ui_helpers" or $name eq "all") 3 0 3
Condition66%2/3
$name eq "ui_helpers" or $name eq "all"
l!l&&r!l&&!r
210
MC/DC0%0/2
$name eq "ui_helpers" or $name eq "all"
$name eq "ui_helpers" $name eq "all"
Truth table66%2/3
A or B
A= $name eq "ui_helpers"B= $name eq "all"
ABresult
1X1
011
000
685 3 my $target = $globals->{into};
686 $REGISTRY{HOOK}{$target}{post}{add_helpers} //= sub {
687 3 ▶ _EXPORT_TAGS( $target )->{ +UI_HELPERS } = [ $EXPORT_TAGS{ +UI_HELPERS }->@* ];
Subroutine __ANON__: called CC=1 SCAR=0.0
688 3 ▶ };
Condition33%1/3
$REGISTRY{"HOOK"}{$target}{"post"}{"add_helpers"} //= sub { _EXPORT_TAGS($target)->{"ui_helpers"} = [@{$EXPORT_TAGS{"ui_helpers"}}]; }
l!l&&r!l&&!r
030
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
689 }
690 3 $class->SUPER::_exporter_expand_tag( $name, $value, $globals );
691 }
692  
693 ▶sub _generate_ui_list_constants ( $class, $name, $args, $globals ) {
Subroutine _generate_ui_list_constants: called CC=1 SCAR=0.0
694 3 my $target = $globals->{into};
695 3 ▶ sub ( $tag, $pfx = q{} ) {
Subroutine __ANON__: called CC=2 SCAR=6.9
696 3 return ui_entry( $target, $tag, $pfx )->{names}->@*;
697 3 };
698 }
699  
700 ▶sub _generate_ui_coerce_constant ( $class, $name, $args, $globals ) {
Subroutine _generate_ui_coerce_constant: called CC=1 SCAR=0.0
701 3 my $target = $globals->{into};
702 6 ▶ sub ( $name, $tag, $pfx = q{} ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
703 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
704 4 return $valsub->();
705 3 };
706 }
707  
708 ▶sub _generate_ui_assert_coerce_constant ( $class, $name, $args, $globals ) {
Subroutine _generate_ui_assert_coerce_constant: called CC=1 SCAR=0.0
709 3 my $target = $globals->{into};
710 2 ▶ sub ( $name, $tag, $pfx = q{} ) {
Subroutine __ANON__: called CC=3 SCAR=11.1
711 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
712 // _croak( "unknown constant $tag: $name" );
713 1 return $valsub->();
714 3 };
715 }
716  
717 8 1;
718  
719 #
720 # This file is part of CXC-Exporter-Util
721 #
722 # This software is Copyright (c) 2022 by Smithsonian Astrophysical Observatory.
723 #
724 # This is free software, licensed under:
725 #
726 # The GNU General Public License, Version 3, June 2007
727 #
728  
729 __END__
↑ Summary Build »