Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/Role/Application/ToRole.pm |
Statements | Executed 14 statements in 1.11ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 14µs | 44µs | BEGIN@13 | Moose::Meta::Role::Application::ToRole::
1 | 1 | 1 | 12µs | 12µs | BEGIN@2 | Moose::Meta::Role::Application::ToRole::
1 | 1 | 1 | 9µs | 14µs | BEGIN@10 | Moose::Meta::Role::Application::ToRole::
1 | 1 | 1 | 9µs | 82µs | BEGIN@15 | Moose::Meta::Role::Application::ToRole::
1 | 1 | 1 | 8µs | 23µs | BEGIN@9 | Moose::Meta::Role::Application::ToRole::
1 | 1 | 1 | 8µs | 488µs | BEGIN@11 | Moose::Meta::Role::Application::ToRole::
0 | 0 | 0 | 0s | 0s | apply | Moose::Meta::Role::Application::ToRole::
0 | 0 | 0 | 0s | 0s | apply_attributes | Moose::Meta::Role::Application::ToRole::
0 | 0 | 0 | 0s | 0s | apply_method_modifiers | Moose::Meta::Role::Application::ToRole::
0 | 0 | 0 | 0s | 0s | apply_methods | Moose::Meta::Role::Application::ToRole::
0 | 0 | 0 | 0s | 0s | apply_override_method_modifiers | Moose::Meta::Role::Application::ToRole::
0 | 0 | 0 | 0s | 0s | check_required_attributes | Moose::Meta::Role::Application::ToRole::
0 | 0 | 0 | 0s | 0s | check_required_methods | Moose::Meta::Role::Application::ToRole::
0 | 0 | 0 | 0s | 0s | check_role_exclusions | Moose::Meta::Role::Application::ToRole::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::Role::Application::ToRole; | ||||
2 | # spent 12µs within Moose::Meta::Role::Application::ToRole::BEGIN@2 which was called:
# once (12µs+0s) by Moose::BEGIN@40 at line 4 | ||||
3 | 1 | 6µs | $Moose::Meta::Role::Application::ToRole::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 41µs | 1 | 12µs | } # spent 12µs making 1 call to Moose::Meta::Role::Application::ToRole::BEGIN@2 |
5 | { | ||||
6 | 2 | 1µs | $Moose::Meta::Role::Application::ToRole::VERSION = '2.1005'; | ||
7 | } | ||||
8 | |||||
9 | 2 | 30µs | 2 | 38µs | # spent 23µs (8+15) within Moose::Meta::Role::Application::ToRole::BEGIN@9 which was called:
# once (8µs+15µs) by Moose::BEGIN@40 at line 9 # spent 23µs making 1 call to Moose::Meta::Role::Application::ToRole::BEGIN@9
# spent 15µs making 1 call to strict::import |
10 | 2 | 28µs | 2 | 18µs | # spent 14µs (9+4) within Moose::Meta::Role::Application::ToRole::BEGIN@10 which was called:
# once (9µs+4µs) by Moose::BEGIN@40 at line 10 # spent 14µs making 1 call to Moose::Meta::Role::Application::ToRole::BEGIN@10
# spent 4µs making 1 call to warnings::import |
11 | 2 | 43µs | 2 | 967µs | # spent 488µs (8+479) within Moose::Meta::Role::Application::ToRole::BEGIN@11 which was called:
# once (8µs+479µs) by Moose::BEGIN@40 at line 11 # spent 488µs making 1 call to Moose::Meta::Role::Application::ToRole::BEGIN@11
# spent 479µs making 1 call to metaclass::import |
12 | |||||
13 | 2 | 34µs | 2 | 75µs | # spent 44µs (14+31) within Moose::Meta::Role::Application::ToRole::BEGIN@13 which was called:
# once (14µs+31µs) by Moose::BEGIN@40 at line 13 # spent 44µs making 1 call to Moose::Meta::Role::Application::ToRole::BEGIN@13
# spent 30µs making 1 call to Exporter::import |
14 | |||||
15 | 2 | 926µs | 2 | 155µs | # spent 82µs (9+73) within Moose::Meta::Role::Application::ToRole::BEGIN@15 which was called:
# once (9µs+73µs) by Moose::BEGIN@40 at line 15 # spent 82µs making 1 call to Moose::Meta::Role::Application::ToRole::BEGIN@15
# spent 73µs making 1 call to base::import |
16 | |||||
17 | sub apply { | ||||
18 | my ($self, $role1, $role2) = @_; | ||||
19 | $self->SUPER::apply($role1, $role2); | ||||
20 | $role2->add_role($role1); | ||||
21 | } | ||||
22 | |||||
23 | sub check_role_exclusions { | ||||
24 | my ($self, $role1, $role2) = @_; | ||||
25 | if ( $role2->excludes_role($role1->name) ) { | ||||
26 | require Moose; | ||||
27 | Moose->throw_error("Conflict detected: " . $role2->name . " excludes role '" . $role1->name . "'"); | ||||
28 | } | ||||
29 | foreach my $excluded_role_name ($role1->get_excluded_roles_list) { | ||||
30 | if ( $role2->does_role($excluded_role_name) ) { | ||||
31 | require Moose; | ||||
32 | Moose->throw_error("The role " . $role2->name . " does the excluded role '$excluded_role_name'"); | ||||
33 | } | ||||
34 | $role2->add_excluded_roles($excluded_role_name); | ||||
35 | } | ||||
36 | } | ||||
37 | |||||
38 | sub check_required_methods { | ||||
39 | my ($self, $role1, $role2) = @_; | ||||
40 | foreach my $required_method ($role1->get_required_method_list) { | ||||
41 | my $required_method_name = $required_method->name; | ||||
42 | |||||
43 | next if $self->is_aliased_method($required_method_name); | ||||
44 | |||||
45 | $role2->add_required_methods($required_method) | ||||
46 | unless $role2->find_method_by_name($required_method_name); | ||||
47 | } | ||||
48 | } | ||||
49 | |||||
50 | sub check_required_attributes { | ||||
51 | |||||
52 | } | ||||
53 | |||||
54 | sub apply_attributes { | ||||
55 | my ($self, $role1, $role2) = @_; | ||||
56 | foreach my $attribute_name ($role1->get_attribute_list) { | ||||
57 | # it if it has one already | ||||
58 | if ($role2->has_attribute($attribute_name) && | ||||
59 | # make sure we haven't seen this one already too | ||||
60 | $role2->get_attribute($attribute_name) != $role1->get_attribute($attribute_name)) { | ||||
61 | |||||
62 | my $role2_name = $role2->name; | ||||
63 | |||||
64 | require Moose; | ||||
65 | Moose->throw_error( "Role '" | ||||
66 | . $role1->name | ||||
67 | . "' has encountered an attribute conflict" | ||||
68 | . " while being composed into '$role2_name'." | ||||
69 | . " This is a fatal error and cannot be disambiguated." | ||||
70 | . " The conflicting attribute is named '$attribute_name'." ); | ||||
71 | } | ||||
72 | else { | ||||
73 | $role2->add_attribute( | ||||
74 | $role1->get_attribute($attribute_name)->clone | ||||
75 | ); | ||||
76 | } | ||||
77 | } | ||||
78 | } | ||||
79 | |||||
80 | sub apply_methods { | ||||
81 | my ( $self, $role1, $role2 ) = @_; | ||||
82 | foreach my $method ( $role1->_get_local_methods ) { | ||||
83 | |||||
84 | my $method_name = $method->name; | ||||
85 | |||||
86 | next if $method->isa('Class::MOP::Method::Meta'); | ||||
87 | |||||
88 | unless ( $self->is_method_excluded($method_name) ) { | ||||
89 | |||||
90 | my $role2_method = $role2->get_method($method_name); | ||||
91 | if ( $role2_method | ||||
92 | && $role2_method->body != $method->body ) { | ||||
93 | |||||
94 | # method conflicts between roles used to result in the method | ||||
95 | # becoming a requirement but now are permitted just like | ||||
96 | # for classes, hence no code in this branch anymore. | ||||
97 | } | ||||
98 | else { | ||||
99 | $role2->add_method( | ||||
100 | $method_name, | ||||
101 | $method, | ||||
102 | ); | ||||
103 | } | ||||
104 | } | ||||
105 | |||||
106 | next unless $self->is_method_aliased($method_name); | ||||
107 | |||||
108 | my $aliased_method_name = $self->get_method_aliases->{$method_name}; | ||||
109 | |||||
110 | my $role2_method = $role2->get_method($aliased_method_name); | ||||
111 | |||||
112 | if ( $role2_method | ||||
113 | && $role2_method->body != $method->body ) { | ||||
114 | |||||
115 | require Moose; | ||||
116 | Moose->throw_error( | ||||
117 | "Cannot create a method alias if a local method of the same name exists" | ||||
118 | ); | ||||
119 | } | ||||
120 | |||||
121 | $role2->add_method( | ||||
122 | $aliased_method_name, | ||||
123 | $role1->get_method($method_name) | ||||
124 | ); | ||||
125 | |||||
126 | if ( !$role2->has_method($method_name) ) { | ||||
127 | $role2->add_required_methods($method_name) | ||||
128 | unless $self->is_method_excluded($method_name); | ||||
129 | } | ||||
130 | } | ||||
131 | } | ||||
132 | |||||
133 | sub apply_override_method_modifiers { | ||||
134 | my ($self, $role1, $role2) = @_; | ||||
135 | foreach my $method_name ($role1->get_method_modifier_list('override')) { | ||||
136 | # it if it has one already then ... | ||||
137 | if ($role2->has_method($method_name)) { | ||||
138 | # if it is being composed into another role | ||||
139 | # we have a conflict here, because you cannot | ||||
140 | # combine an overridden method with a locally | ||||
141 | # defined one | ||||
142 | require Moose; | ||||
143 | Moose->throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " . | ||||
144 | "during composition (A local method of the same name as been found). This " . | ||||
145 | "is fatal error."); | ||||
146 | } | ||||
147 | else { | ||||
148 | # if we are a role, we need to make sure | ||||
149 | # we don't have a conflict with the role | ||||
150 | # we are composing into | ||||
151 | if ($role2->has_override_method_modifier($method_name) && | ||||
152 | $role2->get_override_method_modifier($method_name) != $role2->get_override_method_modifier($method_name)) { | ||||
153 | |||||
154 | require Moose; | ||||
155 | Moose->throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " . | ||||
156 | "during composition (Two 'override' methods of the same name encountered). " . | ||||
157 | "This is fatal error."); | ||||
158 | } | ||||
159 | else { | ||||
160 | # if there is no conflict, | ||||
161 | # just add it to the role | ||||
162 | $role2->add_override_method_modifier( | ||||
163 | $method_name, | ||||
164 | $role1->get_override_method_modifier($method_name) | ||||
165 | ); | ||||
166 | } | ||||
167 | } | ||||
168 | } | ||||
169 | } | ||||
170 | |||||
171 | sub apply_method_modifiers { | ||||
172 | my ($self, $modifier_type, $role1, $role2) = @_; | ||||
173 | my $add = "add_${modifier_type}_method_modifier"; | ||||
174 | my $get = "get_${modifier_type}_method_modifiers"; | ||||
175 | foreach my $method_name ($role1->get_method_modifier_list($modifier_type)) { | ||||
176 | $role2->$add( | ||||
177 | $method_name, | ||||
178 | $_ | ||||
179 | ) foreach $role1->$get($method_name); | ||||
180 | } | ||||
181 | } | ||||
182 | |||||
183 | |||||
184 | 1 | 4µs | 1; | ||
185 | |||||
186 | # ABSTRACT: Compose a role into another role | ||||
187 | |||||
188 | __END__ |