FindApp/Behavior/Exporter.pm

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