blib/lib/Exporter/Tiny.pm

filter: Statementstmt 96.3% 238 / 247 Branchbran 77.4% 110 / 142 Conditioncond 61.3% 27 / 44 MC/DCmcdc 28.5% 8 / 28 Subroutinesub 91.1% 31 / 34 Podpod 0.0% 0 / 2 totaltotal 83.3% 414 / 497 CC 94 SCAR 24.1
CC
94
Cov
87%
_exporter_install_sub
25.4
unimport
15.2
_exporter_merge_opts
13.5
CRAP 11.1
↑ Summary blib/lib/Exporter/Shiny.pm »
1 package Exporter::Tiny;
2  
3 14 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use warnings; no warnings qw(void once uninitialized numeric redefine);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 14 our $AUTHORITY = 'cpan:TOBYINK';
8 14 our $VERSION = '1.003_002';
9 14 our @EXPORT_OK = qw< mkopt mkopt_hash _croak _carp >;
10  
11 7 ▶sub _croak ($;@) { require Carp; my $fmt = shift; @_ = sprintf($fmt, @_); goto \&Carp::croak }
Subroutine _croak: called CC=1 SCAR=0.0
12 1 ▶sub _carp ($;@) { require Carp; my $fmt = shift; @_ = sprintf($fmt, @_); goto \&Carp::carp }
Subroutine _carp: called CC=1 SCAR=0.0
13  
14 my $_process_optlist = sub
15 {
16 38 ▶ my $class = shift;
Subroutine __ANON__: called CC=7 SCAR=19.5
17 38 my ($global_opts, $opts, $want, $not_want) = @_;
18
19 38 ▶ while (@$opts)
Branch: 1 branch
BranchTrueFalseTotal
if (@$opts) 85 38 123
20 {
21 85 my $opt = shift @{$opts};
22 85 my ($name, $value) = @$opt;
23
24 ($name =~ m{\A\!(/.+/[msixpodual]*)\z}) ?
25 do {
26 1 my @not = $class->_exporter_expand_regexp("$1", $value, $global_opts);
27 1 ▶ ++$not_want->{$_->[0]} for @not;
Branch: 3 branches
BranchTrueFalseTotal
$name =~ /\A\!(.+)\z/ ? : 1 83 84
$name =~ /\A[:-](.+)\z/ ? : 17 66 83
$name =~ m[\A/.+/[msixpodual]*\z] ? : 2 64 66
28 } :
29 ($name =~ m{\A\!(.+)\z}) ?
30 85 ▶ (++$not_want->{$1}) :
Branch: 1 branch
BranchTrueFalseTotal
$name =~ m[\A\!(/.+/[msixpodual]*)\z] ? : 1 84 85
31 ($name =~ m{\A[:-](.+)\z}) ?
32 push(@$opts, $class->_exporter_expand_tag("$1", $value, $global_opts)) :
33 ($name =~ m{\A/.+/[msixpodual]*\z}) ?
34 push(@$opts, $class->_exporter_expand_regexp($name, $value, $global_opts)) :
35 # else ?
36 push(@$want, $opt);
37 }
38 14 };
39  
40 sub import
41 {
42 34 ▶ my $class = shift;
Subroutine import: called CC=8 SCAR=20.8
43 34 ▶ my $global_opts = +{ @_ && ref($_[0]) eq q(HASH) ? %{+shift} : () };
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[0] eq 'HASH' ? : 8 26 34
Condition100%3/3
@_ and ref $_[0] eq "HASH"
!ll&&!rl&&r
3238
MC/DC100%2/2
@_ and ref $_[0] eq "HASH"
@_ ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
44 34 ▶ $global_opts->{into} = caller unless exists $global_opts->{into};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $global_opts->{"into"} 28 6 34
45
46 34 my @want;
47 34 my %not_want; $global_opts->{not} = \%not_want;
48 14 ▶ my @args = do { no strict qw(refs); @_ ? @_ : @{"$class\::EXPORT"} };
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 31 3 34
49 34 my $opts = mkopt(\@args);
50 34 $class->$_process_optlist($global_opts, $opts, \@want, \%not_want);
51
52 34 my $permitted = $class->_exporter_permitted_regexp($global_opts);
53 34 $class->_exporter_validate_opts($global_opts);
54
55 34 for my $wanted (@want)
56 {
57 58 ▶ next if $not_want{$wanted->[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $not_want{$wanted->[0]} 2 56 58
58
59 56 my %symbols = $class->_exporter_expand_sub(@$wanted, $global_opts, $permitted);
60 $class->_exporter_install_sub($_, $wanted->[1], $global_opts, $symbols{$_})
61 53 for keys %symbols;
62 }
63 }
64  
65 sub unimport
66 {
67 4 ▶ my $class = shift;
Subroutine unimport: called CC=13 SCAR=27.2
68 4 ▶ my $global_opts = +{ @_ && ref($_[0]) eq q(HASH) ? %{+shift} : () };
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[0] eq 'HASH' ? : 0 4 4
Condition66%2/3
@_ and ref $_[0] eq "HASH"
!ll&&!rl&&r
220
MC/DC0%0/2
@_ and ref $_[0] eq "HASH"
@_ ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
69 4 ▶ $global_opts->{into} = caller unless exists $global_opts->{into};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $global_opts->{"into"} 4 0 4
70 4 $global_opts->{is_unimport} = 1;
71
72 4 my @want;
73 4 my %not_want; $global_opts->{not} = \%not_want;
74 4 ▶ my @args = do { our %TRACKED; @_ ? @_ : keys(%{$TRACKED{$class}{$global_opts->{into}}}) };
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 2 4
75 4 my $opts = mkopt(\@args);
76 4 $class->$_process_optlist($global_opts, $opts, \@want, \%not_want);
77
78 4 my $permitted = $class->_exporter_permitted_regexp($global_opts);
79 4 $class->_exporter_validate_unimport_opts($global_opts);
80
81 4 my $expando = $class->can('_exporter_expand_sub');
82 4 ▶ $expando = undef if $expando == \&_exporter_expand_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $expando == \&Exporter::Tiny::_exporter_expand_sub 4 0 4
83
84 4 for my $wanted (@want)
85 {
86 4 ▶ next if $not_want{$wanted->[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $not_want{$wanted->[0]} 0 4 4
87
88 4 ▶ if ($wanted->[1])
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted->[1]) 1 3 4
89 {
90 _carp("Passing options to unimport '%s' makes no sense", $wanted->[0])
91 1 ▶ unless (ref($wanted->[1]) eq 'HASH' and not keys %{$wanted->[1]});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $wanted->[1] eq "HASH" and not keys %{$$wanted[1];} 0 1 1
Condition33%1/3
ref $wanted->[1] eq "HASH" and not keys %{$$wanted[1];}
!ll&&!rl&&r
001
MC/DC0%0/2
ref $wanted->[1] eq "HASH" and not keys %{$$wanted[1];}
ref $wanted->[1] eq "HASH" not keys %{$$wanted[1];}
Truth table33%1/3
A and not(B)
A= ref $wanted->[1] eq "HASH"B= not keys %{$$wanted[1];}
ABresult
0X0
100
111
92 }
93
94 my %symbols = defined($expando)
95 ? $class->$expando(@$wanted, $global_opts, $permitted)
96 4 ▶ : ($wanted->[0] => sub { "dummy" });
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
defined $expando ? : 0 4 4
97 $class->_exporter_uninstall_sub($_, $wanted->[1], $global_opts)
98 4 for keys %symbols;
99 }
100 }
101  
102 # Called once per import/unimport, passed the "global" import options.
103 # Expected to validate the options and carp or croak if there are problems.
104 # Can also take the opportunity to do other stuff if needed.
105 #
106 34 ▶sub _exporter_validate_opts { 1 }
Subroutine _exporter_validate_opts: called CC=1 SCAR=0.0
107 4 ▶sub _exporter_validate_unimport_opts { 1 }
Subroutine _exporter_validate_unimport_opts: called CC=1 SCAR=0.0
108  
109 # Called after expanding a tag or regexp to merge the tag's options with
110 # any sub-specific options.
111 #
112 sub _exporter_merge_opts
113 {
114 18 ▶ my $class = shift;
Subroutine _exporter_merge_opts: called CC=12 SCAR=26.0
115 18 my ($tag_opts, $global_opts, @stuff) = @_;
116
117 18 ▶ $tag_opts = {} unless ref($tag_opts) eq q(HASH);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tag_opts eq "HASH" 14 4 18
118 _croak('Cannot provide an -as option for tags')
119 18 ▶ if exists $tag_opts->{-as} && ref $tag_opts->{-as} ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if exists $tag_opts->{"-as"} and ref $tag_opts->{"-as"} ne "CODE" 0 18 18
Condition33%1/3
exists $tag_opts->{"-as"} and ref $tag_opts->{"-as"} ne "CODE"
!ll&&!rl&&r
1800
MC/DC0%0/2
exists $tag_opts->{"-as"} and ref $tag_opts->{"-as"} ne "CODE"
exists $tag_opts->{"-as"} ref $tag_opts->{"-as"} ne "CODE"
Truth table33%1/3
A and B
A= exists $tag_opts->{"-as"}B= ref $tag_opts->{"-as"} ne "CODE"
ABresult
0X0
100
111
120
121 18 my $optlist = mkopt(\@stuff);
122 18 for my $export (@$optlist)
123 {
124 35 ▶ next if defined($export->[1]) && ref($export->[1]) ne q(HASH);
Branch: 1 branch
BranchTrueFalseTotal
if defined $export->[1] and ref $export->[1] ne "HASH" 0 35 35
Condition66%2/3
defined $export->[1] and ref $export->[1] ne "HASH"
!ll&&!rl&&r
3140
MC/DC0%0/2
defined $export->[1] and ref $export->[1] ne "HASH"
defined $export->[1] ref $export->[1] ne "HASH"
Truth table66%2/3
A and B
A= defined $export->[1]B= ref $export->[1] ne "HASH"
ABresult
0X0
100
111
125
126 35 ▶ my %sub_opts = ( %{ $export->[1] or {} }, %$tag_opts );
Branch: 1 branch
BranchTrueFalseTotal
$export->[1] or {} 31 4 35
127 $sub_opts{-prefix} = sprintf('%s%s', $tag_opts->{-prefix}, $export->[1]{-prefix})
128 35 ▶ if exists($export->[1]{-prefix}) && exists($tag_opts->{-prefix});
Branch: 1 branch
BranchTrueFalseTotal
if exists $export->[1]{"-prefix"} and exists $tag_opts->{"-prefix"} 2 33 35
Condition66%2/3
exists $export->[1]{"-prefix"} and exists $tag_opts->{"-prefix"}
!ll&&!rl&&r
3302
MC/DC50%1/2
exists $export->[1]{"-prefix"} and exists $tag_opts->{"-prefix"}
exists $export->[1]{"-prefix"} exists $tag_opts->{"-prefix"}
Truth table66%2/3
A and B
A= exists $export->[1]{"-prefix"}B= exists $tag_opts->{"-prefix"}
ABresult
0X0
100
111
129 $sub_opts{-suffix} = sprintf('%s%s', $export->[1]{-suffix}, $tag_opts->{-suffix})
130 35 ▶ if exists($export->[1]{-suffix}) && exists($tag_opts->{-suffix});
Branch: 1 branch
BranchTrueFalseTotal
if exists $export->[1]{"-suffix"} and exists $tag_opts->{"-suffix"} 0 35 35
Condition66%2/3
exists $export->[1]{"-suffix"} and exists $tag_opts->{"-suffix"}
!ll&&!rl&&r
3320
MC/DC0%0/2
exists $export->[1]{"-suffix"} and exists $tag_opts->{"-suffix"}
exists $export->[1]{"-suffix"} exists $tag_opts->{"-suffix"}
Truth table66%2/3
A and B
A= exists $export->[1]{"-suffix"}B= exists $tag_opts->{"-suffix"}
ABresult
0X0
100
111
131 35 $export->[1] = \%sub_opts;
132 }
133 18 return @$optlist;
134 }
135  
136 # Given a tag name, looks it up in %EXPORT_TAGS and returns the list of
137 # associated functions. The default implementation magically handles tags
138 # "all" and "default". The default implementation interprets any undefined
139 # tags as being global options.
140 #
141 sub _exporter_expand_tag
142 {
143 14 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
144
145 17 ▶ my $class = shift;
Subroutine _exporter_expand_tag: called CC=6 SCAR=17.9
146 17 my ($name, $value, $globals) = @_;
147 17 my $tags = \%{"$class\::EXPORT_TAGS"};
148
149 return $class->_exporter_merge_opts($value, $globals, $tags->{$name}->($class, @_))
150 17 ▶ if ref($tags->{$name}) eq q(CODE);
Branch: 1 branch
BranchTrueFalseTotal
if ref $tags->{$name} eq "CODE" 0 17 17
151
152 4 return $class->_exporter_merge_opts($value, $globals, @{$tags->{$name}})
153 17 ▶ if exists $tags->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $tags->{$name} 4 13 17
154
155 13 ▶ return $class->_exporter_merge_opts($value, $globals, @{"$class\::EXPORT"}, @{"$class\::EXPORT_OK"})
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "all" 10 3 13
156 if $name eq 'all';
157
158 3 ▶ return $class->_exporter_merge_opts($value, $globals, @{"$class\::EXPORT"})
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "default" 1 2 3
159 if $name eq 'default';
160
161 2 ▶ $globals->{$name} = $value || 1;
Condition100%2/2
$value || 1
l!l
11
MC/DC100%1/1
$value || 1
$value
Truth table100%2/2
A
A= $value
Aresult
11
00
162 2 return;
163 }
164  
165 # Given a regexp-like string, looks it up in @EXPORT_OK and returns the
166 # list of matching functions.
167 #
168 sub _exporter_expand_regexp
169 {
170 14 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
171 3 ▶ our %TRACKED;
Subroutine _exporter_expand_regexp: called CC=2 SCAR=6.9
172
173 3 my $class = shift;
174 3 my ($name, $value, $globals) = @_;
175 3 my $compiled = eval("qr$name");
176
177 my @possible = $globals->{is_unimport}
178 1 ? keys( %{$TRACKED{$class}{$globals->{into}}} )
179 3 ▶ : @{"$class\::EXPORT_OK"};
Branch: 1 branch
BranchTrueFalseTotal
$globals->{'is_unimport'} ? : 1 2 3
180
181 3 $class->_exporter_merge_opts($value, $globals, grep /$compiled/, @possible);
182 }
183  
184 # Helper for _exporter_expand_sub. Returns a regexp matching all subs in
185 # the exporter package which are available for export.
186 #
187 sub _exporter_permitted_regexp
188 {
189 14 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
190 38 ▶ my $class = shift;
Subroutine _exporter_permitted_regexp: called CC=2 SCAR=6.9
191 my $re = join "|", map quotemeta, sort {
192 65 ▶ length($b) <=> length($a) or $a cmp $b
Branch: 1 branch
BranchTrueFalseTotal
length $b <=> length $a or $a cmp $b 36 29 65
193 38 } @{"$class\::EXPORT"}, @{"$class\::EXPORT_OK"};
194 38 qr{^(?:$re)$}ms;
195 }
196  
197 # Given a sub name, returns a hash of subs to install (usually just one sub).
198 # Keys are sub names, values are coderefs.
199 #
200 sub _exporter_expand_sub
201 {
202 56 ▶ my $class = shift;
Subroutine _exporter_expand_sub: called CC=10 SCAR=23.2
203 56 my ($name, $value, $globals, $permitted) = @_;
204 56 ▶ $permitted ||= $class->_exporter_permitted_regexp($globals);
Condition33%1/3
$permitted ||= $class->_exporter_permitted_regexp($globals)
l!l&&r!l&&!r
5600
MC/DC0%0/2
$permitted ||= $class->_exporter_permitted_regexp($globals)
$permitted $class->_exporter_permitted_regexp($globals)
Truth table33%1/3
A ||= B
A= $permittedB= $class->_exporter_permitted_regexp($globals)
ABresult
1X1
011
000
205
206 14 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
207
208 56 my $sigil = "&";
209 56 ▶ if ($name =~ /\A([&\$\%\@\*])(.+)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\A([&\$\%\@\*])(.+)\z/) 15 41 56
210 15 $sigil = $1;
211 15 $name = $2;
212 15 ▶ if ($sigil eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sigil eq "*") 0 15 15
213 0 _croak("Cannot export symbols with a * sigil");
214 }
215 }
216 56 ▶ my $sigilname = $sigil eq '&' ? $name : "$sigil$name";
Branch: 1 branch
BranchTrueFalseTotal
$sigil eq '&' ? : 41 15 56
217
218 56 ▶ if ($sigilname =~ $permitted)
Branch: 1 branch
BranchTrueFalseTotal
if ($sigilname =~ /$permitted/ms) 54 2 56
219 {
220 my $generatorprefix = {
221 '&' => "_generate_",
222 '$' => "_generateScalar_",
223 '@' => "_generateArray_",
224 '%' => "_generateHash_",
225 54 }->{$sigil};
226
227 54 my $generator = $class->can("$generatorprefix$name");
228 54 ▶ return $sigilname => $class->$generator($sigilname, $value, $globals) if $generator;
Branch: 1 branch
BranchTrueFalseTotal
if $generator 24 30 54
229
230 30 my $sub = $class->can($name);
231 30 ▶ return $sigilname => $sub if $sub;
Branch: 1 branch
BranchTrueFalseTotal
if $sub 21 9 30
232
233 # Could do this more cleverly, but this works.
234 9 ▶ if ($sigil ne '&') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sigil ne "&") 8 1 9
235 8 my $evalled = eval "\\${sigil}${class}::${name}";
236 8 ▶ return $sigilname => $evalled if $evalled;
Branch: 1 branch
BranchTrueFalseTotal
if $evalled 8 0 8
237 }
238 }
239
240 3 $class->_exporter_fail(@_);
241 }
242  
243 # Called by _exporter_expand_sub if it is unable to generate a key-value
244 # pair for a sub.
245 #
246 sub _exporter_fail
247 {
248 3 ▶ my $class = shift;
Subroutine _exporter_fail: called CC=2 SCAR=7.0
249 3 my ($name, $value, $globals) = @_;
250 3 ▶ return if $globals->{is_unimport};
Branch: 1 branch
BranchTrueFalseTotal
if $globals->{"is_unimport"} 0 3 3
251 3 _croak("Could not find sub '%s' exported by %s", $name, $class);
252 }
253  
254 # Actually performs the installation of the sub into the target package. This
255 # also handles renaming the sub.
256 #
257 sub _exporter_install_sub
258 {
259 53 ▶ my $class = shift;
Subroutine _exporter_install_sub: called CC=23 SCAR=32.3
260 53 my ($name, $value, $globals, $sym) = @_;
261
262 53 my $into = $globals->{into};
263 53 ▶ my $installer = $globals->{installer} || $globals->{exporter};
Condition33%1/3
$globals->{'installer'} || $globals->{'exporter'}
l!l&&r!l&&!r
0053
MC/DC0%0/2
$globals->{'installer'} || $globals->{'exporter'}
$globals->{'installer'} $globals->{'exporter'}
Truth table33%1/3
A || B
A= $globals->{'installer'}B= $globals->{'exporter'}
ABresult
1X1
011
000
264  
265 53 ▶ if ( $into eq '-lexical' or $globals->{lexical} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($into eq "-lexical" or $globals->{"lexical"}) 2 51 53
Condition66%2/3
$into eq "-lexical" or $globals->{"lexical"}
l!l&&r!l&&!r
0251
MC/DC50%1/2
$into eq "-lexical" or $globals->{"lexical"}
$into eq "-lexical" $globals->{"lexical"}
Truth table66%2/3
A or B
A= $into eq "-lexical"B= $globals->{"lexical"}
ABresult
1X1
011
000
266 2 ▶ $] ge '5.037002'
Branch: 1 branch
BranchTrueFalseTotal
$] ge "5.037002" or &_croak("Lexical export requires Perl 5.37.2 or above") 0 2 2
267 or _croak( 'Lexical export requires Perl 5.37.2 or above' );
268 $installer ||= sub {
269 2 ▶ my ( $sigilname, $sym ) = @{ $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.0
270 14 ▶ no warnings ( $] ge '5.037002' ? 'experimental::builtin' : () );
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$] ge '5.037002' ? : 14 0 14
271 2 builtin::export_lexically( $sigilname, $sym );
272 2 ▶ };
Condition33%1/3
$installer ||= sub { my($sigilname, $sym) = @{$_[1];}; BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x41\x15\x55\x55\x55\x55\x55\x51\x51\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"} builtin::export_lexically($sigilname, $sym); }
l!l&&r!l&&!r
020
MC/DC0%0/2
$installer ||= sub { my($sigilname, $sym) = @{$_[1];}; BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x41\x15\x55\x55\x55\x55\x55\x51\x51\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"} builtin::export_lexically($sigilname, $sym); }
$installer sub { my($sigilname, $sym) = @{$_[1];}; BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x41\x15\x55\x55\x55\x55\x55\x51\x51\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"} builtin::export_lexically($sigilname, $sym); }
Truth table33%1/3
A ||= B
A= $installerB= sub { my($sigilname, $sym) = @{$_[1];}; BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x41\x15\x55\x55\x55\x55\x55\x51\x51\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"} builtin::export_lexically($sigilname, $sym); }
ABresult
1X1
011
000
273 }
274  
275 $name =
276 ref $globals->{as} ? $globals->{as}->($name) :
277 ref $value->{-as} ? $value->{-as}->($name) :
278 exists $value->{-as} ? $value->{-as} :
279 53 ▶ $name;
Branch: 3 branches
BranchTrueFalseTotal
ref $globals->{'as'} ? : 0 53 53
ref $value->{'-as'} ? : 0 53 53
exists $value->{'-as'} ? : 4 49 53
280
281 53 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 53 53
282
283 53 my $sigil = "&";
284 53 ▶ unless (ref($name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $name) 53 0 53
285 53 ▶ if ($name =~ /\A([&\$\%\@\*])(.+)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\A([&\$\%\@\*])(.+)\z/) 14 39 53
286 14 $sigil = $1;
287 14 $name = $2;
288 14 ▶ if ($sigil eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sigil eq "*") 0 14 14
289 0 _croak("Cannot export symbols with a * sigil");
290 }
291 }
292 53 my ($prefix) = grep defined, $value->{-prefix}, $globals->{prefix}, q();
293 53 my ($suffix) = grep defined, $value->{-suffix}, $globals->{suffix}, q();
294 53 $name = "$prefix$name$suffix";
295 }
296
297 53 ▶ my $sigilname = $sigil eq '&' ? $name : "$sigil$name";
Branch: 1 branch
BranchTrueFalseTotal
$sigil eq '&' ? : 39 14 53
298
299 # if ({qw/$ SCALAR @ ARRAY % HASH & CODE/}->{$sigil} ne ref($sym)) {
300 # warn $sym;
301 # warn $sigilname;
302 # _croak("Reference type %s does not match sigil %s", ref($sym), $sigil);
303 # }
304
305 53 ▶ return ($$name = $sym) if ref($name) eq q(SCALAR);
Branch: 1 branch
BranchTrueFalseTotal
if ref $name eq "SCALAR" 0 53 53
306 53 ▶ return ($into->{$sigilname} = $sym) if ref($into) eq q(HASH);
Branch: 1 branch
BranchTrueFalseTotal
if ref $into eq "HASH" 9 44 53
307
308 14 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
309 44 our %TRACKED;
310
311 44 ▶ if (ref($sym) eq 'CODE' and exists &{"$into\::$name"} and \&{"$into\::$name"} != $sym)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sym eq "CODE" and exists &{"${into}::$name";} and \&{"${into}::$name";} != $sym) 4 40 44
Condition100%6/6
ref $sym eq "CODE" and exists &{"${into}::$name";} and \&{"${into}::$name";} != $sym
!ll&&!rl&&r
3914
ref $sym eq "CODE" and exists &{"${into}::$name";}
!ll&&!rl&&r
8315
MC/DC100%3/3
ref $sym eq "CODE" and exists &{"${into}::$name";} and \&{"${into}::$name";} != $sym
ref $sym eq "CODE" exists &{"${into}::$name";} \&{"${into}::$name";} != $sym
Truth table100%4/4
A and B and C
A= ref $sym eq "CODE"B= exists &{"${into}::$name";}C= \&{"${into}::$name";} != $sym
ABCresult
0XX0
10X0
1100
1111
312 {
313 4 my ($level) = grep defined, $value->{-replace}, $globals->{replace}, q(0);
314 my $action = {
315 carp => \&_carp,
316 0 => \&_carp,
317 '' => \&_carp,
318 warn => \&_carp,
319 nonfatal => \&_carp,
320 croak => \&_croak,
321 fatal => \&_croak,
322 die => \&_croak,
323 4 ▶ }->{$level} || sub {};
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
{'carp', \&Exporter::Tiny::_carp, 0, \&Exporter::Tiny::_carp, '', \&Exporter::Tiny::_carp, 'warn', \&Exporter::Tiny::_carp, 'nonfatal', \&Exporter::Tiny::_carp, 'croak', \&Exporter::Tiny::_croak, 'fatal', \&Exporter::Tiny::_croak, 'die', \&Exporter::Tiny::_croak}->{$level} || sub { }
l!l&&r!l&&!r
400
MC/DC0%0/2
{'carp', \&Exporter::Tiny::_carp, 0, \&Exporter::Tiny::_carp, '', \&Exporter::Tiny::_carp, 'warn', \&Exporter::Tiny::_carp, 'nonfatal', \&Exporter::Tiny::_carp, 'croak', \&Exporter::Tiny::_croak, 'fatal', \&Exporter::Tiny::_croak, 'die', \&Exporter::Tiny::_croak}->{$level} || sub { }
{'carp', \&Exporter::Tiny::_carp, 0, \&Exporter::Tiny::_carp, '', \&Exporter::Tiny::_carp, 'warn', \&Exporter::Tiny::_carp, 'nonfatal', \&Exporter::Tiny::_carp, 'croak', \&Exporter::Tiny::_croak, 'fatal', \&Exporter::Tiny::_croak, 'die', \&Exporter::Tiny::_croak}->{$level} sub { }
Truth table33%1/3
A || B
A= {'carp', \&Exporter::Tiny::_carp, 0, \&Exporter::Tiny::_carp, '', \&Exporter::Tiny::_carp, 'warn', \&Exporter::Tiny::_carp, 'nonfatal', \&Exporter::Tiny::_carp, 'croak', \&Exporter::Tiny::_croak, 'fatal', \&Exporter::Tiny::_croak, 'die', \&Exporter::Tiny::_croak}->{$level}B= sub { }
ABresult
1X1
011
000
324
325 # Don't complain about double-installing the same sub. This isn't ideal
326 # because the same named sub might be generated in two different ways.
327 4 ▶ $action = sub {} if $TRACKED{$class}{$into}{$sigilname};
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $TRACKED{$class}{$into}{$sigilname} 1 3 4
328
329 4 ▶ $action->(
Branch: 1 branch
BranchTrueFalseTotal
$action == \&Exporter::Tiny::_croak ? : 2 2 4
330 $action == \&_croak
331 ? "Refusing to overwrite existing sub '%s::%s' with sub '%s' exported by %s"
332 : "Overwriting existing sub '%s::%s' with sub '%s' exported by %s",
333 $into,
334 $name,
335 $_[0],
336 $class,
337 );
338 }
339
340 42 $TRACKED{$class}{$into}{$sigilname} = $sym;
341
342 14 ▶ no warnings qw(prototype);
Subroutine BEGIN: called CC=1 SCAR=0.0
343 $installer
344 ? $installer->($globals, [$sigilname, $sym])
345 42 ▶ : (*{"$into\::$name"} = $sym);
Branch: 1 branch
BranchTrueFalseTotal
$installer ? : 2 40 42
346 }
347  
348 sub _exporter_uninstall_sub
349 {
350 4 ▶ our %TRACKED;
Subroutine _exporter_uninstall_sub: called CC=10 SCAR=23.1
351 4 my $class = shift;
352 4 my ($name, $value, $globals, $sym) = @_;
353 4 my $into = $globals->{into};
354 4 ▶ ref $into and return;
Branch: 1 branch
BranchTrueFalseTotal
ref $into and return 0 4 4
355
356 14 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
357  
358 4 my $sigil = "&";
359 4 ▶ if ($name =~ /\A([&\$\%\@\*])(.+)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\A([&\$\%\@\*])(.+)\z/) 1 3 4
360 1 $sigil = $1;
361 1 $name = $2;
362 1 ▶ if ($sigil eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sigil eq "*") 0 1 1
363 0 _croak("Cannot export symbols with a * sigil");
364 }
365 }
366 4 ▶ my $sigilname = $sigil eq '&' ? $name : "$sigil$name";
Branch: 1 branch
BranchTrueFalseTotal
$sigil eq '&' ? : 3 1 4
367
368 4 ▶ if ($sigil ne '&') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sigil ne "&") 1 3 4
369 1 _croak("Unimporting non-code symbols not supported yet");
370 }
371  
372 # Cowardly refuse to uninstall a sub that differs from the one
373 # we installed!
374 3 my $our_coderef = $TRACKED{$class}{$into}{$name};
375 3 ▶ my $cur_coderef = exists(&{"$into\::$name"}) ? \&{"$into\::$name"} : -1;
Branch: 1 branch
BranchTrueFalseTotal
exists &{"${into}::$name";} ? : 3 0 3
376 3 ▶ return unless $our_coderef == $cur_coderef;
Branch: 1 branch
BranchTrueFalseTotal
unless $our_coderef == $cur_coderef 0 3 3
377
378 3 my $stash = \%{"$into\::"};
379 3 my $old = delete $stash->{$name};
380 3 my $full_name = join('::', $into, $name);
381 3 foreach my $type (qw(SCALAR HASH ARRAY IO)) # everything but the CODE
382 {
383 12 ▶ next unless defined(*{$old}{$type});
Branch: 1 branch
BranchTrueFalseTotal
unless defined *{$old;}{$type} 9 3 12
384 3 *$full_name = *{$old}{$type};
385 }
386
387 3 delete $TRACKED{$class}{$into}{$name};
388 }
389  
390 sub mkopt
391 {
392 56 ▶ my $in = shift or return [];
Subroutine mkopt: called CC=8 SCAR=21.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
my $in = shift() or return [] 0 56 56
393 56 my @out;
394
395 56 ▶ $in = [map(($_ => ref($in->{$_}) ? $in->{$_} : ()), sort keys %$in)]
Branch: 2 branches
BranchTrueFalseTotal
if ref $in eq "HASH" 0 56 56
ref $in->{$_} ? : 0 0 0
396 if ref($in) eq q(HASH);
397
398 56 ▶ for (my $i = 0; $i < @$in; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$in) 86 56 142
399 {
400 86 my $k = $in->[$i];
401 86 my $v;
402
403 86 ▶ ($i == $#$in) ? ($v = undef) :
Branch: 3 branches
BranchTrueFalseTotal
$i == $in->$#* ? : 48 38 86
!defined($$in[$i + 1]) ? : 0 38 38
!ref($$in[$i + 1]) ? : 22 16 38
404 !defined($in->[$i+1]) ? (++$i, ($v = undef)) :
405 !ref($in->[$i+1]) ? ($v = undef) :
406 ($v = $in->[++$i]);
407
408 86 push @out, [ $k => $v ];
409 }
410
411 56 \@out;
412 }
413  
414 sub mkopt_hash
415 {
416 0 ▶ my $in = shift or return;
Subroutine mkopt_hash: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
my $in = shift() or return 0 0 0
417 0 my %out = map +($_->[0] => $_->[1]), @{ mkopt($in) };
418 0 \%out;
419 }
420  
421 14 1;
422  
423 __END__
↑ Summary blib/lib/Exporter/Shiny.pm »