← Index
NYTProf Performance Profile   « block view • line view • sub view »
For 05.Domain_and_Item.t
  Run on Tue May 4 17:21:41 2010
Reported on Tue May 4 17:23:12 2010

File /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/Class.pm
Statements Executed 7983
Statement Execution Time 18.7ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
14251355.36ms28.5msMoose::Meta::Class::::initializeMoose::Meta::Class::initialize
50443.34ms96.6msMoose::Meta::Class::::new_objectMoose::Meta::Class::new_object
166531.65ms602msMoose::Meta::Class::::superclassesMoose::Meta::Class::superclasses
1111.61ms1.77msMoose::Meta::Class::::BEGIN@22Moose::Meta::Class::BEGIN@22
86431.49ms108msMoose::Meta::Class::::add_attributeMoose::Meta::Class::add_attribute
4811938µs1.51msMoose::Meta::Class::::_superclass_meta_is_compatibleMoose::Meta::Class::_superclass_meta_is_compatible
7821884µs12.6msMoose::Meta::Class::::_check_metaclass_compatibilityMoose::Meta::Class::_check_metaclass_compatibility
1311598µs2.75msMoose::Meta::Class::::excludes_roleMoose::Meta::Class::excludes_role
4811561µs5.17msMoose::Meta::Class::::_fix_metaclass_incompatibilityMoose::Meta::Class::_fix_metaclass_incompatibility
111539µs686µsMoose::Meta::Class::::BEGIN@23Moose::Meta::Class::BEGIN@23
4911496µs15.2msMoose::Meta::Class::::_process_new_attributeMoose::Meta::Class::_process_new_attribute
4911488µs15.7msMoose::Meta::Class::::_process_attributeMoose::Meta::Class::_process_attribute
111321µs407µsMoose::Meta::Class::::BEGIN@19Moose::Meta::Class::BEGIN@19
111319µs841µsMoose::Meta::Class::::BEGIN@18Moose::Meta::Class::BEGIN@18
111295µs1.58msMoose::Meta::Class::::BEGIN@20Moose::Meta::Class::BEGIN@20
4811251µs4.40msMoose::Meta::Class::::_fix_one_incompatible_metaclassMoose::Meta::Class::_fix_one_incompatible_metaclass
111237µs325µsMoose::Meta::Class::::BEGIN@21Moose::Meta::Class::BEGIN@21
222142µs2.81msMoose::Meta::Class::::reinitializeMoose::Meta::Class::reinitialize
1311137µs185µsMoose::Meta::Class::::add_roleMoose::Meta::Class::add_role
111134µs1.85msMoose::Meta::Class::::_reinitialize_withMoose::Meta::Class::_reinitialize_with
1311133µs190µsMoose::Meta::Class::::add_role_applicationMoose::Meta::Class::add_role_application
321180µs80µsMoose::Meta::Class::::__ANON__[:29]Moose::Meta::Class::__ANON__[:29]
71176µs351µsMoose::Meta::Class::::_immutable_optionsMoose::Meta::Class::_immutable_options
321165µs65µsMoose::Meta::Class::::__ANON__[:34]Moose::Meta::Class::__ANON__[:34]
32162µs30.7msMoose::Meta::Class::::createMoose::Meta::Class::create
22258µs29.4msMoose::Meta::Class::::create_anon_classMoose::Meta::Class::create_anon_class
491233µs33µsMoose::Meta::Class::::CORE:matchMoose::Meta::Class::CORE:match (opcode)
11131µs2.02msMoose::Meta::Class::::_reconcile_with_superclass_metaMoose::Meta::Class::_reconcile_with_superclass_meta
21122µs24µsMoose::Meta::Class::::_anon_cache_keyMoose::Meta::Class::_anon_cache_key
11115µs18µsMoose::Meta::Class::::BEGIN@4Moose::Meta::Class::BEGIN@4
1118µs75µsMoose::Meta::Class::::BEGIN@12Moose::Meta::Class::BEGIN@12
1117µs45µsMoose::Meta::Class::::BEGIN@11Moose::Meta::Class::BEGIN@11
1117µs38µsMoose::Meta::Class::::BEGIN@10Moose::Meta::Class::BEGIN@10
1117µs15µsMoose::Meta::Class::::BEGIN@5Moose::Meta::Class::BEGIN@5
1116µs52µsMoose::Meta::Class::::BEGIN@25Moose::Meta::Class::BEGIN@25
1114µs4µsMoose::Meta::Class::::BEGIN@7Moose::Meta::Class::BEGIN@7
1113µs3µsMoose::Meta::Class::::BEGIN@9Moose::Meta::Class::BEGIN@9
2122µs2µsMoose::Meta::Class::::CORE:sortMoose::Meta::Class::CORE:sort (opcode)
0000s0sMoose::Meta::Class::::__ANON__[:407]Moose::Meta::Class::__ANON__[:407]
0000s0sMoose::Meta::Class::::__ANON__[:493]Moose::Meta::Class::__ANON__[:493]
0000s0sMoose::Meta::Class::::__ANON__[:526]Moose::Meta::Class::__ANON__[:526]
0000s0sMoose::Meta::Class::::_all_metaclasses_differ_by_roles_onlyMoose::Meta::Class::_all_metaclasses_differ_by_roles_only
0000s0sMoose::Meta::Class::::_all_rolesMoose::Meta::Class::_all_roles
0000s0sMoose::Meta::Class::::_all_roles_untilMoose::Meta::Class::_all_roles_until
0000s0sMoose::Meta::Class::::_find_common_ancestorMoose::Meta::Class::_find_common_ancestor
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::::_is_role_only_subclass_ofMoose::Meta::Class::_is_role_only_subclass_of
0000s0sMoose::Meta::Class::::_process_inherited_attributeMoose::Meta::Class::_process_inherited_attribute
0000s0sMoose::Meta::Class::::_reconcile_role_differencesMoose::Meta::Class::_reconcile_role_differences
0000s0sMoose::Meta::Class::::add_augment_method_modifierMoose::Meta::Class::add_augment_method_modifier
0000s0sMoose::Meta::Class::::add_override_method_modifierMoose::Meta::Class::add_override_method_modifier
0000s0sMoose::Meta::Class::::calculate_all_rolesMoose::Meta::Class::calculate_all_roles
0000s0sMoose::Meta::Class::::create_errorMoose::Meta::Class::create_error
0000s0sMoose::Meta::Class::::does_roleMoose::Meta::Class::does_role
0000s0sMoose::Meta::Class::::raise_errorMoose::Meta::Class::raise_error
0000s0sMoose::Meta::Class::::role_applicationsMoose::Meta::Class::role_applications
0000s0sMoose::Meta::Class::::throw_errorMoose::Meta::Class::throw_error
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::Class;
3
4319µs221µs
# spent 18µs (15+3) within Moose::Meta::Class::BEGIN@4 which was called # once (15µs+3µs) by Moose::BEGIN@18 at line 4
use strict;
# spent 18µs making 1 call to Moose::Meta::Class::BEGIN@4 # spent 3µs making 1 call to strict::import
5318µs224µs
# spent 15µs (7+9) within Moose::Meta::Class::BEGIN@5 which was called # once (7µs+9µs) by Moose::BEGIN@18 at line 5
use warnings;
# spent 15µs making 1 call to Moose::Meta::Class::BEGIN@5 # spent 9µs making 1 call to warnings::import
6
7316µs14µs
# spent 4µs within Moose::Meta::Class::BEGIN@7 which was called # once (4µs+0s) by Moose::BEGIN@18 at line 7
use Class::MOP;
# spent 4µs making 1 call to Moose::Meta::Class::BEGIN@7
8
9318µs13µs
# spent 3µs within Moose::Meta::Class::BEGIN@9 which was called # once (3µs+0s) by Moose::BEGIN@18 at line 9
use Carp ();
# spent 3µs making 1 call to Moose::Meta::Class::BEGIN@9
10329µs270µs
# spent 38µs (7+32) within Moose::Meta::Class::BEGIN@10 which was called # once (7µs+32µs) by Moose::BEGIN@18 at line 10
use List::Util qw( first );
# spent 38µs making 1 call to Moose::Meta::Class::BEGIN@10 # spent 32µs making 1 call to Exporter::import
11326µs282µs
# spent 45µs (7+37) within Moose::Meta::Class::BEGIN@11 which was called # once (7µs+37µs) by Moose::BEGIN@18 at line 11
use List::MoreUtils qw( any all uniq first_index );
# spent 45µs making 1 call to Moose::Meta::Class::BEGIN@11 # spent 37µs making 1 call to Exporter::import
12342µs2143µs
# spent 75µs (8+67) within Moose::Meta::Class::BEGIN@12 which was called # once (8µs+67µs) by Moose::BEGIN@18 at line 12
use Scalar::Util 'weaken', 'blessed';
# spent 75µs making 1 call to Moose::Meta::Class::BEGIN@12 # spent 67µs making 1 call to Exporter::import
13
141700nsour $VERSION = '0.98';
15114µs$VERSION = eval $VERSION;
161500nsour $AUTHORITY = 'cpan:STEVAN';
17
183121µs1841µs
# spent 841µs (319+522) within Moose::Meta::Class::BEGIN@18 which was called # once (319µs+522µs) by Moose::BEGIN@18 at line 18
use Moose::Meta::Method::Overridden;
# spent 841µs making 1 call to Moose::Meta::Class::BEGIN@18
193108µs1407µs
# spent 407µs (321+87) within Moose::Meta::Class::BEGIN@19 which was called # once (321µs+87µs) by Moose::BEGIN@18 at line 19
use Moose::Meta::Method::Augmented;
# spent 407µs making 1 call to Moose::Meta::Class::BEGIN@19
20399µs11.58ms
# spent 1.58ms (295µs+1.28) within Moose::Meta::Class::BEGIN@20 which was called # once (295µs+1.28ms) by Moose::BEGIN@18 at line 20
use Moose::Error::Default;
# spent 1.58ms making 1 call to Moose::Meta::Class::BEGIN@20
21399µs1325µs
# spent 325µs (237+88) within Moose::Meta::Class::BEGIN@21 which was called # once (237µs+88µs) by Moose::BEGIN@18 at line 21
use Moose::Meta::Class::Immutable::Trait;
# spent 325µs making 1 call to Moose::Meta::Class::BEGIN@21
223109µs11.77ms
# spent 1.77ms (1.61+164µs) within Moose::Meta::Class::BEGIN@22 which was called # once (1.61ms+164µs) by Moose::BEGIN@18 at line 22
use Moose::Meta::Method::Constructor;
# spent 1.77ms making 1 call to Moose::Meta::Class::BEGIN@22
233103µs1686µs
# spent 686µs (539+147) within Moose::Meta::Class::BEGIN@23 which was called # once (539µs+147µs) by Moose::BEGIN@18 at line 23
use Moose::Meta::Method::Destructor;
# spent 686µs making 1 call to Moose::Meta::Class::BEGIN@23
24
2532.12ms298µs
# spent 52µs (6+46) within Moose::Meta::Class::BEGIN@25 which was called # once (6µs+46µs) by Moose::BEGIN@18 at line 25
use base 'Class::MOP::Class';
# spent 52µs making 1 call to Moose::Meta::Class::BEGIN@25 # spent 46µs making 1 call to base::import
26
27__PACKAGE__->meta->add_attribute('roles' => (
28 reader => 'roles',
2932102µs
# spent 80µs within Moose::Meta::Class::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/Class.pm:29] which was called 32 times, avg 2µs/call: # 32 times (80µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of Class/MOP/Mixin/AttributeCore.pm, avg 2µs/call
default => sub { [] }
30120µs2675µs));
# spent 579µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 96µs making 1 call to Class::MOP::Object::meta
31
32__PACKAGE__->meta->add_attribute('role_applications' => (
33 reader => '_get_role_applications',
343284µs
# spent 65µs within Moose::Meta::Class::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/Class.pm:34] which was called 32 times, avg 2µs/call: # 32 times (65µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of Class/MOP/Mixin/AttributeCore.pm, avg 2µs/call
default => sub { [] }
3514µs2275µs));
# spent 264µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Class::MOP::Object::meta
36
3714µs3274µs__PACKAGE__->meta->add_attribute(
# spent 245µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 18µs making 1 call to Class::MOP::Attribute::new # spent 11µs making 1 call to Class::MOP::Object::meta
38 Class::MOP::Attribute->new('immutable_trait' => (
39 accessor => "immutable_trait",
40 default => 'Moose::Meta::Class::Immutable::Trait',
41 ))
42);
43
4412µs2266µs__PACKAGE__->meta->add_attribute('constructor_class' => (
# spent 254µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Class::MOP::Object::meta
45 accessor => 'constructor_class',
46 default => 'Moose::Meta::Method::Constructor',
47));
48
4913µs2268µs__PACKAGE__->meta->add_attribute('destructor_class' => (
# spent 258µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Class::MOP::Object::meta
50 accessor => 'destructor_class',
51 default => 'Moose::Meta::Method::Destructor',
52));
53
5412µs2270µs__PACKAGE__->meta->add_attribute('error_class' => (
# spent 259µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Class::MOP::Object::meta
55 accessor => 'error_class',
56 default => 'Moose::Error::Default',
57));
58
59
# spent 28.5ms (5.36+23.1) within Moose::Meta::Class::initialize which was called 1425 times, avg 20µs/call: # 801 times (2.82ms+765µs) by Class::MOP::Class::get_all_attributes at line 551 of Class/MOP/Class.pm, avg 4µs/call # 150 times (499µs+150µs) by Class::MOP::Class::find_method_by_name at line 729 of Class/MOP/Class.pm, avg 4µs/call # 127 times (573µs+224µs) by Foo::Child::meta or Foo::Domain::meta or Foo::Parent::meta or Foo::SubChild::meta or MooseX::AttributeHelpers::Collection::Hash::meta or SimpleDB::Class::Cache::meta or SimpleDB::Class::Domain::meta or SimpleDB::Class::ResultSet::meta or SimpleDB::Class::SQL::meta or SimpleDB::Class::meta or SimpleDB::Client::meta at line 220 of Moose.pm, avg 6µs/call # 121 times (405µs+144µs) by Class::MOP::Class::find_next_method_by_name at line 779 of Class/MOP/Class.pm, avg 5µs/call # 105 times (399µs+104µs) by Class::MOP::Class::find_attribute_by_name at line 541 of Class/MOP/Class.pm, avg 5µs/call # 48 times (170µs+52µs) by Moose::Meta::Class::_fix_metaclass_incompatibility at line 349, avg 5µs/call # 26 times (253µs+16.1ms) by Moose::init_meta at line 194 of Moose.pm, avg 627µs/call # 24 times (90µs+25µs) by Class::MOP::Class::find_all_methods_by_name at line 762 of Class/MOP/Class.pm, avg 5µs/call # 13 times (51µs+18µs) by Class::MOP::Class::class_precedence_list at line 638 of Class/MOP/Class.pm, avg 5µs/call # 4 times (17µs+-5µs) by Class::MOP::Class::__ANON__::SERIAL::1::meta or Class::MOP::Class::__ANON__::SERIAL::2::meta at line 304 of Class/MOP/Class.pm, avg 3µs/call # 3 times (32µs+2.11ms) by Class::MOP::Class::create at line 298 of Class/MOP/Class.pm, avg 714µs/call # 2 times (19µs+2.51ms) by Class::MOP::Package::reinitialize at line 59 of Class/MOP/Package.pm, avg 1.26ms/call # once (29µs+943µs) by metaclass::import at line 43 of metaclass.pm
sub initialize {
601425388µs my $class = shift;
611425325µs my $pkg = shift;
6214253.99ms145723.2ms return Class::MOP::get_metaclass_by_name($pkg)
# spent 21.6ms making 32 calls to Class::MOP::Class::initialize, avg 674µs/call # spent 1.60ms making 1425 calls to Class::MOP::get_metaclass_by_name, avg 1µs/call
63 || $class->SUPER::initialize($pkg,
64 'attribute_metaclass' => 'Moose::Meta::Attribute',
65 'method_metaclass' => 'Moose::Meta::Method',
66 'instance_metaclass' => 'Moose::Meta::Instance',
67 @_
68 );
69}
70
71
# spent 351µs (76+275) within Moose::Meta::Class::_immutable_options which was called 7 times, avg 50µs/call: # 7 times (76µs+275µs) by Class::MOP::Class::make_immutable at line 892 of Class/MOP/Class.pm, avg 50µs/call
sub _immutable_options {
7278µs my ( $self, @args ) = @_;
73
74769µs7275µs $self->SUPER::_immutable_options(
# spent 275µs making 7 calls to Class::MOP::Class::_immutable_options, avg 39µs/call
75 inline_destructor => 1,
76
77 # Moose always does this when an attribute is created
78 inline_accessors => 0,
79
80 @args,
81 );
82}
83
84
# spent 30.7ms (62µs+30.7) within Moose::Meta::Class::create which was called 3 times, avg 10.2ms/call: # 2 times (49µs+29.2ms) by Class::MOP::Class::create_anon_class at line 230 of Class/MOP/Class.pm, avg 14.6ms/call # once (13µs+1.47ms) by Class::MOP::Class::_immutable_metaclass at line 961 of Class/MOP/Class.pm
sub create {
8537µs my ($self, $package_name, %options) = @_;
86
8735µs (ref $options{roles} eq 'ARRAY')
88 || $self->throw_error("You must pass an ARRAY ref of roles", data => $options{roles})
89 if exists $options{roles};
9033µs my $roles = delete $options{roles};
91
92322µs34.39ms my $class = $self->SUPER::create($package_name, %options);
# spent 4.39ms making 3 calls to Class::MOP::Class::create, avg 1.46ms/call
93
9438µs226.3ms if ($roles) {
# spent 26.3ms making 2 calls to Moose::Util::apply_all_roles, avg 13.1ms/call
95 Moose::Util::apply_all_roles( $class, @$roles );
96 }
97
98315µs return $class;
99}
100
101
# spent 12.6ms (884µs+11.7) within Moose::Meta::Class::_check_metaclass_compatibility which was called 78 times, avg 161µs/call: # 46 times (521µs+10.0ms) by Class::MOP::Class::superclasses at line 579 of Class/MOP/Class.pm, avg 229µs/call # 32 times (363µs+1.67ms) by Class::MOP::Class::_construct_class_instance at line 91 of Class/MOP/Class.pm, avg 64µs/call
sub _check_metaclass_compatibility {
1027826µs my $self = shift;
103
10478283µs1265.40ms if ( my @supers = $self->superclasses ) {
# spent 5.26ms making 48 calls to Moose::Meta::Class::_fix_metaclass_incompatibility, avg 110µs/call, recursion: max depth 1, time 91µs # spent 2.15ms making 78 calls to Moose::Meta::Class::superclasses, avg 28µs/call, recursion: max depth 2, time 1.92ms
105 $self->_fix_metaclass_incompatibility(@supers);
106 }
107
10878424µs784.54ms $self->SUPER::_check_metaclass_compatibility(@_);
# spent 4.54ms making 78 calls to Class::MOP::Class::_check_metaclass_compatibility, avg 58µs/call
109}
110
1111100nsmy %ANON_CLASSES;
112
113
# spent 29.4ms (58µs+29.3) within Moose::Meta::Class::create_anon_class which was called 2 times, avg 14.7ms/call: # once (27µs+22.5ms) by Moose::Util::MetaRole::_make_new_class at line 150 of Moose/Util/MetaRole.pm # once (31µs+6.82ms) by Moose::Meta::Attribute::interpolate_class at line 119 of Moose/Meta/Attribute.pm
sub create_anon_class {
11427µs my ($self, %options) = @_;
115
11623µs my $cache_ok = delete $options{cache};
117
11826µs224µs my $cache_key
# spent 24µs making 2 calls to Moose::Meta::Class::_anon_cache_key, avg 12µs/call
119 = _anon_cache_key( $options{superclasses}, $options{roles} );
120
12122µs if ($cache_ok && defined $ANON_CLASSES{$cache_key}) {
122 return $ANON_CLASSES{$cache_key};
123 }
124
125222µs229.3ms my $new_class = $self->SUPER::create_anon_class(%options);
# spent 29.3ms making 2 calls to Class::MOP::Class::create_anon_class, avg 14.6ms/call
126
12723µs $ANON_CLASSES{$cache_key} = $new_class
128 if $cache_ok;
129
13029µs return $new_class;
131}
132
133
# spent 24µs (22+2) within Moose::Meta::Class::_anon_cache_key which was called 2 times, avg 12µs/call: # 2 times (22µs+2µs) by Moose::Meta::Class::create_anon_class at line 118, avg 12µs/call
sub _anon_cache_key {
134 # Makes something like Super::Class|Super::Class::2=Role|Role::1
135 return join '=' => (
136 join( '|', @{ $_[0] || [] } ),
137226µs22µs join( '|', sort @{ $_[1] || [] } ),
# spent 2µs making 2 calls to Moose::Meta::Class::CORE:sort, avg 1µs/call
138 );
139}
140
141
# spent 2.81ms (142µs+2.67) within Moose::Meta::Class::reinitialize which was called 2 times, avg 1.41ms/call: # once (62µs+1.59ms) by Moose::Meta::Class::_reinitialize_with at line 418 # once (79µs+1.08ms) by Moose::Util::MetaRole::_make_new_metaclass at line 115 of Moose/Util/MetaRole.pm
sub reinitialize {
14222µs my $self = shift;
14322µs my $pkg = shift;
144
145213µs36µs my $meta = blessed $pkg ? $pkg : Class::MOP::class_of($pkg);
# spent 4µs making 1 call to Class::MOP::class_of # spent 2µs making 2 calls to Scalar::Util::blessed, avg 1µs/call
146
1472800ns my $cache_key;
148
1492700ns my %existing_classes;
15022µs if ($meta) {
151249µs1429µs %existing_classes = map { $_ => $meta->$_() } qw(
# spent 5µs making 2 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 3µs/call # spent 5µs making 2 calls to Moose::Meta::Class::constructor_class, avg 3µs/call # spent 5µs making 2 calls to Moose::Meta::Class::destructor_class, avg 2µs/call # spent 4µs making 2 calls to Moose::Meta::Class::error_class, avg 2µs/call # spent 4µs making 2 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 2µs/call # spent 3µs making 2 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 2µs/call # spent 2µs making 2 calls to Class::MOP::Class::instance_metaclass, avg 1µs/call
152 attribute_metaclass
153 method_metaclass
154 wrapped_method_metaclass
155 instance_metaclass
156 constructor_class
157 destructor_class
158 error_class
159 );
160
161 $cache_key = _anon_cache_key(
162 [ $meta->superclasses ],
16324µs214µs [ map { $_->name } @{ $meta->roles } ],
# spent 14µs making 2 calls to Class::MOP::Class::is_anon_class, avg 7µs/call
164 ) if $meta->is_anon_class;
165 }
166
167226µs22.62ms my $new_meta = $self->SUPER::reinitialize(
# spent 2.62ms making 2 calls to Class::MOP::Package::reinitialize, avg 1.31ms/call
168 $pkg,
169 %existing_classes,
170 @_,
171 );
172
173213µs return $new_meta unless defined $cache_key;
174
175 my $new_cache_key = _anon_cache_key(
176 [ $meta->superclasses ],
177 [ map { $_->name } @{ $meta->roles } ],
178 );
179
180 delete $ANON_CLASSES{$cache_key};
181 $ANON_CLASSES{$new_cache_key} = $new_meta;
182
183 return $new_meta;
184}
185
186
# spent 185µs (137+48) within Moose::Meta::Class::add_role which was called 13 times, avg 14µs/call: # 13 times (137µs+48µs) by Moose::Meta::Role::Application::ToClass::apply at line 33 of Moose/Meta/Role/Application/ToClass.pm, avg 14µs/call
sub add_role {
1871310µs my ($self, $role) = @_;
1881381µs2620µs (blessed($role) && $role->isa('Moose::Meta::Role'))
# spent 11µs making 13 calls to UNIVERSAL::isa, avg 862ns/call # spent 9µs making 13 calls to Scalar::Util::blessed, avg 715ns/call
189 || $self->throw_error("Roles must be instances of Moose::Meta::Role", data => $role);
1901360µs1327µs push @{$self->roles} => $role;
# spent 27µs making 13 calls to Moose::Meta::Class::roles, avg 2µs/call
191}
192
193sub role_applications {
194 my ($self) = @_;
195
196 return @{$self->_get_role_applications};
197}
198
199
# spent 190µs (133+56) within Moose::Meta::Class::add_role_application which was called 13 times, avg 15µs/call: # 13 times (133µs+56µs) by Moose::Meta::Role::Application::ToClass::apply at line 34 of Moose/Meta/Role/Application/ToClass.pm, avg 15µs/call
sub add_role_application {
2001311µs my ($self, $application) = @_;
2011377µs2618µs (blessed($application) && $application->isa('Moose::Meta::Role::Application::ToClass'))
# spent 11µs making 13 calls to UNIVERSAL::isa, avg 869ns/call # spent 7µs making 13 calls to Scalar::Util::blessed, avg 531ns/call
202 || $self->throw_error("Role applications must be instances of Moose::Meta::Role::Application::ToClass", data => $application);
2031360µs1338µs push @{$self->_get_role_applications} => $application;
# spent 38µs making 13 calls to Moose::Meta::Class::_get_role_applications, avg 3µs/call
204}
205
206sub calculate_all_roles {
207 my $self = shift;
208 my %seen;
209 grep { !$seen{$_->name}++ } map { $_->calculate_all_roles } @{ $self->roles };
210}
211
212sub does_role {
213 my ($self, $role_name) = @_;
214
215 (defined $role_name)
216 || $self->throw_error("You must supply a role name to look for");
217
218 foreach my $class ($self->class_precedence_list) {
219 my $meta = Class::MOP::class_of($class);
220 # when a Moose metaclass is itself extended with a role,
221 # this check needs to be done since some items in the
222 # class_precedence_list might in fact be Class::MOP
223 # based still.
224 next unless $meta && $meta->can('roles');
225 foreach my $role (@{$meta->roles}) {
226 return 1 if $role->does_role($role_name);
227 }
228 }
229 return 0;
230}
231
232
# spent 2.75ms (598µs+2.15) within Moose::Meta::Class::excludes_role which was called 13 times, avg 212µs/call: # 13 times (598µs+2.15ms) by Moose::Meta::Role::Application::ToClass::check_role_exclusions at line 39 of Moose/Meta/Role/Application/ToClass.pm, avg 212µs/call
sub excludes_role {
2331320µs my ($self, $role_name) = @_;
234
235135µs (defined $role_name)
236 || $self->throw_error("You must supply a role name to look for");
237
2381388µs131.66ms foreach my $class ($self->class_precedence_list) {
# spent 1.66ms making 13 calls to Class::MOP::Class::class_precedence_list, avg 128µs/call
23910477µs104375µs my $meta = Class::MOP::class_of($class);
# spent 375µs making 104 calls to Class::MOP::class_of, avg 4µs/call
240 # when a Moose metaclass is itself extended with a role,
241 # this check needs to be done since some items in the
242 # class_precedence_list might in fact be Class::MOP
243 # based still.
244104274µs10483µs next unless $meta && $meta->can('roles');
# spent 83µs making 104 calls to UNIVERSAL::can, avg 798ns/call
2451540µs1535µs foreach my $role (@{$meta->roles}) {
# spent 35µs making 15 calls to Moose::Meta::Class::roles, avg 2µs/call
246 return 1 if $role->excludes_role($role_name);
247 }
248 }
2491338µs return 0;
250}
251
252
# spent 96.6ms (3.34+93.3) within Moose::Meta::Class::new_object which was called 50 times, avg 1.93ms/call: # 37 times (2.87ms+87.7ms) by Moose::Object::new at line 25 of Moose/Object.pm, avg 2.45ms/call # 9 times (167µs+2.15ms) by Moose::Meta::Method::_new at line 3 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 258µs/call # 3 times (271µs+2.60ms) by Moose::Meta::Attribute::_new at line 4 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 958µs/call # once (32µs+775µs) by Moose::Meta::Method::Accessor::_new at line 3 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm
sub new_object {
2535023µs my $class = shift;
2545047µs my $params = @_ == 1 ? $_[0] : {@_};
25550354µs5084.9ms my $self = $class->SUPER::new_object($params);
# spent 84.9ms making 50 calls to Class::MOP::Class::new_object, avg 1.70ms/call
256
25750199µs502.71ms foreach my $attr ( $class->get_all_attributes() ) {
# spent 2.71ms making 50 calls to Class::MOP::Class::get_all_attributes, avg 54µs/call
258
2595381.85ms938926µs next unless $attr->can('has_trigger') && $attr->has_trigger;
# spent 497µs making 400 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 1µs/call # spent 430µs making 538 calls to UNIVERSAL::can, avg 798ns/call
260
2613046µs3037µs my $init_arg = $attr->init_arg;
# spent 37µs making 30 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 1µs/call
262
2633011µs next unless defined $init_arg;
264
2653016µs next unless exists $params->{$init_arg};
266
26729417µs2034.93ms $attr->trigger->(
# spent 2.31ms making 29 calls to Class::MOP::Attribute::get_read_method_ref, avg 80µs/call # spent 1.67ms making 29 calls to Foo::Domain::__ANON__[lib/Foo/Domain.pm:13], avg 58µs/call # spent 539µs making 29 calls to Foo::Domain::size, avg 19µs/call # spent 273µs making 58 calls to Class::MOP::Method::__ANON__[Class/MOP/Method.pm:19], avg 5µs/call # spent 90µs making 29 calls to Moose::Meta::Mixin::AttributeCore::trigger, avg 3µs/call # spent 42µs making 29 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 1µs/call
268 $self,
269 (
270 $attr->should_coerce
271 ? $attr->get_read_method_ref->($self)
272 : $params->{$init_arg}
273 ),
274 );
275 }
276
27750142µs return $self;
278}
279
280
# spent 602ms (1.65+601) within Moose::Meta::Class::superclasses which was called 166 times, avg 3.63ms/call: # 78 times (621µs+-396µs) by Moose::Meta::Class::_check_metaclass_compatibility at line 104, avg 3µs/call # 53 times (591µs+641µs) by Moose::init_meta at line 226 of Moose.pm, avg 23µs/call # 17 times (247µs+601ms) by Moose::extends at line 53 of Moose.pm, avg 35.3ms/call # 15 times (110µs+-110µs) by Class::MOP::Class::class_precedence_list at line 640 of Class/MOP/Class.pm, avg 0s/call # 3 times (77µs+-77µs) by Class::MOP::Class::create at line 307 of Class/MOP/Class.pm, avg 0s/call
sub superclasses {
28116634µs my $self = shift;
28216691µs my @supers = @_;
283166119µs foreach my $super (@supers) {
2844656µs46597ms Class::MOP::load_class($super);
# spent 598ms making 46 calls to Class::MOP::load_class, avg 13.0ms/call, recursion: max depth 2, time 1.22ms
2854688µs46251µs my $meta = Class::MOP::class_of($super);
# spent 251µs making 46 calls to Class::MOP::class_of, avg 5µs/call
28646258µs4692µs $self->throw_error("You cannot inherit from a Moose Role ($super)")
# spent 92µs making 46 calls to UNIVERSAL::isa, avg 2µs/call
287 if $meta && $meta->isa('Moose::Meta::Role')
288 }
289166909µs16614.8ms return $self->SUPER::superclasses(@supers);
# spent 15.5ms making 166 calls to Class::MOP::Class::superclasses, avg 93µs/call, recursion: max depth 1, time 668µs
290}
291
292### ---------------------------------------------
293
294
# spent 108ms (1.49+107) within Moose::Meta::Class::add_attribute which was called 86 times, avg 1.26ms/call: # 37 times (562µs+45.2ms) by Moose::Meta::Role::Application::ToClass::apply_attributes at line 142 of Moose/Meta/Role/Application/ToClass.pm, avg 1.24ms/call # 34 times (674µs+41.9ms) by Moose::has at line 69 of Moose.pm, avg 1.25ms/call # 13 times (224µs+16.3ms) by SimpleDB::Class::Item::add_attributes at line 110 of ../lib/SimpleDB/Class/Item.pm, avg 1.27ms/call # 2 times (32µs+3.43ms) by SimpleDB::Class::Item::belongs_to at line 281 of ../lib/SimpleDB/Class/Item.pm, avg 1.73ms/call
sub add_attribute {
2958624µs my $self = shift;
29686558µs17215.8ms my $attr =
# spent 15.7ms making 49 calls to Moose::Meta::Class::_process_attribute, avg 321µs/call # spent 64µs making 86 calls to Scalar::Util::blessed, avg 738ns/call # spent 35µs making 37 calls to UNIVERSAL::isa, avg 954ns/call
297 (blessed $_[0] && $_[0]->isa('Class::MOP::Attribute')
298 ? $_[0]
299 : $self->_process_attribute(@_));
30086353µs8690.3ms $self->SUPER::add_attribute($attr);
# spent 90.3ms making 86 calls to Class::MOP::Mixin::HasAttributes::add_attribute, avg 1.05ms/call
301 # it may be a Class::MOP::Attribute, theoretically, which doesn't have
302 # 'bare' and doesn't implement this method
30386429µs172605µs if ($attr->can('_check_associated_methods')) {
# spent 485µs making 86 calls to Moose::Meta::Attribute::_check_associated_methods, avg 6µs/call # spent 120µs making 86 calls to UNIVERSAL::can, avg 1µs/call
304 $attr->_check_associated_methods;
305 }
30686183µs return $attr;
307}
308
309sub add_override_method_modifier {
310 my ($self, $name, $method, $_super_package) = @_;
311
312 (!$self->has_method($name))
313 || $self->throw_error("Cannot add an override method if a local method is already present");
314
315 $self->add_method($name => Moose::Meta::Method::Overridden->new(
316 method => $method,
317 class => $self,
318 package => $_super_package, # need this for roles
319 name => $name,
320 ));
321}
322
323sub add_augment_method_modifier {
324 my ($self, $name, $method) = @_;
325 (!$self->has_method($name))
326 || $self->throw_error("Cannot add an augment method if a local method is already present");
327
328 $self->add_method($name => Moose::Meta::Method::Augmented->new(
329 method => $method,
330 class => $self,
331 name => $name,
332 ));
333}
334
335## Private Utility methods ...
336
337sub _find_next_method_by_name_which_is_not_overridden {
338 my ($self, $name) = @_;
339 foreach my $method ($self->find_all_methods_by_name($name)) {
340 return $method->{code}
341 if blessed($method->{code}) && !$method->{code}->isa('Moose::Meta::Method::Overridden');
342 }
343 return undef;
344}
345
346
# spent 5.17ms (561µs+4.61) within Moose::Meta::Class::_fix_metaclass_incompatibility which was called 48 times, avg 108µs/call: # 48 times (561µs+4.61ms) by Moose::Meta::Class::_check_metaclass_compatibility at line 104, avg 108µs/call
sub _fix_metaclass_incompatibility {
3474846µs my ($self, @superclasses) = @_;
348
3494873µs48222µs $self->_fix_one_incompatible_metaclass($_)
# spent 236µs making 48 calls to Moose::Meta::Class::initialize, avg 5µs/call, recursion: max depth 1, time 13µs
35096323µs484.40ms for map { Moose::Meta::Class->initialize($_) } @superclasses;
# spent 4.47ms making 48 calls to Moose::Meta::Class::_fix_one_incompatible_metaclass, avg 93µs/call, recursion: max depth 1, time 62µs
351}
352
353
# spent 4.40ms (251µs+4.15) within Moose::Meta::Class::_fix_one_incompatible_metaclass which was called 48 times, avg 92µs/call: # 48 times (251µs+4.15ms) by Moose::Meta::Class::_fix_metaclass_incompatibility at line 350, avg 92µs/call
sub _fix_one_incompatible_metaclass {
3544832µs my ($self, $meta) = @_;
355
35648166µs481.51ms return if $self->_superclass_meta_is_compatible($meta);
# spent 1.51ms making 48 calls to Moose::Meta::Class::_superclass_meta_is_compatible, avg 31µs/call
357
35816µs1687µs unless ( $self->is_pristine ) {
# spent 687µs making 1 call to Class::MOP::Class::is_pristine
359 $self->throw_error(
360 "Cannot attempt to reinitialize metaclass for "
361 . $self->name
362 . ", it isn't pristine" );
363 }
364
36515µs12.02ms $self->_reconcile_with_superclass_meta($meta);
366}
367
368
# spent 1.51ms (938µs+569µs) within Moose::Meta::Class::_superclass_meta_is_compatible which was called 48 times, avg 31µs/call: # 48 times (938µs+569µs) by Moose::Meta::Class::_fix_one_incompatible_metaclass at line 356, avg 31µs/call
sub _superclass_meta_is_compatible {
3694817µs my ($self, $super_meta) = @_;
370
37148142µs4841µs next unless $super_meta->isa("Class::MOP::Class");
# spent 41µs making 48 calls to UNIVERSAL::isa, avg 846ns/call
372
37348166µs64287µs my $super_meta_name
# spent 160µs making 14 calls to Class::MOP::Class::Immutable::Class::MOP::Class::is_immutable, avg 11µs/call # spent 59µs making 16 calls to Class::MOP::Class::Immutable::Trait::_get_mutable_metaclass_name, avg 4µs/call # spent 45µs making 32 calls to Class::MOP::Class::is_immutable, avg 1µs/call # spent 22µs making 2 calls to Class::MOP::Class::Immutable::Class::MOP::Class::__ANON__::SERIAL::1::is_immutable, avg 11µs/call
374 = $super_meta->is_immutable
375 ? $super_meta->_get_mutable_metaclass_name
376 : ref($super_meta);
377
37848536µs189242µs return 1
# spent 140µs making 94 calls to Class::MOP::Class::instance_metaclass, avg 1µs/call # spent 102µs making 95 calls to UNIVERSAL::isa, avg 1µs/call
379 if $self->isa($super_meta_name)
380 and
381 $self->instance_metaclass->isa( $super_meta->instance_metaclass );
382}
383
384# I don't want to have to type this >1 time
38512µsmy @MetaClassTypes =
386 qw( attribute_metaclass
387 method_metaclass
388 wrapped_method_metaclass
389 instance_metaclass
390 constructor_class
391 destructor_class
392 error_class );
393
394
# spent 2.02ms (31µs+1.99) within Moose::Meta::Class::_reconcile_with_superclass_meta which was called # once (31µs+1.99ms) by Moose::Meta::Class::_fix_one_incompatible_metaclass at line 365
sub _reconcile_with_superclass_meta {
39511µs my ($self, $super_meta) = @_;
396
39713µs28µs my $super_meta_name
398 = $super_meta->is_immutable
399 ? $super_meta->_get_mutable_metaclass_name
400 : ref($super_meta);
401
40211µs my $self_metaclass = ref $self;
403
404 # If neither of these is true we have a more serious
405 # incompatibility that we just cannot fix (yet?).
406130µs42.00ms if ( $super_meta_name->isa( ref $self )
# spent 1.85ms making 1 call to Moose::Meta::Class::_reinitialize_with # spent 133µs making 1 call to List::MoreUtils::all # spent 20µs making 1 call to Class::MOP::Class::DESTROY # spent 1µs making 1 call to UNIVERSAL::isa
407794µs2133µs && all { $super_meta->$_->isa( $self->$_ ) } @MetaClassTypes ) {
# spent 9µs making 7 calls to UNIVERSAL::isa, avg 1µs/call # spent 4µs making 2 calls to Moose::Meta::Class::error_class, avg 2µs/call # spent 4µs making 2 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 2µs/call # spent 3µs making 2 calls to Class::MOP::Class::instance_metaclass, avg 2µs/call # spent 3µs making 2 calls to Moose::Meta::Class::destructor_class, avg 2µs/call # spent 3µs making 2 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 1µs/call # spent 3µs making 2 calls to Moose::Meta::Class::constructor_class, avg 1µs/call # spent 2µs making 2 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 1µs/call
408 $self->_reinitialize_with($super_meta);
409 }
410 elsif ( $self->_all_metaclasses_differ_by_roles_only($super_meta) ) {
411 $self->_reconcile_role_differences($super_meta);
412 }
413}
414
415
# spent 1.85ms (134µs+1.71) within Moose::Meta::Class::_reinitialize_with which was called # once (134µs+1.71ms) by Moose::Meta::Class::_reconcile_with_superclass_meta at line 406
sub _reinitialize_with {
41611µs my ( $self, $new_meta ) = @_;
417
418118µs51.66ms my $new_self = $new_meta->reinitialize(
# spent 1.66ms making 1 call to Moose::Meta::Class::reinitialize # spent 1µs making 1 call to Class::MOP::Mixin::HasAttributes::attribute_metaclass # spent 1µs making 1 call to Class::MOP::Class::instance_metaclass # spent 900ns making 1 call to Class::MOP::Mixin::HasMethods::method_metaclass # spent 600ns making 1 call to Class::MOP::Package::name
419 $self->name,
420 attribute_metaclass => $new_meta->attribute_metaclass,
421 method_metaclass => $new_meta->method_metaclass,
422 instance_metaclass => $new_meta->instance_metaclass,
423 );
424
425 $new_self->$_( $new_meta->$_ )
426223µs620µs for qw( constructor_class destructor_class error_class );
# spent 7µs making 2 calls to Moose::Meta::Class::constructor_class, avg 4µs/call # spent 6µs making 2 calls to Moose::Meta::Class::error_class, avg 3µs/call # spent 6µs making 2 calls to Moose::Meta::Class::destructor_class, avg 3µs/call
427
428135µs %$self = %$new_self;
429
43014µs bless $self, ref $new_self;
431
432 # We need to replace the cached metaclass instance or else when it
433 # goes out of scope Class::MOP::Class destroy's the namespace for
434 # the metaclass's class, causing much havoc.
435111µs24µs Class::MOP::store_metaclass_by_name( $self->name, $self );
# spent 2µs making 1 call to Class::MOP::store_metaclass_by_name # spent 2µs making 1 call to Class::MOP::Package::name
43619µs110µs Class::MOP::weaken_metaclass( $self->name ) if $self->is_anon_class;
# spent 10µs making 1 call to Class::MOP::Class::is_anon_class
437}
438
439# In the more complex case, we share a common ancestor with our
440# superclass's metaclass, but each metaclass (ours and the parent's)
441# has a different set of roles applied. We reconcile this by first
442# reinitializing into the parent class, and _then_ applying our own
443# roles.
444sub _all_metaclasses_differ_by_roles_only {
445 my ($self, $super_meta) = @_;
446
447 for my $pair (
448 [ ref $self, ref $super_meta ],
449 map { [ $self->$_, $super_meta->$_ ] } @MetaClassTypes
450 ) {
451
452 next if $pair->[0] eq $pair->[1];
453
454 my $self_meta_meta = Class::MOP::Class->initialize( $pair->[0] );
455 my $super_meta_meta = Class::MOP::Class->initialize( $pair->[1] );
456
457 my $common_ancestor
458 = _find_common_ancestor( $self_meta_meta, $super_meta_meta );
459
460 return unless $common_ancestor;
461
462 return
463 unless _is_role_only_subclass_of(
464 $self_meta_meta,
465 $common_ancestor,
466 )
467 && _is_role_only_subclass_of(
468 $super_meta_meta,
469 $common_ancestor,
470 );
471 }
472
473 return 1;
474}
475
476# This, and some other functions, could be called as methods, but
477# they're not for two reasons. One, we just end up ignoring the first
478# argument, because we can't call these directly on one of the real
479# arguments, because one of them could be a Class::MOP::Class object
480# and not a Moose::Meta::Class. Second, only a completely insane
481# person would attempt to subclass this stuff!
482sub _find_common_ancestor {
483 my ($meta1, $meta2) = @_;
484
485 # FIXME? This doesn't account for multiple inheritance (not sure
486 # if it needs to though). For example, is somewhere in $meta1's
487 # history it inherits from both ClassA and ClassB, and $meta2
488 # inherits from ClassB & ClassA, does it matter? And what crazy
489 # fool would do that anyway?
490
491 my %meta1_parents = map { $_ => 1 } $meta1->linearized_isa;
492
493 return first { $meta1_parents{$_} } $meta2->linearized_isa;
494}
495
496sub _is_role_only_subclass_of {
497 my ($meta, $ancestor) = @_;
498
499 return 1 if $meta->name eq $ancestor;
500
501 my @roles = _all_roles_until( $meta, $ancestor );
502
503 my %role_packages = map { $_->name => 1 } @roles;
504
505 my $ancestor_meta = Class::MOP::Class->initialize($ancestor);
506
507 my %shared_ancestors = map { $_ => 1 } $ancestor_meta->linearized_isa;
508
509 for my $method ( $meta->get_all_methods() ) {
510 next if $method->name eq 'meta';
511 next if $method->can('associated_attribute');
512
513 next
514 if $role_packages{ $method->original_package_name }
515 || $shared_ancestors{ $method->original_package_name };
516
517 return 0;
518 }
519
520 # FIXME - this really isn't right. Just because an attribute is
521 # defined in a role doesn't mean it isn't _also_ defined in the
522 # subclass.
523 for my $attr ( $meta->get_all_attributes ) {
524 next if $shared_ancestors{ $attr->associated_class->name };
525
526 next if any { $_->has_attribute( $attr->name ) } @roles;
527
528 return 0;
529 }
530
531 return 1;
532}
533
534sub _all_roles {
535 my $meta = shift;
536
537 return _all_roles_until($meta);
538}
539
540sub _all_roles_until {
541 my ($meta, $stop_at_class) = @_;
542
543 return unless $meta->can('calculate_all_roles');
544
545 my @roles = $meta->calculate_all_roles;
546
547 for my $class ( $meta->linearized_isa ) {
548 last if $stop_at_class && $stop_at_class eq $class;
549
550 my $meta = Class::MOP::Class->initialize($class);
551 last unless $meta->can('calculate_all_roles');
552
553 push @roles, $meta->calculate_all_roles;
554 }
555
556 return uniq @roles;
557}
558
559sub _reconcile_role_differences {
560 my ($self, $super_meta) = @_;
561
562 my $self_meta = Class::MOP::class_of($self);
563
564 my %roles;
565
566 if ( my @roles = map { $_->name } _all_roles($self_meta) ) {
567 $roles{metaclass_roles} = \@roles;
568 }
569
570 for my $thing (@MetaClassTypes) {
571 my $name = $self->$thing();
572
573 my $thing_meta = Class::MOP::Class->initialize($name);
574
575 my @roles = map { $_->name } _all_roles($thing_meta)
576 or next;
577
578 $roles{ $thing . '_roles' } = \@roles;
579 }
580
581 $self->_reinitialize_with($super_meta);
582
583 Moose::Util::MetaRole::apply_metaclass_roles(
584 for_class => $self->name,
585 %roles,
586 );
587
588 return $self;
589}
590
591
# spent 15.7ms (488µs+15.2) within Moose::Meta::Class::_process_attribute which was called 49 times, avg 321µs/call: # 49 times (488µs+15.2ms) by Moose::Meta::Class::add_attribute at line 296, avg 321µs/call
sub _process_attribute {
5924973µs my ( $self, $name, @args ) = @_;
593
5944984µs @args = %{$args[0]} if scalar @args == 1 && ref($args[0]) eq 'HASH';
595
59649138µs4933µs if (($name || '') =~ /^\+(.*)/) {
# spent 33µs making 49 calls to Moose::Meta::Class::CORE:match, avg 669ns/call
597 return $self->_process_inherited_attribute($1, @args);
598 }
599 else {
60049204µs4915.2ms return $self->_process_new_attribute($name, @args);
# spent 15.2ms making 49 calls to Moose::Meta::Class::_process_new_attribute, avg 310µs/call
601 }
602}
603
604
# spent 15.2ms (496µs+14.7) within Moose::Meta::Class::_process_new_attribute which was called 49 times, avg 310µs/call: # 49 times (496µs+14.7ms) by Moose::Meta::Class::_process_attribute at line 600, avg 310µs/call
sub _process_new_attribute {
6054977µs my ( $self, $name, @args ) = @_;
606
60749337µs9814.7ms $self->attribute_metaclass->interpolate_class_and_new($name, @args);
# spent 14.6ms making 49 calls to Moose::Meta::Attribute::interpolate_class_and_new, avg 298µs/call # spent 83µs making 49 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 2µs/call
608}
609
610sub _process_inherited_attribute {
611 my ($self, $attr_name, %options) = @_;
612 my $inherited_attr = $self->find_attribute_by_name($attr_name);
613 (defined $inherited_attr)
614 || $self->throw_error("Could not find an attribute by the name of '$attr_name' to inherit from in ${\$self->name}", data => $attr_name);
615 if ($inherited_attr->isa('Moose::Meta::Attribute')) {
616 return $inherited_attr->clone_and_inherit_options(%options);
617 }
618 else {
619 # NOTE:
620 # kind of a kludge to handle Class::MOP::Attributes
621 return $inherited_attr->Moose::Meta::Attribute::clone_and_inherit_options(%options);
622 }
623}
624
625## -------------------------------------------------
626
6271100nsour $error_level;
628
629sub throw_error {
630 my ( $self, @args ) = @_;
631 local $error_level = ($error_level || 0) + 1;
632 $self->raise_error($self->create_error(@args));
633}
634
635sub raise_error {
636 my ( $self, @args ) = @_;
637 die @args;
638}
639
640sub create_error {
641 my ( $self, @args ) = @_;
642
643 require Carp::Heavy;
644
645 local $error_level = ($error_level || 0 ) + 1;
646
647 if ( @args % 2 == 1 ) {
648 unshift @args, "message";
649 }
650
651 my %args = ( metaclass => $self, last_error => $@, @args );
652
653 $args{depth} += $error_level;
654
655 my $class = ref $self ? $self->error_class : "Moose::Error::Default";
656
657 Class::MOP::load_class($class);
658
659 $class->new(
660 Carp::caller_info($args{depth}),
661 %args
662 );
663}
664
665123µs1;
666
667__END__
668
669=pod
670
671=head1 NAME
672
673Moose::Meta::Class - The Moose metaclass
674
675=head1 DESCRIPTION
676
677This class is a subclass of L<Class::MOP::Class> that provides
678additional Moose-specific functionality.
679
680To really understand this class, you will need to start with the
681L<Class::MOP::Class> documentation. This class can be understood as a
682set of additional features on top of the basic feature provided by
683that parent class.
684
685=head1 INHERITANCE
686
687C<Moose::Meta::Class> is a subclass of L<Class::MOP::Class>.
688
689=head1 METHODS
690
691=over 4
692
693=item B<< Moose::Meta::Class->initialize($package_name, %options) >>
694
695This overrides the parent's method in order to provide its own
696defaults for the C<attribute_metaclass>, C<instance_metaclass>, and
697C<method_metaclass> options.
698
699These all default to the appropriate Moose class.
700
701=item B<< Moose::Meta::Class->create($package_name, %options) >>
702
703This overrides the parent's method in order to accept a C<roles>
704option. This should be an array reference containing roles
705that the class does, each optionally followed by a hashref of options
706(C<-excludes> and C<-alias>).
707
708 my $metaclass = Moose::Meta::Class->create( 'New::Class', roles => [...] );
709
710=item B<< Moose::Meta::Class->create_anon_class >>
711
712This overrides the parent's method to accept a C<roles> option, just
713as C<create> does.
714
715It also accepts a C<cache> option. If this is true, then the anonymous
716class will be cached based on its superclasses and roles. If an
717existing anonymous class in the cache has the same superclasses and
718roles, it will be reused.
719
720 my $metaclass = Moose::Meta::Class->create_anon_class(
721 superclasses => ['Foo'],
722 roles => [qw/Some Roles Go Here/],
723 cache => 1,
724 );
725
726=item B<< $metaclass->make_immutable(%options) >>
727
728This overrides the parent's method to add a few options. Specifically,
729it uses the Moose-specific constructor and destructor classes, and
730enables inlining the destructor.
731
732Also, since Moose always inlines attributes, it sets the
733C<inline_accessors> option to false.
734
735=item B<< $metaclass->new_object(%params) >>
736
737This overrides the parent's method in order to add support for
738attribute triggers.
739
740=item B<< $metaclass->add_override_method_modifier($name, $sub) >>
741
742This adds an C<override> method modifier to the package.
743
744=item B<< $metaclass->add_augment_method_modifier($name, $sub) >>
745
746This adds an C<augment> method modifier to the package.
747
748=item B<< $metaclass->calculate_all_roles >>
749
750This will return a unique array of C<Moose::Meta::Role> instances
751which are attached to this class.
752
753=item B<< $metaclass->add_role($role) >>
754
755This takes a L<Moose::Meta::Role> object, and adds it to the class's
756list of roles. This I<does not> actually apply the role to the class.
757
758=item B<< $metaclass->role_applications >>
759
760Returns a list of L<Moose::Meta::Role::Application::ToClass>
761objects, which contain the arguments to role application.
762
763=item B<< $metaclass->add_role_application($application) >>
764
765This takes a L<Moose::Meta::Role::Application::ToClass> object, and
766adds it to the class's list of role applications. This I<does not>
767actually apply any role to the class; it is only for tracking role
768applications.
769
770=item B<< $metaclass->does_role($role) >>
771
772This returns a boolean indicating whether or not the class does the specified
773role. The role provided can be either a role name or a L<Moose::Meta::Role>
774object. This tests both the class and its parents.
775
776=item B<< $metaclass->excludes_role($role_name) >>
777
778A class excludes a role if it has already composed a role which
779excludes the named role. This tests both the class and its parents.
780
781=item B<< $metaclass->add_attribute($attr_name, %params|$params) >>
782
783This overrides the parent's method in order to allow the parameters to
784be provided as a hash reference.
785
786=item B<< $metaclass->constructor_class ($class_name) >>
787
788=item B<< $metaclass->destructor_class ($class_name) >>
789
790These are the names of classes used when making a class
791immutable. These default to L<Moose::Meta::Method::Constructor> and
792L<Moose::Meta::Method::Destructor> respectively. These accessors are
793read-write, so you can use them to change the class name.
794
795=item B<< $metaclass->error_class($class_name) >>
796
797The name of the class used to throw errors. This defaults to
798L<Moose::Error::Default>, which generates an error with a stacktrace
799just like C<Carp::confess>.
800
801=item B<< $metaclass->throw_error($message, %extra) >>
802
803Throws the error created by C<create_error> using C<raise_error>
804
805=back
806
807=head1 BUGS
808
809See L<Moose/BUGS> for details on reporting bugs.
810
811=head1 AUTHOR
812
813Stevan Little E<lt>stevan@iinteractive.comE<gt>
814
815=head1 COPYRIGHT AND LICENSE
816
817Copyright 2006-2010 by Infinity Interactive, Inc.
818
819L<http://www.iinteractive.com>
820
821This library is free software; you can redistribute it and/or modify
822it under the same terms as Perl itself.
823
824=cut
825
# spent 33µs within Moose::Meta::Class::CORE:match which was called 49 times, avg 669ns/call: # 49 times (33µs+0s) by Moose::Meta::Class::_process_attribute at line 596 of Moose/Meta/Class.pm, avg 669ns/call
sub Moose::Meta::Class::CORE:match; # xsub
# spent 2µs within Moose::Meta::Class::CORE:sort which was called 2 times, avg 1µs/call: # 2 times (2µs+0s) by Moose::Meta::Class::_anon_cache_key at line 137 of Moose/Meta/Class.pm, avg 1µs/call
sub Moose::Meta::Class::CORE:sort; # xsub