Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/Role/Application/RoleSummation.pm |
Statements | Executed 17 statements in 1.91ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 12µs | 12µs | BEGIN@2 | Moose::Meta::Role::Application::RoleSummation::
1 | 1 | 1 | 9µs | 40µs | BEGIN@13 | Moose::Meta::Role::Application::RoleSummation::
1 | 1 | 1 | 9µs | 13µs | BEGIN@10 | Moose::Meta::Role::Application::RoleSummation::
1 | 1 | 1 | 9µs | 94µs | BEGIN@17 | Moose::Meta::Role::Application::RoleSummation::
1 | 1 | 1 | 8µs | 28µs | BEGIN@9 | Moose::Meta::Role::Application::RoleSummation::
1 | 1 | 1 | 8µs | 480µs | BEGIN@11 | Moose::Meta::Role::Application::RoleSummation::
1 | 1 | 1 | 5µs | 5µs | BEGIN@15 | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | __ANON__[:21] | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | apply_attributes | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | apply_method_modifiers | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | apply_methods | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | apply_override_method_modifiers | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | check_required_attributes | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | check_required_methods | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | check_role_exclusions | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | get_exclusions_for_role | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | get_method_aliases_for_role | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | is_aliased_method | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | is_method_aliased | Moose::Meta::Role::Application::RoleSummation::
0 | 0 | 0 | 0s | 0s | is_method_excluded | Moose::Meta::Role::Application::RoleSummation::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::Role::Application::RoleSummation; | ||||
2 | # spent 12µs within Moose::Meta::Role::Application::RoleSummation::BEGIN@2 which was called:
# once (12µs+0s) by Moose::BEGIN@38 at line 4 | ||||
3 | 1 | 7µs | $Moose::Meta::Role::Application::RoleSummation::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 49µs | 1 | 12µs | } # spent 12µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@2 |
5 | { | ||||
6 | 2 | 1µs | $Moose::Meta::Role::Application::RoleSummation::VERSION = '2.1005'; | ||
7 | } | ||||
8 | |||||
9 | 2 | 30µs | 2 | 47µs | # spent 28µs (8+19) within Moose::Meta::Role::Application::RoleSummation::BEGIN@9 which was called:
# once (8µs+19µs) by Moose::BEGIN@38 at line 9 # spent 28µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@9
# spent 19µs making 1 call to strict::import |
10 | 2 | 28µs | 2 | 18µs | # spent 13µs (9+4) within Moose::Meta::Role::Application::RoleSummation::BEGIN@10 which was called:
# once (9µs+4µs) by Moose::BEGIN@38 at line 10 # spent 13µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@10
# spent 4µs making 1 call to warnings::import |
11 | 2 | 39µs | 2 | 951µs | # spent 480µs (8+471) within Moose::Meta::Role::Application::RoleSummation::BEGIN@11 which was called:
# once (8µs+471µs) by Moose::BEGIN@38 at line 11 # spent 480µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@11
# spent 471µs making 1 call to metaclass::import |
12 | |||||
13 | 2 | 34µs | 2 | 70µs | # spent 40µs (9+30) within Moose::Meta::Role::Application::RoleSummation::BEGIN@13 which was called:
# once (9µs+30µs) by Moose::BEGIN@38 at line 13 # spent 40µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@13
# spent 30µs making 1 call to Exporter::import |
14 | |||||
15 | 2 | 36µs | 1 | 5µs | # spent 5µs within Moose::Meta::Role::Application::RoleSummation::BEGIN@15 which was called:
# once (5µs+0s) by Moose::BEGIN@38 at line 15 # spent 5µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@15 |
16 | |||||
17 | 2 | 1.67ms | 2 | 180µs | # spent 94µs (9+86) within Moose::Meta::Role::Application::RoleSummation::BEGIN@17 which was called:
# once (9µs+86µs) by Moose::BEGIN@38 at line 17 # spent 94µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@17
# spent 86µs making 1 call to base::import |
18 | |||||
19 | __PACKAGE__->meta->add_attribute('role_params' => ( | ||||
20 | reader => 'role_params', | ||||
21 | default => sub { {} }, | ||||
22 | 1 | 7µs | 3 | 444µs | Class::MOP::_definition_context(), # spent 416µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 22µs making 1 call to Moose::Meta::Role::Application::RoleSummation::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
23 | )); | ||||
24 | |||||
25 | sub get_exclusions_for_role { | ||||
26 | my ($self, $role) = @_; | ||||
27 | $role = $role->name if blessed $role; | ||||
28 | my $excludes_key = exists $self->role_params->{$role}->{'-excludes'} ? | ||||
29 | '-excludes' : 'excludes'; | ||||
30 | if ($self->role_params->{$role} && defined $self->role_params->{$role}->{$excludes_key}) { | ||||
31 | if (ref $self->role_params->{$role}->{$excludes_key} eq 'ARRAY') { | ||||
32 | return $self->role_params->{$role}->{$excludes_key}; | ||||
33 | } | ||||
34 | return [ $self->role_params->{$role}->{$excludes_key} ]; | ||||
35 | } | ||||
36 | return []; | ||||
37 | } | ||||
38 | |||||
39 | sub get_method_aliases_for_role { | ||||
40 | my ($self, $role) = @_; | ||||
41 | $role = $role->name if blessed $role; | ||||
42 | my $alias_key = exists $self->role_params->{$role}->{'-alias'} ? | ||||
43 | '-alias' : 'alias'; | ||||
44 | if ($self->role_params->{$role} && defined $self->role_params->{$role}->{$alias_key}) { | ||||
45 | return $self->role_params->{$role}->{$alias_key}; | ||||
46 | } | ||||
47 | return {}; | ||||
48 | } | ||||
49 | |||||
50 | sub is_method_excluded { | ||||
51 | my ($self, $role, $method_name) = @_; | ||||
52 | foreach ($self->get_exclusions_for_role($role->name)) { | ||||
53 | return 1 if $_ eq $method_name; | ||||
54 | } | ||||
55 | return 0; | ||||
56 | } | ||||
57 | |||||
58 | sub is_method_aliased { | ||||
59 | my ($self, $role, $method_name) = @_; | ||||
60 | exists $self->get_method_aliases_for_role($role->name)->{$method_name} ? 1 : 0 | ||||
61 | } | ||||
62 | |||||
63 | sub is_aliased_method { | ||||
64 | my ($self, $role, $method_name) = @_; | ||||
65 | my %aliased_names = reverse %{$self->get_method_aliases_for_role($role->name)}; | ||||
66 | exists $aliased_names{$method_name} ? 1 : 0; | ||||
67 | } | ||||
68 | |||||
69 | sub check_role_exclusions { | ||||
70 | my ($self, $c) = @_; | ||||
71 | |||||
72 | my %excluded_roles; | ||||
73 | for my $role (@{ $c->get_roles }) { | ||||
74 | my $name = $role->name; | ||||
75 | |||||
76 | for my $excluded ($role->get_excluded_roles_list) { | ||||
77 | push @{ $excluded_roles{$excluded} }, $name; | ||||
78 | } | ||||
79 | } | ||||
80 | |||||
81 | foreach my $role (@{$c->get_roles}) { | ||||
82 | foreach my $excluded (keys %excluded_roles) { | ||||
83 | next unless $role->does_role($excluded); | ||||
84 | |||||
85 | my @excluding = @{ $excluded_roles{$excluded} }; | ||||
86 | |||||
87 | require Moose; | ||||
88 | Moose->throw_error(sprintf "Conflict detected: Role%s %s exclude%s role '%s'", (@excluding == 1 ? '' : 's'), join(', ', @excluding), (@excluding == 1 ? 's' : ''), $excluded); | ||||
89 | } | ||||
90 | } | ||||
91 | |||||
92 | $c->add_excluded_roles(keys %excluded_roles); | ||||
93 | } | ||||
94 | |||||
95 | sub check_required_methods { | ||||
96 | my ($self, $c) = @_; | ||||
97 | |||||
98 | my %all_required_methods = | ||||
99 | map { $_->name => $_ } | ||||
100 | map { $_->get_required_method_list } | ||||
101 | @{$c->get_roles}; | ||||
102 | |||||
103 | foreach my $role (@{$c->get_roles}) { | ||||
104 | foreach my $required (keys %all_required_methods) { | ||||
105 | |||||
106 | delete $all_required_methods{$required} | ||||
107 | if $role->has_method($required) | ||||
108 | || $self->is_aliased_method($role, $required); | ||||
109 | } | ||||
110 | } | ||||
111 | |||||
112 | $c->add_required_methods(values %all_required_methods); | ||||
113 | } | ||||
114 | |||||
115 | sub check_required_attributes { | ||||
116 | |||||
117 | } | ||||
118 | |||||
119 | sub apply_attributes { | ||||
120 | my ($self, $c) = @_; | ||||
121 | |||||
122 | my @all_attributes; | ||||
123 | |||||
124 | for my $role ( @{ $c->get_roles } ) { | ||||
125 | push @all_attributes, | ||||
126 | map { $role->get_attribute($_) } $role->get_attribute_list; | ||||
127 | } | ||||
128 | |||||
129 | my %seen; | ||||
130 | foreach my $attr (@all_attributes) { | ||||
131 | my $name = $attr->name; | ||||
132 | |||||
133 | if ( exists $seen{$name} ) { | ||||
134 | next if $seen{$name}->is_same_as($attr); | ||||
135 | |||||
136 | my $role1 = $seen{$name}->associated_role->name; | ||||
137 | my $role2 = $attr->associated_role->name; | ||||
138 | |||||
139 | require Moose; | ||||
140 | Moose->throw_error( | ||||
141 | "We have encountered an attribute conflict with '$name' " | ||||
142 | . "during role composition. " | ||||
143 | . " This attribute is defined in both $role1 and $role2." | ||||
144 | . " This is a fatal error and cannot be disambiguated." ); | ||||
145 | } | ||||
146 | |||||
147 | $seen{$name} = $attr; | ||||
148 | } | ||||
149 | |||||
150 | foreach my $attr (@all_attributes) { | ||||
151 | $c->add_attribute( $attr->clone ); | ||||
152 | } | ||||
153 | } | ||||
154 | |||||
155 | sub apply_methods { | ||||
156 | my ($self, $c) = @_; | ||||
157 | |||||
158 | my @all_methods = map { | ||||
159 | my $role = $_; | ||||
160 | my $aliases = $self->get_method_aliases_for_role($role); | ||||
161 | my %excludes = map { $_ => undef } @{ $self->get_exclusions_for_role($role) }; | ||||
162 | ( | ||||
163 | (map { | ||||
164 | exists $excludes{$_} ? () : | ||||
165 | +{ | ||||
166 | role => $role, | ||||
167 | name => $_, | ||||
168 | method => $role->get_method($_), | ||||
169 | } | ||||
170 | } map { $_->name } | ||||
171 | grep { !$_->isa('Class::MOP::Method::Meta') } | ||||
172 | $role->_get_local_methods), | ||||
173 | (map { | ||||
174 | +{ | ||||
175 | role => $role, | ||||
176 | name => $aliases->{$_}, | ||||
177 | method => $role->get_method($_), | ||||
178 | } | ||||
179 | } keys %$aliases) | ||||
180 | ); | ||||
181 | } @{$c->get_roles}; | ||||
182 | |||||
183 | my (%seen, %conflicts, %method_map); | ||||
184 | foreach my $method (@all_methods) { | ||||
185 | next if $conflicts{$method->{name}}; | ||||
186 | my $seen = $seen{$method->{name}}; | ||||
187 | |||||
188 | if ($seen) { | ||||
189 | if ($seen->{method}->body != $method->{method}->body) { | ||||
190 | $c->add_conflicting_method( | ||||
191 | name => $method->{name}, | ||||
192 | roles => [$method->{role}->name, $seen->{role}->name], | ||||
193 | ); | ||||
194 | |||||
195 | delete $method_map{$method->{name}}; | ||||
196 | $conflicts{$method->{name}} = 1; | ||||
197 | next; | ||||
198 | } | ||||
199 | } | ||||
200 | |||||
201 | $seen{$method->{name}} = $method; | ||||
202 | $method_map{$method->{name}} = $method->{method}; | ||||
203 | } | ||||
204 | |||||
205 | $c->add_method($_ => $method_map{$_}) for keys %method_map; | ||||
206 | } | ||||
207 | |||||
208 | sub apply_override_method_modifiers { | ||||
209 | my ($self, $c) = @_; | ||||
210 | |||||
211 | my @all_overrides = map { | ||||
212 | my $role = $_; | ||||
213 | map { | ||||
214 | +{ | ||||
215 | name => $_, | ||||
216 | method => $role->get_override_method_modifier($_), | ||||
217 | } | ||||
218 | } $role->get_method_modifier_list('override'); | ||||
219 | } @{$c->get_roles}; | ||||
220 | |||||
221 | my %seen; | ||||
222 | foreach my $override (@all_overrides) { | ||||
223 | if ( $c->has_method($override->{name}) ){ | ||||
224 | require Moose; | ||||
225 | Moose->throw_error( "Role '" . $c->name . "' has encountered an 'override' method conflict " . | ||||
226 | "during composition (A local method of the same name as been found). This " . | ||||
227 | "is fatal error." ) | ||||
228 | } | ||||
229 | if (exists $seen{$override->{name}}) { | ||||
230 | if ( $seen{$override->{name}} != $override->{method} ) { | ||||
231 | require Moose; | ||||
232 | Moose->throw_error( "We have encountered an 'override' method conflict during " . | ||||
233 | "composition (Two 'override' methods of the same name encountered). " . | ||||
234 | "This is fatal error.") | ||||
235 | } | ||||
236 | } | ||||
237 | $seen{$override->{name}} = $override->{method}; | ||||
238 | } | ||||
239 | |||||
240 | $c->add_override_method_modifier( | ||||
241 | $_->{name}, $_->{method} | ||||
242 | ) for @all_overrides; | ||||
243 | |||||
244 | } | ||||
245 | |||||
246 | sub apply_method_modifiers { | ||||
247 | my ($self, $modifier_type, $c) = @_; | ||||
248 | my $add = "add_${modifier_type}_method_modifier"; | ||||
249 | my $get = "get_${modifier_type}_method_modifiers"; | ||||
250 | foreach my $role (@{$c->get_roles}) { | ||||
251 | foreach my $method_name ($role->get_method_modifier_list($modifier_type)) { | ||||
252 | $c->$add( | ||||
253 | $method_name, | ||||
254 | $_ | ||||
255 | ) foreach $role->$get($method_name); | ||||
256 | } | ||||
257 | } | ||||
258 | } | ||||
259 | |||||
260 | 1 | 7µs | 1; | ||
261 | |||||
262 | # ABSTRACT: Combine two or more roles | ||||
263 | |||||
264 | __END__ |