← Index
NYTProf Performance Profile   « line view »
For script/ponapi
  Run on Wed Feb 10 15:51:26 2016
Reported on Thu Feb 11 09:43:11 2016

Filename/usr/local/lib/perl/5.18.2/Moose/Meta/Role/Application/RoleSummation.pm
StatementsExecuted 5232 statements in 14.2ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
19113.23ms32.8msMoose::Meta::Role::Application::RoleSummation::::apply_methodsMoose::Meta::Role::Application::RoleSummation::apply_methods
111211.12ms1.49msMoose::Meta::Role::Application::RoleSummation::::get_method_aliases_for_roleMoose::Meta::Role::Application::RoleSummation::get_method_aliases_for_role
1911775µs4.81msMoose::Meta::Role::Application::RoleSummation::::apply_attributesMoose::Meta::Role::Application::RoleSummation::apply_attributes
5731711µs1.74msMoose::Meta::Role::Application::RoleSummation::::apply_method_modifiersMoose::Meta::Role::Application::RoleSummation::apply_method_modifiers
6911688µs875µsMoose::Meta::Role::Application::RoleSummation::::get_exclusions_for_roleMoose::Meta::Role::Application::RoleSummation::get_exclusions_for_role
1911666µs7.05msMoose::Meta::Role::Application::RoleSummation::::check_required_methodsMoose::Meta::Role::Application::RoleSummation::check_required_methods
1911578µs1.03msMoose::Meta::Role::Application::RoleSummation::::check_role_exclusionsMoose::Meta::Role::Application::RoleSummation::check_role_exclusions
1911548µs1.17msMoose::Meta::Role::Application::RoleSummation::::apply_override_method_modifiersMoose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers
4211272µs816µsMoose::Meta::Role::Application::RoleSummation::::is_aliased_methodMoose::Meta::Role::Application::RoleSummation::is_aliased_method
1911244µs2.40msMoose::Meta::Role::Application::RoleSummation::::apply_overloadingMoose::Meta::Role::Application::RoleSummation::apply_overloading
11126µs68µsMoose::Meta::Role::Application::RoleSummation::::BEGIN@8Moose::Meta::Role::Application::RoleSummation::BEGIN@8
191120µs20µsMoose::Meta::Role::Application::RoleSummation::::check_required_attributesMoose::Meta::Role::Application::RoleSummation::check_required_attributes
11110µs22µsMoose::Meta::Role::Application::RoleSummation::::BEGIN@4Moose::Meta::Role::Application::RoleSummation::BEGIN@4
1118µs29µsMoose::Meta::Role::Application::RoleSummation::::BEGIN@13Moose::Meta::Role::Application::RoleSummation::BEGIN@13
1118µs12µsMoose::Meta::Role::Application::RoleSummation::::BEGIN@5Moose::Meta::Role::Application::RoleSummation::BEGIN@5
1116µs27µsMoose::Meta::Role::Application::RoleSummation::::BEGIN@9Moose::Meta::Role::Application::RoleSummation::BEGIN@9
1116µs132µsMoose::Meta::Role::Application::RoleSummation::::BEGIN@15Moose::Meta::Role::Application::RoleSummation::BEGIN@15
1116µs389µsMoose::Meta::Role::Application::RoleSummation::::BEGIN@6Moose::Meta::Role::Application::RoleSummation::BEGIN@6
1114µs4µsMoose::Meta::Role::Application::RoleSummation::::BEGIN@11Moose::Meta::Role::Application::RoleSummation::BEGIN@11
0000s0sMoose::Meta::Role::Application::RoleSummation::::__ANON__[:19]Moose::Meta::Role::Application::RoleSummation::__ANON__[:19]
0000s0sMoose::Meta::Role::Application::RoleSummation::::__ANON__[:273]Moose::Meta::Role::Application::RoleSummation::__ANON__[:273]
0000s0sMoose::Meta::Role::Application::RoleSummation::::__ANON__[:283]Moose::Meta::Role::Application::RoleSummation::__ANON__[:283]
0000s0sMoose::Meta::Role::Application::RoleSummation::::__ANON__[:308]Moose::Meta::Role::Application::RoleSummation::__ANON__[:308]
0000s0sMoose::Meta::Role::Application::RoleSummation::::is_method_aliasedMoose::Meta::Role::Application::RoleSummation::is_method_aliased
0000s0sMoose::Meta::Role::Application::RoleSummation::::is_method_excludedMoose::Meta::Role::Application::RoleSummation::is_method_excluded
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Moose::Meta::Role::Application::RoleSummation;
21600nsour $VERSION = '2.1604';
3
4222µs234µs
# spent 22µs (10+12) within Moose::Meta::Role::Application::RoleSummation::BEGIN@4 which was called: # once (10µs+12µs) by Moose::BEGIN@35 at line 4
use strict;
# spent 22µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@4 # spent 12µs making 1 call to strict::import
5218µs218µs
# spent 12µs (8+5) within Moose::Meta::Role::Application::RoleSummation::BEGIN@5 which was called: # once (8µs+5µs) by Moose::BEGIN@35 at line 5
use warnings;
# spent 12µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@5 # spent 5µs making 1 call to warnings::import
6257µs2772µs
# spent 389µs (6+383) within Moose::Meta::Role::Application::RoleSummation::BEGIN@6 which was called: # once (6µs+383µs) by Moose::BEGIN@35 at line 6
use metaclass;
# spent 389µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@6 # spent 383µs making 1 call to metaclass::import
7
8351µs386µs
# spent 68µs (26+42) within Moose::Meta::Role::Application::RoleSummation::BEGIN@8 which was called: # once (26µs+42µs) by Moose::BEGIN@35 at line 8
use List::Util 1.33 qw( all );
# spent 68µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@8 # spent 9µs making 1 call to UNIVERSAL::VERSION # spent 8µs making 1 call to List::Util::import
9221µs248µs
# spent 27µs (6+21) within Moose::Meta::Role::Application::RoleSummation::BEGIN@9 which was called: # once (6µs+21µs) by Moose::BEGIN@35 at line 9
use Scalar::Util 'blessed';
# spent 27µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@9 # spent 21µs making 1 call to Exporter::import
10
11221µs14µs
# spent 4µs within Moose::Meta::Role::Application::RoleSummation::BEGIN@11 which was called: # once (4µs+0s) by Moose::BEGIN@35 at line 11
use Moose::Meta::Role::Composite;
12
13225µs250µs
# spent 29µs (8+21) within Moose::Meta::Role::Application::RoleSummation::BEGIN@13 which was called: # once (8µs+21µs) by Moose::BEGIN@35 at line 13
use parent 'Moose::Meta::Role::Application';
# spent 29µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@13 # spent 21µs making 1 call to parent::import
14
1521.36ms2257µs
# spent 132µs (6+125) within Moose::Meta::Role::Application::RoleSummation::BEGIN@15 which was called: # once (6µs+125µs) by Moose::BEGIN@35 at line 15
use Moose::Util 'throw_exception';
# spent 132µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@15 # spent 125µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337]
16
17__PACKAGE__->meta->add_attribute('role_params' => (
18 reader => 'role_params',
19 default => sub { {} },
2019µs3364µs Class::MOP::_definition_context(),
# spent 332µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 26µs making 1 call to Moose::Meta::Role::Application::RoleSummation::meta # spent 6µs making 1 call to Class::MOP::_definition_context
21));
22
23
# spent 875µs (688+187) within Moose::Meta::Role::Application::RoleSummation::get_exclusions_for_role which was called 69 times, avg 13µs/call: # 69 times (688µs+187µs) by Moose::Meta::Role::Application::RoleSummation::apply_methods at line 158, avg 13µs/call
sub get_exclusions_for_role {
246918µs my ($self, $role) = @_;
2569264µs13859µs $role = $role->name if blessed $role;
# spent 36µs making 69 calls to Scalar::Util::blessed, avg 522ns/call # spent 23µs making 69 calls to Class::MOP::Package::name, avg 329ns/call
266967µs6948µs my $excludes_key = exists $self->role_params->{$role}->{'-excludes'} ?
# spent 48µs making 69 calls to Moose::Meta::Role::Application::RoleSummation::role_params, avg 694ns/call
27 '-excludes' : 'excludes';
2869104µs13881µs if ($self->role_params->{$role} && defined $self->role_params->{$role}->{$excludes_key}) {
# spent 81µs making 138 calls to Moose::Meta::Role::Application::RoleSummation::role_params, avg 585ns/call
29 if (ref $self->role_params->{$role}->{$excludes_key} eq 'ARRAY') {
30 return $self->role_params->{$role}->{$excludes_key};
31 }
32 return [ $self->role_params->{$role}->{$excludes_key} ];
33 }
3469134µs return [];
35}
36
37
# spent 1.49ms (1.12+370µs) within Moose::Meta::Role::Application::RoleSummation::get_method_aliases_for_role which was called 111 times, avg 13µs/call: # 69 times (721µs+241µs) by Moose::Meta::Role::Application::RoleSummation::apply_methods at line 157, avg 14µs/call # 42 times (398µs+129µs) by Moose::Meta::Role::Application::RoleSummation::is_aliased_method at line 63, avg 13µs/call
sub get_method_aliases_for_role {
3811127µs my ($self, $role) = @_;
39111388µs18095µs $role = $role->name if blessed $role;
# spent 58µs making 111 calls to Scalar::Util::blessed, avg 521ns/call # spent 37µs making 69 calls to Class::MOP::Package::name, avg 539ns/call
40111182µs111133µs my $alias_key = exists $self->role_params->{$role}->{'-alias'} ?
# spent 133µs making 111 calls to Moose::Meta::Role::Application::RoleSummation::role_params, avg 1µs/call
41 '-alias' : 'alias';
42111183µs222142µs if ($self->role_params->{$role} && defined $self->role_params->{$role}->{$alias_key}) {
# spent 142µs making 222 calls to Moose::Meta::Role::Application::RoleSummation::role_params, avg 640ns/call
43 return $self->role_params->{$role}->{$alias_key};
44 }
45111232µs return {};
46}
47
48sub is_method_excluded {
49 my ($self, $role, $method_name) = @_;
50 foreach ($self->get_exclusions_for_role($role->name)) {
51 return 1 if $_ eq $method_name;
52 }
53 return 0;
54}
55
56sub is_method_aliased {
57 my ($self, $role, $method_name) = @_;
58 exists $self->get_method_aliases_for_role($role->name)->{$method_name} ? 1 : 0
59}
60
61
# spent 816µs (272+544) within Moose::Meta::Role::Application::RoleSummation::is_aliased_method which was called 42 times, avg 19µs/call: # 42 times (272µs+544µs) by Moose::Meta::Role::Application::RoleSummation::check_required_methods at line 105, avg 19µs/call
sub is_aliased_method {
624215µs my ($self, $role, $method_name) = @_;
6342171µs84544µs my %aliased_names = reverse %{$self->get_method_aliases_for_role($role->name)};
# spent 527µs making 42 calls to Moose::Meta::Role::Application::RoleSummation::get_method_aliases_for_role, avg 13µs/call # spent 17µs making 42 calls to Class::MOP::Package::name, avg 407ns/call
644290µs exists $aliased_names{$method_name} ? 1 : 0;
65}
66
67
# spent 1.03ms (578µs+455µs) within Moose::Meta::Role::Application::RoleSummation::check_role_exclusions which was called 19 times, avg 54µs/call: # 19 times (578µs+455µs) by Moose::Meta::Role::Application::apply at line 54 of Moose/Meta/Role/Application.pm, avg 54µs/call
sub check_role_exclusions {
68196µs my ($self, $c) = @_;
69
70195µs my %excluded_roles;
711959µs1945µs for my $role (@{ $c->get_roles }) {
# spent 45µs making 19 calls to Moose::Meta::Role::get_roles, avg 2µs/call
7269152µs6934µs my $name = $role->name;
# spent 34µs making 69 calls to Class::MOP::Package::name, avg 493ns/call
73
7469129µs69306µs for my $excluded ($role->get_excluded_roles_list) {
# spent 306µs making 69 calls to Moose::Meta::Role::get_excluded_roles_list, avg 4µs/call
75 push @{ $excluded_roles{$excluded} }, $name;
76 }
77 }
78
791933µs1914µs foreach my $role (@{$c->get_roles}) {
# spent 14µs making 19 calls to Moose::Meta::Role::get_roles, avg 763ns/call
806944µs foreach my $excluded (keys %excluded_roles) {
81 next unless $role->does_role($excluded);
82
83 my @excluding = @{ $excluded_roles{$excluded} };
84
85 throw_exception( RoleExclusionConflict => roles => \@excluding,
86 role_name => $excluded
87 );
88 }
89 }
90
911978µs1956µs $c->add_excluded_roles(keys %excluded_roles);
# spent 56µs making 19 calls to Moose::Meta::Role::add_excluded_roles, avg 3µs/call
92}
93
94
# spent 7.05ms (666µs+6.38) within Moose::Meta::Role::Application::RoleSummation::check_required_methods which was called 19 times, avg 371µs/call: # 19 times (666µs+6.38ms) by Moose::Meta::Role::Application::apply at line 55 of Moose/Meta/Role/Application.pm, avg 371µs/call
sub check_required_methods {
95197µs my ($self, $c) = @_;
96
971534µs1540µs my %all_required_methods =
# spent 40µs making 15 calls to Moose::Meta::Role::Method::Required::name, avg 3µs/call
986962µs694.31ms map { $_->name => $_ }
# spent 4.31ms making 69 calls to Moose::Meta::Role::get_required_method_list, avg 62µs/call
99 map { $_->get_required_method_list }
1001971µs1911µs @{$c->get_roles};
# spent 11µs making 19 calls to Moose::Meta::Role::get_roles, avg 574ns/call
101
1021935µs1918µs foreach my $role (@{$c->get_roles}) {
# spent 18µs making 19 calls to Moose::Meta::Role::get_roles, avg 942ns/call
1036968µs foreach my $required (keys %all_required_methods) {
104
10542115µs841.80ms delete $all_required_methods{$required}
# spent 980µs making 42 calls to Class::MOP::Mixin::HasMethods::has_method, avg 23µs/call # spent 816µs making 42 calls to Moose::Meta::Role::Application::RoleSummation::is_aliased_method, avg 19µs/call
106 if $role->has_method($required)
107 || $self->is_aliased_method($role, $required);
108 }
109 }
110
1111980µs19207µs $c->add_required_methods(values %all_required_methods);
# spent 207µs making 19 calls to Moose::Meta::Role::add_required_methods, avg 11µs/call
112}
113
1141934µs
# spent 20µs within Moose::Meta::Role::Application::RoleSummation::check_required_attributes which was called 19 times, avg 1µs/call: # 19 times (20µs+0s) by Moose::Meta::Role::Application::apply at line 56 of Moose/Meta/Role/Application.pm, avg 1µs/call
sub check_required_attributes {
115
116}
117
118
# spent 4.81ms (775µs+4.04) within Moose::Meta::Role::Application::RoleSummation::apply_attributes which was called 19 times, avg 253µs/call: # 19 times (775µs+4.04ms) by Moose::Meta::Role::Application::apply at line 59 of Moose/Meta/Role/Application.pm, avg 253µs/call
sub apply_attributes {
119196µs my ($self, $c) = @_;
120
121194µs my @all_attributes;
122
1231929µs1917µs for my $role ( @{ $c->get_roles } ) {
# spent 17µs making 19 calls to Moose::Meta::Role::get_roles, avg 884ns/call
1245554µs55176µs push @all_attributes,
# spent 176µs making 55 calls to Class::MOP::Mixin::HasAttributes::get_attribute, avg 3µs/call
12569141µs69245µs map { $role->get_attribute($_) } $role->get_attribute_list;
# spent 245µs making 69 calls to Class::MOP::Mixin::HasAttributes::get_attribute_list, avg 4µs/call
126 }
127
128194µs my %seen;
1291915µs foreach my $attr (@all_attributes) {
13055130µs5528µs my $name = $attr->name;
# spent 28µs making 55 calls to Class::MOP::Mixin::AttributeCore::name, avg 505ns/call
131
1325511µs if ( exists $seen{$name} ) {
133 next if $seen{$name}->is_same_as($attr);
134
135 my $role1 = $seen{$name}->associated_role->name;
136 my $role2 = $attr->associated_role->name;
137
138 throw_exception( AttributeConflictInSummation => attribute_name => $name,
139 role_name => $role1,
140 second_role_name => $role2,
141 );
142 }
143
1445537µs $seen{$name} = $attr;
145 }
146
1471959µs foreach my $attr (@all_attributes) {
14855136µs1103.57ms $c->add_attribute( $attr->clone );
# spent 2.24ms making 55 calls to Moose::Meta::Role::add_attribute, avg 41µs/call # spent 1.34ms making 55 calls to Moose::Meta::Role::Attribute::clone, avg 24µs/call
149 }
150}
151
152
# spent 32.8ms (3.23+29.5) within Moose::Meta::Role::Application::RoleSummation::apply_methods which was called 19 times, avg 1.72ms/call: # 19 times (3.23ms+29.5ms) by Moose::Meta::Role::Application::apply at line 60 of Moose/Meta/Role/Application.pm, avg 1.72ms/call
sub apply_methods {
153197µs my ($self, $c) = @_;
154
1556915µs my @all_methods = map {
156 my $role = $_;
1576972µs69962µs my $aliases = $self->get_method_aliases_for_role($role);
# spent 962µs making 69 calls to Moose::Meta::Role::Application::RoleSummation::get_method_aliases_for_role, avg 14µs/call
1586997µs69875µs my %excludes = map { $_ => undef } @{ $self->get_exclusions_for_role($role) };
# spent 875µs making 69 calls to Moose::Meta::Role::Application::RoleSummation::get_exclusions_for_role, avg 13µs/call
159 (
160221439µs2212.86ms (map {
# spent 2.86ms making 221 calls to Class::MOP::Mixin::HasMethods::get_method, avg 13µs/call
161221473µs22199µs exists $excludes{$_} ? () :
# spent 99µs making 221 calls to Class::MOP::Method::name, avg 448ns/call
162 +{
163 role => $role,
164 name => $_,
165 method => $role->get_method($_),
166 }
167290699µs290248µs } map { $_->name }
# spent 248µs making 290 calls to UNIVERSAL::isa, avg 857ns/call
168 grep { !$_->isa('Class::MOP::Method::Meta') }
169 $role->_get_local_methods),
170 (map {
17169368µs699.16ms +{
# spent 9.16ms making 69 calls to Class::MOP::Mixin::HasMethods::_get_local_methods, avg 133µs/call
172 role => $role,
173 name => $aliases->{$_},
174 method => $role->get_method($_),
175 }
176 } keys %$aliases)
177 );
1781993µs1915µs } @{$c->get_roles};
# spent 15µs making 19 calls to Moose::Meta::Role::get_roles, avg 811ns/call
179
180197µs my (%seen, %conflicts, %method_map);
1811919µs foreach my $method (@all_methods) {
18222150µs next if $conflicts{$method->{name}};
18322153µs my $seen = $seen{$method->{name}};
184
18522118µs if ($seen) {
186421µs85µs if ($seen->{method}->body != $method->{method}->body) {
# spent 5µs making 8 calls to Class::MOP::Method::body, avg 638ns/call
187431µs12209µs $c->add_conflicting_method(
# spent 207µs making 4 calls to Moose::Meta::Role::add_conflicting_method, avg 52µs/call # spent 2µs making 8 calls to Class::MOP::Package::name, avg 312ns/call
188 name => $method->{name},
189 roles => [$method->{role}->name, $seen->{role}->name],
190 );
191
19243µs delete $method_map{$method->{name}};
19342µs $conflicts{$method->{name}} = 1;
19443µs next;
195 }
196 }
197
19821781µs $seen{$method->{name}} = $method;
199217107µs $method_map{$method->{name}} = $method->{method};
200 }
201
20219368µs21315.1ms $c->add_method($_ => $method_map{$_}) for keys %method_map;
# spent 15.1ms making 213 calls to Moose::Meta::Role::Composite::add_method, avg 71µs/call
203}
204
205
# spent 1.17ms (548µs+617µs) within Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers which was called 19 times, avg 61µs/call: # 19 times (548µs+617µs) by Moose::Meta::Role::Application::apply at line 62 of Moose/Meta/Role/Application.pm, avg 61µs/call
sub apply_override_method_modifiers {
206199µs my ($self, $c) = @_;
207
2086912µs my @all_overrides = map {
209 my $role = $_;
2101522µs1550µs map {
# spent 50µs making 15 calls to Moose::Meta::Role::get_override_method_modifier, avg 3µs/call
2116985µs69351µs +{
# spent 351µs making 69 calls to Moose::Meta::Role::get_method_modifier_list, avg 5µs/call
212 name => $_,
213 method => $role->get_override_method_modifier($_),
214 }
215 } $role->get_method_modifier_list('override');
2161961µs1918µs } @{$c->get_roles};
# spent 18µs making 19 calls to Moose::Meta::Role::get_roles, avg 921ns/call
217
218194µs my %seen;
2191919µs foreach my $override (@all_overrides) {
2205196µs5123µs my @role_names = map { $_->name } @{$c->get_roles};
# spent 13µs making 36 calls to Class::MOP::Package::name, avg 350ns/call # spent 11µs making 15 calls to Moose::Meta::Role::get_roles, avg 720ns/call
2211518µs1550µs if ( $c->has_method($override->{name}) ){
# spent 50µs making 15 calls to Moose::Meta::Role::Composite::has_method, avg 3µs/call
222 throw_exception( OverrideConflictInSummation => role_names => \@role_names,
223 role_application => $self,
224 method_name => $override->{name}
225 );
226 }
227156µs if (exists $seen{$override->{name}}) {
228 if ( $seen{$override->{name}} != $override->{method} ) {
229 throw_exception( OverrideConflictInSummation => role_names => \@role_names,
230 role_application => $self,
231 method_name => $override->{name},
232 two_overrides_found => 1
233 );
234 }
235 }
2361515µs $seen{$override->{name}} = $override->{method};
237 }
238
239 $c->add_override_method_modifier(
240 $_->{name}, $_->{method}
2411980µs15125µs ) for @all_overrides;
# spent 125µs making 15 calls to Moose::Meta::Role::add_override_method_modifier, avg 8µs/call
242
243}
244
245
# spent 1.74ms (711µs+1.03) within Moose::Meta::Role::Application::RoleSummation::apply_method_modifiers which was called 57 times, avg 31µs/call: # 19 times (250µs+444µs) by Moose::Meta::Role::Application::apply_around_method_modifiers at line 79 of Moose/Meta/Role/Application.pm, avg 37µs/call # 19 times (277µs+292µs) by Moose::Meta::Role::Application::apply_before_method_modifiers at line 78 of Moose/Meta/Role/Application.pm, avg 30µs/call # 19 times (185µs+292µs) by Moose::Meta::Role::Application::apply_after_method_modifiers at line 80 of Moose/Meta/Role/Application.pm, avg 25µs/call
sub apply_method_modifiers {
2465718µs my ($self, $modifier_type, $c) = @_;
2475728µs my $add = "add_${modifier_type}_method_modifier";
2485722µs my $get = "get_${modifier_type}_method_modifiers";
249575.04ms5737µs foreach my $role (@{$c->get_roles}) {
# spent 37µs making 57 calls to Moose::Meta::Role::get_roles, avg 644ns/call
250207260µs207834µs foreach my $method_name ($role->get_method_modifier_list($modifier_type)) {
# spent 834µs making 207 calls to Moose::Meta::Role::get_method_modifier_list, avg 4µs/call
251 $c->$add(
252 $method_name,
253 $_
2541140µs22157µs ) foreach $role->$get($method_name);
# spent 110µs making 11 calls to Moose::Meta::Role::add_around_method_modifier, avg 10µs/call # spent 47µs making 11 calls to Moose::Meta::Role::get_around_method_modifiers, avg 4µs/call
255 }
256 }
257}
258
259
# spent 2.40ms (244µs+2.16) within Moose::Meta::Role::Application::RoleSummation::apply_overloading which was called 19 times, avg 126µs/call: # 19 times (244µs+2.16ms) by Moose::Meta::Role::Application::apply at line 58 of Moose/Meta/Role/Application.pm, avg 126µs/call
sub apply_overloading {
260199µs my ( $self, $c ) = @_;
261
26288149µs882.16ms my @overloaded_roles = grep { $_->is_overloaded } @{ $c->get_roles };
# spent 2.14ms making 69 calls to Class::MOP::Mixin::HasOverloads::is_overloaded, avg 31µs/call # spent 13µs making 19 calls to Moose::Meta::Role::get_roles, avg 705ns/call
2631943µs return unless @overloaded_roles;
264
265 my %fallback;
266 for my $role (@overloaded_roles) {
267 $fallback{ $role->name } = $role->get_overload_fallback_value;
268 }
269
270 for my $role_name ( keys %fallback ) {
271 for my $other_role_name ( grep { $_ ne $role_name } keys %fallback ) {
272 my @fb_values = @fallback{ $role_name, $other_role_name };
273 if ( all {defined} @fb_values ) {
274 next if $fallback{$role_name} eq $fallback{$other_role_name};
275 throw_exception(
276 'OverloadConflictInSummation',
277 role_names => [ $role_name, $other_role_name ],
278 role_application => $self,
279 overloaded_op => 'fallback',
280 );
281 }
282
283 next if all { !defined } @fb_values;
284 throw_exception(
285 'OverloadConflictInSummation',
286 role_names => [ $role_name, $other_role_name ],
287 role_application => $self,
288 overloaded_op => 'fallback',
289 );
290 }
291 }
292
293 if ( keys %fallback ) {
294 $c->set_overload_fallback_value( ( values %fallback )[0] );
295 }
296
297 my %overload_map;
298 for my $role (@overloaded_roles) {
299 for my $overload ( $role->get_all_overloaded_operators ) {
300 $overload_map{ $overload->operator }{ $role->name } = $overload;
301 }
302 }
303
304 for my $op_name ( keys %overload_map ) {
305 my @roles = keys %{ $overload_map{$op_name} };
306 my $overload = $overload_map{$op_name}{ $roles[0] };
307
308 if ( @roles > 1 && !all { $overload->_is_equal_to($_) }
309 values %{ $overload_map{$op_name} } ) {
310
311 throw_exception(
312 'OverloadConflictInSummation',
313 role_names => [ @roles[ 0, 1 ] ],
314 role_application => $self,
315 overloaded_op => $op_name,
316 );
317 }
318
319 $c->add_overloaded_operator(
320 $op_name => $overload_map{$op_name}{ $roles[0] } );
321 }
322}
323
32414µs1;
325
326# ABSTRACT: Combine two or more roles
327
328__END__