lib/FindApp/Utils/Package.pm

filter: Statementstmt 86.3% 101 / 117 Branchbran 43.4% 20 / 46 Conditioncond 30.7% 8 / 26 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 89.6% 26 / 29 Podpod 100% 8 / 8 totaltotal 67.0% 163 / 243 CC 58 SCAR 20.3
CC
58
Cov
68%
subs_in
30.0
__ANON__
11.3
sibpackage
11.3
CRAP 7.6
« lib/FindApp/Object/Behavior.pm ↑ Summary blib/lib/FindApp/Object/Class.pm »
1 package FindApp::Utils::Package;
2  
3 6 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use Carp qw(carp cluck confess croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use FindApp::Utils::Assert qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use FindApp::Utils::Debug qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use FindApp::Utils::Syntax qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # Chicken-and-egg scrambles subuse "Object";
13 6 ▶use FindApp::Utils::Package::Object <{UN,}PACKAGE>;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub export_alias ( $$ ) ;
16 sub export_function ( $$ ) ;
17 sub export_ok ;
18 sub sort_packages_lexically ;
19 sub sort_packages_numerically ;
20 sub stash ( _ ) ;
21 sub stashes ;
22 sub subs_in ;
23  
24 #################################################################
25  
26 6 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 our $VERSION = v1.0;
28 6 our @EXPORT = <{,UN}PACKAGE>;
29 6 our @EXPORT_OK = (
30 <{,UN}PACKAGE>,
31 qw(
32 stashes
33 subs_in
34 ),
35 <sort_packages{,_{lex,numer}ically}>,
36 );
37  
38 6 our %EXPORT_TAGS = (
39 all => \@EXPORT_OK,
40 );
41  
42 sub export_ok {
43 60 ▶ push @EXPORT_OK, @_;
Subroutine export_ok: called CC=1 SCAR=0.0
Pod documented
44 }
45  
46 sub export_function($$) {
47 54 ▶ my($name, $code) = @_;
Subroutine export_function: called CC=1 SCAR=0.0
Pod documented
48 54 function($name, $code);
49 54 export_ok($name);
50 }
51  
52 sub export_alias($$) {
53 6 ▶ my($name, $code) = @_;
Subroutine export_alias: called CC=1 SCAR=0.0
Pod documented
54 6 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
55 6 *$name = $code;
56 6 export_ok($name);
57 }
58  
59 sub sort_packages_lexically {
60 0 ▶ wantarray || croak "need list context for sorting";
Subroutine sort_packages_lexically: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray or croak("need list context for sorting") 0 0 0
61 0 map { UNPACKAGE }
62 sort #{ $a cmp $b } # already default
63 0 map { PACKAGE($_) }
64 @_ ;
65 }
66  
67 6 export_alias sort_packages => \&sort_packages_lexically;
68  
69 sub sort_packages_numerically {
70 0 ▶ wantarray || croak "need list context for sorting";
Subroutine sort_packages_numerically: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray or croak("need list context for sorting") 0 0 0
71 0 map { UNPACKAGE }
72 0 sort { $a <=> $b }
73 0 map { PACKAGE($_) }
74 @_;
75 }
76  
77  
78 9 ▶sub stash(_) { PACKAGE(shift)->stash };
Subroutine stash: called CC=1 SCAR=0.0
Pod documented
79  
80 sub stashes {
81 1 ▶ my @stashes = map { stash } @_;
Subroutine stashes: called CC=2 SCAR=7.1
Pod documented
82 1 ▶ return wantarray ? @stashes : $stashes[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
83 };
84  
85 sub subs_in {
86 0 ▶ my %seen;
Subroutine subs_in: not called CC=5 SCAR=34.0
Pod documented
87 0 for my $stash (stashes @_) {
88 0 ▶ while (my($name, $glob) = each %$stash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$stash) 0 0 0
89 ref \$glob eq "GLOB" && # weird things find their way into the stashes
90 *$glob{CODE} &&
91 0 ▶ $seen{$name}++
Branch: 1 branch
BranchTrueFalseTotal
ref \$glob eq "GLOB" and *$glob{"CODE"} and ++$seen{$name} 0 0 0
Condition0%0/2
ref \$glob eq "GLOB" and *$glob{"CODE"}
!ll
00
MC/DC0%0/1
ref \$glob eq "GLOB" and *$glob{"CODE"}
ref \$glob eq "GLOB"
Truth table0%0/2
A
A= ref \$glob eq "GLOB"
Aresult
00
11
92 ## && warn "already saw $name";
93 }
94 }
95 0 return sort keys(%seen);
96 }
97  
98 6 my %prefix_methods = qw(
99 sib super
100 sub self
101 top left
102 );
103  
104 6 ▶while (my($prefix, $SUBMETH) = each %prefix_methods) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %prefix_methods) 18 6 24
105 # BUILD: subpackage, sibpackage, toppackage
106 114 ▶ export_function "${prefix}package" => sub { &ENTER_TRACE;
Subroutine toppackage: called CC=8 SCAR=24.2
Subroutine __ANON__: called CC=8 SCAR=24.2
Subroutine sibpackage: called CC=8 SCAR=24.2
107 114 ▶ wantarray // croak "useless use of ${prefix}package in void context";
Condition22%2/9
wantarray // croak("useless use of ${prefix}package in void context")
l!l
11400
wantarray // croak("useless use of ${prefix}package in void context")
l!l
28400
wantarray // croak("useless use of ${prefix}package in void context")
l!l
000
MC/DC0%0/2
wantarray // croak("useless use of ${prefix}package in void context")
wantarray croak("useless use of ${prefix}package in void context")
MC/DC0%0/2
wantarray // croak("useless use of ${prefix}package in void context")
wantarray croak("useless use of ${prefix}package in void context")
MC/DC0%0/2
wantarray // croak("useless use of ${prefix}package in void context")
wantarray croak("useless use of ${prefix}package in void context")
Truth table33%1/3
A // B
A= wantarrayB= croak("useless use of ${prefix}package in void context")
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= wantarrayB= croak("useless use of ${prefix}package in void context")
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= wantarrayB= croak("useless use of ${prefix}package in void context")
ABresult
1X1
011
000
108 114 ▶ croak "need list context for multiple arguments" if @_ > 1 && !wantarray;
Branch: 3 branches
BranchTrueFalseTotal
if @_ > 1 and not wantarray 0 114 114
if @_ > 1 and not wantarray 0 290 290
if @_ > 1 and not wantarray 0 0 0
Condition66%4/6
@_ > 1 and not wantarray
!ll&&!rl&&r
11220
@_ > 1 and not wantarray
!ll&&!rl&&r
28040
MC/DC0%0/2
@_ > 1 and not wantarray
@_ > 1 not wantarray
MC/DC0%0/2
@_ > 1 and not wantarray
@_ > 1 not wantarray
Truth table66%2/3
A and not(B)
A= @_ > 1B= not wantarray
ABresult
0X0
100
111
Truth table66%2/3
A and not(B)
A= @_ > 1B= not wantarray
ABresult
0X0
100
111
109 114 ▶ croak "need arguments for list context" if @_ == 0 && wantarray;
Branch: 3 branches
BranchTrueFalseTotal
if @_ == 0 and wantarray 0 114 114
if @_ == 0 and wantarray 0 284 284
if @_ == 0 and wantarray 0 6 6
Condition33%2/6
@_ == 0 and wantarray
!ll&&!rl&&r
11400
@_ == 0 and wantarray
!ll&&!rl&&r
28400
MC/DC0%0/2
@_ == 0 and wantarray
@_ == 0 wantarray
MC/DC0%0/2
@_ == 0 and wantarray
@_ == 0 wantarray
Truth table33%1/3
A and B
A= @_ == 0B= wantarray
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= @_ == 0B= wantarray
ABresult
0X0
100
111
110 114 ▶ @_ = ("") unless @_;
Branch: 2 branches
BranchTrueFalseTotal
unless @_ 0 114 114
unless @_ 0 290 290
111 114 my @packages = PACKAGE(caller)->$SUBMETH->add_all_unblessed(@_);
112 114 ▶ return wantarray ? @packages : $packages[0];
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 2 112 114
wantarray ? : 4 280 284
113 18 };
114 # BUILD: subuse, sibuse, topuse
115 6 ▶ export_function "${prefix}use" => sub { &ENTER_TRACE;
Subroutine topuse: called CC=5 SCAR=17.5
116 6 my($pack, @imports) = @_;
117 6 my $caller = PACKAGE(caller);
118 6 my $package = $caller->$SUBMETH->add($pack);
119 6 my $import = "";
120 6 ▶ if (@imports) {
Branch: 1 branch
BranchTrueFalseTotal
if (@imports) 0 6 6
121 0 ▶ $import = (@imports == 1 && !defined $imports[0])
Branch: 1 branch
BranchTrueFalseTotal
@imports == 1 && !defined($imports[0]) ? : 0 0 0
Condition0%0/3
@imports == 1 and not defined $imports[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@imports == 1 and not defined $imports[0]
@imports == 1 not defined $imports[0]
Truth table0%0/3
A and not(B)
A= @imports == 1B= not defined $imports[0]
ABresult
0X0
100
111
122 ? "()" # hack to allow a null import list
123 : "qw(@imports)"
124 }
125 6 ▶ eval qq{ package $caller; use $package $import; 1 } || die;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval " package $caller; use $package $import; 1 " or die 0 6 6
126 18 };
127 }
128  
129 # The with behaviors have to come first so that the
130 # base class doesn't have to know they exist, since
131 # a new one may override something that doesn't know
132 # it's being overridden.
133 6 ▶export_function implements => sub { &ENTER_TRACE;
Subroutine __ANON__: called CC=1 SCAR=0.0
134 6 return @_ => <Class State Behavior>;
135 6 };
136  
137 12 ▶export_function implementation => sub { &ENTER_TRACE;
Subroutine implementation: called CC=2 SCAR=7.1
Subroutine __ANON__: called CC=2 SCAR=7.1
138 12 ▶ wantarray || panic "need list context for implementation";
Branch: 2 branches
BranchTrueFalseTotal
wantarray or panic("need list context for implementation") 0 12 12
wantarray or panic("need list context for implementation") 0 6 6
139 12 PACKAGE(caller)->add_all_unblessed(&implements);
140 6 };
141  
142 19 ▶export_function with => sub { &ENTER_TRACE;
Subroutine with: called CC=3 SCAR=11.4
143 19 ▶ wantarray || panic "need list context for role loading";
Branch: 1 branch
BranchTrueFalseTotal
wantarray or panic("need list context for role loading") 0 19 19
144 19 ▶ @_ || panic "with what?";
Branch: 1 branch
BranchTrueFalseTotal
@_ or panic("with what?") 0 19 19
145 19 PACKAGE("Behavior")->add_all_unblessed(@_);
146 6 };
147  
148 6 1;
149  
150 ################################################################
151  
152 ################################################################
153  
154 =encoding utf8
155  
156 =head1 NAME
157  
158 FindApp::Utils::Package - FIXME
159  
160 =head1 SYNOPSIS
161  
162 use FindApp::Utils::Package;
163  
164 =head1 DESCRIPTION
165  
166 =head2 Public Methods
167  
168 =over
169  
170 =item FIXME
171  
172 =back
173  
174 =head2 Exports
175  
176 =over
177  
178 =item export_alias
179  
180 =item export_function
181  
182 =item export_ok
183  
184 =item implementation
185  
186 =item implements
187  
188 =item sibpackage
189  
190 =item sibuse
191  
192 =item sort_packages
193  
194 =item sort_packages_lexically
195  
196 =item sort_packages_numerically
197  
198 =item stash
199  
200 =item stashes
201  
202 =item subs_in
203  
204 =item subpackage
205  
206 =item subuse
207  
208 =item toppackage
209  
210 =item topuse
211  
212 =item with
213  
214 =back
215  
216 =head1 EXAMPLES
217  
218 =head1 ENVIRONMENT
219  
220 =head1 SEE ALSO
221  
222 =over
223  
224 =item L<FindApp>
225  
226 =back
227  
228 =head1 CAVEATS AND PROVISOS
229  
230 =head1 BUGS AND LIMITATIONS
231  
232 =head1 HISTORY
233  
234 =head1 AUTHOR
235  
236 Tom Christiansen << <tchrist@perl.com> >>
237  
238 =head1 LICENCE AND COPYRIGHT
239  
240 Copyright (c) 2016, Tom Christiansen C<< <tchrist@perl.com> >>.
241 All Rights Reserved.
242  
243 This module is free software; you can redistribute it and/or
244 modify it under the same terms as Perl itself. See L<perlartistic>.
245  
246 =cut
247  
« lib/FindApp/Object/Behavior.pm ↑ Summary blib/lib/FindApp/Object/Class.pm »