blib/lib/Exporter/Tiny.pm

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