blib/lib/Importer/Zim/Base.pm

filter: Statementstmt 85.9% 92 / 107 Branchbran 72.2% 52 / 72 Conditioncond 51.5% 17 / 33 MC/DCmcdc 11.1% 2 / 18 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 1 totaltotal 71.8% 176 / 245 CC 48 SCAR 24.3
CC
48
Cov
76%
_prepare_args
18.8
_import_opts
12.8
_expand_symbol
12.3
CRAP 11.4
↑ Summary blib/lib/Importer/Zim/Bogus.pm »
1  
2 package Importer::Zim::Base;
3 5 $Importer::Zim::Base::VERSION = '0.12.0';
4 # ABSTRACT: Base module for Importer::Zim backends
5  
6 5 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use Module::Runtime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use Importer::Zim::Utils qw(DEBUG carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub import_into {
13 0 ▶ my $class = shift;
Subroutine import_into: not called CC=2 SCAR=17.9
Pod undocumented
14  
15 0 carp "$class->import(@_)" if DEBUG;
16 0 my @exports = _prepare_args( $class, @_ );
17  
18 0 ▶ if ( $class eq 'Importer::Zim::Lexical' ) { # +Lexical backend
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "Importer::Zim::Lexical") 0 0 0
19  
20 # require Sub::Inject;
21 0 @_ = map { @{$_}{qw(export code)} } @exports;
22 0 goto &Sub::Inject::sub_inject;
23 }
24  
25 0 my $caller = caller;
26 return $class->can('_export_to')->( #
27 0 map { ; "${caller}::$_->{export}" => $_->{code} } @exports
28 );
29  
30 ## Non-optimized code
31 #my $caller = caller;
32 #@_ = $caller, map { @{$_}{qw(export code)} } @exports;
33 #goto &{ $class->can('export_to') };
34 }
35  
36 sub _prepare_args {
37 16 ▶ my $class = shift;
Subroutine _prepare_args: called CC=18 SCAR=29.4
38 16 ▶ my $package = shift
Branch: 1 branch
BranchTrueFalseTotal
my $package = shift() or croak("Usage: use $class MODULE => [%OPTS =>] EXPORTS...\n") 0 16 16
39 or croak qq{Usage: use $class MODULE => [\%OPTS =>] EXPORTS...\n};
40  
41 16 ▶ my $opts = _module_opts( ref $_[0] eq 'HASH' ? shift : {} );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 8 8 16
42 16 ▶ my @version = exists $opts->{-version} ? ( $opts->{-version} ) : ();
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'-version'} ? : 0 16 16
43 16 &Module::Runtime::use_module( $package, @version );
44  
45 16 my $can_export = _can_export($package);
46  
47 16 my ( @exports, %seen );
48 16 ▶ @_ = @{"${package}::EXPORT"} unless @_ || !${"${package}::"}{'EXPORT'};
Branch: 1 branch
BranchTrueFalseTotal
unless @_ or not do { "${package}::" }->{"EXPORT"} 4 12 16
Condition66%2/3
@_ or not do { "${package}::" }->{"EXPORT"}
l!l&&r!l&&!r
1204
MC/DC50%1/2
@_ or not do { "${package}::" }->{"EXPORT"}
@_ not do { "${package}::" }->{"EXPORT"}
Truth table66%2/3
A or not(B)
A= @_B= not do { "${package}::" }->{"EXPORT"}
ABresult
1X1
011
000
49 16 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 166 16 182
50 166 my @symbols = _expand_symbol( $package, shift );
51 166 ▶ my $opts = _import_opts( ref $_[0] eq 'HASH' ? shift : {}, $opts );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 7 159 166
52 exists $opts->{-filter}
53 166 ▶ and @symbols = grep &{ $opts->{-filter} }, @symbols;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{"-filter"} and @symbols = grep(&{$opts->{"-filter"};}, @symbols) 144 22 166
54 166 for my $symbol (@symbols) {
55 croak qq{"$symbol" is not exported by "$package"}
56 89 ▶ if $opts->{-strict} && !$can_export->{$symbol};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"-strict"} and not $can_export->{$symbol} 0 89 89
Condition66%2/3
$opts->{"-strict"} and not $can_export->{$symbol}
!ll&&!rl&&r
2870
MC/DC0%0/2
$opts->{"-strict"} and not $can_export->{$symbol}
$opts->{"-strict"} not $can_export->{$symbol}
Truth table66%2/3
A and not(B)
A= $opts->{"-strict"}B= not $can_export->{$symbol}
ABresult
0X0
100
111
57 89 ▶ croak qq{Can't handle "$symbol"}
Branch: 1 branch
BranchTrueFalseTotal
if $symbol =~ /^[\$\@\%\*]/ 0 89 89
58 if $symbol =~ /^[\$\@\%\*]/;
59 89 my $sub = *{"${package}::${symbol}"}{CODE};
60 89 my $export = do {
61 89 ▶ local $_ = $opts->{-as} // $symbol;
Condition66%2/3
$opts->{"-as"} // $symbol
l!l&&r!l&&!r
6830
MC/DC0%0/2
$opts->{"-as"} // $symbol
$opts->{"-as"} $symbol
Truth table66%2/3
A // B
A= $opts->{"-as"}B= $symbol
ABresult
1X1
011
000
62 89 ▶ exists $opts->{-map} ? $opts->{-map}->() : $_;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'-map'} ? : 8 81 89
63 };
64 89 ▶ croak qq{Can't find "$symbol" in "$package"}
Branch: 1 branch
BranchTrueFalseTotal
unless $sub 0 89 89
65 unless $sub;
66 89 my $seen = $seen{$export}{$sub}++;
67 croak qq{Can't import as "$export" twice}
68 89 ▶ if keys %{ $seen{$export} } > 1;
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$seen{$export};} > 1 0 89 89
69 89 ▶ unless ($seen) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen) 87 2 89
70 87 warn(qq{ Importing "${package}::${symbol}" as "$export"\n})
71 if DEBUG;
72 87 push @exports, { export => $export, code => $sub };
73 }
74 }
75 }
76 16 return @exports;
77 }
78  
79 sub _module_opts {
80 state $IS_MODULE_OPTION
81 16 ▶ = { map { ; "-$_" => 1 } qw(how filter map prefix strict version) };
Subroutine _module_opts: called CC=7 SCAR=20.8
82  
83 16 my %opts = ( -strict => !!1 );
84 16 my $o = $_[0];
85 16 ▶ $opts{-strict} = !!$o->{-strict} if exists $o->{-strict};
Branch: 1 branch
BranchTrueFalseTotal
if exists $o->{"-strict"} 1 15 16
86 16 ▶ exists $o->{-filter} and $opts{-filter} = $o->{-filter};
Branch: 1 branch
BranchTrueFalseTotal
exists $o->{"-filter"} and $opts{"-filter"} = $o->{"-filter"} 4 12 16
87 exists $o->{-map} and $opts{-map} = $o->{-map}
88 16 ▶ or exists $o->{-prefix} and $opts{-map} = sub { $o->{-prefix} . $_ };
Subroutine __ANON__: called CC=1 SCAR=0.9
Branch: 1 branch
BranchTrueFalseTotal
exists $o->{"-map"} and $opts{"-map"} = $o->{"-map"} or exists $o->{"-prefix"} and $opts{"-map"} = sub { $o->{"-prefix"} . $_; } 16 0 16
Condition44%4/9
exists $o->{'-map'} && ($opts{'-map'} = $o->{'-map'}) || exists $o->{'-prefix'} && ($opts{'-map'} = sub { $o->{'-prefix'} . $_; } )
l!l&&r!l&&!r
0160
exists $o->{"-map"} and $opts{"-map"} = $o->{"-map"}
!ll&&!rl&&r
1600
exists $o->{"-prefix"} and $opts{"-map"} = sub { $o->{"-prefix"} . $_; }
!ll&&!rl&&r
1330
MC/DC0%0/4
exists $o->{'-map'} && ($opts{'-map'} = $o->{'-map'}) || exists $o->{'-prefix'} && ($opts{'-map'} = sub { $o->{'-prefix'} . $_; } )
exists $o->{"-map"} $opts{"-map"} = $o->{"-map"} exists $o->{"-prefix"} $opts{"-map"} = sub { $o->{"-prefix"} . $_; }
Truth table0%0/7
A and B || C and D
A= exists $o->{"-map"}B= $opts{"-map"} = $o->{"-map"}C= exists $o->{"-prefix"}D= $opts{"-map"} = sub { $o->{"-prefix"} . $_; }
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
89  
90 16 ▶ if ( my @bad = grep { !$IS_MODULE_OPTION->{$_} } keys %$o ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@bad) = grep({not $IS_MODULE_OPTION->{$_};} keys %$o)) 0 16 16
91 0 carp qq{Ignoring unknown module options (@bad)\n};
92 }
93 16 return \%opts;
94 }
95  
96 # $opts = _import_opts($opts1, $m_opts);
97 sub _import_opts {
98 state $IS_IMPORT_OPTION
99 166 ▶ = { map { ; "-$_" => 1 } qw(as filter map prefix strict) };
Subroutine _import_opts: called CC=11 SCAR=25.5
100  
101 166 my %opts = ( -strict => !!1 );
102 exists $_[1]{-filter}
103 166 ▶ and $opts{-filter} = _expand_filter( $_[1]{-filter} );
Branch: 1 branch
BranchTrueFalseTotal
exists $_[1]{"-filter"} and $opts{"-filter"} = _expand_filter($_[1]{"-filter"}) 144 22 166
104 166 ▶ exists $_[1]{-map} and $opts{-map} = $_[1]{-map};
Branch: 1 branch
BranchTrueFalseTotal
exists $_[1]{"-map"} and $opts{"-map"} = $_[1]{"-map"} 6 160 166
105 166 ▶ exists $_[1]{-strict} and $opts{-strict} = $_[1]{-strict};
Branch: 1 branch
BranchTrueFalseTotal
exists $_[1]{"-strict"} and $opts{"-strict"} = $_[1]{"-strict"} 166 0 166
106 166 my $o = $_[0];
107 166 ▶ $opts{-as} = $o->{-as} if exists $o->{-as};
Branch: 1 branch
BranchTrueFalseTotal
if exists $o->{"-as"} 6 160 166
108 166 ▶ exists $o->{-filter} and $opts{-filter} = _expand_filter( $o->{-filter} );
Branch: 1 branch
BranchTrueFalseTotal
exists $o->{"-filter"} and $opts{"-filter"} = _expand_filter($o->{"-filter"}) 0 166 166
109 exists $o->{-map} and $opts{-map} = $o->{-map}
110 166 ▶ or exists $o->{-prefix} and $opts{-map} = sub { $o->{-prefix} . $_ };
Subroutine __ANON__: called CC=1 SCAR=0.9
Branch: 1 branch
BranchTrueFalseTotal
exists $o->{"-map"} and $opts{"-map"} = $o->{"-map"} or exists $o->{"-prefix"} and $opts{"-map"} = sub { $o->{"-prefix"} . $_; } 166 0 166
Condition44%4/9
exists $o->{'-map'} && ($opts{'-map'} = $o->{'-map'}) || exists $o->{'-prefix'} && ($opts{'-map'} = sub { $o->{'-prefix'} . $_; } )
l!l&&r!l&&!r
01660
exists $o->{"-map"} and $opts{"-map"} = $o->{"-map"}
!ll&&!rl&&r
16600
exists $o->{"-prefix"} and $opts{"-map"} = sub { $o->{"-prefix"} . $_; }
!ll&&!rl&&r
16510
MC/DC0%0/4
exists $o->{'-map'} && ($opts{'-map'} = $o->{'-map'}) || exists $o->{'-prefix'} && ($opts{'-map'} = sub { $o->{'-prefix'} . $_; } )
exists $o->{"-map"} $opts{"-map"} = $o->{"-map"} exists $o->{"-prefix"} $opts{"-map"} = sub { $o->{"-prefix"} . $_; }
Truth table0%0/7
A and B || C and D
A= exists $o->{"-map"}B= $opts{"-map"} = $o->{"-map"}C= exists $o->{"-prefix"}D= $opts{"-map"} = sub { $o->{"-prefix"} . $_; }
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
111 166 ▶ $opts{-strict} = !!$o->{-strict} if exists $o->{-strict};
Branch: 1 branch
BranchTrueFalseTotal
if exists $o->{"-strict"} 1 165 166
112  
113 166 ▶ if ( my @bad = grep { !$IS_IMPORT_OPTION->{$_} } keys %$o ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@bad) = grep({not $IS_IMPORT_OPTION->{$_};} keys %$o)) 0 166 166
114 0 carp qq{Ignoring unknown symbol options (@bad)\n};
115 }
116 166 return \%opts;
117 }
118  
119 sub _expand_filter {
120 144 ▶ my $filter = shift;
Subroutine _expand_filter: called CC=2 SCAR=6.9
121 144 ▶ ref $filter eq 'Regexp' ? sub {/$filter/} : $filter;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
ref $filter eq 'Regexp' ? : 72 72 144
122 }
123  
124 sub _expand_symbol {
125 166 ▶ return $_[1] unless ref $_[1] || $_[1] =~ /^[:&]/;
Subroutine _expand_symbol: called CC=9 SCAR=25.1
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[1] or $_[1] =~ /^[:&]/ 161 5 166
Condition66%2/3
ref $_[1] or $_[1] =~ /^[:&]/
l!l&&r!l&&!r
05161
MC/DC50%1/2
ref $_[1] or $_[1] =~ /^[:&]/
ref $_[1] $_[1] =~ /^[:&]/
Truth table66%2/3
A or B
A= ref $_[1]B= $_[1] =~ /^[:&]/
ABresult
1X1
011
000
126  
127 5 ▶ return map { /^&/ ? substr( $_, 1 ) : $_ } @{ $_[1] } if ref $_[1];
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[1] 0 5 5
/^&/ ? : 0 0 0
128  
129 5 ▶ return substr( $_[1], 1 ) if $_[1] =~ /^&/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] =~ /^&/ 2 3 5
130  
131 3 my ( $package, $tag ) = ( $_[0], substr( $_[1], 1 ) );
132 my $symbols
133 3 ▶ = ${"${package}::"}{'EXPORT_TAGS'} && ${"${package}::EXPORT_TAGS"}{$tag}
Branch: 1 branch
BranchTrueFalseTotal
my $symbols = do { "${package}::" }->{"EXPORT_TAGS"} && do { "${package}::EXPORT_TAGS" }->{$tag} or return $_[1] 0 3 3
Condition33%1/3
do { "${package}::" }->{'EXPORT_TAGS'} && do { "${package}::EXPORT_TAGS" }->{$tag}
!ll&&!rl&&r
003
MC/DC0%0/2
do { "${package}::" }->{'EXPORT_TAGS'} && do { "${package}::EXPORT_TAGS" }->{$tag}
do { "${package}::" }->{'EXPORT_TAGS'} do { "${package}::EXPORT_TAGS" }->{$tag}
Truth table33%1/3
A && B
A= do { "${package}::" }->{'EXPORT_TAGS'}B= do { "${package}::EXPORT_TAGS" }->{$tag}
ABresult
0X0
100
111
134 or return $_[1];
135 3 ▶ return map { /^&/ ? substr( $_, 1 ) : $_ } @$symbols;
Branch: 1 branch
BranchTrueFalseTotal
/^&/ ? : 0 6 6
136 }
137  
138 sub _can_export {
139 16 ▶ my $package = shift;
Subroutine _can_export: called CC=5 SCAR=16.1
140 16 my %exports;
141 16 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
do { "${package}::" }->{'EXPORT'} ? : 4 12 16
142 16 ▶ ( ${"${package}::"}{'EXPORT'} ? @{"${package}::EXPORT"} : () ),
Branch: 1 branch
BranchTrueFalseTotal
do { "${package}::" }->{'EXPORT_OK'} ? : 16 0 16
143 16 ( ${"${package}::"}{'EXPORT_OK'} ? @{"${package}::EXPORT_OK"} : () )
144 )
145 {
146 374 ▶ my $x = /^&/ ? substr( $_, 1 ) : $_;
Branch: 1 branch
BranchTrueFalseTotal
/^&/ ? : 12 362 374
147 374 $exports{$x}++;
148 }
149 16 return \%exports;
150 }
151  
152 5 ▶no Importer::Zim::Utils qw(DEBUG carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
153  
154 5 1;
155  
156 #pod =encoding utf8
157 #pod
158 #pod =head1 DESCRIPTION
159 #pod
160 #pod "The Earth is safe once more, GIR! Now let's go destroy it!"
161 #pod – Zim
162 #pod
163 #pod No public interface.
164 #pod
165 #pod =head1 DEBUGGING
166 #pod
167 #pod You can set the C<IMPORTER_ZIM_DEBUG> environment variable
168 #pod for get some diagnostics information printed to C<STDERR>.
169 #pod
170 #pod IMPORTER_ZIM_DEBUG=1
171 #pod
172 #pod =head1 SEE ALSO
173 #pod
174 #pod L<Importer::Zim>
175 #pod
176 #pod =cut
177  
178 __END__
↑ Summary blib/lib/Importer/Zim/Bogus.pm »