blib/lib/Importer/Zim/Utils.pm

filter: Statementstmt 73.1% 30 / 41 Branchbran 50.0% 3 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 63.6% 7 / 11 Podpod 0.0% 0 / 2 totaltotal 65.0% 41 / 63 SCAR 24.3
CC
9
Cov
69%
_get_exports
5.6
BEGIN
2.5
BEGIN
2.3
CRAP 11.3
« blib/lib/Importer/Zim/Base.pm ↑ Summary blib/lib/Importer/Zim/Bogus.pm »
1  
2 package Importer::Zim::Utils;
3 5 $Importer::Zim::Utils::VERSION = '0.11.0';
4 # ABSTRACT: Utilities for Importer::Zim backends
5  
6 5 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 our @EXPORT_OK = qw(DEBUG carp croak);
9  
10 BEGIN {
11 5 ▶ my $v = $ENV{IMPORTER_ZIM_DEBUG} || 0;
Subroutine BEGIN: called CC=2 SCAR=8.1
Condition50%1/2
$ENV{'IMPORTER_ZIM_DEBUG'} || 0
l!l
05
MC/DC0%0/1
$ENV{'IMPORTER_ZIM_DEBUG'} || 0
$ENV{'IMPORTER_ZIM_DEBUG'}
Truth table50%1/2
A
A= $ENV{'IMPORTER_ZIM_DEBUG'}
Aresult
11
00
12 5 ▶ *DEBUG = sub () {$v};
Subroutine __ANON__: not called CC=1 SCAR=1.2
13 }
14  
15 0 ▶sub carp { require Carp; goto &Carp::carp; }
Subroutine carp: not called CC=1 SCAR=6.9
Pod undocumented
16 0 ▶sub croak { require Carp; goto &Carp::croak; }
Subroutine croak: not called CC=1 SCAR=6.9
Pod undocumented
17  
18 ### import / unimport machinery
19  
20 BEGIN {
21 my $v
22 = $ENV{IMPORTER_ZIM_NO_LEXICAL}
23 5 ▶ ? !1
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine BEGIN: called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'IMPORTER_ZIM_NO_LEXICAL'} ? : 0 5 5
24 : !!eval 'use Sub::Inject 0.2.0 (); 1';
25 5 ▶ *USE_LEXICAL_SUBS = sub () {$v};
Subroutine __ANON__: not called CC=1 SCAR=1.2
26 }
27  
28 sub import {
29 6 ▶ my $exports = shift->_get_exports(@_);
Subroutine import: called CC=2 SCAR=6.9
30  
31 6 if (USE_LEXICAL_SUBS) {
32 @_ = %$exports;
33 goto &Sub::Inject::sub_inject;
34 }
35  
36 6 my $caller = caller;
37 6 *{ $caller . '::' . $_ } = $exports->{$_} for keys %$exports;
38 }
39  
40 sub unimport {
41 6 ▶ my $exports = shift->_get_exports(@_);
Subroutine unimport: called CC=2 SCAR=6.9
42  
43 6 return if USE_LEXICAL_SUBS;
44  
45 6 my $caller = caller;
46 6 delete ${"${caller}::"}{$_} for keys %$exports;
47 }
48  
49 # BEWARE! unimport() will nuke the entire glob associated to
50 # an imported subroutine (if USE_LEXICAL_SUBS is false).
51 # So don't use scalar / hash / array variables with the same
52 # names as any of the symbols in @EXPORT_OK in the user modules.
53  
54 sub _get_exports {
55 12 ▶ my $class = shift;
Subroutine _get_exports: called CC=5 SCAR=17.3
56  
57 12 state $EXPORTABLE = { map { $_ => \&{$_} } @EXPORT_OK };
58  
59 12 my ( %exports, @bad );
60 12 for (@_) {
61 34 ▶ push( @bad, $_ ), next unless my $sub = $EXPORTABLE->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless my $sub = $EXPORTABLE->{$_} 0 34 34
62 34 $exports{$_} = $sub;
63 }
64 12 ▶ if (@bad) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bad) 0 12 12
65 0 my @carp;
66 0 push @carp, qq["$_" is not exported by the $class module\n] for @bad;
67 0 croak(qq[@{carp}Can't continue after import errors]);
68 }
69 12 return \%exports;
70 }
71  
72 5 1;
73  
74 #pod =encoding utf8
75 #pod
76 #pod =head1 SYNOPSIS
77 #pod
78 #pod use Importer::Zim::Utils qw(DEBUG carp croak);
79 #pod ...
80 #pod no Importer::Zim::Utils qw(DEBUG carp croak);
81 #pod
82 #pod =head1 DESCRIPTION
83 #pod
84 #pod "For longer than I can remember, I've been looking for someone like you."
85 #pod – Tak
86 #pod
87 #pod No public interface.
88 #pod
89 #pod =head1 SEE ALSO
90 #pod
91 #pod L<Importer::Zim>
92 #pod
93 #pod =cut
94  
95 __END__
« blib/lib/Importer/Zim/Base.pm ↑ Summary blib/lib/Importer/Zim/Bogus.pm »