blib/lib/Importer/Zim/EndOfScope.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 SCAR 18.3
CC
5
Cov
63%
export_to
20.0
_export_to
2.0
BEGIN
1.0
CRAP 6.3
« Build ↑ Summary
1  
2 package Importer::Zim::EndOfScope;
3 2 $Importer::Zim::EndOfScope::VERSION = '0.4.0';
4 # ABSTRACT: Import functions with compilation block scope
5  
6 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use B::Hooks::EndOfScope ();
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 3 ▶ require Importer::Zim::Base;
Subroutine import: called CC=1 SCAR=0.0
15 3 Importer::Zim::Base->VERSION('0.12.0');
16 3 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 3 ▶ my $old = Sub::Replace::sub_replace(@_);
Subroutine _export_to: called CC=2 SCAR=7.0
28  
29 # Clean it up after a scope finished compilation
30 B::Hooks::EndOfScope::on_scope_end(
31 sub {
32 3 ▶ warn qq{ Restoring @{[map qq{"$_"}, sort keys %$old]}\n}
Subroutine __ANON__: called CC=1 SCAR=0.0
33 if DEBUG;
34 3 Sub::Replace::sub_replace($old);
35 }
36 3 ▶ ) if %$old;
Branch: 1 branch
BranchTrueFalseTotal
if %$old 3 0 3
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::EndOfScope 'Scalar::Util' => 'blessed';
48 #pod use Importer::Zim::EndOfScope 'Scalar::Util' =>
49 #pod ( 'blessed' => { -as => 'typeof' } );
50 #pod
51 #pod use Importer::Zim::EndOfScope 'Mango::BSON' => ':bson';
52 #pod
53 #pod use Importer::Zim::EndOfScope 'Foo' => { -version => '3.0' } => 'foo';
54 #pod
55 #pod use Importer::Zim::EndOfScope 'SpaceTime::Machine' => [qw(robot rubber_pig)];
56 #pod
57 #pod =head1 DESCRIPTION
58 #pod
59 #pod "Wait a minute! What planet is this?"
60 #pod – Zim
61 #pod
62 #pod This is a backend for L<Importer::Zim> which makes
63 #pod imported symbols available during the compilation of
64 #pod the surrounding scope.
65 #pod
66 #pod Unlike L<Importer::Zim::Lexical>, it works for perls before 5.18.
67 #pod Unlike L<Importer::Zim::Lexical> which plays with lexical subs,
68 #pod this meddles with the symbol tables for a (hopefully short)
69 #pod time interval. (This time interval should be even shorter
70 #pod than the one that applies to L<Importer::Zim::Unit>.)
71 #pod
72 #pod =head1 HOW IT WORKS
73 #pod
74 #pod The statement
75 #pod
76 #pod use Importer::Zim::EndOfScope 'Foo' => 'foo';
77 #pod
78 #pod works sort of
79 #pod
80 #pod use B::Hooks::EndOfScope;
81 #pod
82 #pod my $_OLD_SUBS;
83 #pod BEGIN {
84 #pod require Foo;
85 #pod $_OLD_SUBS = Sub::Replace::sub_replace('foo' => \&Foo::foo);
86 #pod }
87 #pod
88 #pod on_scope_end {
89 #pod Sub::Replace::sub_replace($_OLD_SUBS);
90 #pod }
91 #pod
92 #pod That means:
93 #pod
94 #pod =over 4
95 #pod
96 #pod =item *
97 #pod
98 #pod Imported subroutines are installed into the caller namespace at compile time.
99 #pod
100 #pod =item *
101 #pod
102 #pod Imported subroutines are cleaned up after perl finished compiling
103 #pod the surrounding scope.
104 #pod
105 #pod =back
106 #pod
107 #pod See L<Sub::Replace> for a few gotchas about why this is not simply done
108 #pod with Perl statements such as
109 #pod
110 #pod *foo = \&Foo::foo;
111 #pod
112 #pod =head1 DEBUGGING
113 #pod
114 #pod You can set the C<IMPORTER_ZIM_DEBUG> environment variable
115 #pod for get some diagnostics information printed to C<STDERR>.
116 #pod
117 #pod IMPORTER_ZIM_DEBUG=1
118 #pod
119 #pod =head1 SEE ALSO
120 #pod
121 #pod L<Importer::Zim>
122 #pod
123 #pod L<B::Hooks::EndOfScope>
124 #pod
125 #pod L<Importer::Zim::Lexical>
126 #pod
127 #pod =cut
128  
129 __END__
« Build ↑ Summary