line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UR::Role::MethodModifier; |
2
|
1
|
|
|
1
|
|
87
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
3
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = "0.46"; # UR $VERSION |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
3
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
61
|
|
8
|
1
|
|
|
1
|
|
4
|
use Sub::Install; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $idx = 1; |
11
|
|
|
|
|
|
|
UR::Object::Type->define( |
12
|
|
|
|
|
|
|
class_name => 'UR::Role::MethodModifier', |
13
|
|
|
|
|
|
|
is_abstract => 1, |
14
|
|
|
|
|
|
|
id_by => [ |
15
|
|
|
|
|
|
|
idx => { is => 'Integer' }, |
16
|
|
|
|
|
|
|
], |
17
|
|
|
|
|
|
|
has => [ |
18
|
|
|
|
|
|
|
name => { is => 'String' }, |
19
|
|
|
|
|
|
|
code => { is => 'CODE' }, |
20
|
|
|
|
|
|
|
role_name => { is => 'String' }, |
21
|
|
|
|
|
|
|
role => { is => 'UR::Role::Prototype', id_by => 'role_name' }, |
22
|
|
|
|
|
|
|
type => { is => 'String' }, |
23
|
|
|
|
|
|
|
], |
24
|
|
|
|
|
|
|
id_generator => sub { $idx++ }, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub type { |
28
|
0
|
|
|
0
|
0
|
0
|
my $class = ref(shift); |
29
|
0
|
|
|
|
|
0
|
Carp::croak("Class $class didn't define sub type"); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub apply_to_package { |
33
|
5
|
|
|
5
|
0
|
9
|
my($self, $package) = @_; |
34
|
|
|
|
|
|
|
|
35
|
5
|
|
|
|
|
23
|
my $original_sub = $self->_get_original_sub($package); |
36
|
|
|
|
|
|
|
|
37
|
5
|
50
|
|
|
|
11
|
unless ($original_sub) { |
38
|
0
|
|
|
|
|
0
|
my $name = $self->name; |
39
|
0
|
|
|
|
|
0
|
Carp::croak(qq(Cannot apply 'before' modifier to $name: Can't locate method "$name" via package $package)); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
5
|
|
|
|
|
20
|
my $wrapper = $self->create_wrapper_sub($original_sub); |
43
|
5
|
|
|
|
|
15
|
my $fully_qualified_sub_name = join('::', $package, $self->name); |
44
|
|
|
|
|
|
|
|
45
|
5
|
|
|
|
|
21
|
$self->_install_sub($package, $wrapper); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _get_original_sub { |
50
|
5
|
|
|
5
|
|
11
|
my($self, $package) = @_; |
51
|
|
|
|
|
|
|
|
52
|
5
|
|
|
|
|
15
|
my $fully_qualified_subname = join('::', $package, $self->name); |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
66
|
1
|
|
228
|
my $subref = do { no strict 'refs'; exists &$fully_qualified_subname and \&$fully_qualified_subname } |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
104
|
|
|
5
|
|
|
|
|
7
|
|
55
|
|
|
|
|
|
|
|| $package->super_can($self->name); |
56
|
|
|
|
|
|
|
|
57
|
5
|
|
|
|
|
12
|
return $subref; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _install_sub { |
61
|
5
|
|
|
5
|
|
10
|
my($self, $package, $code) = @_; |
62
|
5
|
|
|
|
|
13
|
Sub::Install::reinstall_sub({ |
63
|
|
|
|
|
|
|
into => $package, |
64
|
|
|
|
|
|
|
as => $self->name, |
65
|
|
|
|
|
|
|
code => $code, |
66
|
|
|
|
|
|
|
}); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |