← Index
Performance Profile   « block view • line view • sub view »
For t/test-parsing
  Run on Sun Nov 14 09:49:57 2010
Reported on Sun Nov 14 09:50:08 2010

File /usr/local/lib/perl/5.10.0/Moose/Meta/Class.pm
Statements Executed 641
Total Time 0.0069185 seconds
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
2221821µs972µsMoose::Meta::Class::::_base_metaclassesMoose::Meta::Class::_base_metaclasses
3732631µs37.5msMoose::Meta::Class::::superclassesMoose::Meta::Class::superclasses
811166µs20.3msMoose::Meta::Class::::add_attributeMoose::Meta::Class::add_attribute
822137µs10.7msMoose::Meta::Class::::initializeMoose::Meta::Class::initialize
811106µs4.40msMoose::Meta::Class::::_process_attributeMoose::Meta::Class::_process_attribute
811104µs4.30msMoose::Meta::Class::::_process_new_attributeMoose::Meta::Class::_process_new_attribute
71175µs361µsMoose::Meta::Class::::_immutable_optionsMoose::Meta::Class::_immutable_options
81157µs57µsMoose::Meta::Class::::__ANON__[:35]Moose::Meta::Class::__ANON__[:35]
41156µs2.66msMoose::Meta::Class::::add_override_method_modifierMoose::Meta::Class::add_override_method_modifier
81153µs53µsMoose::Meta::Class::::__ANON__[:40]Moose::Meta::Class::__ANON__[:40]
81139µs39µsMoose::Meta::Class::::_meta_method_classMoose::Meta::Class::_meta_method_class
0000s0sMoose::Meta::Class::::BEGINMoose::Meta::Class::BEGIN
0000s0sMoose::Meta::Class::::_anon_cache_keyMoose::Meta::Class::_anon_cache_key
0000s0sMoose::Meta::Class::::_find_next_method_by_name_which_is_not_overriddenMoose::Meta::Class::_find_next_method_by_name_which_is_not_overridden
0000s0sMoose::Meta::Class::::_fix_class_metaclass_incompatibilityMoose::Meta::Class::_fix_class_metaclass_incompatibility
0000s0sMoose::Meta::Class::::_fix_single_metaclass_incompatibilityMoose::Meta::Class::_fix_single_metaclass_incompatibility
0000s0sMoose::Meta::Class::::_process_inherited_attributeMoose::Meta::Class::_process_inherited_attribute
0000s0sMoose::Meta::Class::::_replace_selfMoose::Meta::Class::_replace_self
0000s0sMoose::Meta::Class::::add_augment_method_modifierMoose::Meta::Class::add_augment_method_modifier
0000s0sMoose::Meta::Class::::add_roleMoose::Meta::Class::add_role
0000s0sMoose::Meta::Class::::add_role_applicationMoose::Meta::Class::add_role_application
0000s0sMoose::Meta::Class::::calculate_all_rolesMoose::Meta::Class::calculate_all_roles
0000s0sMoose::Meta::Class::::calculate_all_roles_with_inheritanceMoose::Meta::Class::calculate_all_roles_with_inheritance
0000s0sMoose::Meta::Class::::createMoose::Meta::Class::create
0000s0sMoose::Meta::Class::::create_anon_classMoose::Meta::Class::create_anon_class
0000s0sMoose::Meta::Class::::create_errorMoose::Meta::Class::create_error
0000s0sMoose::Meta::Class::::does_roleMoose::Meta::Class::does_role
0000s0sMoose::Meta::Class::::excludes_roleMoose::Meta::Class::excludes_role
0000s0sMoose::Meta::Class::::new_objectMoose::Meta::Class::new_object
0000s0sMoose::Meta::Class::::raise_errorMoose::Meta::Class::raise_error
0000s0sMoose::Meta::Class::::reinitializeMoose::Meta::Class::reinitialize
0000s0sMoose::Meta::Class::::role_applicationsMoose::Meta::Class::role_applications
0000s0sMoose::Meta::Class::::throw_errorMoose::Meta::Class::throw_error
LineStmts.Exclusive
Time
Avg.Code
1
2package Moose::Meta::Class;
3
4327µs9µsuse strict;
# spent 11µs making 1 call to strict::import
5330µs10µsuse warnings;
# spent 25µs making 1 call to warnings::import
6
7326µs8µsuse Class::MOP;
# spent 3µs making 1 call to import
8
9328µs9µsuse Carp qw( confess );
# spent 45µs making 1 call to Exporter::import
10336µs12µsuse Data::OptList;
11335µs12µsuse List::Util qw( first );
# spent 43µs making 1 call to Exporter::import
12327µs9µsuse List::MoreUtils qw( any all uniq first_index );
# spent 62µs making 1 call to Exporter::import
13377µs26µsuse Scalar::Util 'weaken', 'blessed';
# spent 47µs making 1 call to Exporter::import
14
1511µs1µsour $VERSION = '1.15';
16124µs24µs$VERSION = eval $VERSION;
171700ns700nsour $AUTHORITY = 'cpan:STEVAN';
18
193118µs39µsuse Moose::Meta::Method::Overridden;
# spent 7µs making 1 call to import
203118µs39µsuse Moose::Meta::Method::Augmented;
# spent 7µs making 1 call to import
213112µs37µsuse Moose::Error::Default;
# spent 4µs making 1 call to import
223135µs45µsuse Moose::Meta::Class::Immutable::Trait;
# spent 4µs making 1 call to import
233119µs40µsuse Moose::Meta::Method::Constructor;
# spent 10µs making 1 call to import
243121µs40µsuse Moose::Meta::Method::Destructor;
# spent 4µs making 1 call to import
253119µs40µsuse Moose::Meta::Method::Meta;
# spent 4µs making 1 call to import
263119µs40µsuse Moose::Util;
27327µs9µsuse Class::MOP::MiniTrait;
# spent 3µs making 1 call to import
28
2932.81ms935µsuse base 'Class::MOP::Class';
# spent 88µs making 1 call to base::import
30
31110µs10µsClass::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
# spent 3.23ms making 1 call to Class::MOP::MiniTrait::apply
32
33__PACKAGE__->meta->add_attribute('roles' => (
34 reader => 'roles',
35815µs2µs
# spent 57µs within Moose::Meta::Class::__ANON__[/usr/local/lib/perl/5.10.0/Moose/Meta/Class.pm:35] which was called 8 times, avg 7µs/call: # 8 times (57µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of /usr/local/lib/perl/5.10.0/Class/MOP/Mixin/AttributeCore.pm, avg 7µs/call
default => sub { [] }
36130µs30µs));
# spent 935µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 27µs making 1 call to Class::MOP::Object::meta
37
38__PACKAGE__->meta->add_attribute('role_applications' => (
39 reader => '_get_role_applications',
40811µs1µs
# spent 53µs within Moose::Meta::Class::__ANON__[/usr/local/lib/perl/5.10.0/Moose/Meta/Class.pm:40] which was called 8 times, avg 7µs/call: # 8 times (53µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of /usr/local/lib/perl/5.10.0/Class/MOP/Mixin/AttributeCore.pm, avg 7µs/call
default => sub { [] }
41118µs18µs));
# spent 585µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 25µs making 1 call to Class::MOP::Object::meta
42
43128µs28µs__PACKAGE__->meta->add_attribute(
# spent 518µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 35µs making 1 call to Class::MOP::Attribute::new # spent 24µs making 1 call to Class::MOP::Object::meta
44 Class::MOP::Attribute->new('immutable_trait' => (
45 accessor => "immutable_trait",
46 default => 'Moose::Meta::Class::Immutable::Trait',
47 ))
48);
49
50114µs14µs__PACKAGE__->meta->add_attribute('constructor_class' => (
# spent 495µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 24µs making 1 call to Class::MOP::Object::meta
51 accessor => 'constructor_class',
52 default => 'Moose::Meta::Method::Constructor',
53));
54
55110µs10µs__PACKAGE__->meta->add_attribute('destructor_class' => (
# spent 458µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 24µs making 1 call to Class::MOP::Object::meta
56 accessor => 'destructor_class',
57 default => 'Moose::Meta::Method::Destructor',
58));
59
60120µs20µs__PACKAGE__->meta->add_attribute('error_class' => (
# spent 483µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 24µs making 1 call to Class::MOP::Object::meta
61 accessor => 'error_class',
62 default => 'Moose::Error::Default',
63));
64
65
# spent 10.7ms (137µs+10.5) within Moose::Meta::Class::initialize which was called 8 times, avg 1.33ms/call: # 7 times (95µs+8.71ms) by Moose::init_meta at line 199 of /usr/local/lib/perl/5.10.0/Moose.pm, avg 1.26ms/call # once (42µs+1.81ms) by metaclass::import at line 45 of /usr/local/lib/perl/5.10.0/metaclass.pm
sub initialize {
6624145µs6µs my $class = shift;
67 my $pkg = shift;
68 return Class::MOP::get_metaclass_by_name($pkg)
# spent 10.5ms making 8 calls to Class::MOP::Class::initialize, avg 1.31ms/call # spent 28µs making 8 calls to Class::MOP::get_metaclass_by_name, avg 3µs/call
69 || $class->SUPER::initialize($pkg,
70 'attribute_metaclass' => 'Moose::Meta::Attribute',
71 'method_metaclass' => 'Moose::Meta::Method',
72 'instance_metaclass' => 'Moose::Meta::Instance',
73 @_
74 );
75}
76
77sub create {
78 my ($class, $package_name, %options) = @_;
79
80 (ref $options{roles} eq 'ARRAY')
81 || $class->throw_error("You must pass an ARRAY ref of roles", data => $options{roles})
82 if exists $options{roles};
83 my $roles = delete $options{roles};
84
85 my $new_meta = $class->SUPER::create($package_name, %options);
86
87 if ($roles) {
88 Moose::Util::apply_all_roles( $new_meta, @$roles );
89 }
90
91 return $new_meta;
92}
93
9415µs5µsmy %ANON_CLASSES;
95
96sub create_anon_class {
97 my ($self, %options) = @_;
98
99 my $cache_ok = delete $options{cache};
100
101 my $cache_key
102 = _anon_cache_key( $options{superclasses}, $options{roles} );
103
104 if ($cache_ok && defined $ANON_CLASSES{$cache_key}) {
105 return $ANON_CLASSES{$cache_key};
106 }
107
108 my $new_class = $self->SUPER::create_anon_class(%options);
109
110 $ANON_CLASSES{$cache_key} = $new_class
111 if $cache_ok;
112
113 return $new_class;
114}
115
116813µs2µs
# spent 39µs within Moose::Meta::Class::_meta_method_class which was called 8 times, avg 5µs/call: # 8 times (39µs+0s) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 30 of /usr/local/lib/perl/5.10.0/Class/MOP/Mixin/HasMethods.pm, avg 5µs/call
sub _meta_method_class { 'Moose::Meta::Method::Meta' }
117
118sub _anon_cache_key {
119 # Makes something like Super::Class|Super::Class::2=Role|Role::1
120 return join '=' => (
121 join( '|', @{ $_[0] || [] } ),
122 join( '|', sort @{ $_[1] || [] } ),
123 );
124}
125
126sub reinitialize {
127 my $self = shift;
128 my $pkg = shift;
129
130 my $meta = blessed $pkg ? $pkg : Class::MOP::class_of($pkg);
131
132 my $cache_key;
133
134 my %existing_classes;
135 if ($meta) {
136 %existing_classes = map { $_ => $meta->$_() } qw(
137 attribute_metaclass
138 method_metaclass
139 wrapped_method_metaclass
140 instance_metaclass
141 constructor_class
142 destructor_class
143 error_class
144 );
145
146 $cache_key = _anon_cache_key(
147 [ $meta->superclasses ],
148 [ map { $_->name } @{ $meta->roles } ],
149 ) if $meta->is_anon_class;
150 }
151
152 my $new_meta = $self->SUPER::reinitialize(
153 $pkg,
154 %existing_classes,
155 @_,
156 );
157
158 return $new_meta unless defined $cache_key;
159
160 my $new_cache_key = _anon_cache_key(
161 [ $meta->superclasses ],
162 [ map { $_->name } @{ $meta->roles } ],
163 );
164
165 delete $ANON_CLASSES{$cache_key};
166 $ANON_CLASSES{$new_cache_key} = $new_meta;
167
168 return $new_meta;
169}
170
171sub add_role {
172 my ($self, $role) = @_;
173 (blessed($role) && $role->isa('Moose::Meta::Role'))
174 || $self->throw_error("Roles must be instances of Moose::Meta::Role", data => $role);
175 push @{$self->roles} => $role;
176}
177
178sub role_applications {
179 my ($self) = @_;
180
181 return @{$self->_get_role_applications};
182}
183
184sub add_role_application {
185 my ($self, $application) = @_;
186 (blessed($application) && $application->isa('Moose::Meta::Role::Application::ToClass'))
187 || $self->throw_error("Role applications must be instances of Moose::Meta::Role::Application::ToClass", data => $application);
188 push @{$self->_get_role_applications} => $application;
189}
190
191sub calculate_all_roles {
192 my $self = shift;
193 my %seen;
194 grep { !$seen{$_->name}++ } map { $_->calculate_all_roles } @{ $self->roles };
195}
196
197sub calculate_all_roles_with_inheritance {
198 my $self = shift;
199 my %seen;
200 grep { !$seen{$_->name}++ }
201 map { Class::MOP::class_of($_)->can('calculate_all_roles')
202 ? Class::MOP::class_of($_)->calculate_all_roles
203 : () }
204 $self->linearized_isa;
205}
206
207sub does_role {
208 my ($self, $role_name) = @_;
209
210 (defined $role_name)
211 || $self->throw_error("You must supply a role name to look for");
212
213 foreach my $class ($self->class_precedence_list) {
214 my $meta = Class::MOP::class_of($class);
215 # when a Moose metaclass is itself extended with a role,
216 # this check needs to be done since some items in the
217 # class_precedence_list might in fact be Class::MOP
218 # based still.
219 next unless $meta && $meta->can('roles');
220 foreach my $role (@{$meta->roles}) {
221 return 1 if $role->does_role($role_name);
222 }
223 }
224 return 0;
225}
226
227sub excludes_role {
228 my ($self, $role_name) = @_;
229
230 (defined $role_name)
231 || $self->throw_error("You must supply a role name to look for");
232
233 foreach my $class ($self->class_precedence_list) {
234 my $meta = Class::MOP::class_of($class);
235 # when a Moose metaclass is itself extended with a role,
236 # this check needs to be done since some items in the
237 # class_precedence_list might in fact be Class::MOP
238 # based still.
239 next unless $meta && $meta->can('roles');
240 foreach my $role (@{$meta->roles}) {
241 return 1 if $role->excludes_role($role_name);
242 }
243 }
244 return 0;
245}
246
247sub new_object {
248 my $self = shift;
249 my $params = @_ == 1 ? $_[0] : {@_};
250 my $object = $self->SUPER::new_object($params);
251
252 foreach my $attr ( $self->get_all_attributes() ) {
253
254 next unless $attr->can('has_trigger') && $attr->has_trigger;
255
256 my $init_arg = $attr->init_arg;
257
258 next unless defined $init_arg;
259
260 next unless exists $params->{$init_arg};
261
262 $attr->trigger->(
263 $object,
264 (
265 $attr->should_coerce
266 ? $attr->get_read_method_ref->($object)
267 : $params->{$init_arg}
268 ),
269 );
270 }
271
272 $object->BUILDALL($params) if $object->can('BUILDALL');
273
274 return $object;
275}
276
277
# spent 37.5ms (631µs+36.9) within Moose::Meta::Class::superclasses which was called 37 times, avg 1.01ms/call: # 19 times (278µs+461µs) by Class::MOP::Class::_check_metaclass_compatibility at line 209 of /usr/local/lib/perl/5.10.0/Class/MOP/Class.pm, avg 39µs/call # 14 times (248µs+6.99ms) by Moose::init_meta at line 218 of /usr/local/lib/perl/5.10.0/Moose.pm, avg 517µs/call # 4 times (106µs+29.4ms) by Moose::extends at line 54 of /usr/local/lib/perl/5.10.0/Moose.pm, avg 7.38ms/call
sub superclasses {
278192956µs5µs my $self = shift;
279 my $supers = Data::OptList::mkopt(\@_);
# spent 465µs making 37 calls to Data::OptList::mkopt, avg 13µs/call
280 foreach my $super (@{ $supers }) {
281 my ($name, $opts) = @{ $super };
282 Class::MOP::load_class($name, $opts);
# spent 24.6ms making 11 calls to Class::MOP::load_class, avg 2.22ms/call, max recursion depth 1
283 my $meta = Class::MOP::class_of($name);
# spent 113µs making 11 calls to Class::MOP::class_of, avg 10µs/call
284 $self->throw_error("You cannot inherit from a Moose Role ($name)")
# spent 134µs making 11 calls to UNIVERSAL::isa, avg 12µs/call
285 if $meta && $meta->isa('Moose::Meta::Role')
286 }
287 return $self->SUPER::superclasses(map { $_->[0] } @{ $supers });
# spent 15.4ms making 37 calls to Class::MOP::Class::superclasses, avg 403µs/call, max recursion depth 1
288}
289
290### ---------------------------------------------
291
292
# spent 20.3ms (166µs+20.2) within Moose::Meta::Class::add_attribute which was called 8 times, avg 2.54ms/call: # 8 times (166µs+20.2ms) by Moose::has at line 70 of /usr/local/lib/perl/5.10.0/Moose.pm, avg 2.54ms/call
sub add_attribute {
29340276µs7µs my $self = shift;
294 my $attr =
# spent 4.40ms making 8 calls to Moose::Meta::Class::_process_attribute, avg 550µs/call # spent 22µs making 8 calls to Scalar::Util::blessed, avg 3µs/call
295 (blessed $_[0] && $_[0]->isa('Class::MOP::Attribute')
296 ? $_[0]
297 : $self->_process_attribute(@_));
298 $self->SUPER::add_attribute($attr);
# spent 15.6ms making 8 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 1.95ms/call
299 # it may be a Class::MOP::Attribute, theoretically, which doesn't have
300 # 'bare' and doesn't implement this method
301 if ($attr->can('_check_associated_methods')) {
# spent 91µs making 8 calls to Moose::Meta::Attribute::_check_associated_methods, avg 11µs/call # spent 36µs making 8 calls to UNIVERSAL::can, avg 5µs/call
302 $attr->_check_associated_methods;
303 }
304 return $attr;
305}
306
307
# spent 2.66ms (56µs+2.60) within Moose::Meta::Class::add_override_method_modifier which was called 4 times, avg 665µs/call: # 4 times (56µs+2.60ms) by Moose::override at line 99 of /usr/local/lib/perl/5.10.0/Moose.pm, avg 665µs/call
sub add_override_method_modifier {
3081288µs7µs my ($self, $name, $method, $_super_package) = @_;
309
310 (!$self->has_method($name))
# spent 411µs making 4 calls to Class::MOP::Mixin::HasMethods::has_method, avg 103µs/call
311 || $self->throw_error("Cannot add an override method if a local method is already present");
312
313 $self->add_method($name => Moose::Meta::Method::Overridden->new(
# spent 1.67ms making 4 calls to Moose::Meta::Method::Overridden::new, avg 418µs/call # spent 521µs making 4 calls to Class::MOP::Mixin::HasMethods::add_method, avg 130µs/call
314 method => $method,
315 class => $self,
316 package => $_super_package, # need this for roles
317 name => $name,
318 ));
319}
320
321sub add_augment_method_modifier {
322 my ($self, $name, $method) = @_;
323 (!$self->has_method($name))
324 || $self->throw_error("Cannot add an augment method if a local method is already present");
325
326 $self->add_method($name => Moose::Meta::Method::Augmented->new(
327 method => $method,
328 class => $self,
329 name => $name,
330 ));
331}
332
333## Private Utility methods ...
334
335sub _find_next_method_by_name_which_is_not_overridden {
336 my ($self, $name) = @_;
337 foreach my $method ($self->find_all_methods_by_name($name)) {
338 return $method->{code}
339 if blessed($method->{code}) && !$method->{code}->isa('Moose::Meta::Method::Overridden');
340 }
341 return undef;
342}
343
344## Metaclass compatibility
345
346
# spent 972µs (821+151) within Moose::Meta::Class::_base_metaclasses which was called 22 times, avg 44µs/call: # 11 times (433µs+83µs) by Class::MOP::Class::_can_fix_metaclass_incompatibility at line 339 of /usr/local/lib/perl/5.10.0/Class/MOP/Class.pm, avg 47µs/call # 11 times (388µs+68µs) by Class::MOP::Class::_check_metaclass_compatibility at line 214 of /usr/local/lib/perl/5.10.0/Class/MOP/Class.pm, avg 41µs/call
sub _base_metaclasses {
347220815µs4µs my $self = shift;
348 my %metaclasses = $self->SUPER::_base_metaclasses;
# spent 151µs making 22 calls to Class::MOP::Class::_base_metaclasses, avg 7µs/call
349 for my $class (keys %metaclasses) {
350 $metaclasses{$class} =~ s/^Class::MOP/Moose::Meta/;
351 }
352 return (
353 %metaclasses,
354 error_class => 'Moose::Error::Default',
355 );
356}
357
358sub _fix_class_metaclass_incompatibility {
359 my $self = shift;
360 my ($super_meta) = @_;
361
362 $self->SUPER::_fix_class_metaclass_incompatibility(@_);
363
364 if ($self->_class_metaclass_can_be_made_compatible($super_meta)) {
365 ($self->is_pristine)
366 || confess "Can't fix metaclass incompatibility for "
367 . $self->name
368 . " because it is not pristine.";
369 my $super_meta_name = $super_meta->_real_ref_name;
370 my $class_meta_subclass_meta_name = Moose::Util::_reconcile_roles_for_metaclass(blessed($self), $super_meta_name);
371 my $new_self = $class_meta_subclass_meta_name->reinitialize(
372 $self->name,
373 );
374
375 $self->_replace_self( $new_self, $class_meta_subclass_meta_name );
376 }
377}
378
379sub _fix_single_metaclass_incompatibility {
380 my $self = shift;
381 my ($metaclass_type, $super_meta) = @_;
382
383 $self->SUPER::_fix_single_metaclass_incompatibility(@_);
384
385 if ($self->_single_metaclass_can_be_made_compatible($super_meta, $metaclass_type)) {
386 ($self->is_pristine)
387 || confess "Can't fix metaclass incompatibility for "
388 . $self->name
389 . " because it is not pristine.";
390 my $super_meta_name = $super_meta->_real_ref_name;
391 my $class_specific_meta_subclass_meta_name = Moose::Util::_reconcile_roles_for_metaclass($self->$metaclass_type, $super_meta->$metaclass_type);
392 my $new_self = $super_meta->reinitialize(
393 $self->name,
394 $metaclass_type => $class_specific_meta_subclass_meta_name,
395 );
396
397 $self->_replace_self( $new_self, $super_meta_name );
398 }
399}
400
401sub _replace_self {
402 my $self = shift;
403 my ( $new_self, $new_class) = @_;
404
405 %$self = %$new_self;
406 bless $self, $new_class;
407
408 # We need to replace the cached metaclass instance or else when it goes
409 # out of scope Class::MOP::Class destroy's the namespace for the
410 # metaclass's class, causing much havoc.
411 Class::MOP::store_metaclass_by_name( $self->name, $self );
412 Class::MOP::weaken_metaclass( $self->name ) if $self->is_anon_class;
413}
414
415
# spent 4.40ms (106µs+4.30) within Moose::Meta::Class::_process_attribute which was called 8 times, avg 550µs/call: # 8 times (106µs+4.30ms) by Moose::Meta::Class::add_attribute at line 294, avg 550µs/call
sub _process_attribute {
41632113µs4µs my ( $self, $name, @args ) = @_;
417
418 @args = %{$args[0]} if scalar @args == 1 && ref($args[0]) eq 'HASH';
419
420 if (($name || '') =~ /^\+(.*)/) {
421 return $self->_process_inherited_attribute($1, @args);
422 }
423 else {
424 return $self->_process_new_attribute($name, @args);
# spent 4.30ms making 8 calls to Moose::Meta::Class::_process_new_attribute, avg 537µs/call
425 }
426}
427
428
# spent 4.30ms (104µs+4.19) within Moose::Meta::Class::_process_new_attribute which was called 8 times, avg 537µs/call: # 8 times (104µs+4.19ms) by Moose::Meta::Class::_process_attribute at line 424, avg 537µs/call
sub _process_new_attribute {
42916144µs9µs my ( $self, $name, @args ) = @_;
430
431 $self->attribute_metaclass->interpolate_class_and_new($name, @args);
# spent 4.15ms making 8 calls to Moose::Meta::Attribute::interpolate_class_and_new, avg 518µs/call # spent 49µs making 8 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 6µs/call
432}
433
434sub _process_inherited_attribute {
435 my ($self, $attr_name, %options) = @_;
436 my $inherited_attr = $self->find_attribute_by_name($attr_name);
437 (defined $inherited_attr)
438 || $self->throw_error("Could not find an attribute by the name of '$attr_name' to inherit from in ${\$self->name}", data => $attr_name);
439 if ($inherited_attr->isa('Moose::Meta::Attribute')) {
440 return $inherited_attr->clone_and_inherit_options(%options);
441 }
442 else {
443 # NOTE:
444 # kind of a kludge to handle Class::MOP::Attributes
445 return $inherited_attr->Moose::Meta::Attribute::clone_and_inherit_options(%options);
446 }
447}
448
449## Immutability
450
451
# spent 361µs (75+285) within Moose::Meta::Class::_immutable_options which was called 7 times, avg 52µs/call: # 7 times (75µs+285µs) by Class::MOP::Class::make_immutable at line 1148 of /usr/local/lib/perl/5.10.0/Class/MOP/Class.pm, avg 52µs/call
sub _immutable_options {
4521475µs5µs my ( $self, @args ) = @_;
453
454 $self->SUPER::_immutable_options(
# spent 285µs making 7 calls to Class::MOP::Class::_immutable_options, avg 41µs/call
455 inline_destructor => 1,
456
457 # Moose always does this when an attribute is created
458 inline_accessors => 0,
459
460 @args,
461 );
462}
463
464## -------------------------------------------------
465
4661300ns300nsour $error_level;
467
468sub throw_error {
469 my ( $self, @args ) = @_;
470 local $error_level = ($error_level || 0) + 1;
471 $self->raise_error($self->create_error(@args));
472}
473
474sub raise_error {
475 my ( $self, @args ) = @_;
476 die @args;
477}
478
479sub create_error {
480 my ( $self, @args ) = @_;
481
482 require Carp::Heavy;
483
484 local $error_level = ($error_level || 0 ) + 1;
485
486 if ( @args % 2 == 1 ) {
487 unshift @args, "message";
488 }
489
490 my %args = ( metaclass => $self, last_error => $@, @args );
491
492 $args{depth} += $error_level;
493
494 my $class = ref $self ? $self->error_class : "Moose::Error::Default";
495
496 Class::MOP::load_class($class);
497
498 $class->new(
499 Carp::caller_info($args{depth}),
500 %args
501 );
502}
503
504127µs27µs1;
505
506__END__
507
508=pod
509
510=head1 NAME
511
512Moose::Meta::Class - The Moose metaclass
513
514=head1 DESCRIPTION
515
516This class is a subclass of L<Class::MOP::Class> that provides
517additional Moose-specific functionality.
518
519To really understand this class, you will need to start with the
520L<Class::MOP::Class> documentation. This class can be understood as a
521set of additional features on top of the basic feature provided by
522that parent class.
523
524=head1 INHERITANCE
525
526C<Moose::Meta::Class> is a subclass of L<Class::MOP::Class>.
527
528=head1 METHODS
529
530=over 4
531
532=item B<< Moose::Meta::Class->initialize($package_name, %options) >>
533
534This overrides the parent's method in order to provide its own
535defaults for the C<attribute_metaclass>, C<instance_metaclass>, and
536C<method_metaclass> options.
537
538These all default to the appropriate Moose class.
539
540=item B<< Moose::Meta::Class->create($package_name, %options) >>
541
542This overrides the parent's method in order to accept a C<roles>
543option. This should be an array reference containing roles
544that the class does, each optionally followed by a hashref of options
545(C<-excludes> and C<-alias>).
546
547 my $metaclass = Moose::Meta::Class->create( 'New::Class', roles => [...] );
548
549=item B<< Moose::Meta::Class->create_anon_class >>
550
551This overrides the parent's method to accept a C<roles> option, just
552as C<create> does.
553
554It also accepts a C<cache> option. If this is true, then the anonymous
555class will be cached based on its superclasses and roles. If an
556existing anonymous class in the cache has the same superclasses and
557roles, it will be reused.
558
559 my $metaclass = Moose::Meta::Class->create_anon_class(
560 superclasses => ['Foo'],
561 roles => [qw/Some Roles Go Here/],
562 cache => 1,
563 );
564
565Each entry in both the C<superclasses> and the C<roles> option can be
566followed by a hash reference with arguments. The C<superclasses>
567option can be supplied with a L<-version|Class::MOP/Class Loading
568Options> option that ensures the loaded superclass satisfies the
569required version. The C<role> option also takes the C<-version> as an
570argument, but the option hash reference can also contain any other
571role relevant values like exclusions or parameterized role arguments.
572
573=item B<< $metaclass->make_immutable(%options) >>
574
575This overrides the parent's method to add a few options. Specifically,
576it uses the Moose-specific constructor and destructor classes, and
577enables inlining the destructor.
578
579Since Moose always inlines attributes, it sets the C<inline_accessors> option
580to false.
581
582=item B<< $metaclass->new_object(%params) >>
583
584This overrides the parent's method in order to add support for
585attribute triggers.
586
587=item B<< $metaclass->superclasses(@superclasses) >>
588
589This is the accessor allowing you to read or change the parents of
590the class.
591
592Each superclass can be followed by a hash reference containing a
593L<-version|Class::MOP/Class Loading Options> value. If the version
594requirement is not satisfied an error will be thrown.
595
596=item B<< $metaclass->add_override_method_modifier($name, $sub) >>
597
598This adds an C<override> method modifier to the package.
599
600=item B<< $metaclass->add_augment_method_modifier($name, $sub) >>
601
602This adds an C<augment> method modifier to the package.
603
604=item B<< $metaclass->calculate_all_roles >>
605
606This will return a unique array of C<Moose::Meta::Role> instances
607which are attached to this class.
608
609=item B<< $metaclass->calculate_all_roles_with_inheritance >>
610
611This will return a unique array of C<Moose::Meta::Role> instances
612which are attached to this class, and each of this class's ancestors.
613
614=item B<< $metaclass->add_role($role) >>
615
616This takes a L<Moose::Meta::Role> object, and adds it to the class's
617list of roles. This I<does not> actually apply the role to the class.
618
619=item B<< $metaclass->role_applications >>
620
621Returns a list of L<Moose::Meta::Role::Application::ToClass>
622objects, which contain the arguments to role application.
623
624=item B<< $metaclass->add_role_application($application) >>
625
626This takes a L<Moose::Meta::Role::Application::ToClass> object, and
627adds it to the class's list of role applications. This I<does not>
628actually apply any role to the class; it is only for tracking role
629applications.
630
631=item B<< $metaclass->does_role($role) >>
632
633This returns a boolean indicating whether or not the class does the specified
634role. The role provided can be either a role name or a L<Moose::Meta::Role>
635object. This tests both the class and its parents.
636
637=item B<< $metaclass->excludes_role($role_name) >>
638
639A class excludes a role if it has already composed a role which
640excludes the named role. This tests both the class and its parents.
641
642=item B<< $metaclass->add_attribute($attr_name, %params|$params) >>
643
644This overrides the parent's method in order to allow the parameters to
645be provided as a hash reference.
646
647=item B<< $metaclass->constructor_class($class_name) >>
648
649=item B<< $metaclass->destructor_class($class_name) >>
650
651These are the names of classes used when making a class immutable. These
652default to L<Moose::Meta::Method::Constructor> and
653L<Moose::Meta::Method::Destructor> respectively. These accessors are
654read-write, so you can use them to change the class name.
655
656=item B<< $metaclass->error_class($class_name) >>
657
658The name of the class used to throw errors. This defaults to
659L<Moose::Error::Default>, which generates an error with a stacktrace
660just like C<Carp::confess>.
661
662=item B<< $metaclass->throw_error($message, %extra) >>
663
664Throws the error created by C<create_error> using C<raise_error>
665
666=back
667
668=head1 BUGS
669
670See L<Moose/BUGS> for details on reporting bugs.
671
672=head1 AUTHOR
673
674Stevan Little E<lt>stevan@iinteractive.comE<gt>
675
676=head1 COPYRIGHT AND LICENSE
677
678Copyright 2006-2010 by Infinity Interactive, Inc.
679
680L<http://www.iinteractive.com>
681
682This library is free software; you can redistribute it and/or modify
683it under the same terms as Perl itself.
684
685=cut
686