| File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/Class.pm |
| Statements Executed | 7983 |
| Statement Execution Time | 18.7ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1425 | 13 | 5 | 5.36ms | 28.5ms | Moose::Meta::Class::initialize |
| 50 | 4 | 4 | 3.34ms | 96.6ms | Moose::Meta::Class::new_object |
| 166 | 5 | 3 | 1.65ms | 602ms | Moose::Meta::Class::superclasses |
| 1 | 1 | 1 | 1.61ms | 1.77ms | Moose::Meta::Class::BEGIN@22 |
| 86 | 4 | 3 | 1.49ms | 108ms | Moose::Meta::Class::add_attribute |
| 48 | 1 | 1 | 938µs | 1.51ms | Moose::Meta::Class::_superclass_meta_is_compatible |
| 78 | 2 | 1 | 884µs | 12.6ms | Moose::Meta::Class::_check_metaclass_compatibility |
| 13 | 1 | 1 | 598µs | 2.75ms | Moose::Meta::Class::excludes_role |
| 48 | 1 | 1 | 561µs | 5.17ms | Moose::Meta::Class::_fix_metaclass_incompatibility |
| 1 | 1 | 1 | 539µs | 686µs | Moose::Meta::Class::BEGIN@23 |
| 49 | 1 | 1 | 496µs | 15.2ms | Moose::Meta::Class::_process_new_attribute |
| 49 | 1 | 1 | 488µs | 15.7ms | Moose::Meta::Class::_process_attribute |
| 1 | 1 | 1 | 321µs | 407µs | Moose::Meta::Class::BEGIN@19 |
| 1 | 1 | 1 | 319µs | 841µs | Moose::Meta::Class::BEGIN@18 |
| 1 | 1 | 1 | 295µs | 1.58ms | Moose::Meta::Class::BEGIN@20 |
| 48 | 1 | 1 | 251µs | 4.40ms | Moose::Meta::Class::_fix_one_incompatible_metaclass |
| 1 | 1 | 1 | 237µs | 325µs | Moose::Meta::Class::BEGIN@21 |
| 2 | 2 | 2 | 142µs | 2.81ms | Moose::Meta::Class::reinitialize |
| 13 | 1 | 1 | 137µs | 185µs | Moose::Meta::Class::add_role |
| 1 | 1 | 1 | 134µs | 1.85ms | Moose::Meta::Class::_reinitialize_with |
| 13 | 1 | 1 | 133µs | 190µs | Moose::Meta::Class::add_role_application |
| 32 | 1 | 1 | 80µs | 80µs | Moose::Meta::Class::__ANON__[:29] |
| 7 | 1 | 1 | 76µs | 351µs | Moose::Meta::Class::_immutable_options |
| 32 | 1 | 1 | 65µs | 65µs | Moose::Meta::Class::__ANON__[:34] |
| 3 | 2 | 1 | 62µs | 30.7ms | Moose::Meta::Class::create |
| 2 | 2 | 2 | 58µs | 29.4ms | Moose::Meta::Class::create_anon_class |
| 49 | 1 | 2 | 33µs | 33µs | Moose::Meta::Class::CORE:match (opcode) |
| 1 | 1 | 1 | 31µs | 2.02ms | Moose::Meta::Class::_reconcile_with_superclass_meta |
| 2 | 1 | 1 | 22µs | 24µs | Moose::Meta::Class::_anon_cache_key |
| 1 | 1 | 1 | 15µs | 18µs | Moose::Meta::Class::BEGIN@4 |
| 1 | 1 | 1 | 8µs | 75µs | Moose::Meta::Class::BEGIN@12 |
| 1 | 1 | 1 | 7µs | 45µs | Moose::Meta::Class::BEGIN@11 |
| 1 | 1 | 1 | 7µs | 38µs | Moose::Meta::Class::BEGIN@10 |
| 1 | 1 | 1 | 7µs | 15µs | Moose::Meta::Class::BEGIN@5 |
| 1 | 1 | 1 | 6µs | 52µs | Moose::Meta::Class::BEGIN@25 |
| 1 | 1 | 1 | 4µs | 4µs | Moose::Meta::Class::BEGIN@7 |
| 1 | 1 | 1 | 3µs | 3µs | Moose::Meta::Class::BEGIN@9 |
| 2 | 1 | 2 | 2µs | 2µs | Moose::Meta::Class::CORE:sort (opcode) |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::__ANON__[:407] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::__ANON__[:493] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::__ANON__[:526] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::_all_metaclasses_differ_by_roles_only |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::_all_roles |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::_all_roles_until |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::_find_common_ancestor |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::_find_next_method_by_name_which_is_not_overridden |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::_is_role_only_subclass_of |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::_process_inherited_attribute |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::_reconcile_role_differences |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::add_augment_method_modifier |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::add_override_method_modifier |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::calculate_all_roles |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::create_error |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::does_role |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::raise_error |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::role_applications |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Class::throw_error |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Moose::Meta::Class; | ||||
| 3 | |||||
| 4 | 3 | 19µs | 2 | 21µ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 # spent 18µs making 1 call to Moose::Meta::Class::BEGIN@4
# spent 3µs making 1 call to strict::import |
| 5 | 3 | 18µs | 2 | 24µ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 # spent 15µs making 1 call to Moose::Meta::Class::BEGIN@5
# spent 9µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 3 | 16µs | 1 | 4µs | # spent 4µs within Moose::Meta::Class::BEGIN@7 which was called
# once (4µs+0s) by Moose::BEGIN@18 at line 7 # spent 4µs making 1 call to Moose::Meta::Class::BEGIN@7 |
| 8 | |||||
| 9 | 3 | 18µs | 1 | 3µs | # spent 3µs within Moose::Meta::Class::BEGIN@9 which was called
# once (3µs+0s) by Moose::BEGIN@18 at line 9 # spent 3µs making 1 call to Moose::Meta::Class::BEGIN@9 |
| 10 | 3 | 29µs | 2 | 70µ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 # spent 38µs making 1 call to Moose::Meta::Class::BEGIN@10
# spent 32µs making 1 call to Exporter::import |
| 11 | 3 | 26µs | 2 | 82µ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 # spent 45µs making 1 call to Moose::Meta::Class::BEGIN@11
# spent 37µs making 1 call to Exporter::import |
| 12 | 3 | 42µs | 2 | 143µ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 # spent 75µs making 1 call to Moose::Meta::Class::BEGIN@12
# spent 67µs making 1 call to Exporter::import |
| 13 | |||||
| 14 | 1 | 700ns | our $VERSION = '0.98'; | ||
| 15 | 1 | 14µs | $VERSION = eval $VERSION; | ||
| 16 | 1 | 500ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 17 | |||||
| 18 | 3 | 121µs | 1 | 841µ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 # spent 841µs making 1 call to Moose::Meta::Class::BEGIN@18 |
| 19 | 3 | 108µs | 1 | 407µ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 # spent 407µs making 1 call to Moose::Meta::Class::BEGIN@19 |
| 20 | 3 | 99µs | 1 | 1.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 # spent 1.58ms making 1 call to Moose::Meta::Class::BEGIN@20 |
| 21 | 3 | 99µs | 1 | 325µ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 # spent 325µs making 1 call to Moose::Meta::Class::BEGIN@21 |
| 22 | 3 | 109µs | 1 | 1.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 # spent 1.77ms making 1 call to Moose::Meta::Class::BEGIN@22 |
| 23 | 3 | 103µs | 1 | 686µ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 # spent 686µs making 1 call to Moose::Meta::Class::BEGIN@23 |
| 24 | |||||
| 25 | 3 | 2.12ms | 2 | 98µ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 # 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', | ||||
| 29 | 32 | 102µ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 | ||
| 30 | 1 | 20µs | 2 | 675µ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', | ||||
| 34 | 32 | 84µ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 | ||
| 35 | 1 | 4µs | 2 | 275µ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 | |||||
| 37 | 1 | 4µs | 3 | 274µ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 | |||||
| 44 | 1 | 2µs | 2 | 266µ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 | |||||
| 49 | 1 | 3µs | 2 | 268µ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 | |||||
| 54 | 1 | 2µs | 2 | 270µ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 | ||||
| 60 | 1425 | 388µs | my $class = shift; | ||
| 61 | 1425 | 325µs | my $pkg = shift; | ||
| 62 | 1425 | 3.99ms | 1457 | 23.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 | ||||
| 72 | 7 | 8µs | my ( $self, @args ) = @_; | ||
| 73 | |||||
| 74 | 7 | 69µs | 7 | 275µ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 | ||||
| 85 | 3 | 7µs | my ($self, $package_name, %options) = @_; | ||
| 86 | |||||
| 87 | 3 | 5µ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}; | ||||
| 90 | 3 | 3µs | my $roles = delete $options{roles}; | ||
| 91 | |||||
| 92 | 3 | 22µs | 3 | 4.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 | |||||
| 94 | 3 | 8µs | 2 | 26.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 | |||||
| 98 | 3 | 15µ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 | ||||
| 102 | 78 | 26µs | my $self = shift; | ||
| 103 | |||||
| 104 | 78 | 283µs | 126 | 5.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 | |||||
| 108 | 78 | 424µs | 78 | 4.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 | |||||
| 111 | 1 | 100ns | my %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 | ||||
| 114 | 2 | 7µs | my ($self, %options) = @_; | ||
| 115 | |||||
| 116 | 2 | 3µs | my $cache_ok = delete $options{cache}; | ||
| 117 | |||||
| 118 | 2 | 6µs | 2 | 24µ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 | |||||
| 121 | 2 | 2µs | if ($cache_ok && defined $ANON_CLASSES{$cache_key}) { | ||
| 122 | return $ANON_CLASSES{$cache_key}; | ||||
| 123 | } | ||||
| 124 | |||||
| 125 | 2 | 22µs | 2 | 29.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 | |||||
| 127 | 2 | 3µs | $ANON_CLASSES{$cache_key} = $new_class | ||
| 128 | if $cache_ok; | ||||
| 129 | |||||
| 130 | 2 | 9µ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 | ||||
| 134 | # Makes something like Super::Class|Super::Class::2=Role|Role::1 | ||||
| 135 | return join '=' => ( | ||||
| 136 | join( '|', @{ $_[0] || [] } ), | ||||
| 137 | 2 | 26µs | 2 | 2µ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 | ||||
| 142 | 2 | 2µs | my $self = shift; | ||
| 143 | 2 | 2µs | my $pkg = shift; | ||
| 144 | |||||
| 145 | 2 | 13µs | 3 | 6µ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 | |||||
| 147 | 2 | 800ns | my $cache_key; | ||
| 148 | |||||
| 149 | 2 | 700ns | my %existing_classes; | ||
| 150 | 2 | 2µs | if ($meta) { | ||
| 151 | 2 | 49µs | 14 | 29µ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 ], | ||||
| 163 | 2 | 4µs | 2 | 14µ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 | |||||
| 167 | 2 | 26µs | 2 | 2.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 | |||||
| 173 | 2 | 13µ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 | ||||
| 187 | 13 | 10µs | my ($self, $role) = @_; | ||
| 188 | 13 | 81µs | 26 | 20µ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); | ||||
| 190 | 13 | 60µs | 13 | 27µs | push @{$self->roles} => $role; # spent 27µs making 13 calls to Moose::Meta::Class::roles, avg 2µs/call |
| 191 | } | ||||
| 192 | |||||
| 193 | sub 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 | ||||
| 200 | 13 | 11µs | my ($self, $application) = @_; | ||
| 201 | 13 | 77µs | 26 | 18µ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); | ||||
| 203 | 13 | 60µs | 13 | 38µ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 | |||||
| 206 | sub calculate_all_roles { | ||||
| 207 | my $self = shift; | ||||
| 208 | my %seen; | ||||
| 209 | grep { !$seen{$_->name}++ } map { $_->calculate_all_roles } @{ $self->roles }; | ||||
| 210 | } | ||||
| 211 | |||||
| 212 | sub 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 | ||||
| 233 | 13 | 20µs | my ($self, $role_name) = @_; | ||
| 234 | |||||
| 235 | 13 | 5µs | (defined $role_name) | ||
| 236 | || $self->throw_error("You must supply a role name to look for"); | ||||
| 237 | |||||
| 238 | 13 | 88µs | 13 | 1.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 |
| 239 | 104 | 77µs | 104 | 375µ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. | ||||
| 244 | 104 | 274µs | 104 | 83µs | next unless $meta && $meta->can('roles'); # spent 83µs making 104 calls to UNIVERSAL::can, avg 798ns/call |
| 245 | 15 | 40µs | 15 | 35µ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 | } | ||||
| 249 | 13 | 38µ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 | ||||
| 253 | 50 | 23µs | my $class = shift; | ||
| 254 | 50 | 47µs | my $params = @_ == 1 ? $_[0] : {@_}; | ||
| 255 | 50 | 354µs | 50 | 84.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 | |||||
| 257 | 50 | 199µs | 50 | 2.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 | |||||
| 259 | 538 | 1.85ms | 938 | 926µ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 | |||||
| 261 | 30 | 46µs | 30 | 37µ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 | |||||
| 263 | 30 | 11µs | next unless defined $init_arg; | ||
| 264 | |||||
| 265 | 30 | 16µs | next unless exists $params->{$init_arg}; | ||
| 266 | |||||
| 267 | 29 | 417µs | 203 | 4.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 | |||||
| 277 | 50 | 142µ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 | ||||
| 281 | 166 | 34µs | my $self = shift; | ||
| 282 | 166 | 91µs | my @supers = @_; | ||
| 283 | 166 | 119µs | foreach my $super (@supers) { | ||
| 284 | 46 | 56µs | 46 | 597ms | 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 |
| 285 | 46 | 88µs | 46 | 251µs | my $meta = Class::MOP::class_of($super); # spent 251µs making 46 calls to Class::MOP::class_of, avg 5µs/call |
| 286 | 46 | 258µs | 46 | 92µ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 | } | ||||
| 289 | 166 | 909µs | 166 | 14.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 | ||||
| 295 | 86 | 24µs | my $self = shift; | ||
| 296 | 86 | 558µs | 172 | 15.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(@_)); | ||||
| 300 | 86 | 353µs | 86 | 90.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 | ||||
| 303 | 86 | 429µs | 172 | 605µ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 | } | ||||
| 306 | 86 | 183µs | return $attr; | ||
| 307 | } | ||||
| 308 | |||||
| 309 | sub 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 | |||||
| 323 | sub 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 | |||||
| 337 | sub _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 | ||||
| 347 | 48 | 46µs | my ($self, @superclasses) = @_; | ||
| 348 | |||||
| 349 | 48 | 73µs | 48 | 222µ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 |
| 350 | 96 | 323µs | 48 | 4.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 | ||||
| 354 | 48 | 32µs | my ($self, $meta) = @_; | ||
| 355 | |||||
| 356 | 48 | 166µs | 48 | 1.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 | |||||
| 358 | 1 | 6µs | 1 | 687µ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 | |||||
| 365 | 1 | 5µs | 1 | 2.02ms | $self->_reconcile_with_superclass_meta($meta); # spent 2.02ms making 1 call to Moose::Meta::Class::_reconcile_with_superclass_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 | ||||
| 369 | 48 | 17µs | my ($self, $super_meta) = @_; | ||
| 370 | |||||
| 371 | 48 | 142µs | 48 | 41µs | next unless $super_meta->isa("Class::MOP::Class"); # spent 41µs making 48 calls to UNIVERSAL::isa, avg 846ns/call |
| 372 | |||||
| 373 | 48 | 166µs | 64 | 287µ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 | |||||
| 378 | 48 | 536µs | 189 | 242µ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 | ||||
| 385 | 1 | 2µs | my @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 | ||||
| 395 | 1 | 1µs | my ($self, $super_meta) = @_; | ||
| 396 | |||||
| 397 | 1 | 3µs | 2 | 8µs | my $super_meta_name # spent 7µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::__ANON__::SERIAL::1::is_immutable
# spent 2µs making 1 call to Class::MOP::Class::Immutable::Trait::_get_mutable_metaclass_name |
| 398 | = $super_meta->is_immutable | ||||
| 399 | ? $super_meta->_get_mutable_metaclass_name | ||||
| 400 | : ref($super_meta); | ||||
| 401 | |||||
| 402 | 1 | 1µ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?). | ||||
| 406 | 1 | 30µs | 4 | 2.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 |
| 407 | 7 | 94µs | 21 | 33µ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 | ||||
| 416 | 1 | 1µs | my ( $self, $new_meta ) = @_; | ||
| 417 | |||||
| 418 | 1 | 18µs | 5 | 1.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->$_ ) | ||||
| 426 | 2 | 23µs | 6 | 20µ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 | |||||
| 428 | 1 | 35µs | %$self = %$new_self; | ||
| 429 | |||||
| 430 | 1 | 4µ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. | ||||
| 435 | 1 | 11µs | 2 | 4µ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 |
| 436 | 1 | 9µs | 1 | 10µ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. | ||||
| 444 | sub _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! | ||||
| 482 | sub _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 | |||||
| 496 | sub _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 | |||||
| 534 | sub _all_roles { | ||||
| 535 | my $meta = shift; | ||||
| 536 | |||||
| 537 | return _all_roles_until($meta); | ||||
| 538 | } | ||||
| 539 | |||||
| 540 | sub _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 | |||||
| 559 | sub _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 | ||||
| 592 | 49 | 73µs | my ( $self, $name, @args ) = @_; | ||
| 593 | |||||
| 594 | 49 | 84µs | @args = %{$args[0]} if scalar @args == 1 && ref($args[0]) eq 'HASH'; | ||
| 595 | |||||
| 596 | 49 | 138µs | 49 | 33µ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 { | ||||
| 600 | 49 | 204µs | 49 | 15.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 | ||||
| 605 | 49 | 77µs | my ( $self, $name, @args ) = @_; | ||
| 606 | |||||
| 607 | 49 | 337µs | 98 | 14.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 | |||||
| 610 | sub _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 | |||||
| 627 | 1 | 100ns | our $error_level; | ||
| 628 | |||||
| 629 | sub throw_error { | ||||
| 630 | my ( $self, @args ) = @_; | ||||
| 631 | local $error_level = ($error_level || 0) + 1; | ||||
| 632 | $self->raise_error($self->create_error(@args)); | ||||
| 633 | } | ||||
| 634 | |||||
| 635 | sub raise_error { | ||||
| 636 | my ( $self, @args ) = @_; | ||||
| 637 | die @args; | ||||
| 638 | } | ||||
| 639 | |||||
| 640 | sub 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 | |||||
| 665 | 1 | 23µs | 1; | ||
| 666 | |||||
| 667 | __END__ | ||||
| 668 | |||||
| 669 | =pod | ||||
| 670 | |||||
| 671 | =head1 NAME | ||||
| 672 | |||||
| 673 | Moose::Meta::Class - The Moose metaclass | ||||
| 674 | |||||
| 675 | =head1 DESCRIPTION | ||||
| 676 | |||||
| 677 | This class is a subclass of L<Class::MOP::Class> that provides | ||||
| 678 | additional Moose-specific functionality. | ||||
| 679 | |||||
| 680 | To really understand this class, you will need to start with the | ||||
| 681 | L<Class::MOP::Class> documentation. This class can be understood as a | ||||
| 682 | set of additional features on top of the basic feature provided by | ||||
| 683 | that parent class. | ||||
| 684 | |||||
| 685 | =head1 INHERITANCE | ||||
| 686 | |||||
| 687 | C<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 | |||||
| 695 | This overrides the parent's method in order to provide its own | ||||
| 696 | defaults for the C<attribute_metaclass>, C<instance_metaclass>, and | ||||
| 697 | C<method_metaclass> options. | ||||
| 698 | |||||
| 699 | These all default to the appropriate Moose class. | ||||
| 700 | |||||
| 701 | =item B<< Moose::Meta::Class->create($package_name, %options) >> | ||||
| 702 | |||||
| 703 | This overrides the parent's method in order to accept a C<roles> | ||||
| 704 | option. This should be an array reference containing roles | ||||
| 705 | that 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 | |||||
| 712 | This overrides the parent's method to accept a C<roles> option, just | ||||
| 713 | as C<create> does. | ||||
| 714 | |||||
| 715 | It also accepts a C<cache> option. If this is true, then the anonymous | ||||
| 716 | class will be cached based on its superclasses and roles. If an | ||||
| 717 | existing anonymous class in the cache has the same superclasses and | ||||
| 718 | roles, 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 | |||||
| 728 | This overrides the parent's method to add a few options. Specifically, | ||||
| 729 | it uses the Moose-specific constructor and destructor classes, and | ||||
| 730 | enables inlining the destructor. | ||||
| 731 | |||||
| 732 | Also, since Moose always inlines attributes, it sets the | ||||
| 733 | C<inline_accessors> option to false. | ||||
| 734 | |||||
| 735 | =item B<< $metaclass->new_object(%params) >> | ||||
| 736 | |||||
| 737 | This overrides the parent's method in order to add support for | ||||
| 738 | attribute triggers. | ||||
| 739 | |||||
| 740 | =item B<< $metaclass->add_override_method_modifier($name, $sub) >> | ||||
| 741 | |||||
| 742 | This adds an C<override> method modifier to the package. | ||||
| 743 | |||||
| 744 | =item B<< $metaclass->add_augment_method_modifier($name, $sub) >> | ||||
| 745 | |||||
| 746 | This adds an C<augment> method modifier to the package. | ||||
| 747 | |||||
| 748 | =item B<< $metaclass->calculate_all_roles >> | ||||
| 749 | |||||
| 750 | This will return a unique array of C<Moose::Meta::Role> instances | ||||
| 751 | which are attached to this class. | ||||
| 752 | |||||
| 753 | =item B<< $metaclass->add_role($role) >> | ||||
| 754 | |||||
| 755 | This takes a L<Moose::Meta::Role> object, and adds it to the class's | ||||
| 756 | list of roles. This I<does not> actually apply the role to the class. | ||||
| 757 | |||||
| 758 | =item B<< $metaclass->role_applications >> | ||||
| 759 | |||||
| 760 | Returns a list of L<Moose::Meta::Role::Application::ToClass> | ||||
| 761 | objects, which contain the arguments to role application. | ||||
| 762 | |||||
| 763 | =item B<< $metaclass->add_role_application($application) >> | ||||
| 764 | |||||
| 765 | This takes a L<Moose::Meta::Role::Application::ToClass> object, and | ||||
| 766 | adds it to the class's list of role applications. This I<does not> | ||||
| 767 | actually apply any role to the class; it is only for tracking role | ||||
| 768 | applications. | ||||
| 769 | |||||
| 770 | =item B<< $metaclass->does_role($role) >> | ||||
| 771 | |||||
| 772 | This returns a boolean indicating whether or not the class does the specified | ||||
| 773 | role. The role provided can be either a role name or a L<Moose::Meta::Role> | ||||
| 774 | object. This tests both the class and its parents. | ||||
| 775 | |||||
| 776 | =item B<< $metaclass->excludes_role($role_name) >> | ||||
| 777 | |||||
| 778 | A class excludes a role if it has already composed a role which | ||||
| 779 | excludes the named role. This tests both the class and its parents. | ||||
| 780 | |||||
| 781 | =item B<< $metaclass->add_attribute($attr_name, %params|$params) >> | ||||
| 782 | |||||
| 783 | This overrides the parent's method in order to allow the parameters to | ||||
| 784 | be provided as a hash reference. | ||||
| 785 | |||||
| 786 | =item B<< $metaclass->constructor_class ($class_name) >> | ||||
| 787 | |||||
| 788 | =item B<< $metaclass->destructor_class ($class_name) >> | ||||
| 789 | |||||
| 790 | These are the names of classes used when making a class | ||||
| 791 | immutable. These default to L<Moose::Meta::Method::Constructor> and | ||||
| 792 | L<Moose::Meta::Method::Destructor> respectively. These accessors are | ||||
| 793 | read-write, so you can use them to change the class name. | ||||
| 794 | |||||
| 795 | =item B<< $metaclass->error_class($class_name) >> | ||||
| 796 | |||||
| 797 | The name of the class used to throw errors. This defaults to | ||||
| 798 | L<Moose::Error::Default>, which generates an error with a stacktrace | ||||
| 799 | just like C<Carp::confess>. | ||||
| 800 | |||||
| 801 | =item B<< $metaclass->throw_error($message, %extra) >> | ||||
| 802 | |||||
| 803 | Throws the error created by C<create_error> using C<raise_error> | ||||
| 804 | |||||
| 805 | =back | ||||
| 806 | |||||
| 807 | =head1 BUGS | ||||
| 808 | |||||
| 809 | See L<Moose/BUGS> for details on reporting bugs. | ||||
| 810 | |||||
| 811 | =head1 AUTHOR | ||||
| 812 | |||||
| 813 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
| 814 | |||||
| 815 | =head1 COPYRIGHT AND LICENSE | ||||
| 816 | |||||
| 817 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
| 818 | |||||
| 819 | L<http://www.iinteractive.com> | ||||
| 820 | |||||
| 821 | This library is free software; you can redistribute it and/or modify | ||||
| 822 | it 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 | |||||
# 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 |