line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monkey::Patch::Action; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23243
|
use 5.010001; |
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
5
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.05'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
511
|
use Monkey::Patch::Action::Handle; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
50
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
9
|
use Exporter qw(import); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
430
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(patch_package); |
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => \@EXPORT_OK); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub patch_package { |
16
|
22
|
|
|
22
|
1
|
86352
|
my ($package, $subname, $action, $code, @extra) = @_; |
17
|
|
|
|
|
|
|
|
18
|
22
|
50
|
|
|
|
72
|
die "Please specify action" unless $action; |
19
|
22
|
100
|
|
|
|
67
|
if ($action eq 'delete') { |
20
|
5
|
100
|
|
|
|
23
|
die "code not needed for 'delete' action" if $code; |
21
|
|
|
|
|
|
|
} else { |
22
|
17
|
50
|
|
|
|
47
|
die "Please specify code" unless $code; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
21
|
|
|
|
|
58
|
my $name = "$package\::$subname"; |
26
|
21
|
|
|
|
|
39
|
my $type; |
27
|
21
|
100
|
|
|
|
97
|
if ($action eq 'add') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
28
|
4
|
100
|
|
|
|
36
|
die "Adding $name: must not already exist" if defined(&$name); |
29
|
3
|
|
|
|
|
8
|
$type = 'sub'; |
30
|
|
|
|
|
|
|
} elsif ($action eq 'replace') { |
31
|
2
|
100
|
|
|
|
25
|
die "Replacing $name: must already exist" unless defined(&$name); |
32
|
1
|
|
|
|
|
3
|
$type = 'sub'; |
33
|
|
|
|
|
|
|
} elsif ($action eq 'add_or_replace') { |
34
|
2
|
|
|
|
|
5
|
$type = 'sub'; |
35
|
|
|
|
|
|
|
} elsif ($action eq 'wrap') { |
36
|
8
|
100
|
|
|
|
42
|
die "Wrapping $name: must already exist" unless defined(&$name); |
37
|
7
|
|
|
|
|
13
|
$type = 'wrap'; |
38
|
|
|
|
|
|
|
} elsif ($action eq 'delete') { |
39
|
4
|
|
|
|
|
7
|
$type = 'delete'; |
40
|
|
|
|
|
|
|
} else { |
41
|
1
|
|
|
|
|
11
|
die "Unknown action '$action', please use either ". |
42
|
|
|
|
|
|
|
"wrap/add/replace/add_or_replace/delete"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
17
|
|
|
|
|
116
|
my @caller = caller(0); |
46
|
|
|
|
|
|
|
|
47
|
17
|
|
|
|
|
116
|
Monkey::Patch::Action::Handle->new( |
48
|
|
|
|
|
|
|
package => $package, |
49
|
|
|
|
|
|
|
subname => $subname, |
50
|
|
|
|
|
|
|
extra => \@extra, |
51
|
|
|
|
|
|
|
patcher => \@caller, |
52
|
|
|
|
|
|
|
code => $code, |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
-type => $type, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
# ABSTRACT: Wrap/add/replace/delete subs from other package (with restore) |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |