blib/lib/Importer/Zim/Unit.pm

filter: Statementstmt 79.3% 23 / 29 Branchbran 16.6% 1 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 1 totaltotal 64.0% 32 / 50 CC 5 SCAR 19.5
CC
5
Cov
63%
export_to
20.0
_export_to
2.0
BEGIN
1.0
CRAP 7.0
↑ Summary Build »
1  
2 package Importer::Zim::Unit;
3 2 $Importer::Zim::Unit::VERSION = '0.5.0';
4 # ABSTRACT: Import functions with compilation unit scope
5  
6 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Devel::Hook ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Sub::Replace ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Importer::Zim::Utils 0.8.0 qw(DEBUG );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub import {
14 1 ▶ require Importer::Zim::Base;
Subroutine import: called CC=1 SCAR=0.0
15 1 Importer::Zim::Base->VERSION('0.12.0');
16 1 goto &Importer::Zim::Base::import_into;
17 }
18  
19 sub export_to {
20 0 ▶ my $t = shift;
Subroutine export_to: not called CC=4 SCAR=30.0
Pod undocumented
21 0 ▶ @_ = %{ $_[0] } if @_ == 1 && ref $_[0] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and ref $_[0] eq "HASH" 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
22 0 ▶ @_ = map { $_ & 1 ? $_[$_] : "${t}::$_[$_]" } 0 .. $#_;
Branch: 1 branch
BranchTrueFalseTotal
$_ & 1 ? : 0 0 0
23 0 goto &_export_to;
24 }
25  
26 sub _export_to {
27 1 ▶ my $old = Sub::Replace::sub_replace(@_);
Subroutine _export_to: called CC=2 SCAR=7.0
28  
29 # Clean it up after compilation
30 Devel::Hook->unshift_UNITCHECK_hook(
31 sub {
32 1 ▶ warn qq{ Restoring @{[map qq{"$_"}, sort keys %$old]}\n}
Subroutine __ANON__: called CC=1 SCAR=0.0
33 if DEBUG;
34 1 Sub::Replace::sub_replace($old);
35 }
36 1 ▶ ) if %$old;
Branch: 1 branch
BranchTrueFalseTotal
if %$old 1 0 1
37 }
38  
39 2 ▶no Importer::Zim::Utils qw(DEBUG );
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 2 1;
42  
43 #pod =encoding utf8
44 #pod
45 #pod =head1 SYNOPSIS
46 #pod
47 #pod use Importer::Zim::Unit 'Scalar::Util' => 'blessed';
48 #pod use Importer::Zim::Unit 'Scalar::Util' =>
49 #pod ( 'blessed' => { -as => 'typeof' } );
50 #pod
51 #pod use Importer::Zim::Unit 'Mango::BSON' => ':bson';
52 #pod
53 #pod use Importer::Zim::Unit 'Foo' => { -version => '3.0' } => 'foo';
54 #pod
55 #pod use Importer::Zim::Unit 'SpaceTime::Machine' => [qw(robot rubber_pig)];
56 #pod
57 #pod =head1 DESCRIPTION
58 #pod
59 #pod "I'm gonna roll around on the floor for a while. KAY?"
60 #pod – GIR
61 #pod
62 #pod This is a backend for L<Importer::Zim> which makes imported
63 #pod symbols available during compilation.
64 #pod
65 #pod Unlike L<Importer::Zim::Lexical>, it works for perls before 5.18.
66 #pod Unlike L<Importer::Zim::Lexical> which plays with lexical subs,
67 #pod this meddles with the symbol tables for a (hopefully short)
68 #pod time interval.
69 #pod
70 #pod =head1 HOW IT WORKS
71 #pod
72 #pod The statement
73 #pod
74 #pod use Importer::Zim::Unit 'Foo' => 'foo';
75 #pod
76 #pod works sort of
77 #pod
78 #pod use Sub::Replace;
79 #pod
80 #pod my $_OLD_SUBS;
81 #pod BEGIN {
82 #pod require Foo;
83 #pod $_OLD_SUBS = Sub::Replace::sub_replace('foo' => \&Foo::foo);
84 #pod }
85 #pod
86 #pod UNITCHECK {
87 #pod Sub::Replace::sub_replace($_OLD_SUBS);
88 #pod }
89 #pod
90 #pod That means:
91 #pod
92 #pod =over 4
93 #pod
94 #pod =item *
95 #pod
96 #pod Imported subroutines are installed into the caller namespace at compile time.
97 #pod
98 #pod =item *
99 #pod
100 #pod Imported subroutines are cleaned up just after the unit which defined
101 #pod them has been compiled.
102 #pod
103 #pod =back
104 #pod
105 #pod See L<< perlsub /BEGIN, UNITCHECK, CHECK, INIT and END >> for
106 #pod the concept of "compilation unit" which is relevant here.
107 #pod
108 #pod See L<Sub::Replace> for a few gotchas about why this is not simply done
109 #pod with Perl statements such as
110 #pod
111 #pod *foo = \&Foo::foo;
112 #pod
113 #pod =head1 DEBUGGING
114 #pod
115 #pod You can set the C<IMPORTER_ZIM_DEBUG> environment variable
116 #pod for get some diagnostics information printed to C<STDERR>.
117 #pod
118 #pod IMPORTER_ZIM_DEBUG=1
119 #pod
120 #pod =head1 SEE ALSO
121 #pod
122 #pod L<Importer::Zim>
123 #pod
124 #pod L<< perlsub /BEGIN, UNITCHECK, CHECK, INIT and END >>
125 #pod
126 #pod L<Importer::Zim::Lexical>
127 #pod
128 #pod L<Importer::Zim::EndOfScope>
129 #pod
130 #pod =cut
131  
132 __END__
↑ Summary Build »