line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MOP::Method; |
2
|
|
|
|
|
|
|
# ABSTRACT: A representation of a method |
3
|
|
|
|
|
|
|
|
4
|
33
|
|
|
33
|
|
231094
|
use strict; |
|
33
|
|
|
|
|
100
|
|
|
33
|
|
|
|
|
827
|
|
5
|
33
|
|
|
33
|
|
149
|
use warnings; |
|
33
|
|
|
|
|
61
|
|
|
33
|
|
|
|
|
744
|
|
6
|
|
|
|
|
|
|
|
7
|
33
|
|
|
33
|
|
10640
|
use attributes (); |
|
33
|
|
|
|
|
31316
|
|
|
33
|
|
|
|
|
709
|
|
8
|
33
|
|
|
33
|
|
195
|
use Carp (); |
|
33
|
|
|
|
|
50
|
|
|
33
|
|
|
|
|
505
|
|
9
|
|
|
|
|
|
|
|
10
|
33
|
|
|
33
|
|
1265
|
use UNIVERSAL::Object::Immutable; |
|
33
|
|
|
|
|
6525
|
|
|
33
|
|
|
|
|
610
|
|
11
|
|
|
|
|
|
|
|
12
|
33
|
|
|
33
|
|
8719
|
use MOP::Method::Attribute; |
|
33
|
|
|
|
|
74
|
|
|
33
|
|
|
|
|
1179
|
|
13
|
|
|
|
|
|
|
|
14
|
33
|
|
|
33
|
|
9236
|
use MOP::Internal::Util; |
|
33
|
|
|
|
|
95
|
|
|
33
|
|
|
|
|
1839
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
17
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
18
|
|
|
|
|
|
|
|
19
|
33
|
|
|
33
|
|
14706
|
our @ISA; BEGIN { @ISA = 'UNIVERSAL::Object::Immutable' }; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub BUILDARGS { |
22
|
1031
|
|
|
1031
|
1
|
19909
|
my $class = shift; |
23
|
1031
|
|
|
|
|
1185
|
my %args; |
24
|
|
|
|
|
|
|
|
25
|
1031
|
100
|
|
|
|
1666
|
if ( scalar( @_ ) == 1 ) { |
26
|
2
|
50
|
|
|
|
5
|
if ( ref $_[0] ) { |
27
|
2
|
100
|
|
|
|
8
|
if ( ref $_[0] eq 'CODE' ) { |
|
|
50
|
|
|
|
|
|
28
|
1
|
|
|
|
|
3
|
%args = ( body => $_[0] ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif (ref $_[0] eq 'HASH') { |
31
|
1
|
|
|
|
|
1
|
%args = %{ $_[0] }; |
|
1
|
|
|
|
|
4
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
1029
|
|
|
|
|
2038
|
%args = @_; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Carp::croak('[ARGS] You must specify a method body') |
40
|
1031
|
100
|
|
|
|
1965
|
unless $args{body}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Carp::croak('[ARGS] The body specified must be a CODE reference') |
43
|
1030
|
100
|
|
|
|
2014
|
unless ref $args{body} eq 'CODE'; |
44
|
|
|
|
|
|
|
|
45
|
1029
|
|
|
|
|
3113
|
return \%args; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub CREATE { |
49
|
1029
|
|
|
1029
|
1
|
8671
|
my ($class, $args) = @_; |
50
|
|
|
|
|
|
|
|
51
|
1029
|
|
|
|
|
1317
|
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
|
|
|
|
|
2125
|
return \$body; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub name { |
60
|
544
|
|
|
544
|
1
|
24269
|
my ($self) = @_; |
61
|
544
|
|
|
|
|
770
|
return MOP::Internal::Util::GET_GLOB_NAME( $self->body ) |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub fully_qualified_name { |
65
|
5
|
|
|
5
|
0
|
10
|
my ($self) = @_; |
66
|
5
|
|
|
|
|
11
|
join '::' => $self->origin_stash, $self->name; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub body { |
70
|
2538
|
|
|
2538
|
1
|
10644
|
my ($self) = @_; |
71
|
2538
|
|
|
|
|
4748
|
return $$self; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub is_required { |
75
|
926
|
|
|
926
|
1
|
1217
|
my ($self) = @_; |
76
|
926
|
|
|
|
|
1194
|
MOP::Internal::Util::IS_CV_NULL( $self->body ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub origin_stash { |
80
|
605
|
|
|
605
|
1
|
1134
|
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
|
|
|
|
|
847
|
return MOP::Internal::Util::GET_GLOB_STASH_NAME( $self->body ) |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub was_aliased_from { |
95
|
25
|
|
|
25
|
1
|
62
|
my ($self, @classnames) = @_; |
96
|
|
|
|
|
|
|
|
97
|
25
|
50
|
|
|
|
77
|
Carp::croak('[ARGS] You must specify at least one classname') |
98
|
|
|
|
|
|
|
if scalar( @classnames ) == 0; |
99
|
|
|
|
|
|
|
|
100
|
25
|
|
|
|
|
53
|
my $class = $self->origin_stash; |
101
|
25
|
|
|
|
|
51
|
foreach my $candidate ( @classnames ) { |
102
|
25
|
100
|
|
|
|
111
|
return 1 if $candidate eq $class; |
103
|
|
|
|
|
|
|
} |
104
|
7
|
|
|
|
|
24
|
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
|
|
|
7
|
$to_match //= '.'; |
116
|
2
|
|
|
|
|
5
|
return map MOP::Method::Attribute->new( $_ ), grep /^$to_match/, attributes::get( $self->body ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |