blib/lib/BEGIN/Lift.pm

filter: Statementstmt 100% 43 / 43 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 1 / 1 totaltotal 100% 60 / 60 SCAR 11.0
CC
3
Cov
100%
install
2.0
__ANON__
2.0
__ANON__
1.0
CRAP 3.0
↑ Summary Lift.xs »
1 package BEGIN::Lift;
2 # ABSTRACT: Lift subroutine calls into the BEGIN phase
3  
4 9 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 9 our $VERSION;
8 9 our $AUTHORITY;
9  
10 9 ▶use Sub::Name ();
Subroutine __ANON__: called CC=1 SCAR=0.0
11 9 ▶use B::CompilerPhase::Hook ();
Subroutine __ANON__: called CC=1 SCAR=0.0
12  
13 9 ▶use Devel::CallParser;
Subroutine __ANON__: called CC=1 SCAR=0.0
14 9 ▶use XSLoader;
Subroutine __ANON__: called CC=1 SCAR=0.0
15 BEGIN {
16 9 ▶ $VERSION = '0.06';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 $AUTHORITY = 'cpan:STEVAN';
18 9 XSLoader::load( __PACKAGE__, $VERSION );
19 }
20  
21 sub install {
22 8 ▶ my ($pkg, $method, $handler) = @_;
Subroutine install: called CC=2 SCAR=6.9
Pod documented
23  
24 # need to force a new CV each time here
25 # not entirely sure why, but I assume
26 # that perl was trying to optimize things
27 # which is not what I actually want.
28 8 my $cv = eval 'sub {}';
29  
30 # now we need to install the stub
31 # we just created, but first we need to
32 # verify that we are the only ones using
33 # the typeglob we are installing into.
34 # This makes it easier/safer to delete
35 # the stub before runtime.
36 {
37 9 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 die "Cannot install the lifted keyword ($method) into package ($pkg) when that typeglob (\*${pkg}::${method}) already exists"
39 8 ▶ if exists ${"${pkg}::"}{$method};
Branch: 1 branch
BranchTrueFalseTotal
if exists do { "${pkg}::" }->{$method} 1 7 8
40 7 *{"${pkg}::${method}"} = $cv;
41 }
42  
43 # give the handler a name so that
44 # it shows up sensibly in stack
45 # traces and the like ...
46 7 Sub::Name::subname( "${pkg}::${method}", $handler );
47  
48 # install the keyword handler ...
49 BEGIN::Lift::Util::install_keyword_handler(
50 10 ▶ $cv, sub { $handler->( $_[0] ? $_[0]->() : () ) }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 6 4 10
51 7 );
52  
53 # clean things up ...
54 B::CompilerPhase::Hook::enqueue_UNITCHECK {
55 9 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
56 # NOTE:
57 # this is safe only because we
58 # confirmed above that there was
59 # no other use of this typeglob
60 # and so it is ok to delete
61 7 ▶ delete ${"${pkg}::"}{$method}
Subroutine __ANON__: called CC=1 SCAR=0.0
62 7 };
63 }
64  
65 9 1;
66  
67 __END__
↑ Summary Lift.xs »