line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BEGIN::Lift; |
2
|
|
|
|
|
|
|
# ABSTRACT: Lift subroutine calls into the BEGIN phase |
3
|
|
|
|
|
|
|
|
4
|
9
|
|
|
9
|
|
434026
|
use strict; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
237
|
|
5
|
9
|
|
|
9
|
|
41
|
use warnings; |
|
9
|
|
|
|
|
28
|
|
|
9
|
|
|
|
|
310
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION; |
8
|
|
|
|
|
|
|
our $AUTHORITY; |
9
|
|
|
|
|
|
|
|
10
|
9
|
|
|
9
|
|
2190
|
use Sub::Name (); |
|
9
|
|
|
|
|
3799
|
|
|
9
|
|
|
|
|
174
|
|
11
|
9
|
|
|
9
|
|
2239
|
use B::CompilerPhase::Hook (); |
|
9
|
|
|
|
|
4280
|
|
|
9
|
|
|
|
|
160
|
|
12
|
|
|
|
|
|
|
|
13
|
9
|
|
|
9
|
|
2432
|
use Devel::CallParser; |
|
9
|
|
|
|
|
15842
|
|
|
9
|
|
|
|
|
407
|
|
14
|
9
|
|
|
9
|
|
52
|
use XSLoader; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
474
|
|
15
|
|
|
|
|
|
|
BEGIN { |
16
|
9
|
|
|
9
|
|
26
|
$VERSION = '0.06'; |
17
|
9
|
|
|
|
|
14
|
$AUTHORITY = 'cpan:STEVAN'; |
18
|
9
|
|
|
|
|
2744
|
XSLoader::load( __PACKAGE__, $VERSION ); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub install { |
22
|
8
|
|
|
8
|
1
|
3613
|
my ($pkg, $method, $handler) = @_; |
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
|
|
|
|
|
433
|
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
|
|
|
9
|
|
57
|
no strict 'refs'; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
1271
|
|
|
8
|
|
|
|
|
17
|
|
38
|
|
|
|
|
|
|
die "Cannot install the lifted keyword ($method) into package ($pkg) when that typeglob (\*${pkg}::${method}) already exists" |
39
|
8
|
100
|
|
|
|
13
|
if exists ${"${pkg}::"}{$method}; |
|
8
|
|
|
|
|
49
|
|
40
|
7
|
|
|
|
|
10
|
*{"${pkg}::${method}"} = $cv; |
|
7
|
|
|
|
|
31
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# give the handler a name so that |
44
|
|
|
|
|
|
|
# it shows up sensibly in stack |
45
|
|
|
|
|
|
|
# traces and the like ... |
46
|
7
|
|
|
|
|
55
|
Sub::Name::subname( "${pkg}::${method}", $handler ); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# install the keyword handler ... |
49
|
|
|
|
|
|
|
BEGIN::Lift::Util::install_keyword_handler( |
50
|
10
|
100
|
|
10
|
|
2594
|
$cv, sub { $handler->( $_[0] ? $_[0]->() : () ) } |
51
|
7
|
|
|
|
|
37
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# clean things up ... |
54
|
|
|
|
|
|
|
B::CompilerPhase::Hook::enqueue_UNITCHECK { |
55
|
9
|
|
|
9
|
|
52
|
no strict 'refs'; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
735
|
|
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
|
|
|
7
|
|
7473
|
delete ${"${pkg}::"}{$method} |
|
7
|
|
|
|
|
2986
|
|
62
|
7
|
|
|
|
|
516
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |