blib/lib/Importer/Zim.pm

filter: Statementstmt 78.8% 41 / 52 Branchbran 42.8% 6 / 14 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 78.5% 11 / 14 Podpod 33.3% 1 / 3 totaltotal 66.3% 61 / 92 CC 11 SCAR 17.5
CC
11
Cov
68%
_trace_backend
20.0
backend
6.5
BEGIN
2.3
CRAP 5.8
↑ Summary Build »
1  
2 package Importer::Zim;
3 2 $Importer::Zim::VERSION = '0.9.2';
4 # ABSTRACT: Import functions à la Invader Zim
5  
6 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Module::Runtime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Importer::Zim::Utils 0.8.0 qw(DEBUG carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 BEGIN {
14 2 ▶ my $v = $ENV{IMPORTER_ZIM_BACKEND} || '+Lexical,+EndOfScope,+Unit,+Bogus';
Subroutine BEGIN: called CC=2 SCAR=8.1
Condition50%1/2
$ENV{'IMPORTER_ZIM_BACKEND'} || '+Lexical,+EndOfScope,+Unit,+Bogus'
l!l
02
MC/DC0%0/1
$ENV{'IMPORTER_ZIM_BACKEND'} || '+Lexical,+EndOfScope,+Unit,+Bogus'
$ENV{'IMPORTER_ZIM_BACKEND'}
Truth table50%1/2
A
A= $ENV{'IMPORTER_ZIM_BACKEND'}
Aresult
11
00
15 2 ▶ *DEFAULT_BACKEND = sub () {$v};
Subroutine __ANON__: not called CC=1 SCAR=1.2
16 }
17  
18 sub import { # Load +Base if import() is called
19 1 ▶ require Importer::Zim::Base;
Subroutine import: called CC=1 SCAR=0.0
20 1 Importer::Zim::Base->VERSION('0.12.1');
21 2 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 *import = \&_import;
23 1 goto &_import;
24 }
25  
26 sub _import {
27 1 ▶ unshift @_, shift->backend(@_);
Subroutine _import: called CC=1 SCAR=0.0
28 1 goto &Importer::Zim::Base::import_into;
29 }
30  
31 2 my %MIN_VERSION = do {
32 2 my %v = (
33 '+Lexical' => '0.10.0',
34 '+EndOfScope' => '0.5.0',
35 '+Unit' => '0.6.0',
36 '+Bogus' => '0.12.0',
37 );
38 2 ▶ /^\+/ and $v{ backend_class($_) } = $v{$_} for keys %v;
Branch: 1 branch
BranchTrueFalseTotal
/^\+/ and $v{backend_class($_)} = $v{$_} 8 0 8
39 2 %v;
40 };
41  
42 sub backend_class {
43 10 ▶ my $how = shift;
Subroutine backend_class: called CC=2 SCAR=7.2
Pod undocumented
44 10 ▶ return ( $how =~ s/^\+// )
Branch: 1 branch
BranchTrueFalseTotal
$how =~ s/^\+// ? : 10 0 10
45 ? ( __PACKAGE__ . '::' . $how )
46 : $how;
47 }
48  
49 sub backend {
50 my @how = split ',',
51 1 ▶ ( ( ref $_[2] eq 'HASH' ? $_[2]->{-how} : undef ) // DEFAULT_BACKEND );
Subroutine backend: called CC=6 SCAR=18.7
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[2] eq 'HASH' ? : 0 1 1
Condition50%1/2
(ref $_[2] eq "HASH" ? $_[2]{"-how"} : undef) // "+Lexical,+EndOfScope,+Unit,+Bogus"
l!l
01
MC/DC0%0/1
(ref $_[2] eq "HASH" ? $_[2]{"-how"} : undef) // "+Lexical,+EndOfScope,+Unit,+Bogus"
(ref $_[2] eq "HASH" ? $_[2]{"-how"} : undef)
Truth table50%1/2
A
A= (ref $_[2] eq "HASH" ? $_[2]{"-how"} : undef)
Aresult
11
00
52 1 for my $how (@how) {
53 2 my $backend = backend_class($how);
54 my @version
55 2 ▶ = exists $MIN_VERSION{$backend} ? ( $MIN_VERSION{$backend} ) : ();
Branch: 1 branch
BranchTrueFalseTotal
exists $MIN_VERSION{$backend} ? : 2 0 2
56 2 my $mod = eval { &Module::Runtime::use_module( $backend, @version ) };
57 2 _trace_backend( $mod, $backend, @version ) if DEBUG;
58 2 ▶ return $mod if $mod;
Branch: 1 branch
BranchTrueFalseTotal
if $mod 1 1 2
59 }
60 0 croak qq{Can't load any backend};
61 }
62  
63 sub export_to {
64 0 ▶ goto &{ __PACKAGE__->backend->can('export_to') };
Subroutine export_to: not called CC=1 SCAR=6.9
Pod documented
65 }
66  
67 sub _trace_backend {
68 0 ▶ my ( $mod, $backend, $version ) = @_;
Subroutine _trace_backend: not called CC=4 SCAR=30.0
69 0 ▶ my $rv = $version ? " $version+" : '';
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 0 0
70 0 ▶ unless ($mod) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mod) 0 0 0
71 0 carp qq{Failed to load "$backend"$rv backend};
72 0 return;
73 }
74 0 ▶ my $v = $mod->VERSION // 'NA';
Condition0%0/2
$mod->VERSION // "NA"
l!l
00
MC/DC0%0/1
$mod->VERSION // "NA"
$mod->VERSION
Truth table0%0/2
A
A= $mod->VERSION
Aresult
11
00
75 0 carp qq{Loaded "$backend"$rv ($v) backend};
76 }
77  
78 2 ▶no Importer::Zim::Utils qw(DEBUG carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
79  
80 2 1;
81  
82 #pod =encoding utf8
83 #pod
84 #pod =head1 SYNOPSIS
85 #pod
86 #pod use Importer::Zim 'Scalar::Util' => 'blessed';
87 #pod use Importer::Zim 'Scalar::Util' => 'blessed' => { -as => 'typeof' };
88 #pod
89 #pod use Importer::Zim 'Mango::BSON' => ':bson';
90 #pod
91 #pod use Importer::Zim 'Foo' => { -version => '3.0' } => 'foo';
92 #pod
93 #pod use Importer::Zim 'SpaceTime::Machine' => [qw(robot rubber_pig)];
94 #pod
95 #pod =head1 DESCRIPTION
96 #pod
97 #pod "Because, when you create a giant monster of doom,
98 #pod no matter how cute, you have to... you have to... I don't know."
99 #pod – Zim
100 #pod
101 #pod This pragma imports subroutines from other modules in a clean way.
102 #pod "Clean imports" here mean that the import symbols are available
103 #pod only at some scope.
104 #pod
105 #pod L<Importer::Zim> relies on pluggable backends which give a precise
106 #pod meaning to "available at some scope". For example,
107 #pod L<Importer::Zim::Lexical> creates lexical subs that go away
108 #pod as soon the lexical scope ends.
109 #pod
110 #pod By default, L<Importer::Zim> looks at package variables
111 #pod C<@EXPORT>, C<@EXPORT_OK> and C<%EXPORT_TAGS> to decide
112 #pod what are exportable subroutines. It tries its best to implement
113 #pod a behavior akin to L<Exporter> without the corresponding namespace pollution.
114 #pod
115 #pod =head1 BACKENDS
116 #pod
117 #pod L<Importer::Zim> will try the following backends in order
118 #pod until one succeeds to load.
119 #pod
120 #pod =over 4
121 #pod
122 #pod =item *
123 #pod
124 #pod L<Importer::Zim::Lexical> - symbols are imported as lexical subroutines
125 #pod
126 #pod =item *
127 #pod
128 #pod L<Importer::Zim::EndOfScope> - symbols are imported to caller namespace
129 #pod while surrounding scope is compiled
130 #pod
131 #pod =item *
132 #pod
133 #pod L<Importer::Zim::Unit> - symbols are imported to caller namespace
134 #pod while current unit is compiled
135 #pod
136 #pod =back
137 #pod
138 #pod Read also L<Importer::Zim::Cookbook/WHICH BACKEND?>.
139 #pod
140 #pod =head1 METHODS
141 #pod
142 #pod =head2 import
143 #pod
144 #pod Importer::Zim->import($class => @imports);
145 #pod Importer::Zim->import($class => \%opts => @imports);
146 #pod
147 #pod =head1 FUNCTIONS
148 #pod
149 #pod =head2 export_to
150 #pod
151 #pod Importer::Zim::export_to($target, %imports);
152 #pod Importer::Zim::export_to($target, \%imports);
153 #pod
154 #pod =head1 DEBUGGING
155 #pod
156 #pod You can set the C<IMPORTER_ZIM_DEBUG> environment variable
157 #pod for get some diagnostics information printed to C<STDERR>.
158 #pod
159 #pod IMPORTER_ZIM_DEBUG=1
160 #pod
161 #pod =head1 SEE ALSO
162 #pod
163 #pod L<zim>
164 #pod
165 #pod L<Importer::Zim::Cookbook>
166 #pod
167 #pod L<Importer> and L<Lexical::Importer>
168 #pod
169 #pod L<lexically>
170 #pod
171 #pod =cut
172  
173 __END__
↑ Summary Build »