FindApp/Utils/Package.pm

filter: Statementstmt 80.8% 93 / 115 Branchbran 50.0% 20 / 40 Conditioncond 36.3% 8 / 22 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 77.4% 24 / 31 Podpod 100% 13 / 13 totaltotal 67.5% 158 / 234 CC 61 SCAR 20.7
CC
61
Cov
68%
subs_in
30.0
subs_in
30.0
__ANON__
9.4
CRAP 7.9
« FindApp/Object/Class.pm ↑ Summary FindApp/Object/Behavior/Devperl.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 60 ▶sub export_ok {
Subroutine export_ok: called CC=1 SCAR=0.0
Pod documented
43 60 ▶ push @EXPORT_OK, @_;
Pod documented
44 }
45  
46 54 ▶sub export_function($$) {
Subroutine export_function: called CC=1 SCAR=0.0
Pod documented
47 54 ▶ my($name, $code) = @_;
Pod documented
48 54 function($name, $code);
49 54 export_ok($name);
50 }
51  
52 6 ▶sub export_alias($$) {
Subroutine export_alias: called CC=1 SCAR=0.0
Pod documented
53 6 ▶ my($name, $code) = @_;
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 0 ▶sub sort_packages_lexically {
Subroutine sort_packages_lexically: not called CC=2 SCAR=17.9
Pod documented
60 0 ▶ wantarray || croak "need list context for sorting";
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 0 ▶sub sort_packages_numerically {
Subroutine sort_packages_numerically: not called CC=2 SCAR=17.9
Pod documented
70 0 ▶ wantarray || croak "need list context for sorting";
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 1 ▶sub stashes {
Subroutine stashes: called CC=2 SCAR=7.1
Pod documented
81 1 my @stashes = map { stash } @_;
82 1 ▶ return wantarray ? @stashes : $stashes[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
83 };
84  
85 0 ▶sub subs_in {
Subroutine subs_in: not called CC=5 SCAR=34.0
Pod documented
86 0 my %seen;
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 171 ▶ export_function "${prefix}package" => sub { &ENTER_TRACE;
Subroutine subpackage: called CC=8 SCAR=22.4
Subroutine toppackage: called CC=8 SCAR=22.4
107 171 ▶ wantarray // croak "useless use of ${prefix}package in void context";
Condition40%2/5
wantarray // croak("useless use of ${prefix}package in void context")
l!l
1710
wantarray // croak("useless use of ${prefix}package in void context")
l!l
22700
MC/DC0%0/1
wantarray // croak("useless use of ${prefix}package in void context")
wantarray
MC/DC0%0/1
wantarray // croak("useless use of ${prefix}package in void context")
wantarray
Truth table50%1/2
A
A= wantarray
Aresult
11
00
Truth table50%1/2
A
A= wantarray
Aresult
11
00
108 171 ▶ croak "need list context for multiple arguments" if @_ > 1 && !wantarray;
Branch: 2 branches
BranchTrueFalseTotal
if @_ > 1 and not wantarray 0 171 171
if @_ > 1 and not wantarray 4 236 240
Condition66%4/6
@_ > 1 and not wantarray
!ll&&!rl&&r
16830
@_ > 1 and not wantarray
!ll&&!rl&&r
22430
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 171 ▶ croak "need arguments for list context" if @_ == 0 && wantarray;
Branch: 2 branches
BranchTrueFalseTotal
if @_ == 0 and wantarray 0 171 171
if @_ == 0 and wantarray 0 227 227
Condition33%2/6
@_ == 0 and wantarray
!ll&&!rl&&r
17100
@_ == 0 and wantarray
!ll&&!rl&&r
22700
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 171 ▶ @_ = ("") unless @_;
Branch: 2 branches
BranchTrueFalseTotal
unless @_ 0 171 171
unless @_ 9 227 236
111 171 my @packages = PACKAGE(caller)->$SUBMETH->add_all_unblessed(@_);
112 171 ▶ return wantarray ? @packages : $packages[0];
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 3 168 171
wantarray ? : 3 224 227
113 18 };
114 # BUILD: subuse, sibuse, topuse
115 0 ▶ export_function "${prefix}use" => sub { &ENTER_TRACE;
Subroutine sibuse: called CC=5 SCAR=18.1
Subroutine subuse: not called CC=5 SCAR=18.1
116 0 my($pack, @imports) = @_;
117 9 my $caller = PACKAGE(caller);
118 9 my $package = $caller->$SUBMETH->add($pack);
119 9 my $import = "";
120 9 ▶ if (@imports) {
Branch: 1 branch
BranchTrueFalseTotal
if (@imports) 0 9 9
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 9 0 9
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 12 ▶export_function implements => sub { &ENTER_TRACE;
Subroutine implements: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
134 0 return @_ => <Class State Behavior>;
135 6 };
136  
137 8 ▶export_function implementation => sub { &ENTER_TRACE;
Subroutine implementation: called CC=2 SCAR=7.1
Subroutine __ANON__: not called CC=2 SCAR=7.1
138 8 ▶ wantarray || panic "need list context for implementation";
Branch: 1 branch
BranchTrueFalseTotal
wantarray or panic("need list context for implementation") 8 0 8
139 8 PACKAGE(caller)->add_all_unblessed(&implements);
140 6 };
141  
142 0 ▶export_function with => sub { &ENTER_TRACE;
Subroutine __ANON__: called CC=3 SCAR=14.2
Subroutine with: not called CC=3 SCAR=14.2
143 0 ▶ wantarray || panic "need list context for role loading";
Branch: 1 branch
BranchTrueFalseTotal
wantarray or panic("need list context for role loading") 19 0 19
144 0 ▶ @_ || panic "with what?";
Branch: 1 branch
BranchTrueFalseTotal
@_ or panic("with what?") 19 0 19
145 0 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  
« FindApp/Object/Class.pm ↑ Summary FindApp/Object/Behavior/Devperl.pm »