← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:41 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/Role.pm
StatementsExecuted 82 statements in 4.76ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.00ms3.81msMoose::Meta::Role::::BEGIN@19Moose::Meta::Role::BEGIN@19
111862µs1.91msMoose::Meta::Role::::BEGIN@22Moose::Meta::Role::BEGIN@22
111397µs1.49msMoose::Meta::Role::::BEGIN@21Moose::Meta::Role::BEGIN@21
111299µs433µsMoose::Meta::Role::::BEGIN@20Moose::Meta::Role::BEGIN@20
11118µs90µsMoose::Meta::Role::::BEGIN@16Moose::Meta::Role::BEGIN@16
11111µs11µsMoose::Meta::Role::::BEGIN@2Moose::Meta::Role::BEGIN@2
11110µs47µsMoose::Meta::Role::::BEGIN@13Moose::Meta::Role::BEGIN@13
1119µs37µsMoose::Meta::Role::::BEGIN@14Moose::Meta::Role::BEGIN@14
1119µs14µsMoose::Meta::Role::::BEGIN@10Moose::Meta::Role::BEGIN@10
1119µs36µsMoose::Meta::Role::::BEGIN@15Moose::Meta::Role::BEGIN@15
1119µs192µsMoose::Meta::Role::::BEGIN@27Moose::Meta::Role::BEGIN@27
1118µs23µsMoose::Meta::Role::::BEGIN@9Moose::Meta::Role::BEGIN@9
1118µs503µsMoose::Meta::Role::::BEGIN@11Moose::Meta::Role::BEGIN@11
1118µs184µsMoose::Meta::Role::::BEGIN@24Moose::Meta::Role::BEGIN@24
1115µs5µsMoose::Meta::Role::::BEGIN@23Moose::Meta::Role::BEGIN@23
1115µs5µsMoose::Meta::Role::::BEGIN@18Moose::Meta::Role::BEGIN@18
1115µs5µsMoose::Meta::Role::::BEGIN@25Moose::Meta::Role::BEGIN@25
0000s0sMoose::Meta::Role::::__ANON__[:104]Moose::Meta::Role::__ANON__[:104]
0000s0sMoose::Meta::Role::::__ANON__[:109]Moose::Meta::Role::__ANON__[:109]
0000s0sMoose::Meta::Role::::__ANON__[:114]Moose::Meta::Role::__ANON__[:114]
0000s0sMoose::Meta::Role::::__ANON__[:119]Moose::Meta::Role::__ANON__[:119]
0000s0sMoose::Meta::Role::::__ANON__[:124]Moose::Meta::Role::__ANON__[:124]
0000s0sMoose::Meta::Role::::__ANON__[:308]Moose::Meta::Role::__ANON__[:308]
0000s0sMoose::Meta::Role::::__ANON__[:318]Moose::Meta::Role::__ANON__[:318]
0000s0sMoose::Meta::Role::::__ANON__[:326]Moose::Meta::Role::__ANON__[:326]
0000s0sMoose::Meta::Role::::__ANON__[:345]Moose::Meta::Role::__ANON__[:345]
0000s0sMoose::Meta::Role::::__ANON__[:354]Moose::Meta::Role::__ANON__[:354]
0000s0sMoose::Meta::Role::::__ANON__[:400]Moose::Meta::Role::__ANON__[:400]
0000s0sMoose::Meta::Role::::__ANON__[:583]Moose::Meta::Role::__ANON__[:583]
0000s0sMoose::Meta::Role::::__ANON__[:91]Moose::Meta::Role::__ANON__[:91]
0000s0sMoose::Meta::Role::::__ANON__[:99]Moose::Meta::Role::__ANON__[:99]
0000s0sMoose::Meta::Role::::_anon_cache_keyMoose::Meta::Role::_anon_cache_key
0000s0sMoose::Meta::Role::::_anon_package_prefixMoose::Meta::Role::_anon_package_prefix
0000s0sMoose::Meta::Role::::_attach_attributeMoose::Meta::Role::_attach_attribute
0000s0sMoose::Meta::Role::::_meta_method_classMoose::Meta::Role::_meta_method_class
0000s0sMoose::Meta::Role::::_restore_metaobjects_fromMoose::Meta::Role::_restore_metaobjects_from
0000s0sMoose::Meta::Role::::_role_for_combinationMoose::Meta::Role::_role_for_combination
0000s0sMoose::Meta::Role::::add_attributeMoose::Meta::Role::add_attribute
0000s0sMoose::Meta::Role::::add_conflicting_methodMoose::Meta::Role::add_conflicting_method
0000s0sMoose::Meta::Role::::add_override_method_modifierMoose::Meta::Role::add_override_method_modifier
0000s0sMoose::Meta::Role::::add_required_methodsMoose::Meta::Role::add_required_methods
0000s0sMoose::Meta::Role::::add_roleMoose::Meta::Role::add_role
0000s0sMoose::Meta::Role::::applyMoose::Meta::Role::apply
0000s0sMoose::Meta::Role::::calculate_all_rolesMoose::Meta::Role::calculate_all_roles
0000s0sMoose::Meta::Role::::combineMoose::Meta::Role::combine
0000s0sMoose::Meta::Role::::composition_class_rolesMoose::Meta::Role::composition_class_roles
0000s0sMoose::Meta::Role::::consumersMoose::Meta::Role::consumers
0000s0sMoose::Meta::Role::::createMoose::Meta::Role::create
0000s0sMoose::Meta::Role::::create_anon_roleMoose::Meta::Role::create_anon_role
0000s0sMoose::Meta::Role::::does_roleMoose::Meta::Role::does_role
0000s0sMoose::Meta::Role::::find_method_by_nameMoose::Meta::Role::find_method_by_name
0000s0sMoose::Meta::Role::::get_method_modifier_listMoose::Meta::Role::get_method_modifier_list
0000s0sMoose::Meta::Role::::get_override_method_modifierMoose::Meta::Role::get_override_method_modifier
0000s0sMoose::Meta::Role::::has_override_method_modifierMoose::Meta::Role::has_override_method_modifier
0000s0sMoose::Meta::Role::::initializeMoose::Meta::Role::initialize
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
1package Moose::Meta::Role;
2
# spent 11µs within Moose::Meta::Role::BEGIN@2 which was called: # once (11µs+0s) by Moose::BEGIN@35 at line 4
BEGIN {
317µs $Moose::Meta::Role::AUTHORITY = 'cpan:STEVAN';
4138µs111µs}
# spent 11µs making 1 call to Moose::Meta::Role::BEGIN@2
5{
621µs $Moose::Meta::Role::VERSION = '2.1005';
7}
8
9229µs238µs
# spent 23µs (8+15) within Moose::Meta::Role::BEGIN@9 which was called: # once (8µs+15µs) by Moose::BEGIN@35 at line 9
use strict;
# spent 23µs making 1 call to Moose::Meta::Role::BEGIN@9 # spent 15µs making 1 call to strict::import
10227µs218µs
# spent 14µs (9+5) within Moose::Meta::Role::BEGIN@10 which was called: # once (9µs+5µs) by Moose::BEGIN@35 at line 10
use warnings;
# spent 14µs making 1 call to Moose::Meta::Role::BEGIN@10 # spent 5µs making 1 call to warnings::import
11238µs2998µs
# spent 503µs (8+495) within Moose::Meta::Role::BEGIN@11 which was called: # once (8µs+495µs) by Moose::BEGIN@35 at line 11
use metaclass;
# spent 503µs making 1 call to Moose::Meta::Role::BEGIN@11 # spent 495µs making 1 call to metaclass::import
12
13234µs284µs
# spent 47µs (10+37) within Moose::Meta::Role::BEGIN@13 which was called: # once (10µs+37µs) by Moose::BEGIN@35 at line 13
use Class::Load qw(load_class);
# spent 47µs making 1 call to Moose::Meta::Role::BEGIN@13 # spent 37µs making 1 call to Exporter::import
14232µs265µs
# spent 37µs (9+28) within Moose::Meta::Role::BEGIN@14 which was called: # once (9µs+28µs) by Moose::BEGIN@35 at line 14
use Scalar::Util 'blessed';
# spent 37µs making 1 call to Moose::Meta::Role::BEGIN@14 # spent 28µs making 1 call to Exporter::import
15232µs263µs
# spent 36µs (9+27) within Moose::Meta::Role::BEGIN@15 which was called: # once (9µs+27µs) by Moose::BEGIN@35 at line 15
use Carp 'confess';
# spent 36µs making 1 call to Moose::Meta::Role::BEGIN@15 # spent 27µs making 1 call to Exporter::import
16237µs2136µs
# spent 90µs (18+72) within Moose::Meta::Role::BEGIN@16 which was called: # once (18µs+72µs) by Moose::BEGIN@35 at line 16
use Devel::GlobalDestruction 'in_global_destruction';
# spent 90µs making 1 call to Moose::Meta::Role::BEGIN@16 # spent 47µs making 1 call to Sub::Exporter::Progressive::__ANON__[Sub/Exporter/Progressive.pm:40]
17
18227µs15µs
# spent 5µs within Moose::Meta::Role::BEGIN@18 which was called: # once (5µs+0s) by Moose::BEGIN@35 at line 18
use Moose::Meta::Class;
# spent 5µs making 1 call to Moose::Meta::Role::BEGIN@18
192157µs13.81ms
# spent 3.81ms (1.00+2.81) within Moose::Meta::Role::BEGIN@19 which was called: # once (1.00ms+2.81ms) by Moose::BEGIN@35 at line 19
use Moose::Meta::Role::Attribute;
# spent 3.81ms making 1 call to Moose::Meta::Role::BEGIN@19
202143µs1433µs
# spent 433µs (299+134) within Moose::Meta::Role::BEGIN@20 which was called: # once (299µs+134µs) by Moose::BEGIN@35 at line 20
use Moose::Meta::Role::Method;
# spent 433µs making 1 call to Moose::Meta::Role::BEGIN@20
212130µs11.49ms
# spent 1.49ms (397µs+1.09) within Moose::Meta::Role::BEGIN@21 which was called: # once (397µs+1.09ms) by Moose::BEGIN@35 at line 21
use Moose::Meta::Role::Method::Required;
# spent 1.49ms making 1 call to Moose::Meta::Role::BEGIN@21
222141µs11.91ms
# spent 1.91ms (862µs+1.05) within Moose::Meta::Role::BEGIN@22 which was called: # once (862µs+1.05ms) by Moose::BEGIN@35 at line 22
use Moose::Meta::Role::Method::Conflicting;
# spent 1.91ms making 1 call to Moose::Meta::Role::BEGIN@22
23233µs15µs
# spent 5µs within Moose::Meta::Role::BEGIN@23 which was called: # once (5µs+0s) by Moose::BEGIN@35 at line 23
use Moose::Meta::Method::Meta;
# spent 5µs making 1 call to Moose::Meta::Role::BEGIN@23
24236µs2360µs
# spent 184µs (8+176) within Moose::Meta::Role::BEGIN@24 which was called: # once (8µs+176µs) by Moose::BEGIN@35 at line 24
use Moose::Util qw( ensure_all_roles );
# spent 184µs making 1 call to Moose::Meta::Role::BEGIN@24 # spent 176µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337]
25236µs15µs
# spent 5µs within Moose::Meta::Role::BEGIN@25 which was called: # once (5µs+0s) by Moose::BEGIN@35 at line 25
use Class::MOP::MiniTrait;
# spent 5µs making 1 call to Moose::Meta::Role::BEGIN@25
26
271500ns
# spent 192µs (9+183) within Moose::Meta::Role::BEGIN@27 which was called: # once (9µs+183µs) by Moose::BEGIN@35 at line 29
use base 'Class::MOP::Module',
28 'Class::MOP::Mixin::HasAttributes',
2913.60ms2375µs 'Class::MOP::Mixin::HasMethods';
# spent 192µs making 1 call to Moose::Meta::Role::BEGIN@27 # spent 183µs making 1 call to base::import
30
3112µs17.51msClass::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
# spent 7.51ms making 1 call to Class::MOP::MiniTrait::apply
32
33## ------------------------------------------------------------------
34## NOTE:
35## I normally don't do this, but I am doing
36## a whole bunch of meta-programmin' in this
37## module, so it just makes sense. For a clearer
38## picture of what is going on in the next
39## several lines of code, look at the really
40## big comment at the end of this file (right
41## before the POD).
42## - SL
43## ------------------------------------------------------------------
44
4512µs115µsmy $META = __PACKAGE__->meta;
# spent 15µs making 1 call to Moose::Meta::Role::meta
46
47## ------------------------------------------------------------------
48## attributes ...
49
50# NOTE:
51# since roles are lazy, we hold all the attributes
52# of the individual role in 'stasis' until which
53# time when it is applied to a class. This means
54# keeping a lot of things in hash maps, so we are
55# using a little of that meta-programmin' magic
56# here and saving lots of extra typin'. And since
57# many of these attributes above require similar
58# functionality to support them, so we again use
59# the wonders of meta-programmin' to deliver a
60# very compact solution to this normally verbose
61# problem.
62# - SL
63
6418µsforeach my $action (
65 {
66 name => 'excluded_roles_map',
67 attr_reader => 'get_excluded_roles_map' ,
68 methods => {
69 add => 'add_excluded_roles',
70 get_keys => 'get_excluded_roles_list',
71 existence => 'excludes_role',
72 }
73 },
74 {
75 name => 'required_methods',
76 attr_reader => 'get_required_methods_map',
77 methods => {
78 remove => 'remove_required_methods',
79 get_values => 'get_required_method_list',
80 existence => 'requires_method',
81 }
82 },
83) {
84
8521µs my $attr_reader = $action->{attr_reader};
862400ns my $methods = $action->{methods};
87
88 # create the attribute
89 $META->add_attribute($action->{name} => (
90 reader => $attr_reader,
91 default => sub { {} },
9229µs4788µs Class::MOP::_definition_context(),
# spent 775µs making 2 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 387µs/call # spent 14µs making 2 calls to Class::MOP::_definition_context, avg 7µs/call
93 ));
94
95 # create some helper methods
96 $META->add_method($methods->{add} => sub {
97 my ($self, @values) = @_;
98 $self->$attr_reader->{$_} = undef foreach @values;
9925µs158µs }) if exists $methods->{add};
# spent 58µs making 1 call to Class::MOP::Mixin::HasMethods::add_method
100
101 $META->add_method($methods->{get_keys} => sub {
102 my ($self) = @_;
103 keys %{$self->$attr_reader};
10424µs154µs }) if exists $methods->{get_keys};
# spent 54µs making 1 call to Class::MOP::Mixin::HasMethods::add_method
105
106 $META->add_method($methods->{get_values} => sub {
107 my ($self) = @_;
108 values %{$self->$attr_reader};
10925µs157µs }) if exists $methods->{get_values};
# spent 57µs making 1 call to Class::MOP::Mixin::HasMethods::add_method
110
111 $META->add_method($methods->{get} => sub {
112 my ($self, $name) = @_;
113 $self->$attr_reader->{$name}
1142600ns }) if exists $methods->{get};
115
116 $META->add_method($methods->{existence} => sub {
117 my ($self, $name) = @_;
118 exists $self->$attr_reader->{$name} ? 1 : 0;
11927µs2104µs }) if exists $methods->{existence};
# spent 104µs making 2 calls to Class::MOP::Mixin::HasMethods::add_method, avg 52µs/call
120
121 $META->add_method($methods->{remove} => sub {
122 my ($self, @values) = @_;
123 delete $self->$attr_reader->{$_} foreach @values;
12426µs154µs }) if exists $methods->{remove};
# spent 54µs making 1 call to Class::MOP::Mixin::HasMethods::add_method
125}
126
127$META->add_attribute(
12813µs2387µs 'method_metaclass',
# spent 380µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 6µs making 1 call to Class::MOP::_definition_context
129 reader => 'method_metaclass',
130 default => 'Moose::Meta::Role::Method',
131 Class::MOP::_definition_context(),
132);
133
13413µs2389µs$META->add_attribute(
# spent 383µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 7µs making 1 call to Class::MOP::_definition_context
135 'required_method_metaclass',
136 reader => 'required_method_metaclass',
137 default => 'Moose::Meta::Role::Method::Required',
138 Class::MOP::_definition_context(),
139);
140
14113µs2376µs$META->add_attribute(
# spent 369µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 7µs making 1 call to Class::MOP::_definition_context
142 'conflicting_method_metaclass',
143 reader => 'conflicting_method_metaclass',
144 default => 'Moose::Meta::Role::Method::Conflicting',
145 Class::MOP::_definition_context(),
146);
147
14813µs2367µs$META->add_attribute(
# spent 361µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 6µs making 1 call to Class::MOP::_definition_context
149 'application_to_class_class',
150 reader => 'application_to_class_class',
151 default => 'Moose::Meta::Role::Application::ToClass',
152 Class::MOP::_definition_context(),
153);
154
15513µs2389µs$META->add_attribute(
# spent 383µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 6µs making 1 call to Class::MOP::_definition_context
156 'application_to_role_class',
157 reader => 'application_to_role_class',
158 default => 'Moose::Meta::Role::Application::ToRole',
159 Class::MOP::_definition_context(),
160);
161
16213µs2371µs$META->add_attribute(
# spent 364µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 7µs making 1 call to Class::MOP::_definition_context
163 'application_to_instance_class',
164 reader => 'application_to_instance_class',
165 default => 'Moose::Meta::Role::Application::ToInstance',
166 Class::MOP::_definition_context(),
167);
168
16913µs2385µs$META->add_attribute(
# spent 378µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 6µs making 1 call to Class::MOP::_definition_context
170 'applied_attribute_metaclass',
171 reader => 'applied_attribute_metaclass',
172 default => 'Moose::Meta::Attribute',
173 Class::MOP::_definition_context(),
174);
175
176# More or less copied from Moose::Meta::Class
177sub initialize {
178 my $class = shift;
179 my @args = @_;
180 unshift @args, 'package' if @args % 2;
181 my %opts = @args;
182 my $package = delete $opts{package};
183 return Class::MOP::get_metaclass_by_name($package)
184 || $class->SUPER::initialize($package,
185 'attribute_metaclass' => 'Moose::Meta::Role::Attribute',
186 %opts,
187 );
188}
189
190sub reinitialize {
191 my $self = shift;
192 my $pkg = shift;
193
194 my $meta = blessed $pkg ? $pkg : Class::MOP::class_of($pkg);
195
196 my %existing_classes;
197 if ($meta) {
198 %existing_classes = map { $_ => $meta->$_() } qw(
199 attribute_metaclass
200 method_metaclass
201 wrapped_method_metaclass
202 required_method_metaclass
203 conflicting_method_metaclass
204 application_to_class_class
205 application_to_role_class
206 application_to_instance_class
207 applied_attribute_metaclass
208 );
209 }
210
211 my %options = @_;
212 $options{weaken} = Class::MOP::metaclass_is_weak($meta->name)
213 if !exists $options{weaken}
214 && blessed($meta)
215 && $meta->isa('Moose::Meta::Role');
216
217 # don't need to remove generated metaobjects here yet, since we don't
218 # yet generate anything in roles. this may change in the future though...
219 # keep an eye on that
220 my $new_meta = $self->SUPER::reinitialize(
221 $pkg,
222 %existing_classes,
223 %options,
224 );
225 $new_meta->_restore_metaobjects_from($meta)
226 if $meta && $meta->isa('Moose::Meta::Role');
227 return $new_meta;
228}
229
230sub _restore_metaobjects_from {
231 my $self = shift;
232 my ($old_meta) = @_;
233
234 $self->_restore_metamethods_from($old_meta);
235 $self->_restore_metaattributes_from($old_meta);
236
237 for my $role ( @{ $old_meta->get_roles } ) {
238 $self->add_role($role);
239 }
240}
241
242sub add_attribute {
243 my $self = shift;
244
245 if (blessed $_[0] && ! $_[0]->isa('Moose::Meta::Role::Attribute') ) {
246 my $class = ref $_[0];
247 Moose->throw_error( "Cannot add a $class as an attribute to a role" );
248 }
249 elsif (!blessed($_[0]) && defined($_[0]) && $_[0] =~ /^\+(.*)/) {
250 Moose->throw_error( "has '+attr' is not supported in roles" );
251 }
252
253 return $self->SUPER::add_attribute(@_);
254}
255
256sub _attach_attribute {
257 my ( $self, $attribute ) = @_;
258
259 $attribute->attach_to_role($self);
260}
261
262sub add_required_methods {
263 my $self = shift;
264
265 for (@_) {
266 my $method = $_;
267 if (!blessed($method)) {
268 $method = $self->required_method_metaclass->new(
269 name => $method,
270 );
271 }
272 $self->get_required_methods_map->{$method->name} = $method;
273 }
274}
275
276sub add_conflicting_method {
277 my $self = shift;
278
279 my $method;
280 if (@_ == 1 && blessed($_[0])) {
281 $method = shift;
282 }
283 else {
284 $method = $self->conflicting_method_metaclass->new(@_);
285 }
286
287 $self->add_required_methods($method);
288}
289
290## ------------------------------------------------------------------
291## method modifiers
292
293# NOTE:
294# the before/around/after method modifiers are
295# stored by name, but there can be many methods
296# then associated with that name. So again we have
297# lots of similar functionality, so we can do some
298# meta-programmin' and save some time.
299# - SL
300
3011900nsforeach my $modifier_type (qw[ before around after ]) {
302
30333µs my $attr_reader = "get_${modifier_type}_method_modifiers_map";
304
305 # create the attribute ...
306 $META->add_attribute("${modifier_type}_method_modifiers" => (
307 reader => $attr_reader,
308 default => sub { {} },
309314µs61.16ms Class::MOP::_definition_context(),
# spent 1.14ms making 3 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 381µs/call # spent 20µs making 3 calls to Class::MOP::_definition_context, avg 7µs/call
310 ));
311
312 # and some helper methods ...
313 $META->add_method("get_${modifier_type}_method_modifiers" => sub {
314 my ($self, $method_name) = @_;
315 #return () unless exists $self->$attr_reader->{$method_name};
316 my $mm = $self->$attr_reader->{$method_name};
317 $mm ? @$mm : ();
318313µs3168µs });
# spent 168µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 56µs/call
319
320 $META->add_method("has_${modifier_type}_method_modifiers" => sub {
321 my ($self, $method_name) = @_;
322 # NOTE:
323 # for now we assume that if it exists,..
324 # it has at least one modifier in it
325 (exists $self->$attr_reader->{$method_name}) ? 1 : 0;
326312µs3154µs });
# spent 154µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 51µs/call
327
328 $META->add_method("add_${modifier_type}_method_modifier" => sub {
329 my ($self, $method_name, $method) = @_;
330
331 $self->$attr_reader->{$method_name} = []
332 unless exists $self->$attr_reader->{$method_name};
333
334 my $modifiers = $self->$attr_reader->{$method_name};
335
336 # NOTE:
337 # check to see that we aren't adding the
338 # same code twice. We err in favor of the
339 # first on here, this may not be as expected
340 foreach my $modifier (@{$modifiers}) {
341 return if $modifier == $method;
342 }
343
344 push @{$modifiers} => $method;
345314µs3153µs });
# spent 153µs making 3 calls to Class::MOP::Mixin::HasMethods::add_method, avg 51µs/call
346
347}
348
349## ------------------------------------------------------------------
350## override method modifiers
351
352$META->add_attribute('override_method_modifiers' => (
353 reader => 'get_override_method_modifiers_map',
354 default => sub { {} },
35515µs2394µs Class::MOP::_definition_context(),
# spent 388µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 7µs making 1 call to Class::MOP::_definition_context
356));
357
358# NOTE:
359# these are a little different because there
360# can only be one per name, whereas the other
361# method modifiers can have multiples.
362# - SL
363
364sub add_override_method_modifier {
365 my ($self, $method_name, $method) = @_;
366 (!$self->has_method($method_name))
367 || Moose->throw_error("Cannot add an override of method '$method_name' " .
368 "because there is a local version of '$method_name'");
369 $self->get_override_method_modifiers_map->{$method_name} = $method;
370}
371
372sub has_override_method_modifier {
373 my ($self, $method_name) = @_;
374 # NOTE:
375 # for now we assume that if it exists,..
376 # it has at least one modifier in it
377 (exists $self->get_override_method_modifiers_map->{$method_name}) ? 1 : 0;
378}
379
380sub get_override_method_modifier {
381 my ($self, $method_name) = @_;
382 $self->get_override_method_modifiers_map->{$method_name};
383}
384
385## general list accessor ...
386
387sub get_method_modifier_list {
388 my ($self, $modifier_type) = @_;
389 my $accessor = "get_${modifier_type}_method_modifiers_map";
390 keys %{$self->$accessor};
391}
392
393sub _meta_method_class { 'Moose::Meta::Method::Meta' }
394
395## ------------------------------------------------------------------
396## subroles
397
398$META->add_attribute('roles' => (
399 reader => 'get_roles',
400 default => sub { [] },
40115µs2370µs Class::MOP::_definition_context(),
# spent 363µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 6µs making 1 call to Class::MOP::_definition_context
402));
403
404sub add_role {
405 my ($self, $role) = @_;
406 (blessed($role) && $role->isa('Moose::Meta::Role'))
407 || Moose->throw_error("Roles must be instances of Moose::Meta::Role");
408 push @{$self->get_roles} => $role;
409 $self->reset_package_cache_flag;
410}
411
412sub calculate_all_roles {
413 my $self = shift;
414 my %seen;
415 grep {
416 !$seen{$_->name}++
417 } ($self, map {
418 $_->calculate_all_roles
419 } @{ $self->get_roles });
420}
421
422sub does_role {
423 my ($self, $role) = @_;
424 (defined $role)
425 || Moose->throw_error("You must supply a role name to look for");
426 my $role_name = blessed $role ? $role->name : $role;
427 # if we are it,.. then return true
428 return 1 if $role_name eq $self->name;
429 # otherwise.. check our children
430 foreach my $role (@{$self->get_roles}) {
431 return 1 if $role->does_role($role_name);
432 }
433 return 0;
434}
435
436sub find_method_by_name { (shift)->get_method(@_) }
437
438## ------------------------------------------------------------------
439## role construction
440## ------------------------------------------------------------------
441
442sub apply {
443 my ($self, $other, %args) = @_;
444
445 (blessed($other))
446 || Moose->throw_error("You must pass in an blessed instance");
447
448 my $application_class;
449 if ($other->isa('Moose::Meta::Role')) {
450 $application_class = $self->application_to_role_class;
451 }
452 elsif ($other->isa('Moose::Meta::Class')) {
453 $application_class = $self->application_to_class_class;
454 }
455 else {
456 $application_class = $self->application_to_instance_class;
457 }
458
459 load_class($application_class);
460
461 if ( exists $args{'-excludes'} ) {
462 # I wish we had coercion here :)
463 $args{'-excludes'} = (
464 ref $args{'-excludes'} eq 'ARRAY'
465 ? $args{'-excludes'}
466 : [ $args{'-excludes'} ]
467 );
468 }
469
470 return $application_class->new(%args)->apply($self, $other, \%args);
471}
472
473sub composition_class_roles { }
474
475sub combine {
476 my ($class, @role_specs) = @_;
477
478 require Moose::Meta::Role::Composite;
479
480 my (@roles, %role_params);
481 while (@role_specs) {
482 my ($role, $params) = @{ splice @role_specs, 0, 1 };
483 my $requested_role
484 = blessed $role
485 ? $role
486 : Class::MOP::class_of($role);
487
488 my $actual_role = $requested_role->_role_for_combination($params);
489 push @roles => $actual_role;
490
491 next unless defined $params;
492 $role_params{$actual_role->name} = $params;
493 }
494
495 my $c = Moose::Meta::Role::Composite->new(roles => \@roles);
496 return $c->apply_params(\%role_params);
497}
498
499sub _role_for_combination {
500 my ($self, $params) = @_;
501 return $self;
502}
503
504sub create {
505 my $class = shift;
506 my @args = @_;
507
508 unshift @args, 'package' if @args % 2 == 1;
509 my %options = @args;
510
511 (ref $options{attributes} eq 'HASH')
512 || confess "You must pass a HASH ref of attributes"
513 if exists $options{attributes};
514
515 (ref $options{methods} eq 'HASH')
516 || confess "You must pass a HASH ref of methods"
517 if exists $options{methods};
518
519 (ref $options{roles} eq 'ARRAY')
520 || confess "You must pass an ARRAY ref of roles"
521 if exists $options{roles};
522
523 my $package = delete $options{package};
524 my $roles = delete $options{roles};
525 my $attributes = delete $options{attributes};
526 my $methods = delete $options{methods};
527 my $meta_name = exists $options{meta_name}
528 ? delete $options{meta_name}
529 : 'meta';
530
531 my $meta = $class->SUPER::create($package => %options);
532
533 $meta->_add_meta_method($meta_name)
534 if defined $meta_name;
535
536 if (defined $attributes) {
537 foreach my $attribute_name (keys %{$attributes}) {
538 my $attr = $attributes->{$attribute_name};
539 $meta->add_attribute(
540 $attribute_name => blessed $attr ? $attr : %{$attr} );
541 }
542 }
543
544 if (defined $methods) {
545 foreach my $method_name (keys %{$methods}) {
546 $meta->add_method($method_name, $methods->{$method_name});
547 }
548 }
549
550 if ($roles) {
551 Moose::Util::apply_all_roles($meta, @$roles);
552 }
553
554 return $meta;
555}
556
557sub consumers {
558 my $self = shift;
559 my @consumers;
560 for my $meta (Class::MOP::get_all_metaclass_instances) {
561 next if $meta->name eq $self->name;
562 next unless $meta->isa('Moose::Meta::Class')
563 || $meta->isa('Moose::Meta::Role');
564 push @consumers, $meta->name
565 if $meta->does_role($self->name);
566 }
567 return @consumers;
568}
569
570# XXX: something more intelligent here?
571sub _anon_package_prefix { 'Moose::Meta::Role::__ANON__::SERIAL::' }
572
573sub create_anon_role { shift->create_anon(@_) }
574sub is_anon_role { shift->is_anon(@_) }
575
576sub _anon_cache_key {
577 my $class = shift;
578 my %options = @_;
579
580 # XXX fix this duplication (see MMC::_anon_cache_key
581 my $roles = Data::OptList::mkopt(($options{roles} || []), {
582 moniker => 'role',
583 val_test => sub { ref($_[0]) eq 'HASH' },
584 });
585
586 my @role_keys;
587 for my $role_spec (@$roles) {
588 my ($role, $params) = @$role_spec;
589 $params = { %$params };
590
591 my $key = blessed($role) ? $role->name : $role;
592
593 if ($params && %$params) {
594 my $alias = delete $params->{'-alias'}
595 || delete $params->{'alias'}
596 || {};
597 my $excludes = delete $params->{'-excludes'}
598 || delete $params->{'excludes'}
599 || [];
600 $excludes = [$excludes] unless ref($excludes) eq 'ARRAY';
601
602 if (%$params) {
603 warn "Roles with parameters cannot be cached. Consider "
604 . "applying the parameters before calling "
605 . "create_anon_class, or using 'weaken => 0' instead";
606 return;
607 }
608
609 my $alias_key = join('%',
610 map { $_ => $alias->{$_} } sort keys %$alias
611 );
612 my $excludes_key = join('%',
613 sort @$excludes
614 );
615 $key .= '<' . join('+', 'a', $alias_key, 'e', $excludes_key) . '>';
616 }
617
618 push @role_keys, $key;
619 }
620
621 # Makes something like Role|Role::1
622 return join('|', sort @role_keys);
623}
624
625#####################################################################
626## NOTE:
627## This is Moose::Meta::Role as defined by Moose (plus the use of
628## MooseX::AttributeHelpers module). It is here as a reference to
629## make it easier to see what is happening above with all the meta
630## programming. - SL
631#####################################################################
632#
633# has 'roles' => (
634# metaclass => 'Array',
635# reader => 'get_roles',
636# isa => 'ArrayRef[Moose::Meta::Role]',
637# default => sub { [] },
638# provides => {
639# 'push' => 'add_role',
640# }
641# );
642#
643# has 'excluded_roles_map' => (
644# metaclass => 'Hash',
645# reader => 'get_excluded_roles_map',
646# isa => 'HashRef[Str]',
647# provides => {
648# # Not exactly set, cause it sets multiple
649# 'set' => 'add_excluded_roles',
650# 'keys' => 'get_excluded_roles_list',
651# 'exists' => 'excludes_role',
652# }
653# );
654#
655# has 'required_methods' => (
656# metaclass => 'Hash',
657# reader => 'get_required_methods_map',
658# isa => 'HashRef[Moose::Meta::Role::Method::Required]',
659# provides => {
660# # not exactly set, or delete since it works for multiple
661# 'set' => 'add_required_methods',
662# 'delete' => 'remove_required_methods',
663# 'keys' => 'get_required_method_list',
664# 'exists' => 'requires_method',
665# }
666# );
667#
668# # the before, around and after modifiers are
669# # HASH keyed by method-name, with ARRAY of
670# # CODE refs to apply in that order
671#
672# has 'before_method_modifiers' => (
673# metaclass => 'Hash',
674# reader => 'get_before_method_modifiers_map',
675# isa => 'HashRef[ArrayRef[CodeRef]]',
676# provides => {
677# 'keys' => 'get_before_method_modifiers',
678# 'exists' => 'has_before_method_modifiers',
679# # This actually makes sure there is an
680# # ARRAY at the given key, and pushed onto
681# # it. It also checks for duplicates as well
682# # 'add' => 'add_before_method_modifier'
683# }
684# );
685#
686# has 'after_method_modifiers' => (
687# metaclass => 'Hash',
688# reader =>'get_after_method_modifiers_map',
689# isa => 'HashRef[ArrayRef[CodeRef]]',
690# provides => {
691# 'keys' => 'get_after_method_modifiers',
692# 'exists' => 'has_after_method_modifiers',
693# # This actually makes sure there is an
694# # ARRAY at the given key, and pushed onto
695# # it. It also checks for duplicates as well
696# # 'add' => 'add_after_method_modifier'
697# }
698# );
699#
700# has 'around_method_modifiers' => (
701# metaclass => 'Hash',
702# reader =>'get_around_method_modifiers_map',
703# isa => 'HashRef[ArrayRef[CodeRef]]',
704# provides => {
705# 'keys' => 'get_around_method_modifiers',
706# 'exists' => 'has_around_method_modifiers',
707# # This actually makes sure there is an
708# # ARRAY at the given key, and pushed onto
709# # it. It also checks for duplicates as well
710# # 'add' => 'add_around_method_modifier'
711# }
712# );
713#
714# # override is similar to the other modifiers
715# # except that it is not an ARRAY of code refs
716# # but instead just a single name->code mapping
717#
718# has 'override_method_modifiers' => (
719# metaclass => 'Hash',
720# reader =>'get_override_method_modifiers_map',
721# isa => 'HashRef[CodeRef]',
722# provides => {
723# 'keys' => 'get_override_method_modifier',
724# 'exists' => 'has_override_method_modifier',
725# 'add' => 'add_override_method_modifier', # checks for local method ..
726# }
727# );
728#
729#####################################################################
730
731
732141µs1;
733
734# ABSTRACT: The Moose Role metaclass
735
736__END__