line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mouse::Meta::Role; |
2
|
282
|
|
|
282
|
|
2456
|
use Mouse::Util qw(:meta); # enables strict and warnings |
|
282
|
|
|
|
|
693
|
|
|
282
|
|
|
|
|
1816
|
|
3
|
|
|
|
|
|
|
|
4
|
282
|
|
|
282
|
|
1968
|
use Mouse::Meta::Module; |
|
282
|
|
|
|
|
3898
|
|
|
282
|
|
|
|
|
208093
|
|
5
|
|
|
|
|
|
|
our @ISA = qw(Mouse::Meta::Module); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub method_metaclass; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub _construct_meta { |
10
|
264
|
|
|
264
|
|
2507
|
my $class = shift; |
11
|
|
|
|
|
|
|
|
12
|
264
|
|
|
|
|
2967
|
my %args = @_; |
13
|
|
|
|
|
|
|
|
14
|
264
|
|
|
|
|
2685
|
$args{methods} = {}; |
15
|
264
|
|
|
|
|
2651
|
$args{attributes} = {}; |
16
|
264
|
|
|
|
|
2503
|
$args{required_methods} = []; |
17
|
264
|
|
|
|
|
2420
|
$args{roles} = []; |
18
|
|
|
|
|
|
|
|
19
|
264
|
|
33
|
|
|
3418
|
my $self = bless \%args, ref($class) || $class; |
20
|
264
|
100
|
|
|
|
2845
|
if($class ne __PACKAGE__){ |
21
|
58
|
|
|
|
|
943
|
$self->meta->_initialize_object($self, \%args); |
22
|
|
|
|
|
|
|
} |
23
|
264
|
|
|
|
|
7279
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub create_anon_role{ |
27
|
68
|
|
|
68
|
0
|
23463
|
my $self = shift; |
28
|
68
|
|
|
|
|
2386
|
return $self->create(undef, @_); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub is_anon_role; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub get_roles; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub calculate_all_roles { |
36
|
12
|
|
|
12
|
0
|
23
|
my $self = shift; |
37
|
12
|
|
|
|
|
18
|
my %seen; |
38
|
14
|
|
|
|
|
91
|
return grep { !$seen{ $_->name }++ } |
39
|
12
|
|
|
|
|
21
|
($self, map { $_->calculate_all_roles } @{ $self->get_roles }); |
|
2
|
|
|
|
|
11
|
|
|
12
|
|
|
|
|
37
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_required_method_list{ |
43
|
162
|
|
|
162
|
0
|
2312
|
return @{ $_[0]->{required_methods} }; |
|
162
|
|
|
|
|
6946
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub add_required_methods { |
47
|
180
|
|
|
180
|
0
|
2585
|
my($self, @methods) = @_; |
48
|
180
|
|
|
|
|
2407
|
my %required = map{ $_ => 1 } @{$self->{required_methods}}; |
|
25
|
|
|
|
|
107
|
|
|
180
|
|
|
|
|
4919
|
|
49
|
180
|
|
100
|
|
|
2622
|
push @{$self->{required_methods}}, grep{ !$required{$_}++ && !$self->has_method($_) } @methods; |
|
180
|
|
|
|
|
4983
|
|
|
71
|
|
|
|
|
449
|
|
50
|
180
|
|
|
|
|
6829
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub requires_method { |
54
|
10
|
|
|
10
|
0
|
658
|
my($self, $name) = @_; |
55
|
10
|
|
|
|
|
24
|
return scalar( grep{ $_ eq $name } @{ $self->{required_methods} } ) != 0; |
|
8
|
|
|
|
|
59
|
|
|
10
|
|
|
|
|
44
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub add_attribute { |
59
|
88
|
|
|
88
|
0
|
869
|
my $self = shift; |
60
|
88
|
|
|
|
|
184
|
my $name = shift; |
61
|
|
|
|
|
|
|
|
62
|
88
|
100
|
|
|
|
489
|
$self->{attributes}->{$name} = (@_ == 1) ? $_[0] : { @_ }; |
63
|
88
|
|
|
|
|
294
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub apply { |
67
|
302
|
|
|
302
|
0
|
3138
|
my $self = shift; |
68
|
302
|
|
|
|
|
3253
|
my $consumer = shift; |
69
|
|
|
|
|
|
|
|
70
|
302
|
|
|
|
|
38339
|
require 'Mouse/Meta/Role/Application.pm'; |
71
|
302
|
|
|
|
|
3952
|
return Mouse::Meta::Role::Application->new(@_)->apply($self, $consumer); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub combine { |
75
|
52
|
|
|
52
|
0
|
823
|
my($self, @role_specs) = @_; |
76
|
|
|
|
|
|
|
|
77
|
52
|
|
|
|
|
11089
|
require 'Mouse/Meta/Role/Composite.pm'; |
78
|
52
|
|
|
|
|
911
|
return Mouse::Meta::Role::Composite->new(roles => \@role_specs); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub add_before_method_modifier; |
82
|
|
|
|
|
|
|
sub add_around_method_modifier; |
83
|
|
|
|
|
|
|
sub add_after_method_modifier; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub get_before_method_modifiers; |
86
|
|
|
|
|
|
|
sub get_around_method_modifiers; |
87
|
|
|
|
|
|
|
sub get_after_method_modifiers; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub add_override_method_modifier{ |
90
|
16
|
|
|
16
|
0
|
47
|
my($self, $method_name, $method) = @_; |
91
|
|
|
|
|
|
|
|
92
|
16
|
100
|
|
|
|
73
|
if($self->has_method($method_name)){ |
93
|
|
|
|
|
|
|
# This error happens in the override keyword or during role composition, |
94
|
|
|
|
|
|
|
# so I added a message, "A local method of ...", only for compatibility (gfx) |
95
|
2
|
|
|
|
|
75
|
$self->throw_error("Cannot add an override of method '$method_name' " |
96
|
|
|
|
|
|
|
. "because there is a local version of '$method_name'" |
97
|
|
|
|
|
|
|
. "(A local method of the same name as been found)"); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
14
|
|
|
|
|
57
|
$self->{override_method_modifiers}->{$method_name} = $method; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub get_override_method_modifier { |
104
|
2
|
|
|
2
|
0
|
7641
|
my ($self, $method_name) = @_; |
105
|
2
|
|
|
|
|
8
|
return $self->{override_method_modifiers}->{$method_name}; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub does_role { |
109
|
1008
|
|
|
1008
|
0
|
10170
|
my ($self, $role_name) = @_; |
110
|
|
|
|
|
|
|
|
111
|
1008
|
50
|
|
|
|
8555
|
(defined $role_name) |
112
|
|
|
|
|
|
|
|| $self->throw_error("You must supply a role name to look for"); |
113
|
|
|
|
|
|
|
|
114
|
1008
|
100
|
|
|
|
8980
|
$role_name = $role_name->name if ref $role_name; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# if we are it,.. then return true |
117
|
1008
|
100
|
|
|
|
15831
|
return 1 if $role_name eq $self->name; |
118
|
|
|
|
|
|
|
# otherwise.. check our children |
119
|
721
|
|
|
|
|
5993
|
for my $role (@{ $self->get_roles }) { |
|
721
|
|
|
|
|
11178
|
|
120
|
503
|
100
|
|
|
|
3380
|
return 1 if $role->does_role($role_name); |
121
|
|
|
|
|
|
|
} |
122
|
454
|
|
|
|
|
8566
|
return 0; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
__END__ |