lib/FindApp/Behavior/Exporter.pm

filter: Statementstmt 76.9% 80 / 104 Branchbran 21.0% 8 / 38 Conditioncond 21.0% 4 / 19 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 65.5% 19 / 29 Podpod 50.0% 1 / 2 totaltotal 55.3% 113 / 204 CC 29 SCAR 34.4
CC
29
Cov
57%
import
87.9
filter_implicits
56.0
__ANON__
6.0
CRAP 31.2
↑ Summary blib/lib/FindApp/Object/State/Group/Behavior.pm »
1 package FindApp::Behavior::Exporter;
2  
3 ################################################################
4 # Class importer and its helpers.
5 ################################################################
6  
7 6 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use mro "c3";
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 ▶use FindApp::Vars qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use FindApp::Utils qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 6 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 6 use pluskeys qw{
20 ORIGINAL_EXPORTS
21 6 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 14 ▶sub init { &ENTER_TRACE;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
24 14 my($self) = @_;
25 14 $self->maybe::next::method;
26 14 $self->original_exports([]);
27 }
28  
29 4 ▶sub import { &ENTER_TRACE;
Subroutine import: called CC=15 SCAR=44.8
30 4 $_[0]->original_exports(@_);
31 4 my $caller = caller;
32 4 my $self = shift;
33  
34 4 feature->import(":5.10");
35  
36 # Can't operate on @_ itself because
37 # its values are readonly in an import!
38 4 my @ARGS = @_;
39 my $adder = function import_adder => sub {
40 0 ▶ my($which, $dir) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Subroutine import_adder: not called CC=2 SCAR=17.9
41 0 ▶ my $file = shift(@ARGS) || botch_import_missing();
Condition0%0/6
shift @ARGS || &botch_import_missing()
l!l&&r!l&&!r
000
shift @ARGS || &botch_import_missing()
l!l&&r!l&&!r
000
MC/DC0%0/2
shift @ARGS || &botch_import_missing()
shift @ARGS &botch_import_missing()
MC/DC0%0/2
shift @ARGS || &botch_import_missing()
shift @ARGS &botch_import_missing()
Truth table0%0/3
A || B
A= shift @ARGSB= &botch_import_missing()
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= shift @ARGSB= &botch_import_missing()
ABresult
1X1
011
000
42 0 $self->group($dir)->$which->add($file);
43 4 };
44  
45 4 ▶ my $add_dir = join "|", alldir_map { quotemeta lc };
Subroutine __ANON__: called CC=1 SCAR=0.0
46 4 ▶ my $let_dir = join "|", subdir_map { quotemeta uc };
Subroutine __ANON__: called CC=1 SCAR=0.0
47 4 my $finder = "findapp_and_export";
48  
49 4 my(@pre_args, @post_args, @subclasses);
50  
51 SWITCH:
52 4 ▶ while (@ARGS && $ARGS[0] =~ s/^--?//) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGS and $ARGS[0] =~ s/^--?//) 0 4 4
Condition33%1/3
@ARGS and $ARGS[0] =~ s/^--?//
!ll&&!rl&&r
400
MC/DC0%0/2
@ARGS and $ARGS[0] =~ s/^--?//
@ARGS $ARGS[0] =~ s/^--?//
Truth table33%1/3
A and B
A= @ARGSB= $ARGS[0] =~ s/^--?//
ABresult
0X0
100
111
53 0 for (shift @ARGS) {
54 0 ▶ /^($add_dir)$/ && case { $adder->(wanted => $1) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
/^($add_dir)$/ and &case(sub { &$adder("wanted", $1); } ) 0 0 0
55 0 ▶ /^($let_dir)$/ && case { $adder->(allowed => $1) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
/^($let_dir)$/ and &case(sub { &$adder("allowed", $1); } ) 0 0 0
56 0 ▶ /^ debug $/x && case { $self->debugging(1) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
/^ debug $/x and &case(sub { $self->debugging(1); } ) 0 0 0
57 0 ▶ /^ here $/x && case { $self->default_origin("cwd") };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
/^ here $/x and &case(sub { $self->default_origin("cwd"); } ) 0 0 0
58 0 ▶ /^ nofind $/x && case { $finder = "" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
/^ nofind $/x and &case(sub { $finder = ""; } ) 0 0 0
59 0 ▶ /^ noload $/x && case { $finder &&= "findapp" };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
/^ noload $/x and &case(sub { $finder &&= "findapp"; } ) 0 0 0
Condition0%0/2
$finder &&= "findapp"
!ll
00
MC/DC0%0/1
$finder &&= "findapp"
$finder
Truth table0%0/2
A
A= $finder
Aresult
00
11
60 0 ▶ /^ trace (\d+)? $/x && case { $self->tracing($1 || 1) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
/^ trace (\d+)? $/x and &case(sub { $self->tracing($1 || 1); } ) 0 0 0
Condition0%0/2
$1 || 1
l!l
00
MC/DC0%0/1
$1 || 1
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
61 0 ▶ /^ vars $/x && case { push @pre_args, ":vars" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
/^ vars $/x and &case(sub { push @pre_args, ":vars"; } ) 0 0 0
62 # This works, but it's more trouble to maintain than it's worth. It's
63 # for dynamic role loading. I may bring it back if I come up with more
64 # roles that it makes sense to leave optional.
65 # /^ subclass $/x && case { push @pre_args, ":subclass" ;
66 # FindApp::Vars->import(":all");
67 # $self->adopts_children($caller);
68 # };
69 #
70 # # convert the shortcuts into normal classes to load
71 # s/^($classic)$/my::\u$1/;
72 # s/^my// && case {
73 # my $mod = ((length) ? $_ : shift @ARGS)
74 # || botch_import_missing("my");
75 # push @subclasses, $mod;
76 # };
77 #######################################################################
78 0 botch_import_unknown();
79 }
80 }
81  
82 # Classes and files aren't "real" imports:
83 4 @ARGS = filter_implicits($self, @ARGS);
84  
85 { # Don't use self here because subclasses don't have "the right stuff".
86 4 my @import_args = (@pre_args, @ARGS, @post_args);
87 4 __PACKAGE__->export_to_level(1, $caller, @import_args);
88 }
89  
90 # Load our parents and become a (potentially new) subclass of them.
91 4 ▶ $self->adopts_parents(@subclasses) if @subclasses;
Branch: 1 branch
BranchTrueFalseTotal
if @subclasses 0 4 4
92  
93 # Don't run the finder if we're just subclassing: that's their job,
94 # either explicitly or else implicitly when this import method is
95 # in turn run on them.
96 4 ▶ if ($finder && !$caller->isa(__PACKAGE__)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($finder and not $caller->isa(__PACKAGE__)) 4 0 4
Condition33%1/3
$finder and not $caller->isa(__PACKAGE__)
!ll&&!rl&&r
004
MC/DC0%0/2
$finder and not $caller->isa(__PACKAGE__)
$finder not $caller->isa(__PACKAGE__)
Truth table33%1/3
A and not(B)
A= $finderB= not $caller->isa(__PACKAGE__)
ABresult
0X0
100
111
97 4 $self->$finder;
98 }
99  
100 } ## sub import
101  
102 18 ▶sub original_exports { &ENTER_TRACE;
Subroutine original_exports: called CC=5 SCAR=16.2
Pod documented
103 18 my $self = &myself;
104 18 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 18 0 18
105 18 ▶ if (@_ == 1 && grep { ref && reftype eq "ARRAY" } @_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and grep {ref $_ and &reftype($_) eq 'ARRAY';} @_) { } 14 4 18
ref $_ and &reftype($_) eq "ARRAY" 14 4 18
Condition66%2/3
@_ == 1 and grep {ref $_ and &reftype($_) eq "ARRAY";} @_
!ll&&!rl&&r
0414
MC/DC50%1/2
@_ == 1 and grep {ref $_ and &reftype($_) eq "ARRAY";} @_
@_ == 1 grep {ref $_ and &reftype($_) eq "ARRAY";} @_
Truth table66%2/3
A and B
A= @_ == 1B= grep {ref $_ and &reftype($_) eq "ARRAY";} @_
ABresult
0X0
100
111
106 14 $$self{+ORIGINAL_EXPORTS} = shift;
107 } else {
108 4 @{ $$self{+ORIGINAL_EXPORTS} } = @_;
109 }
110 }
111 18 return @{ $$self{+ORIGINAL_EXPORTS} };
112 }
113  
114 6 ▶no namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
115  
116 # Look for things that are either modules with colons
117 # to add to libs wanted or paths with slashes to add to
118 # root wanted.
119 sub filter_implicits {
120 my($self, @input) = @_;
121 my @output;
122 SWITCH:
123 for (@input) {
124 ▶ m| ^ !? : |x && case { push @output, $_ }; # import :tag
Branch: 1 branch
BranchTrueFalseTotal
/ ^ !? : /x and &case(sub { push @output, $_; } ) 0 0 0
125 ▶ m| ^ !? / [^/]+ / $ |x && case { push @output, $_ }; # import /pat/
Branch: 1 branch
BranchTrueFalseTotal
m[ ^ !? / [^/]+ / $ ]x and &case(sub { push @output, $_; } ) 0 0 0
126 ▶ m| ^ / |x && case { $self->origin($_) };
Branch: 1 branch
BranchTrueFalseTotal
m[ ^ / ]x and &case(sub { $self->origin($_); } ) 0 0 0
127 ▶ m| :: |x && case { $self->add_libdirs_wanted($_) };
Branch: 1 branch
BranchTrueFalseTotal
/ :: /x and &case(sub { $self->add_libdirs_wanted($_); } ) 0 0 0
128 ▶ m| [/.-] |x && case { $self->add_rootdir_wanted($_) };
Branch: 1 branch
BranchTrueFalseTotal
m[ [/.-] ]x and &case(sub { $self->add_rootdir_wanted($_); } ) 0 0 0
129 push @output, $_;
130 }
131 return @output;
132 }
133  
134 sub botch_import_pragma($);
135  
136 sub botch_import_missing(_) {
137 my($pragma) = @_;
138 botch_import_pragma("expected argument to '-$pragma' import pragma");
139 }
140  
141 sub botch_import_unknown(_) {
142 my($pragma) = @_;
143 botch_import_pragma("import pragma '-$pragma' is unrecognized");
144 }
145  
146 sub botch_import_pragma($) {
147 my($error) = @_;
148 die __PACKAGE__ . " $error; " . q{valid import pragmas are:
149  
150 -root wanted_file_or_dir_in_root
151  
152 -lib wanted_dir_in_libs
153 -bin wanted_dir_in_bins
154 -man wanted_dir_in_mans
155  
156 -LIB allowed_dir_in_libs
157 -BIN allowed_dir_in_bins
158 -MAN allowed_dir_in_mans
159  
160 -vars (import $Root, @Lib, $Lib, @Bin, $Bin, @Man, $Man)
161 -here (to default to cwd not script dir)
162  
163 -subclass (use this to make your package also a subclass of this class)
164  
165 -git (like -my::Git, so like -my FindApp::Git)
166 -devperl (like -my::Devperl, so like -my FindApp::Devperl)
167  
168 -my name_of_subclass (like -my Other::Class, but -my::Git means -my FindApp::Git)
169  
170 -nofind (don't try to find the approot yet)
171 -noload (find the approot but don't load @INC or environment variables)
172  
173 -debug (enable debugging but not tracing, or by setting $FindApp::Debugging to true)
174  
175 -trace (enable tracing, or by setting $FindApp::Tracing to 1, 2, or 3)
176 -trace1 (same as -trace)
177 -trace2 (enable more tracing, or by setting $FindApp::Tracing to 2)
178 -trace3 (enable still more tracing, or by setting $FindApp::Tracing to 3)
179  
180 };
181 }
182  
183 sub exported_envars() {
184 state $vars = [
185 qw($Root),
186 subdir_map { map { ('$'.$_, '@'.$_) } ucfirst },
187 16 ▶ ];
Subroutine exported_envars: called CC=1 SCAR=0.0
188 16 return @$vars;
189 }
190  
191 sub exporter_vars() {
192 10 ▶ return qw(
Subroutine exporter_vars: called CC=1 SCAR=0.0
193 @CARP_NOT
194 @EXPORT_OK
195 %EXPORT_TAGS
196 );
197 }
198  
199 sub exported_subs {
200 6 ▶ @{$FindApp::Utils::EXPORT_TAGS{all}};
Subroutine exported_subs: called CC=1 SCAR=0.0
201  
202 }
203  
204 6 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
205  
206 6 our %EXPORT_TAGS;
207  
208 6 $EXPORT_TAGS{vars} = [ exported_envars() ];
209 6 $EXPORT_TAGS{subclass_subs} = [ exported_subs() ];
210 $EXPORT_TAGS{subclass_vars} = [ exported_envars(), exporter_vars() ],
211  
212 $EXPORT_TAGS{subclass} = [
213 6 (map { @$_ } @EXPORT_TAGS{ <subclass_{sub,var}s> }),
214 ];
215  
216 6 our @EXPORT_OK = (import => sort map { @$_ } values %EXPORT_TAGS);
217  
218 6 1;
219  
220 =encoding utf8
221  
222 =head1 NAME
223  
224 FindApp::Exporter - FIXME
225  
226 =head1 SYNOPSIS
227  
228 use FindApp::Exporter;
229  
230 =head1 DESCRIPTION
231  
232 =head2 Pluskey Attributes
233  
234 These are always private; use the methods insteads.
235  
236 =over
237  
238 =item ORIGINAL_EXPORTS
239  
240 =back
241  
242 =head2 Public Methods
243  
244 =over
245  
246 =item botch_import_missing
247  
248 =item botch_import_pragma
249  
250 =item botch_import_unknown
251  
252 =item exported_envars
253  
254 =item exporter_vars
255  
256 =item filter_implicits
257  
258 =item import
259  
260 =item import_adder
261  
262 =item original_exports
263  
264 =back
265  
266 =over
267  
268 =item FIXME
269  
270 =back
271  
272 =head1 EXAMPLES
273  
274 =head1 ENVIRONMENT
275  
276 =head1 SEE ALSO
277  
278 =over
279  
280 =item L<FindApp>
281  
282 =back
283  
284 =head1 CAVEATS AND PROVISOS
285  
286 =head1 BUGS AND LIMITATIONS
287  
288 =head1 HISTORY
289  
290 =head1 AUTHOR
291  
292 Tom Christiansen << <tchrist@perl.com> >>
293  
294 =head1 LICENCE AND COPYRIGHT
295  
296 Copyright (c) 2016, Tom Christiansen C<< <tchrist@perl.com> >>.
297 All Rights Reserved.
298  
299 This module is free software; you can redistribute it and/or
300 modify it under the same terms as Perl itself. See L<perlartistic>.
301  
302 =cut
303  
↑ Summary blib/lib/FindApp/Object/State/Group/Behavior.pm »