blib/lib/Exporter/Almighty.pm

filter: Statementstmt 99.5% 228 / 229 Branchbran 87.5% 35 / 40 Conditioncond 63.3% 19 / 30 MC/DCmcdc 25.0% 4 / 16 Subroutinesub 100% 37 / 37 Podpod 0.0% 0 / 13 totaltotal 88.4% 323 / 365 SCAR 40.2
CC
55
Cov
94%
finalize_export_variables_for
8.0
steps
8.0
_setup_classes_or_roles_for
6.2
CRAP 55.6
↑ Summary
1 3 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Exporter::Almighty;
6  
7 3 our $AUTHORITY = 'cpan:TOBYINK';
8 3 our $VERSION = '0.001003';
9  
10 3 ▶use parent qw( Exporter::Tiny );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 my @builtins;
13 3 ▶BEGIN { @builtins = qw( is_bool created_as_string created_as_number ) };
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use if $] lt '5.036000', 'builtins::compat' => @builtins;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use if $] ge '5.036000', 'builtin' => @builtins;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶no if $] ge '5.036000', 'warnings' => qw( experimental::builtin );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use B qw( perlstring );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use Eval::TypeTiny qw( eval_closure set_subname );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use Exporter::Tiny qw( mkopt );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use Module::Runtime qw( require_module module_notional_filename );
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use Type::Registry qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 use Types::Common qw(
26 -sigs
27 -types
28 assert_Ref is_Ref
29 assert_ArrayRef is_ArrayRef
30 assert_HashRef is_HashRef
31 is_NonEmptySimpleStr
32 3 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 sub _exporter_validate_opts {
35 1 ▶ my ( $me, $options ) = @_;
Subroutine _exporter_validate_opts: called CC=1 SCAR=0.0
36 1 my $into = $options->{into};
37 1 my $setup = $options->{setup};
38 1 strict->import::into( $into );
39 1 warnings->import::into( $into );
40 1 $me->setup_for( $into, $setup );
41 }
42  
43 # Subclasses may wish to provide a subclass of Exporter::Tiny here.
44 sub base_exporter {
45 7 ▶ return 'Exporter::Tiny';
Subroutine base_exporter: called CC=1 SCAR=0.0
Pod undocumented
46 }
47  
48 sub standard_package_variables {
49 19 ▶ my ( $me, $into ) = @_;
Subroutine standard_package_variables: called CC=1 SCAR=0.0
Pod undocumented
50 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
51 return (
52 19 \@{"$into\::ISA"},
53 19 \@{"$into\::EXPORT"},
54 19 \@{"$into\::EXPORT_OK"},
55 19 \%{"$into\::EXPORT_TAGS"},
56 );
57 }
58  
59 3 signature_for setup_for => (
60 method => 1,
61 head => [ NonEmptySimpleStr ],
62 named => [
63 tag => Optional[HashRef],
64 also => Optional[ArrayRef],
65 enum => Optional[HashRef[ArrayRef]],
66 class => Optional[ArrayRef],
67 role => Optional[ArrayRef],
68 duck => Optional[HashRef[ArrayRef]],
69 type => Optional[ArrayRef],
70 const => Optional[HashRef],
71 ],
72 );
73  
74 sub setup_for {
75 6 ▶ my ( $me, $into, $setup ) = @_;
Subroutine setup_for: called CC=3 SCAR=11.0
76 6 ▶ $INC{ module_notional_filename($into) } //= __FILE__;
Condition50%1/2
$INC{&module_notional_filename($into)} //= __FILE__
l!l
06
MC/DC0%0/1
$INC{&module_notional_filename($into)} //= __FILE__
$INC{&module_notional_filename($into)}
Truth table50%1/2
A
A= $INC{&module_notional_filename($into)}
Aresult
11
00
77 6 my @steps = $me->steps( $into, $setup );
78 6 for my $step ( @steps ) {
79 21 $me->$step( $into, $setup );
80 }
81 6 return;
82 }
83  
84 # Subclasses can wrap this to easily add and remove steps.
85 sub steps {
86 15 ▶ my ( $me, $into, $setup ) = @_;
Subroutine steps: called CC=8 SCAR=20.8
Pod undocumented
87 15 my @steps;
88 15 push @steps, 'setup_exporter_for';
89 15 ▶ push @steps, 'setup_reexports_for' if $setup->{also};
Branch: 1 branch
BranchTrueFalseTotal
if $setup->{"also"} 5 10 15
90 15 ▶ push @steps, 'setup_enums_for' if $setup->{enum};
Branch: 1 branch
BranchTrueFalseTotal
if $setup->{"enum"} 5 10 15
91 15 ▶ push @steps, 'setup_classes_for' if $setup->{class};
Branch: 1 branch
BranchTrueFalseTotal
if $setup->{"class"} 1 14 15
92 15 ▶ push @steps, 'setup_roles_for' if $setup->{role};
Branch: 1 branch
BranchTrueFalseTotal
if $setup->{"role"} 1 14 15
93 15 ▶ push @steps, 'setup_ducks_for' if $setup->{duck};
Branch: 1 branch
BranchTrueFalseTotal
if $setup->{"duck"} 1 14 15
94 15 ▶ push @steps, 'setup_types_for' if $setup->{type};
Branch: 1 branch
BranchTrueFalseTotal
if $setup->{"type"} 1 14 15
95 15 ▶ push @steps, 'setup_constants_for' if $setup->{const};
Branch: 1 branch
BranchTrueFalseTotal
if $setup->{"const"} 5 10 15
96 15 push @steps, 'finalize_export_variables_for';
97 15 return @steps;
98 }
99  
100 sub setup_exporter_for {
101 6 ▶ my ( $me, $into, $setup ) = @_;
Subroutine setup_exporter_for: called CC=5 SCAR=16.2
Pod undocumented
102
103 6 my ( $into_ISA, undef, undef, $into_EXPORT_TAGS ) =
104 $me->standard_package_variables( $into );
105
106 # Set up @ISA in caller package.
107 6 my $base = $me->base_exporter( $into, $setup );
108 6 ▶ push @$into_ISA, $base unless $into->isa( $base );
Branch: 1 branch
BranchTrueFalseTotal
unless $into->isa($base) 6 0 6
109
110 # Set up %EXPORT_TAGS in caller package.
111 6 ▶ my %tags = %{ $setup->{tag} // {} };
Condition100%2/2
$setup->{"tag"} // {}
l!l
51
MC/DC100%1/1
$setup->{"tag"} // {}
$setup->{"tag"}
Truth table100%2/2
A
A= $setup->{"tag"}
Aresult
11
00
112 6 for my $tag_name ( keys %tags ) {
113 7 my @exports = @{ assert_ArrayRef $tags{$tag_name} };
114 7 $tag_name =~ s/^[-:]//;
115 7 ▶ push @{ $into_EXPORT_TAGS->{$tag_name} //= [] }, @exports;
Condition50%1/2
$into_EXPORT_TAGS->{$tag_name} //= []
l!l
07
MC/DC0%0/1
$into_EXPORT_TAGS->{$tag_name} //= []
$into_EXPORT_TAGS->{$tag_name}
Truth table50%1/2
A
A= $into_EXPORT_TAGS->{$tag_name}
Aresult
11
00
116 }
117
118 6 return;
119 }
120  
121 sub setup_reexports_for {
122 2 ▶ my ( $me, $into, $setup ) = @_;
Subroutine setup_reexports_for: called CC=2 SCAR=6.9
Pod undocumented
123
124 2 my $next = $into->can( '_exporter_validate_opts' );
125
126 2 my $optlist = mkopt( $setup->{also} );
127 2 require_module( $_->[0] ) for @$optlist;
128
129 2 my $method_name = "$into\::_exporter_validate_opts";
130 my $method_code = sub {
131 2 ▶ my ( $class, $opts ) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.1
132 2 ▶ is_NonEmptySimpleStr( my $caller = $opts->{into} ) or return;
Branch: 1 branch
BranchTrueFalseTotal
&is_NonEmptySimpleStr(my $caller = $opts->{"into"}) or return 0 2 2
133 2 for my $also ( @$optlist ) {
134 4 my ( $module, $args ) = @$also;
135 4 ▶ $module->import::into( $caller, @{ $args // [] } );
Condition100%2/2
$args // []
l!l
22
MC/DC100%1/1
$args // []
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
136 }
137 2 ▶ goto $next if $next;
Branch: 1 branch
BranchTrueFalseTotal
if $next 1 1 2
138 2 };
139 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
140 2 *$method_name = set_subname $method_name => $method_code;
141 }
142  
143 sub setup_enums_for {
144 2 ▶ my ( $me, $into, $setup ) = @_;
Subroutine setup_enums_for: called CC=3 SCAR=11.0
Pod undocumented
145
146 2 require Type::Tiny::Enum;
147 2 my $reg = Type::Registry->for_class( $into );
148 2 $me->_ensure_isa_type_library( $into );
149
150 2 ▶ my %tags = %{ assert_HashRef $setup->{enum} // {} };
Condition50%1/2
$setup->{"enum"} // {}
l!l
20
MC/DC0%0/1
$setup->{"enum"} // {}
$setup->{"enum"}
Truth table50%1/2
A
A= $setup->{"enum"}
Aresult
11
00
151 2 for my $tag_name ( keys %tags ) {
152 2 my $values = $tags{$tag_name};
153 2 $tag_name =~ s/^[-:]//;
154 2 my $type_name = $tag_name;
155 2 $tag_name = lc $tag_name;
156
157 2 Type::Tiny::Enum->import( { into => $into }, $type_name, $values );
158 2 $into->add_type( $reg->lookup( $type_name ) );
159 }
160
161 2 return;
162 }
163  
164 sub setup_classes_for {
165 1 ▶ my ( $me, $into, $setup ) = @_;
Subroutine setup_classes_for: called CC=1 SCAR=0.0
Pod undocumented
166 1 require Type::Tiny::Class;
167 1 $me->_setup_classes_or_roles_for( $into, $setup, 'class', 'Type::Tiny::Class' );
168 }
169  
170 sub setup_roles_for {
171 1 ▶ my ( $me, $into, $setup ) = @_;
Subroutine setup_roles_for: called CC=1 SCAR=0.0
Pod undocumented
172 1 require Type::Tiny::Role;
173 1 $me->_setup_classes_or_roles_for( $into, $setup, 'role', 'Type::Tiny::Role' );
174 }
175  
176 sub _setup_classes_or_roles_for {
177 2 ▶ my ( $me, $into, $setup, $kind, $tt_class ) = @_;
Subroutine _setup_classes_or_roles_for: called CC=6 SCAR=18.3
178
179 2 my $reg = Type::Registry->for_class( $into );
180 2 $me->_ensure_isa_type_library( $into );
181
182 2 my $optlist = mkopt( $setup->{$kind} );
183 2 for my $dfn ( @$optlist ) {
184 2 ▶ ( my $pkg_name = ( $dfn->[1] //= {} )->{$kind} // $dfn->[0] );
Condition60%3/5
+($dfn->[1] //= {})->{$kind} // $dfn->[0]
l!l&&r!l&&!r
020
$dfn->[1] //= {}
l!l
11
MC/DC0%0/2
+($dfn->[1] //= {})->{$kind} // $dfn->[0]
+($dfn->[1] //= {})->{$kind} $dfn->[0]
MC/DC100%1/1
$dfn->[1] //= {}
$dfn->[1]
Truth table33%1/3
A // B
A= +($dfn->[1] //= {})->{$kind}B= $dfn->[0]
ABresult
1X1
011
000
Truth table100%2/2
A
A= $dfn->[1]
Aresult
11
00
185 2 ▶ ( my $type_name = ( $dfn->[1] //= {} )->{name} // $dfn->[0] ) =~ s/:://g;
Condition60%3/5
+($dfn->[1] //= {})->{"name"} // $dfn->[0]
l!l&&r!l&&!r
110
$dfn->[1] //= {}
l!l
20
MC/DC0%0/2
+($dfn->[1] //= {})->{"name"} // $dfn->[0]
+($dfn->[1] //= {})->{"name"} $dfn->[0]
MC/DC0%0/1
$dfn->[1] //= {}
$dfn->[1]
Truth table66%2/3
A // B
A= +($dfn->[1] //= {})->{"name"}B= $dfn->[0]
ABresult
1X1
011
000
Truth table50%1/2
A
A= $dfn->[1]
Aresult
11
00
186 2 $tt_class->import( { into => $into }, @$dfn );
187 2 $into->add_type( $reg->lookup( $type_name ) );
188 2 eval { require_module( $pkg_name ) };
189 }
190
191 2 return;
192 }
193  
194 sub setup_ducks_for {
195 1 ▶ my ( $me, $into, $setup ) = @_;
Subroutine setup_ducks_for: called CC=3 SCAR=11.0
Pod undocumented
196
197 1 require Type::Tiny::Duck;
198 1 my $reg = Type::Registry->for_class( $into );
199 1 $me->_ensure_isa_type_library( $into );
200
201 1 ▶ my %types = %{ assert_HashRef $setup->{duck} // {} };
Condition50%1/2
$setup->{"duck"} // {}
l!l
10
MC/DC0%0/1
$setup->{"duck"} // {}
$setup->{"duck"}
Truth table50%1/2
A
A= $setup->{"duck"}
Aresult
11
00
202 1 for my $type_name ( keys %types ) {
203 1 my $values = $types{$type_name};
204 1 Type::Tiny::Duck->import( { into => $into }, $type_name, $values );
205 1 $into->add_type( $reg->lookup( $type_name ) );
206 }
207
208 1 return;
209 }
210  
211 sub setup_types_for {
212 2 ▶ my ( $me, $into, $setup ) = @_;
Subroutine setup_types_for: called CC=5 SCAR=16.1
Pod undocumented
213
214 2 my $reg = Type::Registry->for_class( $into );
215 2 $me->_ensure_isa_type_library( $into );
216
217 2 my $optlist = mkopt( $setup->{type} );
218 2 my @extends = ();
219 2 for my $dfn ( @$optlist ) {
220 2 my ( $lib, $list ) = @$dfn;
221 2 eval { require_module( $lib ) };
222 2 ▶ if ( is_ArrayRef $list ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_ArrayRef($list)) { } 1 1 2
223 1 for my $type_name ( @$list ) {
224 1 $into->add_type( $lib->get_type( $type_name ) );
225 }
226 }
227 else {
228 1 push @extends, $lib;
229 }
230 }
231
232 2 ▶ if ( @extends ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@extends) 1 1 2
233 1 require Type::Utils;
234 1 my $wrapper = eval "sub { package $into; &Type::Utils::extends; }";
235 1 $wrapper->( @extends );
236 }
237
238 2 return;
239 }
240  
241 sub _ensure_isa_type_library {
242 7 ▶ my ( $me, $into ) = @_;
Subroutine _ensure_isa_type_library: called CC=5 SCAR=16.3
243 7 ▶ return if $into->isa( 'Type::Library' );
Branch: 1 branch
BranchTrueFalseTotal
if $into->isa("Type::Library") 0 7 7
244 7 my ( $old_isa ) = $me->standard_package_variables( $into );
245 7 my $new_isa = [];
246 7 my $saw_exporter_tiny = 0;
247 7 for my $pkg ( @$old_isa ) {
248 1 ▶ if ( $pkg eq 'Exporter::Tiny' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg eq 'Exporter::Tiny') { } 1 0 1
249 1 push @$new_isa, 'Type::Library';
250 1 $saw_exporter_tiny++;
251 }
252 else {
253 0 push @$new_isa, $pkg;
254 }
255 }
256 7 ▶ push @$new_isa, 'Type::Library' unless $saw_exporter_tiny;
Branch: 1 branch
BranchTrueFalseTotal
unless $saw_exporter_tiny 6 1 7
257 7 @$old_isa = @$new_isa;
258 }
259  
260 sub setup_constants_for {
261 2 ▶ my ( $me, $into, $setup ) = @_;
Subroutine setup_constants_for: called CC=5 SCAR=16.1
Pod undocumented
262
263 2 my ( $into_ISA, undef, undef, $into_EXPORT_TAGS ) =
264 $me->standard_package_variables( $into );
265  
266 2 ▶ my %tags = %{ assert_HashRef $setup->{const} // {} };
Condition50%1/2
$setup->{"const"} // {}
l!l
20
MC/DC0%0/1
$setup->{"const"} // {}
$setup->{"const"}
Truth table50%1/2
A
A= $setup->{"const"}
Aresult
11
00
267 2 for my $tag_name ( keys %tags ) {
268 3 my %exports = %{ assert_HashRef $tags{$tag_name} };
269 3 $tag_name =~ s/^[-:]//;
270 3 ▶ push @{ $into_EXPORT_TAGS->{$tag_name} //= [] }, sort keys %exports;
Condition50%1/2
$into_EXPORT_TAGS->{$tag_name} //= []
l!l
03
MC/DC0%0/1
$into_EXPORT_TAGS->{$tag_name} //= []
$into_EXPORT_TAGS->{$tag_name}
Truth table50%1/2
A
A= $into_EXPORT_TAGS->{$tag_name}
Aresult
11
00
271 3 ▶ push @{ $into_EXPORT_TAGS->{'constants'} //= [] }, sort keys %exports;
Condition100%2/2
$into_EXPORT_TAGS->{"constants"} //= []
l!l
21
MC/DC100%1/1
$into_EXPORT_TAGS->{"constants"} //= []
$into_EXPORT_TAGS->{"constants"}
Truth table100%2/2
A
A= $into_EXPORT_TAGS->{"constants"}
Aresult
11
00
272 3 $me->make_constant_subs( $into, \%exports );
273 }
274
275 2 return;
276 }
277  
278 sub make_constant_subs {
279 4 ▶ my ( $me, $into, $constants ) = @_;
Subroutine make_constant_subs: called CC=5 SCAR=16.1
Pod undocumented
280
281 4 for my $key ( keys %$constants ) {
282 14 my $value = $constants->{$key};
283 14 my $full_name = "$into\::$key";
284
285 14 my $coderef;
286 14 ▶ if ( is_Ref $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_Ref($value)) { } 2 12 14
287 2 $coderef = eval_closure(
288 source => 'sub () { $value }',
289 environment => { '$value' => \$value },
290 );
291 }
292 else {
293 12 ▶ $coderef = eval sprintf(
Branch: 2 branches
BranchTrueFalseTotal
builtin::is_bool($value) ? : 2 10 12
created_as_number $value ? : 2 8 10
294 'sub () { %s %s }',
295 is_bool( $value ) ? '!!' : ( created_as_number( $value ) ? '0+' : '' ),
296 perlstring( $value ),
297 );
298 }
299
300 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
301 14 *$full_name = set_subname $full_name => $coderef;
302 }
303 }
304  
305 sub finalize_export_variables_for {
306 2 ▶ my ( $me, $into, $setup ) = @_;
Subroutine finalize_export_variables_for: called CC=8 SCAR=20.9
Pod undocumented
307
308 2 my ( $into_ISA, $into_EXPORT, $into_EXPORT_OK, $into_EXPORT_TAGS ) =
309 $me->standard_package_variables( $into );
310
311 2 my %all_exports;
312 2 ▶ for my $list ( $into_EXPORT, $into_EXPORT_OK, values %{ $into_EXPORT_TAGS // {} } ) {
Condition50%1/2
$into_EXPORT_TAGS // {}
l!l
20
MC/DC0%0/1
$into_EXPORT_TAGS // {}
$into_EXPORT_TAGS
Truth table50%1/2
A
A= $into_EXPORT_TAGS
Aresult
11
00
313 16 ▶ is_ArrayRef $list or next;
Branch: 1 branch
BranchTrueFalseTotal
is_ArrayRef($list) or next 0 16 16
314 16 $all_exports{$_}++ for @$list;
315 }
316 2 @{ $into_EXPORT_OK } = sort keys %all_exports;
317
318 2 my %default_exports;
319 2 for my $list ( $into_EXPORT, $into_EXPORT_TAGS->{default} ) {
320 4 ▶ is_ArrayRef $list or next;
Branch: 1 branch
BranchTrueFalseTotal
is_ArrayRef($list) or next 1 3 4
321 3 $default_exports{$_}++ for @$list;
322 }
323 2 @{ $into_EXPORT } = sort keys %default_exports;
324
325 2 return;
326 }
327  
328 3 1;
329  
330 __END__
↑ Summary