line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MOP::Method; |
2
|
|
|
|
|
|
|
# ABSTRACT: A representation of a method |
3
|
|
|
|
|
|
|
|
4
|
33
|
|
|
33
|
|
314910
|
use strict; |
|
33
|
|
|
|
|
138
|
|
|
33
|
|
|
|
|
2178
|
|
5
|
33
|
|
|
33
|
|
203
|
use warnings; |
|
33
|
|
|
|
|
72
|
|
|
33
|
|
|
|
|
1210
|
|
6
|
|
|
|
|
|
|
|
7
|
33
|
|
|
33
|
|
12806
|
use attributes (); |
|
33
|
|
|
|
|
41105
|
|
|
33
|
|
|
|
|
854
|
|
8
|
33
|
|
|
33
|
|
248
|
use Carp (); |
|
33
|
|
|
|
|
76
|
|
|
33
|
|
|
|
|
759
|
|
9
|
|
|
|
|
|
|
|
10
|
33
|
|
|
33
|
|
1774
|
use UNIVERSAL::Object::Immutable; |
|
33
|
|
|
|
|
8772
|
|
|
33
|
|
|
|
|
1035
|
|
11
|
|
|
|
|
|
|
|
12
|
33
|
|
|
33
|
|
10928
|
use MOP::Method::Attribute; |
|
33
|
|
|
|
|
97
|
|
|
33
|
|
|
|
|
1196
|
|
13
|
|
|
|
|
|
|
|
14
|
33
|
|
|
33
|
|
11227
|
use MOP::Internal::Util; |
|
33
|
|
|
|
|
141
|
|
|
33
|
|
|
|
|
2496
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
17
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
18
|
|
|
|
|
|
|
|
19
|
33
|
|
|
33
|
|
20471
|
our @ISA; BEGIN { @ISA = 'UNIVERSAL::Object::Immutable' }; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub BUILDARGS { |
22
|
1031
|
|
|
1031
|
1
|
29794
|
my $class = shift; |
23
|
1031
|
|
|
|
|
1423
|
my %args; |
24
|
|
|
|
|
|
|
|
25
|
1031
|
100
|
|
|
|
2040
|
if ( scalar( @_ ) == 1 ) { |
26
|
2
|
50
|
|
|
|
11
|
if ( ref $_[0] ) { |
27
|
2
|
100
|
|
|
|
14
|
if ( ref $_[0] eq 'CODE' ) { |
|
|
50
|
|
|
|
|
|
28
|
1
|
|
|
|
|
6
|
%args = ( body => $_[0] ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif (ref $_[0] eq 'HASH') { |
31
|
1
|
|
|
|
|
3
|
%args = %{ $_[0] }; |
|
1
|
|
|
|
|
6
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
1029
|
|
|
|
|
2483
|
%args = @_; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Carp::confess('[ARGS] You must specify a method body') |
40
|
1031
|
100
|
|
|
|
2578
|
unless $args{body}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Carp::confess('[ARGS] The body specified must be a CODE reference') |
43
|
1030
|
100
|
|
|
|
2441
|
unless ref $args{body} eq 'CODE'; |
44
|
|
|
|
|
|
|
|
45
|
1029
|
|
|
|
|
2383
|
return \%args; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub CREATE { |
49
|
1029
|
|
|
1029
|
1
|
10727
|
my ($class, $args) = @_; |
50
|
|
|
|
|
|
|
|
51
|
1029
|
|
|
|
|
1623
|
my $body = $args->{body}; |
52
|
|
|
|
|
|
|
# this will get blessed, so we |
53
|
|
|
|
|
|
|
# do not actually want the CV |
54
|
|
|
|
|
|
|
# to get touched, so we get a |
55
|
|
|
|
|
|
|
# ref of a ref here ... |
56
|
1029
|
|
|
|
|
2623
|
return \$body; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub name { |
60
|
546
|
|
|
546
|
1
|
28445
|
my ($self) = @_; |
61
|
546
|
|
|
|
|
1030
|
return MOP::Internal::Util::GET_GLOB_NAME( $self->body ) |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub fully_qualified_name { |
65
|
5
|
|
|
5
|
0
|
41
|
my ($self) = @_; |
66
|
5
|
|
|
|
|
31
|
join '::' => $self->origin_stash, $self->name; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub body { |
70
|
2540
|
|
|
2540
|
1
|
13767
|
my ($self) = @_; |
71
|
2540
|
|
|
|
|
6165
|
return $$self; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub is_required { |
75
|
926
|
|
|
926
|
1
|
1544
|
my ($self) = @_; |
76
|
926
|
|
|
|
|
1576
|
MOP::Internal::Util::IS_CV_NULL( $self->body ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub origin_stash { |
80
|
605
|
|
|
605
|
1
|
1461
|
my ($self) = @_; |
81
|
|
|
|
|
|
|
# NOTE: |
82
|
|
|
|
|
|
|
# Here we actually want the stash that is |
83
|
|
|
|
|
|
|
# associated with the GV (glob) that the |
84
|
|
|
|
|
|
|
# method body is associated with. This is |
85
|
|
|
|
|
|
|
# sometimes different then the COMP_STASH |
86
|
|
|
|
|
|
|
# meaning the stash it was compiled in. It |
87
|
|
|
|
|
|
|
# seems to vary most with required subs, |
88
|
|
|
|
|
|
|
# which seem to be compiled in main:: even |
89
|
|
|
|
|
|
|
# when I am expecting it not to be. |
90
|
|
|
|
|
|
|
# - SL |
91
|
605
|
|
|
|
|
1087
|
return MOP::Internal::Util::GET_GLOB_STASH_NAME( $self->body ) |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub was_aliased_from { |
95
|
25
|
|
|
25
|
1
|
81
|
my ($self, @classnames) = @_; |
96
|
|
|
|
|
|
|
|
97
|
25
|
50
|
|
|
|
91
|
Carp::confess('[ARGS] You must specify at least one classname') |
98
|
|
|
|
|
|
|
if scalar( @classnames ) == 0; |
99
|
|
|
|
|
|
|
|
100
|
25
|
|
|
|
|
71
|
my $class = $self->origin_stash; |
101
|
25
|
|
|
|
|
71
|
foreach my $candidate ( @classnames ) { |
102
|
25
|
100
|
|
|
|
151
|
return 1 if $candidate eq $class; |
103
|
|
|
|
|
|
|
} |
104
|
7
|
|
|
|
|
37
|
return 0; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub has_code_attributes { |
108
|
0
|
|
|
0
|
1
|
0
|
my ($self, $to_match) = @_; |
109
|
0
|
|
0
|
|
|
0
|
$to_match //= '.'; |
110
|
0
|
|
|
|
|
0
|
return scalar grep /^$to_match/, attributes::get( $self->body ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub get_code_attributes { |
114
|
2
|
|
|
2
|
1
|
6
|
my ($self, $to_match) = @_; |
115
|
2
|
|
50
|
|
|
6
|
$to_match //= '.'; |
116
|
2
|
|
|
|
|
4
|
return map MOP::Method::Attribute->new( $_ ), grep /^$to_match/, attributes::get( $self->body ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |