line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package # this is an example for modify_subroutine()/subroutne_modifier(). |
2
|
|
|
|
|
|
|
Method::Modifiers; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
30735
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
42
|
|
5
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
64
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.64'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
5
|
use Exporter qw(import); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
120
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(before around after); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = (@EXPORT, qw(add_method_modifier)); |
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
14
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
15
|
|
|
|
|
|
|
moose => \@EXPORT, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
686
|
use Data::Util (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
218
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _croak{ |
21
|
0
|
|
|
0
|
|
0
|
require Data::Util::Error; |
22
|
0
|
|
|
|
|
0
|
goto &Data::Util::Error::croak; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub add_method_modifier{ |
26
|
12
|
|
|
12
|
1
|
10
|
my $into = shift; |
27
|
12
|
|
|
|
|
11
|
my $type = shift; |
28
|
12
|
|
|
|
|
7
|
my $modifier = pop; |
29
|
|
|
|
|
|
|
|
30
|
12
|
|
|
|
|
14
|
foreach my $name(@_){ |
31
|
12
|
|
|
|
|
22
|
my $method = Data::Util::get_code_ref($into, $name); |
32
|
|
|
|
|
|
|
|
33
|
12
|
100
|
66
|
|
|
39
|
if(!$method || !Data::Util::subroutine_modifier($method)){ |
34
|
|
|
|
|
|
|
|
35
|
4
|
50
|
|
|
|
5
|
unless($method){ |
36
|
4
|
50
|
|
|
|
44
|
$method = $into->can($name) |
37
|
|
|
|
|
|
|
or _croak(qq{The method '$name' is not found in the inheritance hierarchy for class $into}); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
4
|
|
|
|
|
21
|
$method = Data::Util::modify_subroutine($method, $type => [$modifier]); |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
2
|
|
8
|
no warnings 'redefine'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
276
|
|
43
|
4
|
|
|
|
|
12
|
Data::Util::install_subroutine($into, $name => $method); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else{ # $method exists and is modified |
46
|
8
|
|
|
|
|
22
|
Data::Util::subroutine_modifier($method, $type => $modifier); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
12
|
|
|
|
|
1064
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub before{ |
53
|
4
|
|
|
4
|
1
|
18
|
my $into = caller; |
54
|
4
|
|
|
|
|
10
|
add_method_modifier($into, before => @_); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
sub around{ |
57
|
4
|
|
|
4
|
1
|
17
|
my $into = caller; |
58
|
4
|
|
|
|
|
7
|
add_method_modifier($into, around => @_); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
sub after{ |
61
|
4
|
|
|
4
|
1
|
447
|
my $into = caller; |
62
|
4
|
|
|
|
|
8
|
add_method_modifier($into, after => @_); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
__END__ |