← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 22:00:36 2010
Reported on Wed Nov 17 22:10:07 2010

Filename/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm
StatementsExecuted 8449 statements in 116ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
5966318.2ms26.3msMoose::Meta::Role::::get_method_modifier_listMoose::Meta::Role::get_method_modifier_list
1414216.8ms1.82sMoose::Meta::Role::::applyMoose::Meta::Role::apply
82226.90ms319msMoose::Meta::Role::::initializeMoose::Meta::Role::initialize
42115.52ms397msMoose::Meta::Role::::createMoose::Meta::Role::create
68114.46ms7.10msMoose::Meta::Role::::add_roleMoose::Meta::Role::add_role
255622.60ms2.60msMoose::Meta::Role::::__ANON__[:302]Moose::Meta::Role::__ANON__[:302]
1112.60ms13.8msMoose::Meta::Role::::BEGIN@17Moose::Meta::Role::BEGIN@17
60332.52ms10.8msMoose::Meta::Role::::add_override_method_modifierMoose::Meta::Role::add_override_method_modifier
93332.46ms3.53msMoose::Meta::Role::::get_override_method_modifierMoose::Meta::Role::get_override_method_modifier
112222.38ms30.2msMoose::Meta::Role::::find_method_by_nameMoose::Meta::Role::find_method_by_name
42112.15ms399msMoose::Meta::Role::::create_anon_roleMoose::Meta::Role::create_anon_role
23442.05ms4.33msMoose::Meta::Role::::add_required_methodsMoose::Meta::Role::add_required_methods
24221.71ms9.88msMoose::Meta::Role::::add_attributeMoose::Meta::Role::add_attribute
170521.70ms1.70msMoose::Meta::Role::::__ANON__[:89]Moose::Meta::Role::__ANON__[:89]
1111.38ms7.33msMoose::Meta::Role::::BEGIN@19Moose::Meta::Role::BEGIN@19
48111.28ms1.81msMoose::Meta::Role::::has_override_method_modifierMoose::Meta::Role::has_override_method_modifier
1111.18ms6.42msMoose::Meta::Role::::BEGIN@20Moose::Meta::Role::BEGIN@20
111965µs1.47msMoose::Meta::Role::::BEGIN@18Moose::Meta::Role::BEGIN@18
8532896µs896µsMoose::Meta::Role::::__ANON__[:347]Moose::Meta::Role::__ANON__[:347]
8211822µs822µsMoose::Meta::Role::::_meta_method_classMoose::Meta::Role::_meta_method_class
8222797µs797µsMoose::Meta::Role::::__ANON__[:392]Moose::Meta::Role::__ANON__[:392]
1222755µs982µsMoose::Meta::Role::::calculate_all_rolesMoose::Meta::Role::calculate_all_roles (recurses: max depth 1, inclusive time 375µs)
311565µs73.4msMoose::Meta::Role::::combineMoose::Meta::Role::combine
2411521µs1.97msMoose::Meta::Role::::_attach_attributeMoose::Meta::Role::_attach_attribute
611426µs564µsMoose::Meta::Role::::does_roleMoose::Meta::Role::does_role
211161µs976µsMoose::Meta::Role::::add_conflicting_methodMoose::Meta::Role::add_conflicting_method
81186µs86µsMoose::Meta::Role::::_role_for_combinationMoose::Meta::Role::_role_for_combination
11170µs88µsMoose::Meta::Role::::BEGIN@4Moose::Meta::Role::BEGIN@4
11163µs296µsMoose::Meta::Role::::BEGIN@8Moose::Meta::Role::BEGIN@8
11162µs268µsMoose::Meta::Role::::BEGIN@9Moose::Meta::Role::BEGIN@9
11159µs1.30msMoose::Meta::Role::::BEGIN@10Moose::Meta::Role::BEGIN@10
11156µs133µsMoose::Meta::Role::::BEGIN@599Moose::Meta::Role::BEGIN@599
81150µs50µsMoose::Meta::Role::::composition_class_rolesMoose::Meta::Role::composition_class_roles
11148µs3.92msMoose::Meta::Role::::BEGIN@6Moose::Meta::Role::BEGIN@6
11145µs105µsMoose::Meta::Role::::BEGIN@621Moose::Meta::Role::BEGIN@621
11139µs104µsMoose::Meta::Role::::BEGIN@636Moose::Meta::Role::BEGIN@636
11139µs919µsMoose::Meta::Role::::BEGIN@22Moose::Meta::Role::BEGIN@22
11138µs633µsMoose::Meta::Role::::BEGIN@25Moose::Meta::Role::BEGIN@25
11138µs38µsMoose::Meta::Role::::BEGIN@21Moose::Meta::Role::BEGIN@21
11138µs104µsMoose::Meta::Role::::BEGIN@5Moose::Meta::Role::BEGIN@5
11130µs30µsMoose::Meta::Role::::BEGIN@16Moose::Meta::Role::BEGIN@16
11127µs27µsMoose::Meta::Role::::BEGIN@23Moose::Meta::Role::BEGIN@23
0000s0sMoose::Meta::Role::::DESTROYMoose::Meta::Role::DESTROY
0000s0sMoose::Meta::Role::::__ANON__[:101]Moose::Meta::Role::__ANON__[:101]
0000s0sMoose::Meta::Role::::__ANON__[:106]Moose::Meta::Role::__ANON__[:106]
0000s0sMoose::Meta::Role::::__ANON__[:111]Moose::Meta::Role::__ANON__[:111]
0000s0sMoose::Meta::Role::::__ANON__[:116]Moose::Meta::Role::__ANON__[:116]
0000s0sMoose::Meta::Role::::__ANON__[:121]Moose::Meta::Role::__ANON__[:121]
0000s0sMoose::Meta::Role::::__ANON__[:311]Moose::Meta::Role::__ANON__[:311]
0000s0sMoose::Meta::Role::::__ANON__[:319]Moose::Meta::Role::__ANON__[:319]
0000s0sMoose::Meta::Role::::__ANON__[:338]Moose::Meta::Role::__ANON__[:338]
0000s0sMoose::Meta::Role::::__ANON__[:96]Moose::Meta::Role::__ANON__[:96]
0000s0sMoose::Meta::Role::::_restore_metaobjects_fromMoose::Meta::Role::_restore_metaobjects_from
0000s0sMoose::Meta::Role::::consumersMoose::Meta::Role::consumers
0000s0sMoose::Meta::Role::::is_anon_roleMoose::Meta::Role::is_anon_role
0000s0sMoose::Meta::Role::::reinitializeMoose::Meta::Role::reinitialize
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Moose::Meta::Role;
3
43100µs2106µs
# spent 88µs (70+18) within Moose::Meta::Role::BEGIN@4 which was called: # once (70µs+18µs) by Moose::BEGIN@27 at line 4
use strict;
# spent 88µs making 1 call to Moose::Meta::Role::BEGIN@4 # spent 19µs making 1 call to strict::import
5393µs2171µs
# spent 104µs (38+66) within Moose::Meta::Role::BEGIN@5 which was called: # once (38µs+66µs) by Moose::BEGIN@27 at line 5
use warnings;
# spent 104µs making 1 call to Moose::Meta::Role::BEGIN@5 # spent 66µs making 1 call to warnings::import
63206µs27.80ms
# spent 3.92ms (48µs+3.88) within Moose::Meta::Role::BEGIN@6 which was called: # once (48µs+3.88ms) by Moose::BEGIN@27 at line 6
use metaclass;
# spent 3.92ms making 1 call to Moose::Meta::Role::BEGIN@6 # spent 3.88ms making 1 call to metaclass::import
7
83181µs2530µs
# spent 296µs (63+234) within Moose::Meta::Role::BEGIN@8 which was called: # once (63µs+234µs) by Moose::BEGIN@27 at line 8
use Scalar::Util 'blessed';
# spent 296µs making 1 call to Moose::Meta::Role::BEGIN@8 # spent 234µs making 1 call to Exporter::import
93181µs2474µs
# spent 268µs (62+206) within Moose::Meta::Role::BEGIN@9 which was called: # once (62µs+206µs) by Moose::BEGIN@27 at line 9
use Carp 'confess';
# spent 268µs making 1 call to Moose::Meta::Role::BEGIN@9 # spent 206µs making 1 call to Exporter::import
103296µs22.54ms
# spent 1.30ms (59µs+1.24) within Moose::Meta::Role::BEGIN@10 which was called: # once (59µs+1.24ms) by Moose::BEGIN@27 at line 10
use Devel::GlobalDestruction 'in_global_destruction';
# spent 1.30ms making 1 call to Moose::Meta::Role::BEGIN@10 # spent 1.24ms making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
11
1215µsour $VERSION = '1.19';
13174µs$VERSION = eval $VERSION;
# spent 11µs executing statements in string eval
1414µsour $AUTHORITY = 'cpan:STEVAN';
15
163128µs130µs
# spent 30µs within Moose::Meta::Role::BEGIN@16 which was called: # once (30µs+0s) by Moose::BEGIN@27 at line 16
use Moose::Meta::Class;
# spent 30µs making 1 call to Moose::Meta::Role::BEGIN@16
173502µs113.8ms
# spent 13.8ms (2.60+11.2) within Moose::Meta::Role::BEGIN@17 which was called: # once (2.60ms+11.2ms) by Moose::BEGIN@27 at line 17
use Moose::Meta::Role::Attribute;
# spent 13.8ms making 1 call to Moose::Meta::Role::BEGIN@17
183878µs11.47ms
# spent 1.47ms (965µs+502µs) within Moose::Meta::Role::BEGIN@18 which was called: # once (965µs+502µs) by Moose::BEGIN@27 at line 18
use Moose::Meta::Role::Method;
# spent 1.47ms making 1 call to Moose::Meta::Role::BEGIN@18
193530µs17.33ms
# spent 7.33ms (1.38+5.95) within Moose::Meta::Role::BEGIN@19 which was called: # once (1.38ms+5.95ms) by Moose::BEGIN@27 at line 19
use Moose::Meta::Role::Method::Required;
# spent 7.33ms making 1 call to Moose::Meta::Role::BEGIN@19
203508µs16.42ms
# spent 6.42ms (1.18+5.24) within Moose::Meta::Role::BEGIN@20 which was called: # once (1.18ms+5.24ms) by Moose::BEGIN@27 at line 20
use Moose::Meta::Role::Method::Conflicting;
# spent 6.42ms making 1 call to Moose::Meta::Role::BEGIN@20
213119µs138µs
# spent 38µs within Moose::Meta::Role::BEGIN@21 which was called: # once (38µs+0s) by Moose::BEGIN@27 at line 21
use Moose::Meta::Method::Meta;
# spent 38µs making 1 call to Moose::Meta::Role::BEGIN@21
223136µs21.80ms
# spent 919µs (39+880) within Moose::Meta::Role::BEGIN@22 which was called: # once (39µs+880µs) by Moose::BEGIN@27 at line 22
use Moose::Util qw( ensure_all_roles );
# spent 919µs making 1 call to Moose::Meta::Role::BEGIN@22 # spent 880µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
233110µs127µs
# spent 27µs within Moose::Meta::Role::BEGIN@23 which was called: # once (27µs+0s) by Moose::BEGIN@27 at line 23
use Class::MOP::MiniTrait;
# spent 27µs making 1 call to Moose::Meta::Role::BEGIN@23
24
251594µs
# spent 633µs (38+594) within Moose::Meta::Role::BEGIN@25 which was called: # once (38µs+594µs) by Moose::BEGIN@27 at line 27
use base 'Class::MOP::Module',
# spent 594µs making 1 call to base::import
26 'Class::MOP::Mixin::HasAttributes',
2738.56ms1633µs 'Class::MOP::Mixin::HasMethods';
# spent 633µs making 1 call to Moose::Meta::Role::BEGIN@25
28
29114µs16.90msClass::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
# spent 6.90ms making 1 call to Class::MOP::MiniTrait::apply
30
31## ------------------------------------------------------------------
32## NOTE:
33## I normally don't do this, but I am doing
34## a whole bunch of meta-programmin in this
35## module, so it just makes sense. For a clearer
36## picture of what is going on in the next
37## several lines of code, look at the really
38## big comment at the end of this file (right
39## before the POD).
40## - SL
41## ------------------------------------------------------------------
42
43114µs190µsmy $META = __PACKAGE__->meta;
# spent 90µs making 1 call to Moose::Meta::Role::meta
44
45## ------------------------------------------------------------------
46## attributes ...
47
48# NOTE:
49# since roles are lazy, we hold all the attributes
50# of the individual role in 'statis' until which
51# time when it is applied to a class. This means
52# keeping a lot of things in hash maps, so we are
53# using a little of that meta-programmin' magic
54# here an saving lots of extra typin. And since
55# many of these attributes above require similar
56# functionality to support them, so we again use
57# the wonders of meta-programmin' to deliver a
58# very compact solution to this normally verbose
59# problem.
60# - SL
61
62149µsforeach my $action (
63 {
64 name => 'excluded_roles_map',
65 attr_reader => 'get_excluded_roles_map' ,
66 methods => {
67 add => 'add_excluded_roles',
68 get_keys => 'get_excluded_roles_list',
69 existence => 'excludes_role',
70 }
71 },
72 {
73 name => 'required_methods',
74 attr_reader => 'get_required_methods_map',
75 methods => {
76 remove => 'remove_required_methods',
77 get_values => 'get_required_method_list',
78 existence => 'requires_method',
79 }
80 },
81) {
82
83210µs my $attr_reader = $action->{attr_reader};
8425µs my $methods = $action->{methods};
85
86 # create the attribute
87 $META->add_attribute($action->{name} => (
88 reader => $attr_reader,
891702.25ms
# spent 1.70ms within Moose::Meta::Role::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm:89] which was called 170 times, avg 10µs/call: # 88 times (979µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 43 of Class/MOP/Mixin/AttributeCore.pm, avg 11µs/call # 38 times (337µs+0s) by Moose::Meta::Role::_new at line 111 of generated method (unknown origin), avg 9µs/call # 38 times (333µs+0s) by Moose::Meta::Role::_new at line 81 of generated method (unknown origin), avg 9µs/call # 3 times (26µs+0s) by Moose::Meta::Role::Composite::_new at line 87 of generated method (unknown origin), avg 9µs/call # 3 times (25µs+0s) by Moose::Meta::Role::Composite::_new at line 120 of generated method (unknown origin), avg 8µs/call
default => sub { {} }
90240µs24.01ms ));
# spent 4.01ms making 2 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 2.00ms/call
91
92 # create some helper methods
93 $META->add_method($methods->{add} => sub {
94976µs my ($self, @values) = @_;
95 $self->$attr_reader->{$_} = undef foreach @values;
96229µs1323µs }) if exists $methods->{add};
# spent 323µs making 1 call to Class::MOP::Mixin::HasMethods::add_method
97
98 $META->add_method($methods->{get_keys} => sub {
992983.82ms my ($self) = @_;
1001491.82ms keys %{$self->$attr_reader};
# spent 1.82ms making 149 calls to Moose::Meta::Role::get_excluded_roles_map, avg 12µs/call
101224µs1266µs }) if exists $methods->{get_keys};
# spent 266µs making 1 call to Class::MOP::Mixin::HasMethods::add_method
102
103 $META->add_method($methods->{get_values} => sub {
1042983.83ms my ($self) = @_;
1051491.91ms values %{$self->$attr_reader};
# spent 1.91ms making 149 calls to Moose::Meta::Role::get_required_methods_map, avg 13µs/call
106227µs1294µs }) if exists $methods->{get_values};
# spent 294µs making 1 call to Class::MOP::Mixin::HasMethods::add_method
107
108 $META->add_method($methods->{get} => sub {
109 my ($self, $name) = @_;
110 $self->$attr_reader->{$name}
11126µs }) if exists $methods->{get};
112
113 $META->add_method($methods->{existence} => sub {
1142884.02ms my ($self, $name) = @_;
1151441.95ms exists $self->$attr_reader->{$name} ? 1 : 0;
# spent 1.95ms making 144 calls to Moose::Meta::Role::get_excluded_roles_map, avg 14µs/call
116240µs2556µs }) if exists $methods->{existence};
# spent 556µs making 2 calls to Class::MOP::Mixin::HasMethods::add_method, avg 278µs/call
117
118 $META->add_method($methods->{remove} => sub {
119 my ($self, @values) = @_;
120 delete $self->$attr_reader->{$_} foreach @values;
121235µs1285µs }) if exists $methods->{remove};
# spent 285µs making 1 call to Class::MOP::Mixin::HasMethods::add_method
122}
123
124$META->add_attribute(
125113µs11.93ms 'method_metaclass',
# spent 1.93ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
126 reader => 'method_metaclass',
127 default => 'Moose::Meta::Role::Method',
128);
129
130114µs11.91ms$META->add_attribute(
# spent 1.91ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
131 'required_method_metaclass',
132 reader => 'required_method_metaclass',
133 default => 'Moose::Meta::Role::Method::Required',
134);
135
136114µs11.85ms$META->add_attribute(
# spent 1.85ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
137 'conflicting_method_metaclass',
138 reader => 'conflicting_method_metaclass',
139 default => 'Moose::Meta::Role::Method::Conflicting',
140);
141
142113µs12.14ms$META->add_attribute(
# spent 2.14ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
143 'application_to_class_class',
144 reader => 'application_to_class_class',
145 default => 'Moose::Meta::Role::Application::ToClass',
146);
147
148113µs11.96ms$META->add_attribute(
# spent 1.96ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
149 'application_to_role_class',
150 reader => 'application_to_role_class',
151 default => 'Moose::Meta::Role::Application::ToRole',
152);
153
154113µs12.02ms$META->add_attribute(
# spent 2.02ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
155 'application_to_instance_class',
156 reader => 'application_to_instance_class',
157 default => 'Moose::Meta::Role::Application::ToInstance',
158);
159
160114µs11.89ms$META->add_attribute(
# spent 1.89ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
161 'applied_attribute_metaclass',
162 reader => 'applied_attribute_metaclass',
163 default => 'Moose::Meta::Attribute',
164);
165
166# More or less copied from Moose::Meta::Class
167
# spent 319ms (6.90+312) within Moose::Meta::Role::initialize which was called 82 times, avg 3.89ms/call: # 42 times (3.94ms+274ms) by Moose::Meta::Role::create at line 543, avg 6.61ms/call # 40 times (2.96ms+38.2ms) by Moose::Role::init_meta at line 131 of Moose/Role.pm, avg 1.03ms/call
sub initialize {
1685746.41ms my $class = shift;
169 my $pkg = shift;
170
17182695µs if (defined(my $meta = Class::MOP::get_metaclass_by_name($pkg))) {
# spent 695µs making 82 calls to Class::MOP::get_metaclass_by_name, avg 8µs/call
172 return $meta;
173 }
174
175 my %options = @_;
176
17782310ms my $meta = $class->SUPER::initialize(
# spent 310ms making 82 calls to Class::MOP::Package::initialize, avg 3.78ms/call
178 $pkg,
179 'attribute_metaclass' => 'Moose::Meta::Role::Attribute',
180 %options,
181 );
182
183421.27ms Class::MOP::weaken_metaclass($pkg) if $options{weaken};
# spent 1.27ms making 42 calls to Class::MOP::weaken_metaclass, avg 30µs/call
184
185 return $meta;
186}
187
188sub reinitialize {
189 my $self = shift;
190 my $pkg = shift;
191
192 my $meta = blessed $pkg ? $pkg : Class::MOP::class_of($pkg);
193
194 my %existing_classes;
195 if ($meta) {
196 %existing_classes = map { $_ => $meta->$_() } qw(
197 attribute_metaclass
198 method_metaclass
199 wrapped_method_metaclass
200 required_method_metaclass
201 conflicting_method_metaclass
202 application_to_class_class
203 application_to_role_class
204 application_to_instance_class
205 applied_attribute_metaclass
206 );
207 }
208
209 my %options = @_;
210 $options{weaken} = Class::MOP::metaclass_is_weak($meta->name)
211 if !exists $options{weaken}
212 && blessed($meta)
213 && $meta->isa('Moose::Meta::Role');
214
215 # don't need to remove generated metaobjects here yet, since we don't
216 # yet generate anything in roles. this may change in the future though...
217 # keep an eye on that
218 my $new_meta = $self->SUPER::reinitialize(
219 $pkg,
220 %existing_classes,
221 %options,
222 );
223 $new_meta->_restore_metaobjects_from($meta)
224 if $meta && $meta->isa('Moose::Meta::Role');
225 return $new_meta;
226}
227
228sub _restore_metaobjects_from {
229 my $self = shift;
230 my ($old_meta) = @_;
231
232 $self->_restore_metamethods_from($old_meta);
233 $self->_restore_metaattributes_from($old_meta);
234}
235
236
# spent 9.88ms (1.71+8.17) within Moose::Meta::Role::add_attribute which was called 24 times, avg 412µs/call: # 15 times (970µs+4.33ms) by Moose::Meta::Role::Application::ToRole::apply_attributes at line 71 of Moose/Meta/Role/Application/ToRole.pm, avg 353µs/call # 9 times (740µs+3.84ms) by Moose::Role::has at line 47 of Moose/Role.pm, avg 509µs/call
sub add_attribute {
237722.09ms my $self = shift;
238
23972379µs if (blessed $_[0] && ! $_[0]->isa('Moose::Meta::Role::Attribute') ) {
# spent 240µs making 48 calls to Scalar::Util::blessed, avg 5µs/call # spent 92µs making 15 calls to UNIVERSAL::isa, avg 6µs/call # spent 48µs making 9 calls to Moose::Meta::Role::CORE:match, avg 5µs/call
240 my $class = ref $_[0];
241 Moose->throw_error( "Cannot add a $class as an attribute to a role" );
242 }
243 elsif (!blessed($_[0]) && defined($_[0]) && $_[0] =~ /^\+(.*)/) {
244 Moose->throw_error( "has '+attr' is not supported in roles" );
245 }
246
247247.79ms return $self->SUPER::add_attribute(@_);
# spent 7.79ms making 24 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 325µs/call
248}
249
250
# spent 1.97ms (521µs+1.45) within Moose::Meta::Role::_attach_attribute which was called 24 times, avg 82µs/call: # 24 times (521µs+1.45ms) by Class::MOP::Mixin::HasAttributes::add_attribute at line 25 of Class/MOP/Mixin/HasAttributes.pm, avg 82µs/call
sub _attach_attribute {
25148516µs my ( $self, $attribute ) = @_;
252
253241.45ms $attribute->attach_to_role($self);
# spent 1.45ms making 24 calls to Moose::Meta::Role::Attribute::attach_to_role, avg 61µs/call
254}
255
256
# spent 4.33ms (2.05+2.28) within Moose::Meta::Role::add_required_methods which was called 23 times, avg 188µs/call: # 9 times (1.04ms+1.77ms) by Moose::Role::requires at line 32 of Moose/Role.pm, avg 312µs/call # 9 times (571µs+284µs) by Moose::Meta::Role::Application::ToRole::check_required_methods at line 43 of Moose/Meta/Role/Application/ToRole.pm, avg 95µs/call # 3 times (295µs+157µs) by Moose::Meta::Role::Application::RoleSummation::check_required_methods at line 109 of Moose/Meta/Role/Application/RoleSummation.pm, avg 151µs/call # 2 times (144µs+69µs) by Moose::Meta::Role::add_conflicting_method at line 281, avg 106µs/call
sub add_required_methods {
2571242.07ms my $self = shift;
258
259 for (@_) {
260 my $method = $_;
261461.53ms if (!blessed($method)) {
# spent 1.22ms making 10 calls to Moose::Meta::Role::Method::Required::new, avg 122µs/call # spent 156µs making 10 calls to Moose::Meta::Role::required_method_metaclass, avg 16µs/call # spent 148µs making 26 calls to Scalar::Util::blessed, avg 6µs/call
262 $method = $self->required_method_metaclass->new(
263 name => $method,
264 );
265 }
26652752µs $self->get_required_methods_map->{$method->name} = $method;
# spent 386µs making 26 calls to Moose::Meta::Role::get_required_methods_map, avg 15µs/call # spent 367µs making 26 calls to Moose::Meta::Role::Method::Required::name, avg 14µs/call
267 }
268}
269
270
# spent 976µs (161+816) within Moose::Meta::Role::add_conflicting_method which was called 2 times, avg 488µs/call: # 2 times (161µs+816µs) by Moose::Meta::Role::Application::RoleSummation::apply_methods at line 186 of Moose/Meta/Role/Application/RoleSummation.pm, avg 488µs/call
sub add_conflicting_method {
27110139µs my $self = shift;
272
273 my $method;
274 if (@_ == 1 && blessed($_[0])) {
275 $method = shift;
276 }
277 else {
2784603µs $method = $self->conflicting_method_metaclass->new(@_);
# spent 569µs making 2 calls to Moose::Meta::Role::Method::Required::new, avg 284µs/call # spent 34µs making 2 calls to Moose::Meta::Role::conflicting_method_metaclass, avg 17µs/call
279 }
280
2812213µs $self->add_required_methods($method);
# spent 213µs making 2 calls to Moose::Meta::Role::add_required_methods, avg 106µs/call
282}
283
284## ------------------------------------------------------------------
285## method modifiers
286
287# NOTE:
288# the before/around/after method modifiers are
289# stored by name, but there can be many methods
290# then associated with that name. So again we have
291# lots of similar functionality, so we can do some
292# meta-programmin' and save some time.
293# - SL
294
29517µsforeach my $modifier_type (qw[ before around after ]) {
296
297321µs my $attr_reader = "get_${modifier_type}_method_modifiers_map";
298
299 # create the attribute ...
300 $META->add_attribute("${modifier_type}_method_modifiers" => (
301 reader => $attr_reader,
3022553.22ms
# spent 2.60ms within Moose::Meta::Role::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm:302] which was called 255 times, avg 10µs/call: # 132 times (1.42ms+0s) by Class::MOP::Mixin::AttributeCore::default at line 43 of Class/MOP/Mixin/AttributeCore.pm, avg 11µs/call # 41 times (450µs+0s) by Moose::Meta::Role::Composite::_new or Moose::Meta::Role::_new at line 18 of generated method (unknown origin), avg 11µs/call # 38 times (366µs+0s) by Moose::Meta::Role::_new at line 69 of generated method (unknown origin), avg 10µs/call # 38 times (318µs+0s) by Moose::Meta::Role::_new at line 48 of generated method (unknown origin), avg 8µs/call # 3 times (26µs+0s) by Moose::Meta::Role::Composite::_new at line 54 of generated method (unknown origin), avg 9µs/call # 3 times (25µs+0s) by Moose::Meta::Role::Composite::_new at line 75 of generated method (unknown origin), avg 8µs/call
default => sub { {} }
3033123µs35.90ms ));
# spent 5.90ms making 3 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 1.97ms/call
304
305 # and some helper methods ...
306 $META->add_method("get_${modifier_type}_method_modifiers" => sub {
3074174.39ms my ($self, $method_name) = @_;
308 #return () unless exists $self->$attr_reader->{$method_name};
3091391.59ms my $mm = $self->$attr_reader->{$method_name};
# spent 1.25ms making 107 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 12µs/call # spent 228µs making 21 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 11µs/call # spent 113µs making 11 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 10µs/call
310 $mm ? @$mm : ();
311381µs3879µs });
# spent 879µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 293µs/call
312
313 $META->add_method("has_${modifier_type}_method_modifiers" => sub {
314 my ($self, $method_name) = @_;
315 # NOTE:
316 # for now we assume that if it exists,..
317 # it has at least one modifier in it
318 (exists $self->$attr_reader->{$method_name}) ? 1 : 0;
319369µs3853µs });
# spent 853µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 284µs/call
320
321 $META->add_method("add_${modifier_type}_method_modifier" => sub {
3224505.43ms my ($self, $method_name, $method) = @_;
323
3241801.94ms $self->$attr_reader->{$method_name} = []
# spent 1.50ms making 140 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 11µs/call # spent 291µs making 26 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 11µs/call # spent 152µs making 14 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 11µs/call
325 unless exists $self->$attr_reader->{$method_name};
326
32790969µs my $modifiers = $self->$attr_reader->{$method_name};
# spent 736µs making 70 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 11µs/call # spent 135µs making 13 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 10µs/call # spent 98µs making 7 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 14µs/call
328
329 # NOTE:
330 # check to see that we aren't adding the
331 # same code twice. We err in favor of the
332 # first on here, this may not be as expected
333 foreach my $modifier (@{$modifiers}) {
334 return if $modifier == $method;
335 }
336
337 push @{$modifiers} => $method;
338382µs3843µs });
# spent 843µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 281µs/call
339
340}
341
342## ------------------------------------------------------------------
343## override method mofidiers
344
345$META->add_attribute('override_method_modifiers' => (
346 reader => 'get_override_method_modifiers_map',
347851.10ms
# spent 896µs within Moose::Meta::Role::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm:347] which was called 85 times, avg 11µs/call: # 44 times (516µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 43 of Class/MOP/Mixin/AttributeCore.pm, avg 12µs/call # 38 times (352µs+0s) by Moose::Meta::Role::_new at line 96 of generated method (unknown origin), avg 9µs/call # 3 times (28µs+0s) by Moose::Meta::Role::Composite::_new at line 105 of generated method (unknown origin), avg 9µs/call
default => sub { {} }
348119µs11.95ms));
# spent 1.95ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
349
350# NOTE:
351# these are a little different because there
352# can only be one per name, whereas the other
353# method modifiers can have multiples.
354# - SL
355
356
# spent 10.8ms (2.52+8.31) within Moose::Meta::Role::add_override_method_modifier which was called 60 times, avg 181µs/call: # 48 times (2.00ms+7.41ms) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 163 of Moose/Meta/Role/Application/ToRole.pm, avg 196µs/call # 9 times (362µs+388µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 237 of Moose/Meta/Role/Application/RoleSummation.pm, avg 83µs/call # 3 times (160µs+521µs) by Moose::Role::override at line 77 of Moose/Role.pm, avg 227µs/call
sub add_override_method_modifier {
3571802.27ms my ($self, $method_name, $method) = @_;
358607.58ms (!$self->has_method($method_name))
# spent 7.29ms making 51 calls to Class::MOP::Mixin::HasMethods::has_method, avg 143µs/call # spent 290µs making 9 calls to Moose::Meta::Role::Composite::has_method, avg 32µs/call
359 || Moose->throw_error("Cannot add an override of method '$method_name' " .
360 "because there is a local version of '$method_name'");
36160735µs $self->get_override_method_modifiers_map->{$method_name} = $method;
# spent 735µs making 60 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 12µs/call
362}
363
364
# spent 1.81ms (1.28+532µs) within Moose::Meta::Role::has_override_method_modifier which was called 48 times, avg 38µs/call: # 48 times (1.28ms+532µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 152 of Moose/Meta/Role/Application/ToRole.pm, avg 38µs/call
sub has_override_method_modifier {
365961.17ms my ($self, $method_name) = @_;
366 # NOTE:
367 # for now we assume that if it exists,..
368 # it has at least one modifier in it
36948532µs (exists $self->get_override_method_modifiers_map->{$method_name}) ? 1 : 0;
# spent 532µs making 48 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 11µs/call
370}
371
372
# spent 3.53ms (2.46+1.07) within Moose::Meta::Role::get_override_method_modifier which was called 93 times, avg 38µs/call: # 48 times (1.21ms+516µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 163 of Moose/Meta/Role/Application/ToRole.pm, avg 36µs/call # 36 times (1.03ms+462µs) by Moose::Meta::Role::Application::ToClass::apply_override_method_modifiers at line 205 of Moose/Meta/Role/Application/ToClass.pm, avg 41µs/call # 9 times (220µs+89µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 208 of Moose/Meta/Role/Application/RoleSummation.pm, avg 34µs/call
sub get_override_method_modifier {
3731862.31ms my ($self, $method_name) = @_;
374931.07ms $self->get_override_method_modifiers_map->{$method_name};
# spent 1.07ms making 93 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 11µs/call
375}
376
377## general list accessor ...
378
379
# spent 26.3ms (18.2+8.11) within Moose::Meta::Role::get_method_modifier_list which was called 596 times, avg 44µs/call: # 219 times (6.53ms+3.08ms) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 217 of Moose/Meta/Role/Application/ToClass.pm, avg 44µs/call # 204 times (5.98ms+2.73ms) by Moose::Meta::Role::Application::ToRole::apply_method_modifiers at line 176 of Moose/Meta/Role/Application/ToRole.pm, avg 43µs/call # 73 times (2.47ms+992µs) by Moose::Meta::Role::Application::ToClass::apply_override_method_modifiers at line 195 of Moose/Meta/Role/Application/ToClass.pm, avg 47µs/call # 68 times (2.31ms+964µs) by Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers at line 136 of Moose/Meta/Role/Application/ToRole.pm, avg 48µs/call # 24 times (685µs+263µs) by Moose::Meta::Role::Application::RoleSummation::apply_method_modifiers at line 246 of Moose/Meta/Role/Application/RoleSummation.pm, avg 40µs/call # 8 times (243µs+88µs) by Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers at line 209 of Moose/Meta/Role/Application/RoleSummation.pm, avg 41µs/call
sub get_method_modifier_list {
380178817.8ms my ($self, $modifier_type) = @_;
381 my $accessor = "get_${modifier_type}_method_modifiers_map";
3825968.11ms keys %{$self->$accessor};
# spent 2.10ms making 149 calls to Moose::Meta::Role::get_before_method_modifiers_map, avg 14µs/call # spent 2.04ms making 149 calls to Moose::Meta::Role::get_override_method_modifiers_map, avg 14µs/call # spent 2.01ms making 149 calls to Moose::Meta::Role::get_around_method_modifiers_map, avg 13µs/call # spent 1.96ms making 149 calls to Moose::Meta::Role::get_after_method_modifiers_map, avg 13µs/call
383}
384
385821.01ms
# spent 822µs within Moose::Meta::Role::_meta_method_class which was called 82 times, avg 10µs/call: # 82 times (822µs+0s) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 28 of Class/MOP/Mixin/HasMethods.pm, avg 10µs/call
sub _meta_method_class { 'Moose::Meta::Method::Meta' }
386
387## ------------------------------------------------------------------
388## subroles
389
390$META->add_attribute('roles' => (
391 reader => 'get_roles',
392821.02ms
# spent 797µs within Moose::Meta::Role::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Role.pm:392] which was called 82 times, avg 10µs/call: # 44 times (440µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 43 of Class/MOP/Mixin/AttributeCore.pm, avg 10µs/call # 38 times (357µs+0s) by Moose::Meta::Role::_new at line 117 of generated method (unknown origin), avg 9µs/call
default => sub { [] }
393120µs11.89ms));
# spent 1.89ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
394
395
# spent 7.10ms (4.46+2.64) within Moose::Meta::Role::add_role which was called 68 times, avg 104µs/call: # 68 times (4.46ms+2.64ms) by Moose::Meta::Role::Application::ToRole::apply at line 18 of Moose/Meta/Role/Application/ToRole.pm, avg 104µs/call
sub add_role {
3962725.13ms my ($self, $role) = @_;
397136943µs (blessed($role) && $role->isa('Moose::Meta::Role'))
# spent 527µs making 68 calls to Scalar::Util::blessed, avg 8µs/call # spent 416µs making 68 calls to UNIVERSAL::isa, avg 6µs/call
398 || Moose->throw_error("Roles must be instances of Moose::Meta::Role");
39968933µs push @{$self->get_roles} => $role;
# spent 933µs making 68 calls to Moose::Meta::Role::get_roles, avg 14µs/call
40068761µs $self->reset_package_cache_flag;
# spent 761µs making 68 calls to Class::MOP::Mixin::HasMethods::reset_package_cache_flag, avg 11µs/call
401}
402
403
# spent 982µs (755+227) within Moose::Meta::Role::calculate_all_roles which was called 12 times, avg 82µs/call: # 6 times (480µs+502µs) by Moose::Meta::Class::calculate_all_roles at line 200 of Moose/Meta/Class.pm, avg 164µs/call # 6 times (276µs+-276µs) by Moose::Meta::Role::calculate_all_roles at line 407, avg 0s/call
sub calculate_all_roles {
40460816µs my $self = shift;
405 my %seen;
4061896µs grep {
# spent 96µs making 18 calls to Class::MOP::Package::name, avg 5µs/call
40760s !$seen{$_->name}++
# spent 375µs making 6 calls to Moose::Meta::Role::calculate_all_roles, avg 63µs/call, recursion: max depth 1, sum of overlapping time 375µs
408 } ($self, map {
409 $_->calculate_all_roles
41012130µs } @{ $self->get_roles });
# spent 130µs making 12 calls to Moose::Meta::Role::get_roles, avg 11µs/call
411}
412
413
# spent 564µs (426+138) within Moose::Meta::Role::does_role which was called 6 times, avg 94µs/call: # 6 times (426µs+138µs) by Moose::Meta::Class::does_role at line 227 of Moose/Meta/Class.pm, avg 94µs/call
sub does_role {
41436488µs my ($self, $role) = @_;
415 (defined $role)
416 || Moose->throw_error("You must supply a role name to look for");
417628µs my $role_name = blessed $role ? $role->name : $role;
# spent 28µs making 6 calls to Scalar::Util::blessed, avg 5µs/call
418 # if we are it,.. then return true
419636µs return 1 if $role_name eq $self->name;
# spent 36µs making 6 calls to Class::MOP::Package::name, avg 6µs/call
420 # otherwise.. check our children
421674µs foreach my $role (@{$self->get_roles}) {
# spent 74µs making 6 calls to Moose::Meta::Role::get_roles, avg 12µs/call
422 return 1 if $role->does_role($role_name);
423 }
424 return 0;
425}
426
4271122.27ms11227.8ms
# spent 30.2ms (2.38+27.8) within Moose::Meta::Role::find_method_by_name which was called 112 times, avg 269µs/call: # 82 times (1.73ms+14.3ms) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 23 of Class/MOP/Mixin/HasMethods.pm, avg 195µs/call # 30 times (655µs+13.5ms) by Moose::Meta::Role::Application::ToRole::check_required_methods at line 43 of Moose/Meta/Role/Application/ToRole.pm, avg 472µs/call
sub find_method_by_name { (shift)->get_method(@_) }
# spent 27.8ms making 112 calls to Class::MOP::Mixin::HasMethods::get_method, avg 248µs/call
428
429## ------------------------------------------------------------------
430## role construction
431## ------------------------------------------------------------------
432
433
# spent 1.82s (16.8ms+1.80) within Moose::Meta::Role::apply which was called 141 times, avg 12.9ms/call: # 54 times (6.58ms+1.23s) by Moose::Util::_apply_all_roles at line 137 of Moose/Util.pm, avg 22.8ms/call # 42 times (5.04ms+379ms) by MooseX::Role::Parameterized::Meta::Role::Parameterizable::apply at line 121 of MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm, avg 9.13ms/call # 42 times (4.83ms+123ms) by MooseX::Role::Parameterized::Meta::Role::Parameterizable::apply_parameterizable_role at line 127 of MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm, avg 3.04ms/call # 3 times (352µs+70.6ms) by Moose::Util::_apply_all_roles at line 140 of Moose/Util.pm, avg 23.6ms/call
sub apply {
434155119.0ms my ($self, $other, %args) = @_;
435
436141940µs (blessed($other))
# spent 940µs making 141 calls to Scalar::Util::blessed, avg 7µs/call
437 || Moose->throw_error("You must pass in an blessed instance");
438
439 my $application_class;
4403553.99ms if ($other->isa('Moose::Meta::Role')) {
# spent 1.67ms making 214 calls to UNIVERSAL::isa, avg 8µs/call # spent 1.18ms making 73 calls to Moose::Meta::Role::application_to_class_class, avg 16µs/call # spent 1.14ms making 68 calls to Moose::Meta::Role::application_to_role_class, avg 17µs/call
441 $application_class = $self->application_to_role_class;
442 }
443 elsif ($other->isa('Moose::Meta::Class')) {
444 $application_class = $self->application_to_class_class;
445 }
446 else {
447 $application_class = $self->application_to_instance_class;
448 }
449
45014127.8ms Class::MOP::load_class($application_class);
# spent 34.0ms making 141 calls to Class::MOP::load_class, avg 241µs/call, recursion: max depth 3, sum of overlapping time 6.21ms
451
452 my $deprecation_check = 0;
453
454 if ( exists $args{excludes} && !exists $args{'-excludes'} ) {
455 $args{'-excludes'} = delete $args{excludes};
456 $deprecation_check = 1;
457 }
458 if ( exists $args{alias} && !exists $args{'-alias'} ) {
459 $args{'-alias'} = delete $args{alias};
460 $deprecation_check = 1;
461 }
462
463 if ( $deprecation_check ) {
464 Moose::Deprecated::deprecated(
465 feature => 'alias or excludes',
466 message =>
467 'The alias and excludes options for role application'.
468 ' have been renamed -alias and -excludes'.
469 " (${\$other->name} is consuming ${\$self->name}".
470 " - do you need to upgrade ${\$other->name}?)"
471 );
472 }
473
474 if ( exists $args{'-excludes'} ) {
475 # I wish we had coercion here :)
476 $args{'-excludes'} = (
477 ref $args{'-excludes'} eq 'ARRAY'
478 ? $args{'-excludes'}
479 : [ $args{'-excludes'} ]
480 );
481 }
482
4832821.76s return $application_class->new(%args)->apply($self, $other, \%args);
# spent 1.21s making 73 calls to Moose::Meta::Role::Application::ToClass::apply, avg 16.6ms/call # spent 530ms making 68 calls to Moose::Meta::Role::Application::ToRole::apply, avg 7.80ms/call # spent 21.0ms making 141 calls to Moose::Meta::Role::Application::new, avg 149µs/call
484}
485
486881µs
# spent 50µs within Moose::Meta::Role::composition_class_roles which was called 8 times, avg 6µs/call: # 8 times (50µs+0s) by Moose::Meta::Role::Composite::new at line 50 of Moose/Meta/Role/Composite.pm, avg 6µs/call
sub composition_class_roles { }
487
488
# spent 73.4ms (565µs+72.8) within Moose::Meta::Role::combine which was called 3 times, avg 24.5ms/call: # 3 times (565µs+72.8ms) by Moose::Util::_apply_all_roles at line 140 of Moose/Util.pm, avg 24.5ms/call
sub combine {
48961587µs my ($class, @role_specs) = @_;
490
491 require Moose::Meta::Role::Composite;
492
493 my (@roles, %role_params);
494 while (@role_specs) {
495 my ($role, $params) = @{ splice @role_specs, 0, 1 };
496844µs my $requested_role
# spent 44µs making 8 calls to Scalar::Util::blessed, avg 6µs/call
497 = blessed $role
498 ? $role
499 : Class::MOP::class_of($role);
500
501886µs my $actual_role = $requested_role->_role_for_combination($params);
# spent 86µs making 8 calls to Moose::Meta::Role::_role_for_combination, avg 11µs/call
502 push @roles => $actual_role;
503
504 next unless defined $params;
505324µs $role_params{$actual_role->name} = $params;
# spent 24µs making 3 calls to Class::MOP::Package::name, avg 8µs/call
506 }
507
50832.38ms my $c = Moose::Meta::Role::Composite->new(roles => \@roles);
# spent 2.38ms making 3 calls to Moose::Meta::Role::Composite::new, avg 793µs/call
509370.3ms return $c->apply_params(\%role_params);
# spent 70.3ms making 3 calls to Moose::Meta::Role::Composite::apply_params, avg 23.4ms/call
510}
511
512
# spent 86µs within Moose::Meta::Role::_role_for_combination which was called 8 times, avg 11µs/call: # 8 times (86µs+0s) by Moose::Meta::Role::combine at line 501, avg 11µs/call
sub _role_for_combination {
51316119µs my ($self, $params) = @_;
514 return $self;
515}
516
517
# spent 397ms (5.52+392) within Moose::Meta::Role::create which was called 42 times, avg 9.45ms/call: # 42 times (5.52ms+392ms) by Moose::Meta::Role::create_anon_role at line 607, avg 9.45ms/call
sub create {
5185465.41ms my ( $role, $package_name, %options ) = @_;
519
520 $options{package} = $package_name;
521
522 (ref $options{attributes} eq 'HASH')
523 || confess "You must pass a HASH ref of attributes"
524 if exists $options{attributes};
525
526 (ref $options{methods} eq 'HASH')
527 || confess "You must pass a HASH ref of methods"
528 if exists $options{methods};
529
530 $options{meta_name} = 'meta'
531 unless exists $options{meta_name};
532
533 my (%initialize_options) = %options;
534 delete @initialize_options{qw(
535 package
536 attributes
537 methods
538 meta_name
539 version
540 authority
541 )};
542
54342278ms my $meta = $role->initialize( $package_name => %initialize_options );
# spent 278ms making 42 calls to Moose::Meta::Role::initialize, avg 6.61ms/call
544
545425.68ms $meta->_instantiate_module( $options{version}, $options{authority} );
# spent 5.68ms making 42 calls to Class::MOP::Module::_instantiate_module, avg 135µs/call
546
54742108ms $meta->_add_meta_method($options{meta_name})
# spent 108ms making 42 calls to Class::MOP::Mixin::HasMethods::_add_meta_method, avg 2.58ms/call
548 if defined $options{meta_name};
549
550 if (exists $options{attributes}) {
551 foreach my $attribute_name (keys %{$options{attributes}}) {
552 my $attr = $options{attributes}->{$attribute_name};
553 $meta->add_attribute(
554 $attribute_name => blessed $attr ? $attr : %{$attr} );
555 }
556 }
557
558 if (exists $options{methods}) {
559 foreach my $method_name (keys %{$options{methods}}) {
560 $meta->add_method($method_name, $options{methods}->{$method_name});
561 }
562 }
563
564 return $meta;
565}
566
567sub consumers {
568 my $self = shift;
569 my @consumers;
570 for my $meta (Class::MOP::get_all_metaclass_instances) {
571 next if $meta->name eq $self->name;
572 next unless $meta->isa('Moose::Meta::Class')
573 || $meta->isa('Moose::Meta::Role');
574 push @consumers, $meta->name
575 if $meta->does_role($self->name);
576 }
577 return @consumers;
578}
579
580# anonymous roles. most of it is copied straight out of Class::MOP::Class.
581# an intrepid hacker might find great riches if he unifies this code with that
582# code in Class::MOP::Module or Class::MOP::Package
583{
584 # NOTE:
585 # this should be sufficient, if you have a
586 # use case where it is not, write a test and
587 # I will change it.
58827µs my $ANON_ROLE_SERIAL = 0;
589
590 # NOTE:
591 # we need a sufficiently annoying prefix
592 # this should suffice for now, this is
593 # used in a couple of places below, so
594 # need to put it up here for now.
59514µs my $ANON_ROLE_PREFIX = 'Moose::Meta::Role::__ANON__::SERIAL::';
596
597 sub is_anon_role {
598 my $self = shift;
5993454µs2210µs
# spent 133µs (56+77) within Moose::Meta::Role::BEGIN@599 which was called: # once (56µs+77µs) by Moose::BEGIN@27 at line 599
no warnings 'uninitialized';
# spent 133µs making 1 call to Moose::Meta::Role::BEGIN@599 # spent 77µs making 1 call to warnings::unimport
600 $self->name =~ /^$ANON_ROLE_PREFIX/;
601 }
602
603
# spent 399ms (2.15+397) within Moose::Meta::Role::create_anon_role which was called 42 times, avg 9.51ms/call: # 42 times (2.15ms+397ms) by MooseX::Role::Parameterized::Meta::Role::Parameterizable::generate_role at line 85 of MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm, avg 9.51ms/call
sub create_anon_role {
6041682.10ms my ($role, %options) = @_;
605 $options{weaken} = 1 unless exists $options{weaken};
606 my $package_name = $ANON_ROLE_PREFIX . ++$ANON_ROLE_SERIAL;
60742397ms return $role->create($package_name, %options);
# spent 397ms making 42 calls to Moose::Meta::Role::create, avg 9.45ms/call
608 }
609
610 # NOTE:
611 # this will only get called for
612 # anon-roles, all other calls
613 # are assumed to occur during
614 # global destruction and so don't
615 # really need to be handled explicitly
616 sub DESTROY {
617 my $self = shift;
618
619 return if in_global_destruction(); # it'll happen soon anyway and this just makes things more complicated
620
6213233µs2165µs
# spent 105µs (45+60) within Moose::Meta::Role::BEGIN@621 which was called: # once (45µs+60µs) by Moose::BEGIN@27 at line 621
no warnings 'uninitialized';
# spent 105µs making 1 call to Moose::Meta::Role::BEGIN@621 # spent 60µs making 1 call to warnings::unimport
622 return unless $self->name =~ /^$ANON_ROLE_PREFIX/;
623
624 # XXX: is this necessary for us? I don't understand what it's doing
625 # -sartak
626
627 # Moose does a weird thing where it replaces the metaclass for
628 # class when fixing metaclass incompatibility. In that case,
629 # we don't want to clean out the namespace now. We can detect
630 # that because Moose will explicitly update the singleton
631 # cache in Class::MOP.
632 #my $current_meta = Class::MOP::get_metaclass_by_name($self->name);
633 #return if $current_meta ne $self;
634
635 my ($serial_id) = ($self->name =~ /^$ANON_ROLE_PREFIX(\d+)/);
6363533µs2170µs
# spent 104µs (39+65) within Moose::Meta::Role::BEGIN@636 which was called: # once (39µs+65µs) by Moose::BEGIN@27 at line 636
no strict 'refs';
# spent 104µs making 1 call to Moose::Meta::Role::BEGIN@636 # spent 65µs making 1 call to strict::unimport
637 foreach my $key (keys %{$ANON_ROLE_PREFIX . $serial_id}) {
638 delete ${$ANON_ROLE_PREFIX . $serial_id}{$key};
639 }
640 delete ${'main::' . $ANON_ROLE_PREFIX}{$serial_id . '::'};
641 }
642}
643
644#####################################################################
645## NOTE:
646## This is Moose::Meta::Role as defined by Moose (plus the use of
647## MooseX::AttributeHelpers module). It is here as a reference to
648## make it easier to see what is happening above with all the meta
649## programming. - SL
650#####################################################################
651#
652# has 'roles' => (
653# metaclass => 'Array',
654# reader => 'get_roles',
655# isa => 'ArrayRef[Moose::Meta::Role]',
656# default => sub { [] },
657# provides => {
658# 'push' => 'add_role',
659# }
660# );
661#
662# has 'excluded_roles_map' => (
663# metaclass => 'Hash',
664# reader => 'get_excluded_roles_map',
665# isa => 'HashRef[Str]',
666# provides => {
667# # Not exactly set, cause it sets multiple
668# 'set' => 'add_excluded_roles',
669# 'keys' => 'get_excluded_roles_list',
670# 'exists' => 'excludes_role',
671# }
672# );
673#
674# has 'required_methods' => (
675# metaclass => 'Hash',
676# reader => 'get_required_methods_map',
677# isa => 'HashRef[Moose::Meta::Role::Method::Required]',
678# provides => {
679# # not exactly set, or delete since it works for multiple
680# 'set' => 'add_required_methods',
681# 'delete' => 'remove_required_methods',
682# 'keys' => 'get_required_method_list',
683# 'exists' => 'requires_method',
684# }
685# );
686#
687# # the before, around and after modifiers are
688# # HASH keyed by method-name, with ARRAY of
689# # CODE refs to apply in that order
690#
691# has 'before_method_modifiers' => (
692# metaclass => 'Hash',
693# reader => 'get_before_method_modifiers_map',
694# isa => 'HashRef[ArrayRef[CodeRef]]',
695# provides => {
696# 'keys' => 'get_before_method_modifiers',
697# 'exists' => 'has_before_method_modifiers',
698# # This actually makes sure there is an
699# # ARRAY at the given key, and pushed onto
700# # it. It also checks for duplicates as well
701# # 'add' => 'add_before_method_modifier'
702# }
703# );
704#
705# has 'after_method_modifiers' => (
706# metaclass => 'Hash',
707# reader =>'get_after_method_modifiers_map',
708# isa => 'HashRef[ArrayRef[CodeRef]]',
709# provides => {
710# 'keys' => 'get_after_method_modifiers',
711# 'exists' => 'has_after_method_modifiers',
712# # This actually makes sure there is an
713# # ARRAY at the given key, and pushed onto
714# # it. It also checks for duplicates as well
715# # 'add' => 'add_after_method_modifier'
716# }
717# );
718#
719# has 'around_method_modifiers' => (
720# metaclass => 'Hash',
721# reader =>'get_around_method_modifiers_map',
722# isa => 'HashRef[ArrayRef[CodeRef]]',
723# provides => {
724# 'keys' => 'get_around_method_modifiers',
725# 'exists' => 'has_around_method_modifiers',
726# # This actually makes sure there is an
727# # ARRAY at the given key, and pushed onto
728# # it. It also checks for duplicates as well
729# # 'add' => 'add_around_method_modifier'
730# }
731# );
732#
733# # override is similar to the other modifiers
734# # except that it is not an ARRAY of code refs
735# # but instead just a single name->code mapping
736#
737# has 'override_method_modifiers' => (
738# metaclass => 'Hash',
739# reader =>'get_override_method_modifiers_map',
740# isa => 'HashRef[CodeRef]',
741# provides => {
742# 'keys' => 'get_override_method_modifier',
743# 'exists' => 'has_override_method_modifier',
744# 'add' => 'add_override_method_modifier', # checks for local method ..
745# }
746# );
747#
748#####################################################################
749
750
7511132µs1;
752
753__END__