Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Class/MOP/Class.pm |
Statements | Executed 31569 statements in 44.7ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1529 | 20 | 12 | 5.78ms | 24.5ms | initialize (recurses: max depth 2, inclusive time 418µs) | Class::MOP::Class::
1 | 1 | 1 | 5.26ms | 6.59ms | BEGIN@9 | Class::MOP::Class::
62 | 2 | 1 | 5.24ms | 5.59ms | CORE:sort (opcode) | Class::MOP::Class::
49 | 1 | 1 | 4.94ms | 13.2ms | _can_fix_metaclass_incompatibility | Class::MOP::Class::
282 | 2 | 1 | 4.71ms | 14.0ms | _inline_init_attr_from_default | Class::MOP::Class::
131 | 8 | 4 | 2.21ms | 4.18ms | get_all_attributes | Class::MOP::Class::
294 | 1 | 1 | 1.69ms | 7.47ms | _single_metaclass_can_be_made_compatible | Class::MOP::Class::
286 | 2 | 2 | 1.46ms | 29.5ms | _inline_slot_initializer | Class::MOP::Class::
271 | 1 | 1 | 1.16ms | 13.4ms | _inline_init_attr_from_constructor | Class::MOP::Class::
90 | 5 | 5 | 1.12ms | 8.20ms | find_method_by_name | Class::MOP::Class::
309 | 4 | 2 | 878µs | 1.19ms | linearized_isa | Class::MOP::Class::
35 | 2 | 1 | 812µs | 4.97ms | _construct_instance | Class::MOP::Class::
69 | 1 | 1 | 775µs | 18.1ms | _construct_class_instance (recurses: max depth 1, inclusive time 230µs) | Class::MOP::Class::
1 | 1 | 1 | 765µs | 834µs | BEGIN@7 | Class::MOP::Class::
135 | 1 | 1 | 758µs | 40.5ms | _post_add_attribute | Class::MOP::Class::
285 | 2 | 2 | 752µs | 1.04ms | _inline_default_value | Class::MOP::Class::
75 | 2 | 2 | 686µs | 6.51ms | find_next_method_by_name | Class::MOP::Class::
1 | 1 | 1 | 632µs | 708µs | BEGIN@8 | Class::MOP::Class::
31 | 1 | 1 | 578µs | 58.3ms | _inline_constructor | Class::MOP::Class::
55 | 1 | 1 | 568µs | 30.2ms | _immutable_metaclass (recurses: max depth 1, inclusive time 111µs) | Class::MOP::Class::
72 | 2 | 1 | 565µs | 16.5ms | _check_metaclass_compatibility (recurses: max depth 1, inclusive time 182µs) | Class::MOP::Class::
67 | 1 | 1 | 537µs | 537µs | _new | Class::MOP::Class::
31 | 1 | 1 | 513µs | 35.2ms | _inline_slot_initializers | Class::MOP::Class::
55 | 7 | 5 | 513µs | 125ms | make_immutable (recurses: max depth 1, inclusive time 214µs) | Class::MOP::Class::
43 | 1 | 1 | 483µs | 8.76ms | __ANON__[:1082] | Class::MOP::Class::
31 | 2 | 2 | 462µs | 2.97ms | _eval_environment | Class::MOP::Class::
135 | 1 | 1 | 458µs | 37.0ms | try {...} | Class::MOP::Class::
135 | 1 | 1 | 425µs | 532µs | invalidate_meta_instances | Class::MOP::Class::
52 | 1 | 1 | 367µs | 4.20ms | _create_meta_instance | Class::MOP::Class::
1 | 1 | 1 | 365µs | 870µs | BEGIN@10 | Class::MOP::Class::
55 | 2 | 2 | 356µs | 438µs | _immutable_options | Class::MOP::Class::
55 | 1 | 1 | 345µs | 1.18ms | find_attribute_by_name | Class::MOP::Class::
55 | 1 | 1 | 331µs | 94.2ms | _initialize_immutable | Class::MOP::Class::
55 | 1 | 1 | 303µs | 93.9ms | _install_inlined_code | Class::MOP::Class::
31 | 1 | 1 | 302µs | 37.1ms | _inline_new_object | Class::MOP::Class::
33 | 1 | 1 | 301µs | 34.8ms | _inline_accessors | Class::MOP::Class::
174 | 4 | 1 | 286µs | 955µs | _method_lookup_order | Class::MOP::Class::
324 | 10 | 5 | 276µs | 4.47ms | get_meta_instance | Class::MOP::Class::
38 | 1 | 1 | 274µs | 13.8ms | _fix_metaclass_incompatibility (recurses: max depth 1, inclusive time 104µs) | Class::MOP::Class::
135 | 1 | 1 | 249µs | 928µs | _attach_attribute | Class::MOP::Class::
7 | 1 | 1 | 232µs | 5.14ms | get_all_methods | Class::MOP::Class::
33 | 5 | 5 | 211µs | 4.49ms | new_object | Class::MOP::Class::
43 | 1 | 1 | 210µs | 16.5ms | add_around_method_modifier | Class::MOP::Class::
49 | 1 | 1 | 174µs | 736µs | _class_metaclass_can_be_made_compatible | Class::MOP::Class::
55 | 1 | 1 | 171µs | 30.3ms | _rebless_as_immutable (recurses: max depth 1, inclusive time 122µs) | Class::MOP::Class::
1 | 1 | 1 | 162µs | 198µs | BEGIN@11 | Class::MOP::Class::
61 | 4 | 1 | 156µs | 473µs | _real_ref_name | Class::MOP::Class::
31 | 1 | 1 | 136µs | 181µs | _inline_fallback_constructor | Class::MOP::Class::
87 | 3 | 2 | 120µs | 120µs | _base_metaclasses | Class::MOP::Class::
135 | 1 | 1 | 107µs | 107µs | invalidate_meta_instance | Class::MOP::Class::
31 | 1 | 1 | 98µs | 183µs | _inline_preserve_weak_metaclasses | Class::MOP::Class::
31 | 1 | 1 | 96µs | 775µs | _inline_create_instance | Class::MOP::Class::
31 | 1 | 1 | 77µs | 853µs | _inline_generate_instance | Class::MOP::Class::
32 | 2 | 1 | 59µs | 59µs | _add_inlined_method | Class::MOP::Class::
6 | 1 | 1 | 58µs | 77µs | _single_metaclass_is_compatible | Class::MOP::Class::
2 | 1 | 1 | 38µs | 1.23ms | create | Class::MOP::Class::
30 | 1 | 1 | 36µs | 36µs | _inline_params | Class::MOP::Class::
88 | 4 | 3 | 36µs | 36µs | is_mutable | Class::MOP::Class::
30 | 1 | 1 | 36µs | 36µs | _generate_fallback_constructor | Class::MOP::Class::
3 | 1 | 1 | 34µs | 85µs | _superclasses_updated | Class::MOP::Class::
1 | 1 | 1 | 34µs | 524µs | _inline_destructor | Class::MOP::Class::
2 | 2 | 2 | 25µs | 104µs | find_all_methods_by_name | Class::MOP::Class::
38 | 1 | 1 | 18µs | 18µs | is_immutable | Class::MOP::Class::
30 | 1 | 1 | 13µs | 13µs | _inline_extra_init | Class::MOP::Class::
6 | 1 | 1 | 12µs | 89µs | _check_single_metaclass_compatibility | Class::MOP::Class::
1 | 1 | 1 | 9µs | 10µs | BEGIN@4 | Class::MOP::Class::
1 | 1 | 1 | 9µs | 39µs | BEGIN@18 | Class::MOP::Class::
1 | 1 | 1 | 7µs | 12µs | _class_metaclass_is_compatible | Class::MOP::Class::
3 | 1 | 1 | 7µs | 7µs | _superclass_metas | Class::MOP::Class::
1 | 1 | 1 | 6µs | 9µs | BEGIN@5 | Class::MOP::Class::
1 | 1 | 1 | 5µs | 17µs | _check_class_metaclass_compatibility | Class::MOP::Class::
1 | 1 | 1 | 5µs | 23µs | BEGIN@13 | Class::MOP::Class::
1 | 1 | 1 | 5µs | 2.11ms | BEGIN@20 | Class::MOP::Class::
3 | 1 | 1 | 4µs | 4µs | update_meta_instance_dependencies | Class::MOP::Class::
1 | 1 | 1 | 4µs | 10µs | BEGIN@14 | Class::MOP::Class::
1 | 1 | 1 | 4µs | 16µs | BEGIN@15 | Class::MOP::Class::
1 | 1 | 1 | 4µs | 14µs | BEGIN@16 | Class::MOP::Class::
1 | 1 | 1 | 4µs | 19µs | BEGIN@17 | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | __ANON__[:210] | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | __ANON__[:900] | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | __ANON__[:904] | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _anon_cache_key | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _anon_package_prefix | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _clone_instance | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _fix_class_metaclass_incompatibility | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _fix_single_metaclass_incompatibility | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _fixup_attributes_after_rebless | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _force_rebless_instance | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _inline_clear_mop_slot | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _inline_get_mop_slot | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _inline_rebless_instance | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _inline_set_mop_slot | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _inlined_methods | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _rebless_as_mutable | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _remove_generated_metaobjects | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _remove_inlined_code | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | _restore_metaobjects_from | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | add_after_method_modifier | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | add_before_method_modifier | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | add_dependent_meta_instance | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | add_meta_instance_dependencies | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | catch {...} | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | class_precedence_list | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | clone_object | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | create_anon_class | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | direct_subclasses | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | get_all_method_names | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | immutable_options | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | is_anon_class | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | is_pristine | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | make_mutable | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | rebless_instance | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | rebless_instance_away | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | rebless_instance_back | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | reinitialize | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | remove_attribute | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | remove_dependent_meta_instance | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | remove_meta_instance_dependencies | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | subclasses | Class::MOP::Class::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Class::MOP::Class; | ||||
2 | 1 | 800ns | our $VERSION = '2.1605'; | ||
3 | |||||
4 | 2 | 14µs | 2 | 12µs | # spent 10µs (9+2) within Class::MOP::Class::BEGIN@4 which was called:
# once (9µs+2µs) by Class::MOP::BEGIN@18 at line 4 # spent 10µs making 1 call to Class::MOP::Class::BEGIN@4
# spent 2µs making 1 call to strict::import |
5 | 2 | 14µs | 2 | 12µs | # spent 9µs (6+3) within Class::MOP::Class::BEGIN@5 which was called:
# once (6µs+3µs) by Class::MOP::BEGIN@18 at line 5 # spent 9µs making 1 call to Class::MOP::Class::BEGIN@5
# spent 3µs making 1 call to warnings::import |
6 | |||||
7 | 2 | 63µs | 1 | 834µs | # spent 834µs (765+69) within Class::MOP::Class::BEGIN@7 which was called:
# once (765µs+69µs) by Class::MOP::BEGIN@18 at line 7 # spent 834µs making 1 call to Class::MOP::Class::BEGIN@7 |
8 | 2 | 70µs | 1 | 708µs | # spent 708µs (632+76) within Class::MOP::Class::BEGIN@8 which was called:
# once (632µs+76µs) by Class::MOP::BEGIN@18 at line 8 # spent 708µs making 1 call to Class::MOP::Class::BEGIN@8 |
9 | 2 | 88µs | 1 | 6.59ms | # spent 6.59ms (5.26+1.33) within Class::MOP::Class::BEGIN@9 which was called:
# once (5.26ms+1.33ms) by Class::MOP::BEGIN@18 at line 9 # spent 6.59ms making 1 call to Class::MOP::Class::BEGIN@9 |
10 | 2 | 70µs | 1 | 870µs | # spent 870µs (365+505) within Class::MOP::Class::BEGIN@10 which was called:
# once (365µs+505µs) by Class::MOP::BEGIN@18 at line 10 # spent 870µs making 1 call to Class::MOP::Class::BEGIN@10 |
11 | 2 | 65µs | 1 | 198µs | # spent 198µs (162+36) within Class::MOP::Class::BEGIN@11 which was called:
# once (162µs+36µs) by Class::MOP::BEGIN@18 at line 11 # spent 198µs making 1 call to Class::MOP::Class::BEGIN@11 |
12 | |||||
13 | 2 | 15µs | 2 | 42µs | # spent 23µs (5+18) within Class::MOP::Class::BEGIN@13 which was called:
# once (5µs+18µs) by Class::MOP::BEGIN@18 at line 13 # spent 23µs making 1 call to Class::MOP::Class::BEGIN@13
# spent 18µs making 1 call to Exporter::import |
14 | 2 | 12µs | 2 | 16µs | # spent 10µs (4+6) within Class::MOP::Class::BEGIN@14 which was called:
# once (4µs+6µs) by Class::MOP::BEGIN@18 at line 14 # spent 10µs making 1 call to Class::MOP::Class::BEGIN@14
# spent 6µs making 1 call to Module::Runtime::import |
15 | 2 | 12µs | 2 | 28µs | # spent 16µs (4+12) within Class::MOP::Class::BEGIN@15 which was called:
# once (4µs+12µs) by Class::MOP::BEGIN@18 at line 15 # spent 16µs making 1 call to Class::MOP::Class::BEGIN@15
# spent 12µs making 1 call to Exporter::import |
16 | 2 | 12µs | 2 | 25µs | # spent 14µs (4+11) within Class::MOP::Class::BEGIN@16 which was called:
# once (4µs+11µs) by Class::MOP::BEGIN@18 at line 16 # spent 14µs making 1 call to Class::MOP::Class::BEGIN@16
# spent 11µs making 1 call to Exporter::import |
17 | 2 | 15µs | 2 | 34µs | # spent 19µs (4+15) within Class::MOP::Class::BEGIN@17 which was called:
# once (4µs+15µs) by Class::MOP::BEGIN@18 at line 17 # spent 19µs making 1 call to Class::MOP::Class::BEGIN@17
# spent 15µs making 1 call to Exporter::import |
18 | 3 | 33µs | 3 | 58µs | # spent 39µs (9+30) within Class::MOP::Class::BEGIN@18 which was called:
# once (9µs+30µs) by Class::MOP::BEGIN@18 at line 18 # spent 39µs making 1 call to Class::MOP::Class::BEGIN@18
# spent 11µs making 1 call to UNIVERSAL::VERSION
# spent 8µs making 1 call to List::Util::import |
19 | |||||
20 | 1 | 3µs | 1 | 2.10ms | # spent 2.11ms (5µs+2.10) within Class::MOP::Class::BEGIN@20 which was called:
# once (5µs+2.10ms) by Class::MOP::BEGIN@18 at line 23 # spent 2.10ms making 1 call to parent::import |
21 | 'Class::MOP::Mixin::HasAttributes', | ||||
22 | 'Class::MOP::Mixin::HasMethods', | ||||
23 | 1 | 3.44ms | 1 | 2.11ms | 'Class::MOP::Mixin::HasOverloads'; # spent 2.11ms making 1 call to Class::MOP::Class::BEGIN@20 |
24 | |||||
25 | # Creation | ||||
26 | |||||
27 | # spent 24.5ms (5.78+18.7) within Class::MOP::Class::initialize which was called 1529 times, avg 16µs/call:
# 557 times (945µs+191µs) by Class::MOP::Class::get_all_attributes at line 936, avg 2µs/call
# 345 times (649µs+340µs) by Class::MOP::Class::find_method_by_name at line 1133, avg 3µs/call
# 195 times (3.17ms+2.02ms) by Class::MOP::Mixin::meta or Class::MOP::Object::meta or DBIx::MultiStatementDo::meta or Moose::Meta::Role::Application::RoleSummation::meta or Moose::Meta::Role::Application::ToClass::meta or Moose::Meta::Role::Application::ToInstance::meta or Moose::Meta::Role::Application::ToRole::meta or Moose::Meta::Role::Application::meta or Moose::Meta::Role::Composite::meta or Moose::Meta::Role::Method::Required::meta or Moose::Meta::Role::meta or Moose::Meta::TypeCoercion::Union::meta or Moose::Meta::TypeCoercion::meta or Moose::Meta::TypeConstraint::Class::meta or Moose::Meta::TypeConstraint::DuckType::meta or Moose::Meta::TypeConstraint::Enum::meta or Moose::Meta::TypeConstraint::Parameterizable::meta or Moose::Meta::TypeConstraint::Parameterized::meta or Moose::Meta::TypeConstraint::Registry::meta or Moose::Meta::TypeConstraint::Role::meta or Moose::Meta::TypeConstraint::Union::meta or Moose::Meta::TypeConstraint::meta at line 42 of Class/MOP/Method/Meta.pm, avg 27µs/call
# 150 times (289µs+64µs) by Class::MOP::Class::find_next_method_by_name at line 1181, avg 2µs/call
# 59 times (181µs+3.16ms) by Class::MOP::Mixin::meta at line 12 of Class/MOP/Mixin.pm, avg 57µs/call
# 55 times (89µs+18µs) by Class::MOP::Class::find_attribute_by_name at line 926, avg 2µs/call
# 49 times (112µs+-104µs) by Class::MOP::Class::_fix_metaclass_incompatibility at line 291, avg 169ns/call
# 24 times (44µs+5.14ms) by Class::MOP::Method::_new at line 59 of Class/MOP/Method.pm, avg 216µs/call
# 19 times (108µs+1.12ms) by metaclass::import at line 38 of metaclass.pm, avg 65µs/call
# 15 times (26µs+7µs) by Class::MOP::Class::get_all_methods at line 1144, avg 2µs/call
# 12 times (47µs+5.32ms) by Class::MOP::MiniTrait::apply at line 14 of Class/MOP/MiniTrait.pm, avg 447µs/call
# 12 times (23µs+5µs) by Class::MOP::Attribute::has_value at line 332 of Class/MOP/Attribute.pm, avg 2µs/call
# 12 times (22µs+5µs) by Class::MOP::Attribute::get_raw_value at line 311 of Class/MOP/Attribute.pm, avg 2µs/call
# 7 times (22µs+223µs) by Moose::BEGIN@43 at line 12 of Moose/Meta/Attribute/Native.pm, avg 35µs/call
# 6 times (16µs+231µs) by Class::MOP::Method::Accessor::_new at line 51 of Class/MOP/Method/Accessor.pm, avg 41µs/call
# 6 times (11µs+2µs) by Class::MOP::Class::find_all_methods_by_name at line 1164, avg 2µs/call
# 2 times (10µs+875µs) by Moose::Meta::Class::initialize at line 64 of Moose/Meta/Class.pm, avg 442µs/call
# 2 times (7µs+114µs) by Class::MOP::Package::create at line 67 of Class/MOP/Package.pm, avg 60µs/call
# once (2µs+500ns) by Class::MOP::Attribute::_new at line 69 of Class/MOP/Attribute.pm
# once (2µs+500ns) by Moose::Meta::Method::_new at line 7 of (eval 33)[Eval/Closure.pm:142] | ||||
28 | 1529 | 191µs | my $class = shift; | ||
29 | |||||
30 | 1529 | 125µs | my $package_name; | ||
31 | |||||
32 | 1529 | 377µs | if ( @_ % 2 ) { | ||
33 | $package_name = shift; | ||||
34 | } else { | ||||
35 | my %options = @_; | ||||
36 | $package_name = $options{package}; | ||||
37 | } | ||||
38 | |||||
39 | 1529 | 209µs | ($package_name && !ref($package_name)) | ||
40 | || ($class||__PACKAGE__)->_throw_exception( InitializeTakesUnBlessedPackageName => package_name => $package_name ); | ||||
41 | 1529 | 2.23ms | 1598 | 18.9ms | return Class::MOP::get_metaclass_by_name($package_name) # spent 18.4ms making 69 calls to Class::MOP::Class::_construct_class_instance, avg 266µs/call, recursion: max depth 1, sum of overlapping time 230µs
# spent 774µs making 1529 calls to Class::MOP::get_metaclass_by_name, avg 506ns/call |
42 | || $class->_construct_class_instance(package => $package_name, @_); | ||||
43 | } | ||||
44 | |||||
45 | sub reinitialize { | ||||
46 | my ( $class, @args ) = @_; | ||||
47 | unshift @args, "package" if @args % 2; | ||||
48 | my %options = @args; | ||||
49 | my $old_metaclass = blessed($options{package}) | ||||
50 | ? $options{package} | ||||
51 | : Class::MOP::get_metaclass_by_name($options{package}); | ||||
52 | $options{weaken} = Class::MOP::metaclass_is_weak($old_metaclass->name) | ||||
53 | if !exists $options{weaken} | ||||
54 | && blessed($old_metaclass) | ||||
55 | && $old_metaclass->isa('Class::MOP::Class'); | ||||
56 | $old_metaclass->_remove_generated_metaobjects | ||||
57 | if $old_metaclass && $old_metaclass->isa('Class::MOP::Class'); | ||||
58 | my $new_metaclass = $class->SUPER::reinitialize(%options); | ||||
59 | $new_metaclass->_restore_metaobjects_from($old_metaclass) | ||||
60 | if $old_metaclass && $old_metaclass->isa('Class::MOP::Class'); | ||||
61 | return $new_metaclass; | ||||
62 | } | ||||
63 | |||||
64 | # NOTE: (meta-circularity) | ||||
65 | # this is a special form of _construct_instance | ||||
66 | # (see below), which is used to construct class | ||||
67 | # meta-object instances for any Class::MOP::* | ||||
68 | # class. All other classes will use the more | ||||
69 | # normal &construct_instance. | ||||
70 | # spent 18.1ms (775µs+17.4) within Class::MOP::Class::_construct_class_instance which was called 69 times, avg 263µs/call:
# 69 times (775µs+17.4ms) by Class::MOP::Class::initialize at line 41, avg 263µs/call | ||||
71 | 69 | 15µs | my $class = shift; | ||
72 | 69 | 71µs | my $options = @_ == 1 ? $_[0] : {@_}; | ||
73 | 69 | 21µs | my $package_name = $options->{package}; | ||
74 | 69 | 22µs | (defined $package_name && $package_name) | ||
75 | || $class->_throw_exception("ConstructClassInstanceTakesPackageName"); | ||||
76 | # NOTE: | ||||
77 | # return the metaclass if we have it cached, | ||||
78 | # and it is still defined (it has not been | ||||
79 | # reaped by DESTROY yet, which can happen | ||||
80 | # annoyingly enough during global destruction) | ||||
81 | |||||
82 | 69 | 44µs | 69 | 22µs | if (defined(my $meta = Class::MOP::get_metaclass_by_name($package_name))) { # spent 22µs making 69 calls to Class::MOP::get_metaclass_by_name, avg 323ns/call |
83 | return $meta; | ||||
84 | } | ||||
85 | |||||
86 | $class | ||||
87 | 69 | 27µs | 9 | 160µs | = ref $class # spent 160µs making 9 calls to Class::MOP::Class::_real_ref_name, avg 18µs/call |
88 | ? $class->_real_ref_name | ||||
89 | : $class; | ||||
90 | |||||
91 | # now create the metaclass | ||||
92 | 69 | 7µs | my $meta; | ||
93 | 69 | 103µs | 67 | 537µs | if ($class eq 'Class::MOP::Class') { # spent 537µs making 67 calls to Class::MOP::Class::_new, avg 8µs/call |
94 | $meta = $class->_new($options); | ||||
95 | } | ||||
96 | else { | ||||
97 | # NOTE: | ||||
98 | # it is safe to use meta here because | ||||
99 | # class will always be a subclass of | ||||
100 | # Class::MOP::Class, which defines meta | ||||
101 | 2 | 5µs | 4 | 763µs | $meta = $class->meta->_construct_instance($options) # spent 750µs making 2 calls to Class::MOP::Class::_construct_instance, avg 375µs/call
# spent 12µs making 2 calls to Class::MOP::Object::meta, avg 6µs/call |
102 | } | ||||
103 | |||||
104 | # and check the metaclass compatibility | ||||
105 | 69 | 121µs | 69 | 15.9ms | $meta->_check_metaclass_compatibility(); # spent 16.0ms making 69 calls to Class::MOP::Class::_check_metaclass_compatibility, avg 232µs/call, recursion: max depth 1, sum of overlapping time 182µs |
106 | |||||
107 | 69 | 55µs | 69 | 80µs | Class::MOP::store_metaclass_by_name($package_name, $meta); # spent 80µs making 69 calls to Class::MOP::store_metaclass_by_name, avg 1µs/call |
108 | |||||
109 | # NOTE: | ||||
110 | # we need to weaken any anon classes | ||||
111 | # so that they can call DESTROY properly | ||||
112 | 69 | 21µs | Class::MOP::weaken_metaclass($package_name) if $options->{weaken}; | ||
113 | |||||
114 | 69 | 120µs | $meta; | ||
115 | } | ||||
116 | |||||
117 | # spent 473µs (156+317) within Class::MOP::Class::_real_ref_name which was called 61 times, avg 8µs/call:
# 49 times (114µs+179µs) by Class::MOP::Class::_class_metaclass_can_be_made_compatible at line 336, avg 6µs/call
# 9 times (34µs+126µs) by Class::MOP::Class::_construct_class_instance at line 87, avg 18µs/call
# 2 times (7µs+12µs) by Class::MOP::Class::_immutable_metaclass at line 1364, avg 9µs/call
# once (1µs+400ns) by Class::MOP::Class::_class_metaclass_is_compatible at line 250 | ||||
118 | 61 | 8µs | my $self = shift; | ||
119 | |||||
120 | # NOTE: we need to deal with the possibility of class immutability here, | ||||
121 | # and then get the name of the class appropriately | ||||
122 | 61 | 145µs | 84 | 317µs | return $self->is_immutable # spent 265µs making 23 calls to Class::MOP::Class::Immutable::Class::MOP::Class::is_immutable, avg 12µs/call
# spent 34µs making 23 calls to Class::MOP::Class::Immutable::Trait::_get_mutable_metaclass_name, avg 1µs/call
# spent 18µs making 38 calls to Class::MOP::Class::is_immutable, avg 476ns/call |
123 | ? $self->_get_mutable_metaclass_name() | ||||
124 | : ref $self; | ||||
125 | } | ||||
126 | |||||
127 | # spent 537µs within Class::MOP::Class::_new which was called 67 times, avg 8µs/call:
# 67 times (537µs+0s) by Class::MOP::Class::_construct_class_instance at line 93, avg 8µs/call | ||||
128 | 67 | 12µs | my $class = shift; | ||
129 | |||||
130 | 67 | 16µs | return Class::MOP::Class->initialize($class)->new_object(@_) | ||
131 | if $class ne __PACKAGE__; | ||||
132 | |||||
133 | 67 | 23µs | my $options = @_ == 1 ? $_[0] : {@_}; | ||
134 | |||||
135 | return bless { | ||||
136 | # inherited from Class::MOP::Package | ||||
137 | 'package' => $options->{package}, | ||||
138 | |||||
139 | # NOTE: | ||||
140 | # since the following attributes will | ||||
141 | # actually be loaded from the symbol | ||||
142 | # table, and actually bypass the instance | ||||
143 | # entirely, we can just leave these things | ||||
144 | # listed here for reference, because they | ||||
145 | # should not actually have a value associated | ||||
146 | # with the slot. | ||||
147 | 'namespace' => \undef, | ||||
148 | 'methods' => {}, | ||||
149 | |||||
150 | # inherited from Class::MOP::Module | ||||
151 | 'version' => \undef, | ||||
152 | 'authority' => \undef, | ||||
153 | |||||
154 | # defined in Class::MOP::Class | ||||
155 | 'superclasses' => \undef, | ||||
156 | |||||
157 | 'attributes' => {}, | ||||
158 | 'attribute_metaclass' => | ||||
159 | ( $options->{'attribute_metaclass'} || 'Class::MOP::Attribute' ), | ||||
160 | 'method_metaclass' => | ||||
161 | ( $options->{'method_metaclass'} || 'Class::MOP::Method' ), | ||||
162 | 'wrapped_method_metaclass' => ( | ||||
163 | $options->{'wrapped_method_metaclass'} | ||||
164 | || 'Class::MOP::Method::Wrapped' | ||||
165 | ), | ||||
166 | 'instance_metaclass' => | ||||
167 | ( $options->{'instance_metaclass'} || 'Class::MOP::Instance' ), | ||||
168 | 'immutable_trait' => ( | ||||
169 | $options->{'immutable_trait'} | ||||
170 | || 'Class::MOP::Class::Immutable::Trait' | ||||
171 | ), | ||||
172 | 'constructor_name' => ( $options->{constructor_name} || 'new' ), | ||||
173 | 'constructor_class' => ( | ||||
174 | $options->{constructor_class} || 'Class::MOP::Method::Constructor' | ||||
175 | ), | ||||
176 | 'destructor_class' => $options->{destructor_class}, | ||||
177 | 67 | 526µs | }, $class; | ||
178 | } | ||||
179 | |||||
180 | ## Metaclass compatibility | ||||
181 | { | ||||
182 | 1 | 6µs | my %base_metaclass = ( | ||
183 | attribute_metaclass => 'Class::MOP::Attribute', | ||||
184 | method_metaclass => 'Class::MOP::Method', | ||||
185 | wrapped_method_metaclass => 'Class::MOP::Method::Wrapped', | ||||
186 | instance_metaclass => 'Class::MOP::Instance', | ||||
187 | constructor_class => 'Class::MOP::Method::Constructor', | ||||
188 | destructor_class => 'Class::MOP::Method::Destructor', | ||||
189 | ); | ||||
190 | |||||
191 | 87 | 171µs | # spent 120µs within Class::MOP::Class::_base_metaclasses which was called 87 times, avg 1µs/call:
# 48 times (78µs+0s) by Class::MOP::Class::_can_fix_metaclass_incompatibility at line 324, avg 2µs/call
# 37 times (40µs+0s) by Class::MOP::Class::_check_metaclass_compatibility at line 202, avg 1µs/call
# 2 times (3µs+0s) by Moose::Meta::Class::_base_metaclasses at line 628 of Moose/Meta/Class.pm, avg 1µs/call | ||
192 | } | ||||
193 | |||||
194 | 1 | 500ns | # spent 16.5ms (565µs+15.9) within Class::MOP::Class::_check_metaclass_compatibility which was called 72 times, avg 229µs/call:
# 69 times (504µs+15.3ms) by Class::MOP::Class::_construct_class_instance at line 105, avg 230µs/call
# 3 times (61µs+540µs) by Class::MOP::Class::superclasses at line 966, avg 200µs/call | ||
195 | 72 | 16µs | my $self = shift; | ||
196 | |||||
197 | 72 | 174µs | 72 | 1.56ms | my @superclasses = $self->superclasses # spent 1.49ms making 69 calls to Class::MOP::Class::superclasses, avg 22µs/call, recursion: max depth 1, sum of overlapping time 14µs
# spent 100µs making 3 calls to Moose::Meta::Class::superclasses, avg 33µs/call, recursion: max depth 1, sum of overlapping time 25µs |
198 | or return; | ||||
199 | |||||
200 | 38 | 46µs | 38 | 13.8ms | $self->_fix_metaclass_incompatibility(@superclasses); # spent 13.9ms making 38 calls to Class::MOP::Class::_fix_metaclass_incompatibility, avg 366µs/call, recursion: max depth 1, sum of overlapping time 104µs |
201 | |||||
202 | 38 | 68µs | 38 | 52µs | my %base_metaclass = $self->_base_metaclasses; # spent 40µs making 37 calls to Class::MOP::Class::_base_metaclasses, avg 1µs/call
# spent 13µs making 1 call to Moose::Meta::Class::_base_metaclasses |
203 | |||||
204 | # this is always okay ... | ||||
205 | return | ||||
206 | if ref($self) eq 'Class::MOP::Class' | ||||
207 | && all { | ||||
208 | 222 | 312µs | 222 | 48µs | my $meta = $self->$_; # spent 9µs making 37 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 235ns/call
# spent 8µs making 37 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 222ns/call
# spent 8µs making 37 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 216ns/call
# spent 8µs making 37 calls to Class::MOP::Class::constructor_class, avg 214ns/call
# spent 8µs making 37 calls to Class::MOP::Class::destructor_class, avg 211ns/call
# spent 7µs making 37 calls to Class::MOP::Class::instance_metaclass, avg 200ns/call |
209 | 222 | 174µs | !defined($meta) || $meta eq $base_metaclass{$_}; | ||
210 | } | ||||
211 | 38 | 133µs | 37 | 426µs | keys %base_metaclass; # spent 426µs making 37 calls to List::Util::all, avg 12µs/call |
212 | |||||
213 | 1 | 2µs | for my $superclass (@superclasses) { | ||
214 | 1 | 3µs | 1 | 17µs | $self->_check_class_metaclass_compatibility($superclass); # spent 17µs making 1 call to Class::MOP::Class::_check_class_metaclass_compatibility |
215 | } | ||||
216 | |||||
217 | 1 | 3µs | for my $metaclass_type ( keys %base_metaclass ) { | ||
218 | 6 | 11µs | 6 | 2µs | next unless defined $self->$metaclass_type; # spent 500ns making 1 call to Moose::Meta::Class::constructor_class
# spent 500ns making 1 call to Moose::Meta::Class::destructor_class
# spent 300ns making 1 call to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass
# spent 200ns making 1 call to Class::MOP::Class::instance_metaclass
# spent 200ns making 1 call to Class::MOP::Mixin::HasAttributes::attribute_metaclass
# spent 200ns making 1 call to Class::MOP::Mixin::HasMethods::method_metaclass |
219 | 6 | 3µs | for my $superclass (@superclasses) { | ||
220 | 6 | 7µs | 6 | 89µs | $self->_check_single_metaclass_compatibility( $metaclass_type, # spent 89µs making 6 calls to Class::MOP::Class::_check_single_metaclass_compatibility, avg 15µs/call |
221 | $superclass ); | ||||
222 | } | ||||
223 | } | ||||
224 | } | ||||
225 | |||||
226 | # spent 17µs (5+12) within Class::MOP::Class::_check_class_metaclass_compatibility which was called:
# once (5µs+12µs) by Class::MOP::Class::_check_metaclass_compatibility at line 214 | ||||
227 | 1 | 300ns | my $self = shift; | ||
228 | 1 | 600ns | my ( $superclass_name ) = @_; | ||
229 | |||||
230 | 1 | 4µs | 1 | 12µs | if (!$self->_class_metaclass_is_compatible($superclass_name)) { # spent 12µs making 1 call to Class::MOP::Class::_class_metaclass_is_compatible |
231 | my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name); | ||||
232 | |||||
233 | my $super_meta_type = $super_meta->_real_ref_name; | ||||
234 | |||||
235 | $self->_throw_exception( IncompatibleMetaclassOfSuperclass => class_name => $self->name, | ||||
236 | class_meta_type => ref( $self ), | ||||
237 | superclass_name => $superclass_name, | ||||
238 | superclass_meta_type => $super_meta_type | ||||
239 | ); | ||||
240 | } | ||||
241 | } | ||||
242 | |||||
243 | # spent 12µs (7+4) within Class::MOP::Class::_class_metaclass_is_compatible which was called:
# once (7µs+4µs) by Class::MOP::Class::_check_class_metaclass_compatibility at line 230 | ||||
244 | 1 | 200ns | my $self = shift; | ||
245 | 1 | 300ns | my ( $superclass_name ) = @_; | ||
246 | |||||
247 | 1 | 1µs | 1 | 700ns | my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name) # spent 700ns making 1 call to Class::MOP::get_metaclass_by_name |
248 | || return 1; | ||||
249 | |||||
250 | 1 | 1µs | 1 | 2µs | my $super_meta_name = $super_meta->_real_ref_name; # spent 2µs making 1 call to Class::MOP::Class::_real_ref_name |
251 | |||||
252 | 1 | 3µs | 1 | 2µs | return $self->_is_compatible_with($super_meta_name); # spent 2µs making 1 call to Class::MOP::Object::_is_compatible_with |
253 | } | ||||
254 | |||||
255 | # spent 89µs (12+77) within Class::MOP::Class::_check_single_metaclass_compatibility which was called 6 times, avg 15µs/call:
# 6 times (12µs+77µs) by Class::MOP::Class::_check_metaclass_compatibility at line 220, avg 15µs/call | ||||
256 | 6 | 800ns | my $self = shift; | ||
257 | 6 | 1µs | my ( $metaclass_type, $superclass_name ) = @_; | ||
258 | |||||
259 | 6 | 9µs | 6 | 77µs | if (!$self->_single_metaclass_is_compatible($metaclass_type, $superclass_name)) { # spent 77µs making 6 calls to Class::MOP::Class::_single_metaclass_is_compatible, avg 13µs/call |
260 | my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name); | ||||
261 | |||||
262 | $self->_throw_exception( MetaclassTypeIncompatible => class_name => $self->name, | ||||
263 | superclass_name => $superclass_name, | ||||
264 | metaclass_type => $metaclass_type | ||||
265 | ); | ||||
266 | } | ||||
267 | } | ||||
268 | |||||
269 | # spent 77µs (58+19) within Class::MOP::Class::_single_metaclass_is_compatible which was called 6 times, avg 13µs/call:
# 6 times (58µs+19µs) by Class::MOP::Class::_check_single_metaclass_compatibility at line 259, avg 13µs/call | ||||
270 | 6 | 700ns | my $self = shift; | ||
271 | 6 | 800ns | my ( $metaclass_type, $superclass_name ) = @_; | ||
272 | |||||
273 | 6 | 3µs | 6 | 2µs | my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name) # spent 2µs making 6 calls to Class::MOP::get_metaclass_by_name, avg 317ns/call |
274 | || return 1; | ||||
275 | |||||
276 | # for instance, Moose::Meta::Class has a error_class attribute, but | ||||
277 | # Class::MOP::Class doesn't - this shouldn't be an error | ||||
278 | 6 | 8µs | 6 | 2µs | return 1 unless $super_meta->can($metaclass_type); # spent 2µs making 6 calls to UNIVERSAL::can, avg 300ns/call |
279 | # for instance, Moose::Meta::Class has a destructor_class, but | ||||
280 | # Class::MOP::Class doesn't - this shouldn't be an error | ||||
281 | 6 | 7µs | 6 | 1µs | return 1 unless defined $super_meta->$metaclass_type; # spent 400ns making 1 call to Moose::Meta::Class::destructor_class
# spent 300ns making 1 call to Moose::Meta::Class::constructor_class
# spent 200ns making 1 call to Class::MOP::Mixin::HasAttributes::attribute_metaclass
# spent 200ns making 1 call to Class::MOP::Mixin::HasMethods::method_metaclass
# spent 200ns making 1 call to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass
# spent 100ns making 1 call to Class::MOP::Class::instance_metaclass |
282 | # if metaclass is defined in superclass but not here, it's not compatible | ||||
283 | # this is a really odd case | ||||
284 | 6 | 8µs | 6 | 1µs | return 0 unless defined $self->$metaclass_type; # spent 400ns making 1 call to Moose::Meta::Class::constructor_class
# spent 400ns making 1 call to Moose::Meta::Class::destructor_class
# spent 200ns making 1 call to Class::MOP::Mixin::HasAttributes::attribute_metaclass
# spent 100ns making 1 call to Class::MOP::Class::instance_metaclass
# spent 100ns making 1 call to Class::MOP::Mixin::HasMethods::method_metaclass
# spent 100ns making 1 call to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass |
285 | |||||
286 | 6 | 22µs | 18 | 12µs | return $self->$metaclass_type->_is_compatible_with($super_meta->$metaclass_type); # spent 10µs making 6 calls to Class::MOP::Object::_is_compatible_with, avg 2µs/call
# spent 800ns making 2 calls to Moose::Meta::Class::destructor_class, avg 400ns/call
# spent 600ns making 2 calls to Moose::Meta::Class::constructor_class, avg 300ns/call
# spent 300ns making 2 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 150ns/call
# spent 200ns making 2 calls to Class::MOP::Class::instance_metaclass, avg 100ns/call
# spent 200ns making 2 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 100ns/call
# spent 200ns making 2 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 100ns/call |
287 | } | ||||
288 | |||||
289 | # spent 13.8ms (274µs+13.5) within Class::MOP::Class::_fix_metaclass_incompatibility which was called 38 times, avg 363µs/call:
# 38 times (274µs+13.5ms) by Class::MOP::Class::_check_metaclass_compatibility at line 200, avg 363µs/call | ||||
290 | 38 | 7µs | my $self = shift; | ||
291 | 87 | 93µs | 49 | 8µs | my @supers = map { Class::MOP::Class->initialize($_) } @_; # spent 370µs making 49 calls to Class::MOP::Class::initialize, avg 8µs/call, recursion: max depth 2, sum of overlapping time 362µs |
292 | |||||
293 | 38 | 10µs | my $necessary = 0; | ||
294 | 38 | 21µs | for my $super (@supers) { | ||
295 | 49 | 51µs | 49 | 13.2ms | $necessary = 1 # spent 13.2ms making 49 calls to Class::MOP::Class::_can_fix_metaclass_incompatibility, avg 270µs/call |
296 | if $self->_can_fix_metaclass_incompatibility($super); | ||||
297 | } | ||||
298 | 38 | 53µs | return unless $necessary; | ||
299 | |||||
300 | for my $super (@supers) { | ||||
301 | if (!$self->_class_metaclass_is_compatible($super->name)) { | ||||
302 | $self->_fix_class_metaclass_incompatibility($super); | ||||
303 | } | ||||
304 | } | ||||
305 | |||||
306 | my %base_metaclass = $self->_base_metaclasses; | ||||
307 | for my $metaclass_type (keys %base_metaclass) { | ||||
308 | for my $super (@supers) { | ||||
309 | if (!$self->_single_metaclass_is_compatible($metaclass_type, $super->name)) { | ||||
310 | $self->_fix_single_metaclass_incompatibility( | ||||
311 | $metaclass_type, $super | ||||
312 | ); | ||||
313 | } | ||||
314 | } | ||||
315 | } | ||||
316 | } | ||||
317 | |||||
318 | # spent 13.2ms (4.94+8.30) within Class::MOP::Class::_can_fix_metaclass_incompatibility which was called 49 times, avg 270µs/call:
# 49 times (4.94ms+8.30ms) by Class::MOP::Class::_fix_metaclass_incompatibility at line 295, avg 270µs/call | ||||
319 | 49 | 11µs | my $self = shift; | ||
320 | 49 | 10µs | my ($super_meta) = @_; | ||
321 | |||||
322 | 49 | 50µs | 49 | 736µs | return 1 if $self->_class_metaclass_can_be_made_compatible($super_meta); # spent 736µs making 49 calls to Class::MOP::Class::_class_metaclass_can_be_made_compatible, avg 15µs/call |
323 | |||||
324 | 49 | 102µs | 49 | 100µs | my %base_metaclass = $self->_base_metaclasses; # spent 78µs making 48 calls to Class::MOP::Class::_base_metaclasses, avg 2µs/call
# spent 22µs making 1 call to Moose::Meta::Class::_base_metaclasses |
325 | 49 | 51µs | for my $metaclass_type (keys %base_metaclass) { | ||
326 | 294 | 215µs | 294 | 7.47ms | return 1 if $self->_single_metaclass_can_be_made_compatible($super_meta, $metaclass_type); # spent 7.47ms making 294 calls to Class::MOP::Class::_single_metaclass_can_be_made_compatible, avg 25µs/call |
327 | } | ||||
328 | |||||
329 | 49 | 81µs | return; | ||
330 | } | ||||
331 | |||||
332 | # spent 736µs (174+562) within Class::MOP::Class::_class_metaclass_can_be_made_compatible which was called 49 times, avg 15µs/call:
# 49 times (174µs+562µs) by Class::MOP::Class::_can_fix_metaclass_incompatibility at line 322, avg 15µs/call | ||||
333 | 49 | 7µs | my $self = shift; | ||
334 | 49 | 5µs | my ($super_meta) = @_; | ||
335 | |||||
336 | 49 | 149µs | 98 | 562µs | return $self->_can_be_made_compatible_with($super_meta->_real_ref_name); # spent 293µs making 49 calls to Class::MOP::Class::_real_ref_name, avg 6µs/call
# spent 269µs making 49 calls to Class::MOP::Object::_can_be_made_compatible_with, avg 5µs/call |
337 | } | ||||
338 | |||||
339 | # spent 7.47ms (1.69+5.78) within Class::MOP::Class::_single_metaclass_can_be_made_compatible which was called 294 times, avg 25µs/call:
# 294 times (1.69ms+5.78ms) by Class::MOP::Class::_can_fix_metaclass_incompatibility at line 326, avg 25µs/call | ||||
340 | 294 | 34µs | my $self = shift; | ||
341 | 294 | 41µs | my ($super_meta, $metaclass_type) = @_; | ||
342 | |||||
343 | 294 | 539µs | 294 | 98µs | my $specific_meta = $self->$metaclass_type; # spent 18µs making 49 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 365ns/call
# spent 17µs making 49 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 345ns/call
# spent 16µs making 48 calls to Class::MOP::Class::constructor_class, avg 335ns/call
# spent 15µs making 49 calls to Class::MOP::Class::instance_metaclass, avg 298ns/call
# spent 14µs making 48 calls to Class::MOP::Class::destructor_class, avg 290ns/call
# spent 14µs making 49 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 284ns/call
# spent 3µs making 1 call to Moose::Meta::Class::destructor_class
# spent 2µs making 1 call to Moose::Meta::Class::constructor_class |
344 | |||||
345 | 294 | 394µs | 294 | 98µs | return unless $super_meta->can($metaclass_type); # spent 98µs making 294 calls to UNIVERSAL::can, avg 332ns/call |
346 | 294 | 410µs | 294 | 74µs | my $super_specific_meta = $super_meta->$metaclass_type; # spent 22µs making 49 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 439ns/call
# spent 13µs making 49 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 269ns/call
# spent 10µs making 48 calls to Class::MOP::Class::constructor_class, avg 215ns/call
# spent 10µs making 48 calls to Class::MOP::Class::destructor_class, avg 200ns/call
# spent 9µs making 49 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 188ns/call
# spent 9µs making 49 calls to Class::MOP::Class::instance_metaclass, avg 182ns/call
# spent 500ns making 1 call to Moose::Meta::Class::constructor_class
# spent 500ns making 1 call to Moose::Meta::Class::destructor_class |
347 | |||||
348 | # for instance, Moose::Meta::Class has a destructor_class, but | ||||
349 | # Class::MOP::Class doesn't - this shouldn't be an error | ||||
350 | 294 | 81µs | return unless defined $super_specific_meta; | ||
351 | |||||
352 | # if metaclass is defined in superclass but not here, it's fixable | ||||
353 | # this is a really odd case | ||||
354 | 246 | 18µs | return 1 unless defined $specific_meta; | ||
355 | |||||
356 | 246 | 4.67ms | 246 | 5.51ms | return 1 if $specific_meta->_can_be_made_compatible_with($super_specific_meta); # spent 5.51ms making 246 calls to Class::MOP::Object::_can_be_made_compatible_with, avg 22µs/call |
357 | } | ||||
358 | |||||
359 | sub _fix_class_metaclass_incompatibility { | ||||
360 | my $self = shift; | ||||
361 | my ( $super_meta ) = @_; | ||||
362 | |||||
363 | if ($self->_class_metaclass_can_be_made_compatible($super_meta)) { | ||||
364 | ($self->is_pristine) | ||||
365 | || $self->_throw_exception( CannotFixMetaclassCompatibility => class_name => $self->name, | ||||
366 | superclass => $super_meta | ||||
367 | ); | ||||
368 | |||||
369 | my $super_meta_name = $super_meta->_real_ref_name; | ||||
370 | |||||
371 | $self->_make_compatible_with($super_meta_name); | ||||
372 | } | ||||
373 | } | ||||
374 | |||||
375 | sub _fix_single_metaclass_incompatibility { | ||||
376 | my $self = shift; | ||||
377 | my ( $metaclass_type, $super_meta ) = @_; | ||||
378 | |||||
379 | if ($self->_single_metaclass_can_be_made_compatible($super_meta, $metaclass_type)) { | ||||
380 | ($self->is_pristine) | ||||
381 | || $self->_throw_exception( CannotFixMetaclassCompatibility => class_name => $self->name, | ||||
382 | superclass => $super_meta, | ||||
383 | metaclass_type => $metaclass_type | ||||
384 | ); | ||||
385 | |||||
386 | my $new_metaclass = $self->$metaclass_type | ||||
387 | ? $self->$metaclass_type->_get_compatible_metaclass($super_meta->$metaclass_type) | ||||
388 | : $super_meta->$metaclass_type; | ||||
389 | $self->{$metaclass_type} = $new_metaclass; | ||||
390 | } | ||||
391 | } | ||||
392 | |||||
393 | sub _restore_metaobjects_from { | ||||
394 | my $self = shift; | ||||
395 | my ($old_meta) = @_; | ||||
396 | |||||
397 | $self->_restore_metamethods_from($old_meta); | ||||
398 | $self->_restore_metaattributes_from($old_meta); | ||||
399 | } | ||||
400 | |||||
401 | sub _remove_generated_metaobjects { | ||||
402 | my $self = shift; | ||||
403 | |||||
404 | for my $attr (map { $self->get_attribute($_) } $self->get_attribute_list) { | ||||
405 | $attr->remove_accessors; | ||||
406 | } | ||||
407 | } | ||||
408 | |||||
409 | # creating classes with MOP ... | ||||
410 | |||||
411 | # spent 1.23ms (38µs+1.19) within Class::MOP::Class::create which was called 2 times, avg 615µs/call:
# 2 times (38µs+1.19ms) by Class::MOP::Class::_immutable_metaclass at line 1366, avg 615µs/call | ||||
412 | 2 | 700ns | my $class = shift; | ||
413 | 2 | 1µs | my @args = @_; | ||
414 | |||||
415 | 2 | 2µs | unshift @args, 'package' if @args % 2 == 1; | ||
416 | 2 | 2µs | my %options = @args; | ||
417 | |||||
418 | (ref $options{superclasses} eq 'ARRAY') | ||||
419 | || __PACKAGE__->_throw_exception( CreateMOPClassTakesArrayRefOfSuperclasses => class => $class, | ||||
420 | params => \%options | ||||
421 | ) | ||||
422 | 2 | 2µs | if exists $options{superclasses}; | ||
423 | |||||
424 | (ref $options{attributes} eq 'ARRAY') | ||||
425 | || __PACKAGE__->_throw_exception( CreateMOPClassTakesArrayRefOfAttributes => class => $class, | ||||
426 | params => \%options | ||||
427 | ) | ||||
428 | 2 | 600ns | if exists $options{attributes}; | ||
429 | |||||
430 | (ref $options{methods} eq 'HASH') | ||||
431 | || __PACKAGE__->_throw_exception( CreateMOPClassTakesHashRefOfMethods => class => $class, | ||||
432 | params => \%options | ||||
433 | ) | ||||
434 | 2 | 600ns | if exists $options{methods}; | ||
435 | |||||
436 | 2 | 1µs | my $package = delete $options{package}; | ||
437 | 2 | 600ns | my $superclasses = delete $options{superclasses}; | ||
438 | 2 | 2µs | my $attributes = delete $options{attributes}; | ||
439 | 2 | 500ns | my $methods = delete $options{methods}; | ||
440 | my $meta_name = exists $options{meta_name} | ||||
441 | ? delete $options{meta_name} | ||||
442 | 2 | 1µs | : 'meta'; | ||
443 | |||||
444 | 2 | 4µs | 2 | 202µs | my $meta = $class->SUPER::create($package => %options); # spent 202µs making 2 calls to Class::MOP::Module::create, avg 101µs/call |
445 | |||||
446 | 2 | 4µs | 2 | 629µs | $meta->_add_meta_method($meta_name) # spent 629µs making 2 calls to Class::MOP::Mixin::HasMethods::_add_meta_method, avg 315µs/call |
447 | if defined $meta_name; | ||||
448 | |||||
449 | 2 | 2µs | 2 | 362µs | $meta->superclasses(@{$superclasses}) # spent 362µs making 2 calls to Class::MOP::Class::superclasses, avg 181µs/call |
450 | if defined $superclasses; | ||||
451 | # NOTE: | ||||
452 | # process attributes first, so that they can | ||||
453 | # install accessors, but locally defined methods | ||||
454 | # can then overwrite them. It is maybe a little odd, but | ||||
455 | # I think this should be the order of things. | ||||
456 | 2 | 900ns | if (defined $attributes) { | ||
457 | foreach my $attr (@{$attributes}) { | ||||
458 | $meta->add_attribute($attr); | ||||
459 | } | ||||
460 | } | ||||
461 | 2 | 500ns | if (defined $methods) { | ||
462 | foreach my $method_name (keys %{$methods}) { | ||||
463 | $meta->add_method($method_name, $methods->{$method_name}); | ||||
464 | } | ||||
465 | } | ||||
466 | 2 | 5µs | return $meta; | ||
467 | } | ||||
468 | |||||
469 | # XXX: something more intelligent here? | ||||
470 | sub _anon_package_prefix { 'Class::MOP::Class::__ANON__::SERIAL::' } | ||||
471 | |||||
472 | sub create_anon_class { shift->create_anon(@_) } | ||||
473 | sub is_anon_class { shift->is_anon(@_) } | ||||
474 | |||||
475 | sub _anon_cache_key { | ||||
476 | my $class = shift; | ||||
477 | my %options = @_; | ||||
478 | # Makes something like Super::Class|Super::Class::2 | ||||
479 | return join '=' => ( | ||||
480 | join( '|', sort @{ $options{superclasses} || [] } ), | ||||
481 | ); | ||||
482 | } | ||||
483 | |||||
484 | # Instance Construction & Cloning | ||||
485 | |||||
486 | # spent 4.49ms (211µs+4.28) within Class::MOP::Class::new_object which was called 33 times, avg 136µs/call:
# 24 times (136µs+2.64ms) by Class::MOP::Method::_new at line 59 of Class/MOP/Method.pm, avg 116µs/call
# 6 times (38µs+921µs) by Class::MOP::Method::Accessor::_new at line 51 of Class/MOP/Method/Accessor.pm, avg 160µs/call
# once (20µs+339µs) by Class::MOP::Attribute::_new at line 69 of Class/MOP/Attribute.pm
# once (9µs+197µs) by Class::MOP::Object::_new at line 23 of Class/MOP/Object.pm
# once (8µs+183µs) by Moose::Meta::Method::_new at line 7 of (eval 33)[Eval/Closure.pm:142] | ||||
487 | 33 | 8µs | my $class = shift; | ||
488 | |||||
489 | # NOTE: | ||||
490 | # we need to protect the integrity of the | ||||
491 | # Class::MOP::Class singletons here, so we | ||||
492 | # delegate this to &construct_class_instance | ||||
493 | # which will deal with the singletons | ||||
494 | 33 | 171µs | 66 | 52µs | return $class->_construct_class_instance(@_) # spent 39µs making 33 calls to UNIVERSAL::isa, avg 1µs/call
# spent 14µs making 33 calls to Class::MOP::Package::name, avg 412ns/call |
495 | if $class->name->isa('Class::MOP::Class'); | ||||
496 | 33 | 76µs | 33 | 4.22ms | return $class->_construct_instance(@_); # spent 4.22ms making 33 calls to Class::MOP::Class::_construct_instance, avg 128µs/call |
497 | } | ||||
498 | |||||
499 | # spent 4.97ms (812µs+4.16) within Class::MOP::Class::_construct_instance which was called 35 times, avg 142µs/call:
# 33 times (746µs+3.48ms) by Class::MOP::Class::new_object at line 496, avg 128µs/call
# 2 times (66µs+685µs) by Class::MOP::Class::_construct_class_instance at line 101, avg 375µs/call | ||||
500 | 35 | 7µs | my $class = shift; | ||
501 | 35 | 14µs | my $params = @_ == 1 ? $_[0] : {@_}; | ||
502 | 35 | 49µs | 35 | 1.05ms | my $meta_instance = $class->get_meta_instance(); # spent 681µs making 10 calls to Class::MOP::Class::get_meta_instance, avg 68µs/call
# spent 366µs making 25 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 15µs/call |
503 | # FIXME: | ||||
504 | # the code below is almost certainly incorrect | ||||
505 | # but this is foreign inheritance, so we might | ||||
506 | # have to kludge it in the end. | ||||
507 | 35 | 5µs | my $instance; | ||
508 | 35 | 125µs | 35 | 25µs | if (my $instance_class = blessed($params->{__INSTANCE__})) { # spent 25µs making 35 calls to Scalar::Util::blessed, avg 726ns/call |
509 | ($instance_class eq $class->name) | ||||
510 | || $class->_throw_exception( InstanceBlessedIntoWrongClass => class_name => $class->name, | ||||
511 | params => $params, | ||||
512 | instance => $params->{__INSTANCE__} | ||||
513 | ); | ||||
514 | $instance = $params->{__INSTANCE__}; | ||||
515 | } | ||||
516 | elsif (exists $params->{__INSTANCE__}) { | ||||
517 | $class->_throw_exception( InstanceMustBeABlessedReference => class_name => $class->name, | ||||
518 | params => $params, | ||||
519 | instance => $params->{__INSTANCE__} | ||||
520 | ); | ||||
521 | } | ||||
522 | else { | ||||
523 | 35 | 51µs | 35 | 172µs | $instance = $meta_instance->create_instance(); # spent 172µs making 35 calls to Class::MOP::Instance::create_instance, avg 5µs/call |
524 | } | ||||
525 | 35 | 62µs | 35 | 774µs | foreach my $attr ($class->get_all_attributes()) { # spent 435µs making 25 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 17µs/call
# spent 338µs making 10 calls to Class::MOP::Class::get_all_attributes, avg 34µs/call |
526 | 245 | 180µs | 245 | 2.03ms | $attr->initialize_instance_slot($meta_instance, $instance, $params); # spent 2.03ms making 245 calls to Class::MOP::Attribute::initialize_instance_slot, avg 8µs/call |
527 | } | ||||
528 | 35 | 84µs | 70 | 118µs | if (Class::MOP::metaclass_is_weak($class->name)) { # spent 109µs making 35 calls to Class::MOP::metaclass_is_weak, avg 3µs/call
# spent 9µs making 35 calls to Class::MOP::Package::name, avg 251ns/call |
529 | $meta_instance->_set_mop_slot($instance, $class); | ||||
530 | } | ||||
531 | 35 | 69µs | return $instance; | ||
532 | } | ||||
533 | |||||
534 | # spent 37.1ms (302µs+36.8) within Class::MOP::Class::_inline_new_object which was called 31 times, avg 1.20ms/call:
# 31 times (302µs+36.8ms) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 98 of Class/MOP/Method/Constructor.pm, avg 1.20ms/call | ||||
535 | 31 | 5µs | my $self = shift; | ||
536 | |||||
537 | return ( | ||||
538 | 31 | 197µs | 186 | 36.8ms | 'my $class = shift;', # spent 35.2ms making 31 calls to Class::MOP::Class::_inline_slot_initializers, avg 1.14ms/call
# spent 853µs making 31 calls to Class::MOP::Class::_inline_generate_instance, avg 28µs/call
# spent 189µs making 1 call to Moose::Meta::Class::_inline_params
# spent 183µs making 31 calls to Class::MOP::Class::_inline_preserve_weak_metaclasses, avg 6µs/call
# spent 181µs making 31 calls to Class::MOP::Class::_inline_fallback_constructor, avg 6µs/call
# spent 139µs making 1 call to Moose::Meta::Class::_inline_extra_init
# spent 36µs making 30 calls to Class::MOP::Class::_inline_params, avg 1µs/call
# spent 13µs making 30 calls to Class::MOP::Class::_inline_extra_init, avg 430ns/call |
539 | '$class = Scalar::Util::blessed($class) || $class;', | ||||
540 | $self->_inline_fallback_constructor('$class'), | ||||
541 | $self->_inline_params('$params', '$class'), | ||||
542 | $self->_inline_generate_instance('$instance', '$class'), | ||||
543 | $self->_inline_slot_initializers, | ||||
544 | $self->_inline_preserve_weak_metaclasses, | ||||
545 | $self->_inline_extra_init, | ||||
546 | 'return $instance', | ||||
547 | ); | ||||
548 | } | ||||
549 | |||||
550 | # spent 181µs (136+45) within Class::MOP::Class::_inline_fallback_constructor which was called 31 times, avg 6µs/call:
# 31 times (136µs+45µs) by Class::MOP::Class::_inline_new_object at line 538, avg 6µs/call | ||||
551 | 31 | 4µs | my $self = shift; | ||
552 | 31 | 6µs | my ($class) = @_; | ||
553 | return ( | ||||
554 | 31 | 126µs | 62 | 45µs | 'return ' . $self->_generate_fallback_constructor($class), # spent 36µs making 30 calls to Class::MOP::Class::_generate_fallback_constructor, avg 1µs/call
# spent 7µs making 31 calls to Class::MOP::Package::name, avg 223ns/call
# spent 2µs making 1 call to Moose::Meta::Class::_generate_fallback_constructor |
555 | 'if ' . $class . ' ne \'' . $self->name . '\';', | ||||
556 | ); | ||||
557 | } | ||||
558 | |||||
559 | # spent 36µs within Class::MOP::Class::_generate_fallback_constructor which was called 30 times, avg 1µs/call:
# 30 times (36µs+0s) by Class::MOP::Class::_inline_fallback_constructor at line 554, avg 1µs/call | ||||
560 | 30 | 4µs | my $self = shift; | ||
561 | 30 | 5µs | my ($class) = @_; | ||
562 | 30 | 46µs | return 'Class::MOP::Class->initialize(' . $class . ')->new_object(@_)', | ||
563 | } | ||||
564 | |||||
565 | # spent 36µs within Class::MOP::Class::_inline_params which was called 30 times, avg 1µs/call:
# 30 times (36µs+0s) by Class::MOP::Class::_inline_new_object at line 538, avg 1µs/call | ||||
566 | 30 | 5µs | my $self = shift; | ||
567 | 30 | 7µs | my ($params, $class) = @_; | ||
568 | return ( | ||||
569 | 30 | 41µs | 'my ' . $params . ' = @_ == 1 ? $_[0] : {@_};', | ||
570 | ); | ||||
571 | } | ||||
572 | |||||
573 | # spent 853µs (77+775) within Class::MOP::Class::_inline_generate_instance which was called 31 times, avg 28µs/call:
# 31 times (77µs+775µs) by Class::MOP::Class::_inline_new_object at line 538, avg 28µs/call | ||||
574 | 31 | 5µs | my $self = shift; | ||
575 | 31 | 6µs | my ($inst, $class) = @_; | ||
576 | return ( | ||||
577 | 31 | 85µs | 31 | 775µs | 'my ' . $inst . ' = ' . $self->_inline_create_instance($class) . ';', # spent 775µs making 31 calls to Class::MOP::Class::_inline_create_instance, avg 25µs/call |
578 | ); | ||||
579 | } | ||||
580 | |||||
581 | # spent 775µs (96+679) within Class::MOP::Class::_inline_create_instance which was called 31 times, avg 25µs/call:
# 31 times (96µs+679µs) by Class::MOP::Class::_inline_generate_instance at line 577, avg 25µs/call | ||||
582 | 31 | 3µs | my $self = shift; | ||
583 | |||||
584 | 31 | 71µs | 62 | 679µs | return $self->get_meta_instance->inline_create_instance(@_); # spent 647µs making 31 calls to Class::MOP::Class::get_meta_instance, avg 21µs/call
# spent 32µs making 31 calls to Class::MOP::Instance::inline_create_instance, avg 1µs/call |
585 | } | ||||
586 | |||||
587 | # spent 35.2ms (513µs+34.7) within Class::MOP::Class::_inline_slot_initializers which was called 31 times, avg 1.14ms/call:
# 31 times (513µs+34.7ms) by Class::MOP::Class::_inline_new_object at line 538, avg 1.14ms/call | ||||
588 | 31 | 4µs | my $self = shift; | ||
589 | |||||
590 | 31 | 5µs | my $idx = 0; | ||
591 | |||||
592 | 286 | 193µs | 286 | 29.6ms | return map { $self->_inline_slot_initializer($_, $idx++) } # spent 28.9ms making 282 calls to Class::MOP::Class::_inline_slot_initializer, avg 102µs/call
# spent 711µs making 4 calls to Moose::Meta::Class::_inline_slot_initializer, avg 178µs/call |
593 | 775 | 4.29ms | 1550 | 5.29ms | sort { $a->name cmp $b->name } $self->get_all_attributes; # spent 4.13ms making 31 calls to Class::MOP::Class::CORE:sort, avg 133µs/call
# spent 995µs making 31 calls to Class::MOP::Class::get_all_attributes, avg 32µs/call
# spent 172µs making 1488 calls to Class::MOP::Mixin::AttributeCore::name, avg 115ns/call |
594 | } | ||||
595 | |||||
596 | # spent 29.5ms (1.46+28.1) within Class::MOP::Class::_inline_slot_initializer which was called 286 times, avg 103µs/call:
# 282 times (1.42ms+27.5ms) by Class::MOP::Class::_inline_slot_initializers at line 592, avg 102µs/call
# 4 times (40µs+610µs) by Moose::Meta::Class::_inline_slot_initializer at line 365 of Moose/Meta/Class.pm, avg 162µs/call | ||||
597 | 286 | 28µs | my $self = shift; | ||
598 | 286 | 36µs | my ($attr, $idx) = @_; | ||
599 | |||||
600 | 286 | 429µs | 297 | 449µs | if (defined(my $init_arg = $attr->init_arg)) { # spent 367µs making 11 calls to Class::MOP::Class::_inline_init_attr_from_default, avg 33µs/call
# spent 82µs making 286 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 288ns/call |
601 | 275 | 282µs | 275 | 13.7ms | my @source = ( # spent 13.4ms making 271 calls to Class::MOP::Class::_inline_init_attr_from_constructor, avg 49µs/call
# spent 359µs making 4 calls to Moose::Meta::Class::_inline_init_attr_from_constructor, avg 90µs/call |
602 | 'if (exists $params->{\'' . $init_arg . '\'}) {', | ||||
603 | $self->_inline_init_attr_from_constructor($attr, $idx), | ||||
604 | '}', | ||||
605 | ); | ||||
606 | 275 | 199µs | 275 | 13.9ms | if (my @default = $self->_inline_init_attr_from_default($attr, $idx)) { # spent 13.6ms making 271 calls to Class::MOP::Class::_inline_init_attr_from_default, avg 50µs/call
# spent 251µs making 4 calls to Moose::Meta::Class::_inline_init_attr_from_default, avg 63µs/call |
607 | push @source, ( | ||||
608 | 'else {', | ||||
609 | @default, | ||||
610 | '}', | ||||
611 | ); | ||||
612 | } | ||||
613 | 275 | 399µs | return @source; | ||
614 | } | ||||
615 | elsif (my @default = $self->_inline_init_attr_from_default($attr, $idx)) { | ||||
616 | return ( | ||||
617 | '{', | ||||
618 | @default, | ||||
619 | '}', | ||||
620 | ); | ||||
621 | } | ||||
622 | else { | ||||
623 | 1 | 1µs | return (); | ||
624 | } | ||||
625 | } | ||||
626 | |||||
627 | # spent 13.4ms (1.16+12.2) within Class::MOP::Class::_inline_init_attr_from_constructor which was called 271 times, avg 49µs/call:
# 271 times (1.16ms+12.2ms) by Class::MOP::Class::_inline_slot_initializer at line 601, avg 49µs/call | ||||
628 | 271 | 26µs | my $self = shift; | ||
629 | 271 | 29µs | my ($attr, $idx) = @_; | ||
630 | |||||
631 | 271 | 553µs | 542 | 12.1ms | my @initial_value = $attr->_inline_set_value( # spent 11.7ms making 269 calls to Class::MOP::Attribute::_inline_set_value, avg 43µs/call
# spent 386µs making 2 calls to Moose::Meta::Attribute::_inline_set_value, avg 193µs/call
# spent 29µs making 271 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 108ns/call |
632 | '$instance', '$params->{\'' . $attr->init_arg . '\'}', | ||||
633 | ); | ||||
634 | |||||
635 | 271 | 144µs | 271 | 132µs | push @initial_value, ( # spent 132µs making 271 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 486ns/call |
636 | '$attrs->[' . $idx . ']->set_initial_value(', | ||||
637 | '$instance,', | ||||
638 | $attr->_inline_instance_get('$instance'), | ||||
639 | ');', | ||||
640 | ) if $attr->has_initializer; | ||||
641 | |||||
642 | 271 | 288µs | return @initial_value; | ||
643 | } | ||||
644 | |||||
645 | # spent 14.0ms (4.71+9.30) within Class::MOP::Class::_inline_init_attr_from_default which was called 282 times, avg 50µs/call:
# 271 times (4.67ms+8.98ms) by Class::MOP::Class::_inline_slot_initializer at line 606, avg 50µs/call
# 11 times (41µs+326µs) by Class::MOP::Class::_inline_slot_initializer at line 600, avg 33µs/call | ||||
646 | 282 | 26µs | my $self = shift; | ||
647 | 282 | 33µs | my ($attr, $idx) = @_; | ||
648 | |||||
649 | 282 | 153µs | 282 | 1.02ms | my $default = $self->_inline_default_value($attr, $idx); # spent 1.02ms making 282 calls to Class::MOP::Class::_inline_default_value, avg 4µs/call |
650 | 282 | 169µs | return unless $default; | ||
651 | |||||
652 | 99 | 73µs | 99 | 8.24ms | my @initial_value = $attr->_inline_set_value('$instance', $default); # spent 8.24ms making 99 calls to Class::MOP::Attribute::_inline_set_value, avg 83µs/call |
653 | |||||
654 | 99 | 49µs | 99 | 38µs | push @initial_value, ( # spent 38µs making 99 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 382ns/call |
655 | '$attrs->[' . $idx . ']->set_initial_value(', | ||||
656 | '$instance,', | ||||
657 | $attr->_inline_instance_get('$instance'), | ||||
658 | ');', | ||||
659 | ) if $attr->has_initializer; | ||||
660 | |||||
661 | 99 | 102µs | return @initial_value; | ||
662 | } | ||||
663 | |||||
664 | # spent 1.04ms (752µs+285µs) within Class::MOP::Class::_inline_default_value which was called 285 times, avg 4µs/call:
# 282 times (740µs+281µs) by Class::MOP::Class::_inline_init_attr_from_default at line 649, avg 4µs/call
# 3 times (12µs+3µs) by Moose::Meta::Class::_inline_init_attr_from_default at line 422 of Moose/Meta/Class.pm, avg 5µs/call | ||||
665 | 285 | 25µs | my $self = shift; | ||
666 | 285 | 25µs | my ($attr, $index) = @_; | ||
667 | |||||
668 | 285 | 346µs | 570 | 284µs | if ($attr->has_default) { # spent 105µs making 285 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 369ns/call
# spent 101µs making 101 calls to Class::MOP::Mixin::AttributeCore::is_default_a_coderef, avg 997ns/call
# spent 79µs making 184 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 427ns/call |
669 | # NOTE: | ||||
670 | # default values can either be CODE refs | ||||
671 | # in which case we need to call them. Or | ||||
672 | # they can be scalars (strings/numbers) | ||||
673 | # in which case we can just deal with them | ||||
674 | # in the code we eval. | ||||
675 | if ($attr->is_default_a_coderef) { | ||||
676 | return '$defaults->[' . $index . ']->($instance)'; | ||||
677 | } | ||||
678 | else { | ||||
679 | 31 | 35µs | return '$defaults->[' . $index . ']'; | ||
680 | } | ||||
681 | } | ||||
682 | elsif ($attr->has_builder) { | ||||
683 | return '$instance->' . $attr->builder; | ||||
684 | } | ||||
685 | else { | ||||
686 | 184 | 4.16ms | return; | ||
687 | } | ||||
688 | } | ||||
689 | |||||
690 | # spent 183µs (98+85) within Class::MOP::Class::_inline_preserve_weak_metaclasses which was called 31 times, avg 6µs/call:
# 31 times (98µs+85µs) by Class::MOP::Class::_inline_new_object at line 538, avg 6µs/call | ||||
691 | 31 | 5µs | my $self = shift; | ||
692 | 31 | 68µs | 62 | 85µs | if (Class::MOP::metaclass_is_weak($self->name)) { # spent 74µs making 31 calls to Class::MOP::metaclass_is_weak, avg 2µs/call
# spent 11µs making 31 calls to Class::MOP::Package::name, avg 358ns/call |
693 | return ( | ||||
694 | $self->_inline_set_mop_slot( | ||||
695 | '$instance', 'Class::MOP::class_of($class)' | ||||
696 | ) . ';' | ||||
697 | ); | ||||
698 | } | ||||
699 | else { | ||||
700 | 31 | 38µs | return (); | ||
701 | } | ||||
702 | } | ||||
703 | |||||
704 | 30 | 32µs | # spent 13µs within Class::MOP::Class::_inline_extra_init which was called 30 times, avg 430ns/call:
# 30 times (13µs+0s) by Class::MOP::Class::_inline_new_object at line 538, avg 430ns/call | ||
705 | |||||
706 | # spent 2.97ms (462µs+2.51) within Class::MOP::Class::_eval_environment which was called 31 times, avg 96µs/call:
# 30 times (452µs+2.49ms) by Class::MOP::Method::Constructor::_eval_environment at line 86 of Class/MOP/Method/Constructor.pm, avg 98µs/call
# once (10µs+26µs) by Moose::Meta::Class::_eval_environment at line 542 of Moose/Meta/Class.pm | ||||
707 | 31 | 4µs | my $self = shift; | ||
708 | |||||
709 | 784 | 1.53ms | 1568 | 2.54ms | my @attrs = sort { $a->name cmp $b->name } $self->get_all_attributes; # spent 1.46ms making 31 calls to Class::MOP::Class::CORE:sort, avg 47µs/call
# spent 901µs making 31 calls to Class::MOP::Class::get_all_attributes, avg 29µs/call
# spent 174µs making 1506 calls to Class::MOP::Mixin::AttributeCore::name, avg 116ns/call |
710 | |||||
711 | 317 | 190µs | 286 | 150µs | my $defaults = [map { $_->default } @attrs]; # spent 150µs making 286 calls to Class::MOP::Mixin::AttributeCore::default, avg 525ns/call |
712 | |||||
713 | return { | ||||
714 | 31 | 67µs | '$defaults' => \$defaults, | ||
715 | }; | ||||
716 | } | ||||
717 | |||||
718 | |||||
719 | # spent 4.47ms (276µs+4.20) within Class::MOP::Class::get_meta_instance which was called 324 times, avg 14µs/call:
# 154 times (97µs+864µs) by Class::MOP::Attribute::_inline_instance_set at line 301 of Class/MOP/Attribute.pm, avg 6µs/call
# 83 times (68µs+976µs) by Class::MOP::Attribute::_inline_instance_get at line 324 of Class/MOP/Attribute.pm, avg 13µs/call
# 31 times (35µs+612µs) by Class::MOP::Class::_inline_create_instance at line 584, avg 21µs/call
# 22 times (33µs+971µs) by Class::MOP::Class:::around at line 77 of Class/MOP/Class/Immutable/Trait.pm, avg 46µs/call
# 17 times (13µs+57µs) by Class::MOP::Attribute::_inline_instance_has at line 345 of Class/MOP/Attribute.pm, avg 4µs/call
# 10 times (25µs+656µs) by Class::MOP::Class::_construct_instance at line 502, avg 68µs/call
# 3 times (2µs+0s) by Class::MOP::Attribute::has_value at line 332 of Class/MOP/Attribute.pm, avg 500ns/call
# 2 times (1µs+0s) by Class::MOP::Attribute::get_raw_value at line 311 of Class/MOP/Attribute.pm, avg 550ns/call
# once (2µs+58µs) by Moose::Exporter::BEGIN@8 at line 733 of Class/MOP.pm
# once (500ns+0s) by Moose::Meta::Attribute::_inline_weaken_value at line 737 of Moose/Meta/Attribute.pm | ||||
720 | 324 | 28µs | my $self = shift; | ||
721 | 324 | 407µs | 52 | 4.20ms | $self->{'_meta_instance'} ||= $self->_create_meta_instance(); # spent 4.20ms making 52 calls to Class::MOP::Class::_create_meta_instance, avg 81µs/call |
722 | } | ||||
723 | |||||
724 | # spent 4.20ms (367µs+3.83) within Class::MOP::Class::_create_meta_instance which was called 52 times, avg 81µs/call:
# 52 times (367µs+3.83ms) by Class::MOP::Class::get_meta_instance at line 721, avg 81µs/call | ||||
725 | 52 | 7µs | my $self = shift; | ||
726 | |||||
727 | 52 | 201µs | 156 | 3.80ms | my $instance = $self->instance_metaclass->new( # spent 2.07ms making 52 calls to Class::MOP::Instance::new, avg 40µs/call
# spent 1.21ms making 40 calls to Class::MOP::Class::get_all_attributes, avg 30µs/call
# spent 497µs making 12 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 41µs/call
# spent 16µs making 52 calls to Class::MOP::Class::instance_metaclass, avg 304ns/call |
728 | associated_metaclass => $self, | ||||
729 | attributes => [ $self->get_all_attributes() ], | ||||
730 | ); | ||||
731 | |||||
732 | 52 | 43µs | 52 | 28µs | $self->add_meta_instance_dependencies() # spent 28µs making 52 calls to Class::MOP::Instance::is_dependent_on_superclasses, avg 548ns/call |
733 | if $instance->is_dependent_on_superclasses(); | ||||
734 | |||||
735 | 52 | 68µs | return $instance; | ||
736 | } | ||||
737 | |||||
738 | # TODO: this is actually not being used! | ||||
739 | sub _inline_rebless_instance { | ||||
740 | my $self = shift; | ||||
741 | |||||
742 | return $self->get_meta_instance->inline_rebless_instance_structure(@_); | ||||
743 | } | ||||
744 | |||||
745 | sub _inline_get_mop_slot { | ||||
746 | my $self = shift; | ||||
747 | |||||
748 | return $self->get_meta_instance->_inline_get_mop_slot(@_); | ||||
749 | } | ||||
750 | |||||
751 | sub _inline_set_mop_slot { | ||||
752 | my $self = shift; | ||||
753 | |||||
754 | return $self->get_meta_instance->_inline_set_mop_slot(@_); | ||||
755 | } | ||||
756 | |||||
757 | sub _inline_clear_mop_slot { | ||||
758 | my $self = shift; | ||||
759 | |||||
760 | return $self->get_meta_instance->_inline_clear_mop_slot(@_); | ||||
761 | } | ||||
762 | |||||
763 | sub clone_object { | ||||
764 | my $class = shift; | ||||
765 | my $instance = shift; | ||||
766 | (blessed($instance) && $instance->isa($class->name)) | ||||
767 | || $class->_throw_exception( CloneObjectExpectsAnInstanceOfMetaclass => class_name => $class->name, | ||||
768 | instance => $instance, | ||||
769 | ); | ||||
770 | # NOTE: | ||||
771 | # we need to protect the integrity of the | ||||
772 | # Class::MOP::Class singletons here, they | ||||
773 | # should not be cloned. | ||||
774 | return $instance if $instance->isa('Class::MOP::Class'); | ||||
775 | $class->_clone_instance($instance, @_); | ||||
776 | } | ||||
777 | |||||
778 | sub _clone_instance { | ||||
779 | my ($class, $instance, %params) = @_; | ||||
780 | (blessed($instance)) | ||||
781 | || $class->_throw_exception( OnlyInstancesCanBeCloned => class_name => $class->name, | ||||
782 | instance => $instance, | ||||
783 | params => \%params | ||||
784 | ); | ||||
785 | my $meta_instance = $class->get_meta_instance(); | ||||
786 | my $clone = $meta_instance->clone_instance($instance); | ||||
787 | foreach my $attr ($class->get_all_attributes()) { | ||||
788 | if ( defined( my $init_arg = $attr->init_arg ) ) { | ||||
789 | if (exists $params{$init_arg}) { | ||||
790 | $attr->set_value($clone, $params{$init_arg}); | ||||
791 | } | ||||
792 | } | ||||
793 | } | ||||
794 | return $clone; | ||||
795 | } | ||||
796 | |||||
797 | sub _force_rebless_instance { | ||||
798 | my ($self, $instance, %params) = @_; | ||||
799 | my $old_metaclass = Class::MOP::class_of($instance); | ||||
800 | |||||
801 | $old_metaclass->rebless_instance_away($instance, $self, %params) | ||||
802 | if $old_metaclass; | ||||
803 | |||||
804 | my $meta_instance = $self->get_meta_instance; | ||||
805 | |||||
806 | if (Class::MOP::metaclass_is_weak($old_metaclass->name)) { | ||||
807 | $meta_instance->_clear_mop_slot($instance); | ||||
808 | } | ||||
809 | |||||
810 | # rebless! | ||||
811 | # we use $_[1] here because of t/cmop/rebless_overload.t regressions | ||||
812 | # on 5.8.8 | ||||
813 | $meta_instance->rebless_instance_structure($_[1], $self); | ||||
814 | |||||
815 | $self->_fixup_attributes_after_rebless($instance, $old_metaclass, %params); | ||||
816 | |||||
817 | if (Class::MOP::metaclass_is_weak($self->name)) { | ||||
818 | $meta_instance->_set_mop_slot($instance, $self); | ||||
819 | } | ||||
820 | } | ||||
821 | |||||
822 | sub rebless_instance { | ||||
823 | my ($self, $instance, %params) = @_; | ||||
824 | my $old_metaclass = Class::MOP::class_of($instance); | ||||
825 | |||||
826 | my $old_class = $old_metaclass ? $old_metaclass->name : blessed($instance); | ||||
827 | $self->name->isa($old_class) | ||||
828 | || $self->_throw_exception( CanReblessOnlyIntoASubclass => class_name => $self->name, | ||||
829 | instance => $instance, | ||||
830 | instance_class => blessed( $instance ), | ||||
831 | params => \%params, | ||||
832 | ); | ||||
833 | |||||
834 | $self->_force_rebless_instance($_[1], %params); | ||||
835 | |||||
836 | return $instance; | ||||
837 | } | ||||
838 | |||||
839 | sub rebless_instance_back { | ||||
840 | my ( $self, $instance ) = @_; | ||||
841 | my $old_metaclass = Class::MOP::class_of($instance); | ||||
842 | my $old_class | ||||
843 | = $old_metaclass ? $old_metaclass->name : blessed($instance); | ||||
844 | $old_class->isa( $self->name ) | ||||
845 | || $self->_throw_exception( CanReblessOnlyIntoASuperclass => class_name => $self->name, | ||||
846 | instance => $instance, | ||||
847 | instance_class => blessed( $instance ), | ||||
848 | ); | ||||
849 | |||||
850 | $self->_force_rebless_instance($_[1]); | ||||
851 | |||||
852 | return $instance; | ||||
853 | } | ||||
854 | |||||
855 | sub rebless_instance_away { | ||||
856 | # this intentionally does nothing, it is just a hook | ||||
857 | } | ||||
858 | |||||
859 | sub _fixup_attributes_after_rebless { | ||||
860 | my $self = shift; | ||||
861 | my ($instance, $rebless_from, %params) = @_; | ||||
862 | my $meta_instance = $self->get_meta_instance; | ||||
863 | |||||
864 | for my $attr ( $rebless_from->get_all_attributes ) { | ||||
865 | next if $self->find_attribute_by_name( $attr->name ); | ||||
866 | $meta_instance->deinitialize_slot( $instance, $_ ) for $attr->slots; | ||||
867 | } | ||||
868 | |||||
869 | foreach my $attr ( $self->get_all_attributes ) { | ||||
870 | if ( $attr->has_value($instance) ) { | ||||
871 | if ( defined( my $init_arg = $attr->init_arg ) ) { | ||||
872 | $params{$init_arg} = $attr->get_value($instance) | ||||
873 | unless exists $params{$init_arg}; | ||||
874 | } | ||||
875 | else { | ||||
876 | $attr->set_value($instance, $attr->get_value($instance)); | ||||
877 | } | ||||
878 | } | ||||
879 | } | ||||
880 | |||||
881 | foreach my $attr ($self->get_all_attributes) { | ||||
882 | $attr->initialize_instance_slot($meta_instance, $instance, \%params); | ||||
883 | } | ||||
884 | } | ||||
885 | |||||
886 | # spent 928µs (249+680) within Class::MOP::Class::_attach_attribute which was called 135 times, avg 7µs/call:
# 135 times (249µs+680µs) by Class::MOP::Mixin::HasAttributes::add_attribute at line 22 of Class/MOP/Mixin/HasAttributes.pm, avg 7µs/call | ||||
887 | 135 | 26µs | my ($self, $attribute) = @_; | ||
888 | 135 | 220µs | 135 | 680µs | $attribute->attach_to_class($self); # spent 680µs making 135 calls to Class::MOP::Attribute::attach_to_class, avg 5µs/call |
889 | } | ||||
890 | |||||
891 | # spent 40.5ms (758µs+39.7) within Class::MOP::Class::_post_add_attribute which was called 135 times, avg 300µs/call:
# 135 times (758µs+39.7ms) by Class::MOP::Mixin::HasAttributes::add_attribute at line 39 of Class/MOP/Mixin/HasAttributes.pm, avg 300µs/call | ||||
892 | 135 | 27µs | my ( $self, $attribute ) = @_; | ||
893 | |||||
894 | 135 | 102µs | 135 | 532µs | $self->invalidate_meta_instances; # spent 532µs making 135 calls to Class::MOP::Class::invalidate_meta_instances, avg 4µs/call |
895 | |||||
896 | # invalidate package flag here | ||||
897 | # spent 37.0ms (458µs+36.5) within Class::MOP::Class::try {...} which was called 135 times, avg 274µs/call:
# 135 times (458µs+36.5ms) by Try::Tiny::try at line 92 of Try/Tiny.pm, avg 274µs/call | ||||
898 | 135 | 132µs | local $SIG{__DIE__}; | ||
899 | 135 | 314µs | 135 | 36.5ms | $attribute->install_accessors; # spent 26.8ms making 130 calls to Class::MOP::Attribute::install_accessors, avg 206µs/call
# spent 9.68ms making 5 calls to Moose::Meta::Attribute::install_accessors, avg 1.94ms/call |
900 | } | ||||
901 | catch { | ||||
902 | $self->remove_attribute( $attribute->name ); | ||||
903 | die $_; | ||||
904 | 135 | 529µs | 270 | 39.2ms | }; # spent 38.3ms making 135 calls to Try::Tiny::try, avg 284µs/call
# spent 879µs making 135 calls to Try::Tiny::catch, avg 7µs/call |
905 | } | ||||
906 | |||||
907 | sub remove_attribute { | ||||
908 | my $self = shift; | ||||
909 | |||||
910 | my $removed_attribute = $self->SUPER::remove_attribute(@_) | ||||
911 | or return; | ||||
912 | |||||
913 | $self->invalidate_meta_instances; | ||||
914 | |||||
915 | $removed_attribute->remove_accessors; | ||||
916 | $removed_attribute->detach_from_class; | ||||
917 | |||||
918 | return$removed_attribute; | ||||
919 | } | ||||
920 | |||||
921 | # spent 1.18ms (345µs+834µs) within Class::MOP::Class::find_attribute_by_name which was called 55 times, avg 21µs/call:
# 55 times (345µs+834µs) by Class::MOP::Class::_immutable_metaclass at line 1343, avg 21µs/call | ||||
922 | 55 | 11µs | my ( $self, $attr_name ) = @_; | ||
923 | |||||
924 | 55 | 54µs | 55 | 485µs | foreach my $class ( $self->linearized_isa ) { # spent 471µs making 51 calls to Class::MOP::Class::Immutable::Class::MOP::Class::linearized_isa, avg 9µs/call
# spent 14µs making 4 calls to Class::MOP::Class::linearized_isa, avg 4µs/call |
925 | # fetch the meta-class ... | ||||
926 | 55 | 42µs | 55 | 107µs | my $meta = Class::MOP::Class->initialize($class); # spent 107µs making 55 calls to Class::MOP::Class::initialize, avg 2µs/call |
927 | 55 | 139µs | 110 | 241µs | return $meta->get_attribute($attr_name) # spent 142µs making 55 calls to Class::MOP::Mixin::HasAttributes::has_attribute, avg 3µs/call
# spent 99µs making 55 calls to Class::MOP::Mixin::HasAttributes::get_attribute, avg 2µs/call |
928 | if $meta->has_attribute($attr_name); | ||||
929 | } | ||||
930 | |||||
931 | return; | ||||
932 | } | ||||
933 | |||||
934 | # spent 4.18ms (2.21+1.98) within Class::MOP::Class::get_all_attributes which was called 131 times, avg 32µs/call:
# 40 times (673µs+539µs) by Class::MOP::Class::_create_meta_instance at line 727, avg 30µs/call
# 31 times (529µs+465µs) by Class::MOP::Class::_inline_slot_initializers at line 593, avg 32µs/call
# 31 times (488µs+413µs) by Class::MOP::Class::_eval_environment at line 709, avg 29µs/call
# 16 times (279µs+376µs) by Class::MOP::Class:::around at line 71 of Class/MOP/Class/Immutable/Trait.pm, avg 41µs/call
# 10 times (188µs+151µs) by Class::MOP::Class::_construct_instance at line 525, avg 34µs/call
# once (34µs+15µs) by Moose::Meta::Attribute::new at line 58 of Moose/Meta/Attribute.pm
# once (9µs+8µs) by Moose::Meta::Class::_inline_triggers at line 459 of Moose/Meta/Class.pm
# once (8µs+7µs) by Moose::Meta::Class::_eval_environment at line 497 of Moose/Meta/Class.pm | ||||
935 | 131 | 17µs | my $self = shift; | ||
936 | 1245 | 1.78ms | 1245 | 1.93ms | my %attrs = map { %{ Class::MOP::Class->initialize($_)->_attribute_map } } # spent 1.19ms making 557 calls to Class::MOP::Class::initialize, avg 2µs/call, recursion: max depth 1, sum of overlapping time 50µs
# spent 437µs making 115 calls to Class::MOP::Class::linearized_isa, avg 4µs/call
# spent 215µs making 16 calls to Class::MOP::Class::Immutable::Class::MOP::Class::linearized_isa, avg 13µs/call
# spent 138µs making 557 calls to Class::MOP::Mixin::HasAttributes::_attribute_map, avg 247ns/call |
937 | reverse $self->linearized_isa; | ||||
938 | 131 | 283µs | return values %attrs; | ||
939 | } | ||||
940 | |||||
941 | # Inheritance | ||||
942 | |||||
943 | sub superclasses { | ||||
944 | 79 | 11µs | my $self = shift; | ||
945 | |||||
946 | 79 | 104µs | 79 | 1.35ms | my $isa = $self->get_or_add_package_symbol('@ISA'); # spent 1.35ms making 79 calls to Class::MOP::Package::get_or_add_package_symbol, avg 17µs/call |
947 | |||||
948 | 79 | 22µs | if (@_) { | ||
949 | 3 | 2µs | my @supers = @_; | ||
950 | 3 | 26µs | @{$isa} = @supers; | ||
951 | |||||
952 | # NOTE: | ||||
953 | # on 5.8 and below, we need to call | ||||
954 | # a method to get Perl to detect | ||||
955 | # a cycle in the class hierarchy | ||||
956 | 3 | 7µs | 3 | 1µs | my $class = $self->name; # spent 1µs making 3 calls to Class::MOP::Package::name, avg 333ns/call |
957 | 3 | 12µs | 3 | 1µs | $class->isa($class); # spent 1µs making 3 calls to UNIVERSAL::isa, avg 433ns/call |
958 | |||||
959 | # NOTE: | ||||
960 | # we need to check the metaclass | ||||
961 | # compatibility here so that we can | ||||
962 | # be sure that the superclass is | ||||
963 | # not potentially creating an issues | ||||
964 | # we don't know about | ||||
965 | |||||
966 | 3 | 7µs | 3 | 601µs | $self->_check_metaclass_compatibility(); # spent 601µs making 3 calls to Class::MOP::Class::_check_metaclass_compatibility, avg 200µs/call |
967 | 3 | 6µs | 3 | 85µs | $self->_superclasses_updated(); # spent 85µs making 3 calls to Class::MOP::Class::_superclasses_updated, avg 28µs/call |
968 | } | ||||
969 | |||||
970 | 79 | 125µs | return @{$isa}; | ||
971 | } | ||||
972 | |||||
973 | # spent 85µs (34+51) within Class::MOP::Class::_superclasses_updated which was called 3 times, avg 28µs/call:
# 3 times (34µs+51µs) by Class::MOP::Class::superclasses at line 967, avg 28µs/call | ||||
974 | 3 | 900ns | my $self = shift; | ||
975 | 3 | 5µs | 3 | 4µs | $self->update_meta_instance_dependencies(); # spent 4µs making 3 calls to Class::MOP::Class::update_meta_instance_dependencies, avg 2µs/call |
976 | # keep strong references to all our parents, so they don't disappear if | ||||
977 | # they are anon classes and don't have any direct instances | ||||
978 | $self->_superclass_metas( | ||||
979 | 6 | 19µs | 9 | 17µs | map { Class::MOP::class_of($_) } $self->superclasses # spent 10µs making 3 calls to Class::MOP::class_of, avg 3µs/call
# spent 7µs making 3 calls to Class::MOP::Class::_superclass_metas, avg 2µs/call
# spent 14µs making 2 calls to Class::MOP::Class::superclasses, avg 7µs/call, recursion: max depth 1, sum of overlapping time 14µs
# spent 15µs making 1 call to Moose::Meta::Class::superclasses, recursion: max depth 1, sum of overlapping time 15µs |
980 | ); | ||||
981 | } | ||||
982 | |||||
983 | # spent 7µs within Class::MOP::Class::_superclass_metas which was called 3 times, avg 2µs/call:
# 3 times (7µs+0s) by Class::MOP::Class::_superclasses_updated at line 979, avg 2µs/call | ||||
984 | 3 | 1µs | my $self = shift; | ||
985 | 3 | 8µs | $self->{_superclass_metas} = [@_]; | ||
986 | } | ||||
987 | |||||
988 | sub subclasses { | ||||
989 | my $self = shift; | ||||
990 | my $super_class = $self->name; | ||||
991 | |||||
992 | return @{ $super_class->mro::get_isarev() }; | ||||
993 | } | ||||
994 | |||||
995 | sub direct_subclasses { | ||||
996 | my $self = shift; | ||||
997 | my $super_class = $self->name; | ||||
998 | |||||
999 | return grep { | ||||
1000 | grep { | ||||
1001 | $_ eq $super_class | ||||
1002 | } Class::MOP::Class->initialize($_)->superclasses | ||||
1003 | } $self->subclasses; | ||||
1004 | } | ||||
1005 | |||||
1006 | # spent 1.19ms (878µs+313µs) within Class::MOP::Class::linearized_isa which was called 309 times, avg 4µs/call:
# 174 times (488µs+180µs) by Class::MOP::Class::_method_lookup_order at line 1045, avg 4µs/call
# 115 times (329µs+108µs) by Class::MOP::Class::get_all_attributes at line 936, avg 4µs/call
# 16 times (51µs+20µs) by Class::MOP::Class:::around at line 53 of Class/MOP/Class/Immutable/Trait.pm, avg 4µs/call
# 4 times (10µs+4µs) by Class::MOP::Class::find_attribute_by_name at line 924, avg 4µs/call | ||||
1007 | 309 | 1.35ms | 618 | 313µs | return @{ mro::get_linear_isa( (shift)->name ) }; # spent 231µs making 309 calls to mro::get_linear_isa, avg 747ns/call
# spent 82µs making 309 calls to Class::MOP::Package::name, avg 265ns/call |
1008 | } | ||||
1009 | |||||
1010 | sub class_precedence_list { | ||||
1011 | my $self = shift; | ||||
1012 | my $name = $self->name; | ||||
1013 | |||||
1014 | unless (Class::MOP::IS_RUNNING_ON_5_10()) { | ||||
1015 | # NOTE: | ||||
1016 | # We need to check for circular inheritance here | ||||
1017 | # if we are not on 5.10, cause 5.8 detects it late. | ||||
1018 | # This will do nothing if all is well, and blow up | ||||
1019 | # otherwise. Yes, it's an ugly hack, better | ||||
1020 | # suggestions are welcome. | ||||
1021 | # - SL | ||||
1022 | ($name || return)->isa('This is a test for circular inheritance') | ||||
1023 | } | ||||
1024 | |||||
1025 | # if our mro is c3, we can | ||||
1026 | # just grab the linear_isa | ||||
1027 | if (mro::get_mro($name) eq 'c3') { | ||||
1028 | return @{ mro::get_linear_isa($name) } | ||||
1029 | } | ||||
1030 | else { | ||||
1031 | # NOTE: | ||||
1032 | # we can't grab the linear_isa for dfs | ||||
1033 | # since it has all the duplicates | ||||
1034 | # already removed. | ||||
1035 | return ( | ||||
1036 | $name, | ||||
1037 | map { | ||||
1038 | Class::MOP::Class->initialize($_)->class_precedence_list() | ||||
1039 | } $self->superclasses() | ||||
1040 | ); | ||||
1041 | } | ||||
1042 | } | ||||
1043 | |||||
1044 | # spent 955µs (286+669) within Class::MOP::Class::_method_lookup_order which was called 174 times, avg 5µs/call:
# 90 times (155µs+382µs) by Class::MOP::Class::find_method_by_name at line 1132, avg 6µs/call
# 75 times (113µs+242µs) by Class::MOP::Class::find_next_method_by_name at line 1178, avg 5µs/call
# 7 times (15µs+38µs) by Class::MOP::Class::get_all_methods at line 1143, avg 8µs/call
# 2 times (3µs+6µs) by Class::MOP::Class::find_all_methods_by_name at line 1162, avg 5µs/call | ||||
1045 | 174 | 298µs | 174 | 669µs | return (shift->linearized_isa, 'UNIVERSAL'); # spent 669µs making 174 calls to Class::MOP::Class::linearized_isa, avg 4µs/call |
1046 | } | ||||
1047 | |||||
1048 | ## Methods | ||||
1049 | |||||
1050 | { | ||||
1051 | # spent 8.76ms (483µs+8.28) within Class::MOP::Class::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Class/MOP/Class.pm:1082] which was called 43 times, avg 204µs/call:
# 43 times (483µs+8.28ms) by Class::MOP::Class::add_around_method_modifier at line 1108, avg 204µs/call | ||||
1052 | 43 | 9µs | my ($self, $method_name) = @_; | ||
1053 | 43 | 83µs | 43 | 16µs | my $wrapped_metaclass = $self->wrapped_method_metaclass; # spent 16µs making 43 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 360ns/call |
1054 | # fetch it locally | ||||
1055 | 43 | 24µs | 43 | 413µs | my $method = $self->get_method($method_name); # spent 413µs making 43 calls to Class::MOP::Mixin::HasMethods::get_method, avg 10µs/call |
1056 | # if we don't have local ... | ||||
1057 | 43 | 15µs | unless ($method) { | ||
1058 | # try to find the next method | ||||
1059 | 43 | 38µs | 43 | 4.89ms | $method = $self->find_next_method_by_name($method_name); # spent 4.89ms making 43 calls to Class::MOP::Class::find_next_method_by_name, avg 114µs/call |
1060 | # die if it does not exist | ||||
1061 | 43 | 7µs | (defined $method) | ||
1062 | || $self->_throw_exception( MethodNameNotFoundInInheritanceHierarchy => class_name => $self->name, | ||||
1063 | method_name => $method_name | ||||
1064 | ); | ||||
1065 | # and now make sure to wrap it | ||||
1066 | # even if it is already wrapped | ||||
1067 | # because we need a new sub ref | ||||
1068 | 43 | 126µs | 86 | 1.23ms | $method = $wrapped_metaclass->wrap($method, # spent 1.22ms making 43 calls to Class::MOP::Method::Wrapped::wrap, avg 28µs/call
# spent 10µs making 43 calls to Class::MOP::Package::name, avg 233ns/call |
1069 | package_name => $self->name, | ||||
1070 | name => $method_name, | ||||
1071 | ); | ||||
1072 | } | ||||
1073 | else { | ||||
1074 | # now make sure we wrap it properly | ||||
1075 | $method = $wrapped_metaclass->wrap($method, | ||||
1076 | package_name => $self->name, | ||||
1077 | name => $method_name, | ||||
1078 | ) unless $method->isa($wrapped_metaclass); | ||||
1079 | } | ||||
1080 | 43 | 35µs | 43 | 1.73ms | $self->add_method($method_name => $method); # spent 1.73ms making 43 calls to Class::MOP::Mixin::HasMethods::add_method, avg 40µs/call |
1081 | 43 | 64µs | return $method; | ||
1082 | 1 | 3µs | }; | ||
1083 | |||||
1084 | sub add_before_method_modifier { | ||||
1085 | my ($self, $method_name, $method_modifier) = @_; | ||||
1086 | (defined $method_name && length $method_name) | ||||
1087 | || $self->_throw_exception( MethodModifierNeedsMethodName => class_name => $self->name ); | ||||
1088 | my $method = $fetch_and_prepare_method->($self, $method_name); | ||||
1089 | $method->add_before_modifier( | ||||
1090 | subname(':before' => $method_modifier) | ||||
1091 | ); | ||||
1092 | } | ||||
1093 | |||||
1094 | sub add_after_method_modifier { | ||||
1095 | my ($self, $method_name, $method_modifier) = @_; | ||||
1096 | (defined $method_name && length $method_name) | ||||
1097 | || $self->_throw_exception( MethodModifierNeedsMethodName => class_name => $self->name ); | ||||
1098 | my $method = $fetch_and_prepare_method->($self, $method_name); | ||||
1099 | $method->add_after_modifier( | ||||
1100 | subname(':after' => $method_modifier) | ||||
1101 | ); | ||||
1102 | } | ||||
1103 | |||||
1104 | # spent 16.5ms (210µs+16.2) within Class::MOP::Class::add_around_method_modifier which was called 43 times, avg 383µs/call:
# 43 times (210µs+16.2ms) by Class::MOP::MiniTrait::apply at line 21 of Class/MOP/MiniTrait.pm, avg 383µs/call | ||||
1105 | 43 | 12µs | my ($self, $method_name, $method_modifier) = @_; | ||
1106 | 43 | 7µs | (defined $method_name && length $method_name) | ||
1107 | || $self->_throw_exception( MethodModifierNeedsMethodName => class_name => $self->name ); | ||||
1108 | 43 | 40µs | 43 | 8.76ms | my $method = $fetch_and_prepare_method->($self, $method_name); # spent 8.76ms making 43 calls to Class::MOP::Class::__ANON__[Class/MOP/Class.pm:1082], avg 204µs/call |
1109 | 43 | 213µs | 86 | 7.48ms | $method->add_around_modifier( # spent 7.39ms making 43 calls to Class::MOP::Method::Wrapped::add_around_modifier, avg 172µs/call
# spent 90µs making 43 calls to Sub::Name::subname, avg 2µs/call |
1110 | subname(':around' => $method_modifier) | ||||
1111 | ); | ||||
1112 | } | ||||
1113 | |||||
1114 | # NOTE: | ||||
1115 | # the methods above used to be named like this: | ||||
1116 | # ${pkg}::${method}:(before|after|around) | ||||
1117 | # but this proved problematic when using one modifier | ||||
1118 | # to wrap multiple methods (something which is likely | ||||
1119 | # to happen pretty regularly IMO). So instead of naming | ||||
1120 | # it like this, I have chosen to just name them purely | ||||
1121 | # with their modifier names, like so: | ||||
1122 | # :(before|after|around) | ||||
1123 | # The fact is that in a stack trace, it will be fairly | ||||
1124 | # evident from the context what method they are attached | ||||
1125 | # to, and so don't need the fully qualified name. | ||||
1126 | } | ||||
1127 | |||||
1128 | 1 | 200ns | # spent 8.20ms (1.12+7.08) within Class::MOP::Class::find_method_by_name which was called 90 times, avg 91µs/call:
# 56 times (789µs+5.35ms) by Class::MOP::MiniTrait::apply at line 21 of Class/MOP/MiniTrait.pm, avg 110µs/call
# 25 times (263µs+1.34ms) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 19 of Class/MOP/Mixin/HasMethods.pm, avg 64µs/call
# 7 times (47µs+198µs) by Moose::BEGIN@43 at line 16 of Moose/Meta/Attribute/Native.pm, avg 35µs/call
# once (12µs+140µs) by Moose::Meta::Class::_inline_BUILDARGS at line 325 of Moose/Meta/Class.pm
# once (8µs+58µs) by Moose::Meta::Method::Destructor::is_needed at line 66 of Moose/Meta/Method/Destructor.pm | ||
1129 | 90 | 21µs | my ($self, $method_name) = @_; | ||
1130 | 90 | 31µs | (defined $method_name && length $method_name) | ||
1131 | || $self->_throw_exception( MethodNameNotGiven => class_name => $self->name ); | ||||
1132 | 90 | 101µs | 90 | 537µs | foreach my $class ($self->_method_lookup_order) { # spent 537µs making 90 calls to Class::MOP::Class::_method_lookup_order, avg 6µs/call |
1133 | 345 | 370µs | 690 | 6.54ms | my $method = Class::MOP::Class->initialize($class)->get_method($method_name); # spent 5.55ms making 345 calls to Class::MOP::Mixin::HasMethods::get_method, avg 16µs/call
# spent 990µs making 345 calls to Class::MOP::Class::initialize, avg 3µs/call |
1134 | 345 | 153µs | return $method if defined $method; | ||
1135 | } | ||||
1136 | 43 | 51µs | return; | ||
1137 | } | ||||
1138 | |||||
1139 | # spent 5.14ms (232µs+4.91) within Class::MOP::Class::get_all_methods which was called 7 times, avg 734µs/call:
# 7 times (232µs+4.91ms) by Class::MOP::MiniTrait::apply at line 17 of Class/MOP/MiniTrait.pm, avg 734µs/call | ||||
1140 | 7 | 2µs | my $self = shift; | ||
1141 | |||||
1142 | 7 | 2µs | my %methods; | ||
1143 | 7 | 16µs | 7 | 53µs | for my $class ( reverse $self->_method_lookup_order ) { # spent 53µs making 7 calls to Class::MOP::Class::_method_lookup_order, avg 8µs/call |
1144 | 15 | 12µs | 15 | 33µs | my $meta = Class::MOP::Class->initialize($class); # spent 33µs making 15 calls to Class::MOP::Class::initialize, avg 2µs/call |
1145 | |||||
1146 | 15 | 180µs | 115 | 4.82ms | $methods{ $_->name } = $_ for $meta->_get_local_methods; # spent 4.79ms making 15 calls to Class::MOP::Mixin::HasMethods::_get_local_methods, avg 320µs/call
# spent 24µs making 100 calls to Class::MOP::Method::name, avg 235ns/call |
1147 | } | ||||
1148 | |||||
1149 | 7 | 23µs | return values %methods; | ||
1150 | } | ||||
1151 | |||||
1152 | sub get_all_method_names { | ||||
1153 | my $self = shift; | ||||
1154 | map { $_->name } $self->get_all_methods; | ||||
1155 | } | ||||
1156 | |||||
1157 | # spent 104µs (25+79) within Class::MOP::Class::find_all_methods_by_name which was called 2 times, avg 52µs/call:
# once (15µs+42µs) by Moose::Meta::Class::_inline_BUILDALL at line 483 of Moose/Meta/Class.pm
# once (10µs+38µs) by Moose::Meta::Method::Destructor::_generate_DEMOLISHALL at line 116 of Moose/Meta/Method/Destructor.pm | ||||
1158 | 2 | 700ns | my ($self, $method_name) = @_; | ||
1159 | 2 | 800ns | (defined $method_name && length $method_name) | ||
1160 | || $self->_throw_exception( MethodNameNotGiven => class_name => $self->name ); | ||||
1161 | 2 | 300ns | my @methods; | ||
1162 | 2 | 2µs | 2 | 9µs | foreach my $class ($self->_method_lookup_order) { # spent 9µs making 2 calls to Class::MOP::Class::_method_lookup_order, avg 5µs/call |
1163 | # fetch the meta-class ... | ||||
1164 | 6 | 4µs | 6 | 13µs | my $meta = Class::MOP::Class->initialize($class); # spent 13µs making 6 calls to Class::MOP::Class::initialize, avg 2µs/call |
1165 | 6 | 5µs | 6 | 57µs | push @methods => { # spent 57µs making 6 calls to Class::MOP::Mixin::HasMethods::has_method, avg 10µs/call |
1166 | name => $method_name, | ||||
1167 | class => $class, | ||||
1168 | code => $meta->get_method($method_name) | ||||
1169 | } if $meta->has_method($method_name); | ||||
1170 | } | ||||
1171 | 2 | 4µs | return @methods; | ||
1172 | } | ||||
1173 | |||||
1174 | # spent 6.51ms (686µs+5.82) within Class::MOP::Class::find_next_method_by_name which was called 75 times, avg 87µs/call:
# 43 times (429µs+4.46ms) by Class::MOP::Class::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Class/MOP/Class.pm:1082] at line 1059, avg 114µs/call
# 32 times (256µs+1.36ms) by Class::MOP::Method::Inlined::can_be_inlined at line 34 of Class/MOP/Method/Inlined.pm, avg 51µs/call | ||||
1175 | 75 | 18µs | my ($self, $method_name) = @_; | ||
1176 | 75 | 21µs | (defined $method_name && length $method_name) | ||
1177 | || $self->_throw_exception( MethodNameNotGiven => class_name => $self->name ); | ||||
1178 | 75 | 107µs | 75 | 355µs | my @cpl = ($self->_method_lookup_order); # spent 355µs making 75 calls to Class::MOP::Class::_method_lookup_order, avg 5µs/call |
1179 | 75 | 18µs | shift @cpl; # discard ourselves | ||
1180 | 75 | 28µs | foreach my $class (@cpl) { | ||
1181 | 150 | 178µs | 300 | 5.47ms | my $method = Class::MOP::Class->initialize($class)->get_method($method_name); # spent 5.11ms making 150 calls to Class::MOP::Mixin::HasMethods::get_method, avg 34µs/call
# spent 353µs making 150 calls to Class::MOP::Class::initialize, avg 2µs/call |
1182 | 150 | 143µs | return $method if defined $method; | ||
1183 | } | ||||
1184 | 2 | 2µs | return; | ||
1185 | } | ||||
1186 | |||||
1187 | # spent 4µs within Class::MOP::Class::update_meta_instance_dependencies which was called 3 times, avg 2µs/call:
# 3 times (4µs+0s) by Class::MOP::Class::_superclasses_updated at line 975, avg 2µs/call | ||||
1188 | 3 | 700ns | my $self = shift; | ||
1189 | |||||
1190 | 3 | 6µs | if ( $self->{meta_instance_dependencies} ) { | ||
1191 | return $self->add_meta_instance_dependencies; | ||||
1192 | } | ||||
1193 | } | ||||
1194 | |||||
1195 | sub add_meta_instance_dependencies { | ||||
1196 | my $self = shift; | ||||
1197 | |||||
1198 | $self->remove_meta_instance_dependencies; | ||||
1199 | |||||
1200 | my @attrs = $self->get_all_attributes(); | ||||
1201 | |||||
1202 | my %seen; | ||||
1203 | my @classes = grep { not $seen{ $_->name }++ } | ||||
1204 | map { $_->associated_class } @attrs; | ||||
1205 | |||||
1206 | foreach my $class (@classes) { | ||||
1207 | $class->add_dependent_meta_instance($self); | ||||
1208 | } | ||||
1209 | |||||
1210 | $self->{meta_instance_dependencies} = \@classes; | ||||
1211 | } | ||||
1212 | |||||
1213 | sub remove_meta_instance_dependencies { | ||||
1214 | my $self = shift; | ||||
1215 | |||||
1216 | if ( my $classes = delete $self->{meta_instance_dependencies} ) { | ||||
1217 | foreach my $class (@$classes) { | ||||
1218 | $class->remove_dependent_meta_instance($self); | ||||
1219 | } | ||||
1220 | |||||
1221 | return $classes; | ||||
1222 | } | ||||
1223 | |||||
1224 | return; | ||||
1225 | |||||
1226 | } | ||||
1227 | |||||
1228 | sub add_dependent_meta_instance { | ||||
1229 | my ( $self, $metaclass ) = @_; | ||||
1230 | push @{ $self->{dependent_meta_instances} }, $metaclass; | ||||
1231 | } | ||||
1232 | |||||
1233 | sub remove_dependent_meta_instance { | ||||
1234 | my ( $self, $metaclass ) = @_; | ||||
1235 | my $name = $metaclass->name; | ||||
1236 | @$_ = grep { $_->name ne $name } @$_ | ||||
1237 | for $self->{dependent_meta_instances}; | ||||
1238 | } | ||||
1239 | |||||
1240 | # spent 532µs (425+107) within Class::MOP::Class::invalidate_meta_instances which was called 135 times, avg 4µs/call:
# 135 times (425µs+107µs) by Class::MOP::Class::_post_add_attribute at line 894, avg 4µs/call | ||||
1241 | 135 | 20µs | my $self = shift; | ||
1242 | $_->invalidate_meta_instance() | ||||
1243 | 135 | 370µs | 135 | 107µs | for $self, @{ $self->{dependent_meta_instances} }; # spent 107µs making 135 calls to Class::MOP::Class::invalidate_meta_instance, avg 796ns/call |
1244 | } | ||||
1245 | |||||
1246 | # spent 107µs within Class::MOP::Class::invalidate_meta_instance which was called 135 times, avg 796ns/call:
# 135 times (107µs+0s) by Class::MOP::Class::invalidate_meta_instances at line 1243, avg 796ns/call | ||||
1247 | 135 | 14µs | my $self = shift; | ||
1248 | 135 | 198µs | undef $self->{_meta_instance}; | ||
1249 | } | ||||
1250 | |||||
1251 | # check if we can reinitialize | ||||
1252 | sub is_pristine { | ||||
1253 | my $self = shift; | ||||
1254 | |||||
1255 | # if any local attr is defined | ||||
1256 | return if $self->get_attribute_list; | ||||
1257 | |||||
1258 | # or any non-declared methods | ||||
1259 | for my $method ( map { $self->get_method($_) } $self->get_method_list ) { | ||||
1260 | return if $method->isa("Class::MOP::Method::Generated"); | ||||
1261 | # FIXME do we need to enforce this too? return unless $method->isa( $self->method_metaclass ); | ||||
1262 | } | ||||
1263 | |||||
1264 | return 1; | ||||
1265 | } | ||||
1266 | |||||
1267 | ## Class closing | ||||
1268 | |||||
1269 | 88 | 89µs | # spent 36µs within Class::MOP::Class::is_mutable which was called 88 times, avg 407ns/call:
# 55 times (29µs+0s) by Class::MOP::Class::make_immutable at line 1293, avg 524ns/call
# 21 times (4µs+0s) by DBIx::MultiStatementDo::BEGIN@8 at line 243 of Moose.pm, avg 200ns/call
# 9 times (2µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 717 of Moose/Util/TypeConstraints.pm, avg 244ns/call
# 3 times (600ns+0s) by DBIx::MultiStatementDo::BEGIN@8 at line 279 of Moose.pm, avg 200ns/call | ||
1270 | 38 | 38µs | # spent 18µs within Class::MOP::Class::is_immutable which was called 38 times, avg 476ns/call:
# 38 times (18µs+0s) by Class::MOP::Class::_real_ref_name at line 122, avg 476ns/call | ||
1271 | |||||
1272 | sub immutable_options { %{ $_[0]{__immutable}{options} || {} } } | ||||
1273 | |||||
1274 | # spent 438µs (356+83) within Class::MOP::Class::_immutable_options which was called 55 times, avg 8µs/call:
# 54 times (343µs+76µs) by Class::MOP::Class::make_immutable at line 1297, avg 8µs/call
# once (13µs+6µs) by Moose::Meta::Class::_immutable_options at line 757 of Moose/Meta/Class.pm | ||||
1275 | 55 | 25µs | my ( $self, @args ) = @_; | ||
1276 | |||||
1277 | return ( | ||||
1278 | 55 | 431µs | 220 | 83µs | inline_accessors => 1, # spent 28µs making 54 calls to Class::MOP::Class::immutable_trait, avg 515ns/call
# spent 21µs making 55 calls to Class::MOP::Class::constructor_name, avg 380ns/call
# spent 15µs making 54 calls to Class::MOP::Class::destructor_class, avg 278ns/call
# spent 13µs making 54 calls to Class::MOP::Class::constructor_class, avg 243ns/call
# spent 2µs making 1 call to Moose::Meta::Class::immutable_trait
# spent 2µs making 1 call to Moose::Meta::Class::constructor_class
# spent 2µs making 1 call to Moose::Meta::Class::destructor_class |
1279 | inline_constructor => 1, | ||||
1280 | inline_destructor => 0, | ||||
1281 | debug => 0, | ||||
1282 | immutable_trait => $self->immutable_trait, | ||||
1283 | constructor_name => $self->constructor_name, | ||||
1284 | constructor_class => $self->constructor_class, | ||||
1285 | destructor_class => $self->destructor_class, | ||||
1286 | @args, | ||||
1287 | ); | ||||
1288 | } | ||||
1289 | |||||
1290 | # spent 125ms (513µs+125) within Class::MOP::Class::make_immutable which was called 55 times, avg 2.28ms/call:
# 21 times (193µs+56.7ms) by DBIx::MultiStatementDo::BEGIN@8 at line 243 of Moose.pm, avg 2.71ms/call
# 14 times (96µs+14.4ms) by Moose::Exporter::BEGIN@8 at line 748 of Class/MOP.pm, avg 1.04ms/call
# 9 times (121µs+28.1ms) by Moose::Meta::Attribute::BEGIN@16 at line 717 of Moose/Util/TypeConstraints.pm, avg 3.13ms/call
# 5 times (30µs+214µs) by Moose::Exporter::BEGIN@8 at line 775 of Class/MOP.pm, avg 49µs/call
# 3 times (23µs+8.21ms) by DBIx::MultiStatementDo::BEGIN@8 at line 279 of Moose.pm, avg 2.74ms/call
# 2 times (32µs+-32µs) by Class::MOP::Class::_immutable_metaclass at line 1373, avg 0s/call
# once (18µs+17.3ms) by BenchmarkAnything::Storage::Frontend::Lib::BEGIN@280 at line 114 of DBIx/MultiStatementDo.pm | ||||
1291 | 55 | 31µs | my ( $self, @args ) = @_; | ||
1292 | |||||
1293 | 55 | 39µs | 55 | 29µs | return $self unless $self->is_mutable; # spent 29µs making 55 calls to Class::MOP::Class::is_mutable, avg 524ns/call |
1294 | |||||
1295 | 55 | 95µs | my ($file, $line) = (caller)[1..2]; | ||
1296 | |||||
1297 | 55 | 124µs | 110 | 94.6ms | $self->_initialize_immutable( # spent 94.2ms making 55 calls to Class::MOP::Class::_initialize_immutable, avg 1.71ms/call
# spent 419µs making 54 calls to Class::MOP::Class::_immutable_options, avg 8µs/call
# spent 25µs making 1 call to Moose::Meta::Class::_immutable_options |
1298 | file => $file, | ||||
1299 | line => $line, | ||||
1300 | $self->_immutable_options(@args), | ||||
1301 | ); | ||||
1302 | 55 | 53µs | 55 | 30.3ms | $self->_rebless_as_immutable(@args); # spent 30.5ms making 55 calls to Class::MOP::Class::_rebless_as_immutable, avg 554µs/call, recursion: max depth 1, sum of overlapping time 122µs |
1303 | |||||
1304 | 55 | 100µs | return $self; | ||
1305 | } | ||||
1306 | |||||
1307 | sub make_mutable { | ||||
1308 | my $self = shift; | ||||
1309 | |||||
1310 | if ( $self->is_immutable ) { | ||||
1311 | my @args = $self->immutable_options; | ||||
1312 | $self->_rebless_as_mutable(); | ||||
1313 | $self->_remove_inlined_code(@args); | ||||
1314 | delete $self->{__immutable}; | ||||
1315 | return $self; | ||||
1316 | } | ||||
1317 | else { | ||||
1318 | return; | ||||
1319 | } | ||||
1320 | } | ||||
1321 | |||||
1322 | # spent 30.3ms (171µs+30.2) within Class::MOP::Class::_rebless_as_immutable which was called 55 times, avg 552µs/call:
# 55 times (171µs+30.2ms) by Class::MOP::Class::make_immutable at line 1302, avg 552µs/call | ||||
1323 | 55 | 32µs | my ( $self, @args ) = @_; | ||
1324 | |||||
1325 | 55 | 27µs | $self->{__immutable}{original_class} = ref $self; | ||
1326 | |||||
1327 | 55 | 120µs | 55 | 30.2ms | bless $self => $self->_immutable_metaclass(@args); # spent 30.3ms making 55 calls to Class::MOP::Class::_immutable_metaclass, avg 551µs/call, recursion: max depth 1, sum of overlapping time 111µs |
1328 | } | ||||
1329 | |||||
1330 | # spent 30.2ms (568µs+29.6) within Class::MOP::Class::_immutable_metaclass which was called 55 times, avg 549µs/call:
# 55 times (568µs+29.6ms) by Class::MOP::Class::_rebless_as_immutable at line 1327, avg 549µs/call | ||||
1331 | 55 | 40µs | my ( $self, %args ) = @_; | ||
1332 | |||||
1333 | 55 | 16µs | if ( my $class = $args{immutable_metaclass} ) { | ||
1334 | return $class; | ||||
1335 | } | ||||
1336 | |||||
1337 | 55 | 104µs | 55 | 17µs | my $trait = $args{immutable_trait} = $self->immutable_trait # spent 16µs making 54 calls to Class::MOP::Class::immutable_trait, avg 298ns/call
# spent 1µs making 1 call to Moose::Meta::Class::immutable_trait |
1338 | || $self->_throw_exception( NoImmutableTraitSpecifiedForClass => class_name => $self->name, | ||||
1339 | params => \%args | ||||
1340 | ); | ||||
1341 | |||||
1342 | 55 | 51µs | 55 | 313µs | my $meta = $self->meta; # spent 313µs making 55 calls to Class::MOP::Object::meta, avg 6µs/call |
1343 | 55 | 58µs | 55 | 1.18ms | my $meta_attr = $meta->find_attribute_by_name("immutable_trait"); # spent 1.18ms making 55 calls to Class::MOP::Class::find_attribute_by_name, avg 21µs/call |
1344 | |||||
1345 | 55 | 7µs | my $class_name; | ||
1346 | |||||
1347 | 55 | 79µs | 55 | 50µs | if ( $meta_attr and $trait eq $meta_attr->default ) { # spent 50µs making 55 calls to Class::MOP::Mixin::AttributeCore::default, avg 902ns/call |
1348 | # if the trait is the same as the default we try and pick a | ||||
1349 | # predictable name for the immutable metaclass | ||||
1350 | $class_name = 'Class::MOP::Class::Immutable::' . ref($self); | ||||
1351 | } | ||||
1352 | else { | ||||
1353 | $class_name = join '::', 'Class::MOP::Class::Immutable::CustomTrait', | ||||
1354 | $trait, 'ForMetaClass', ref($self); | ||||
1355 | } | ||||
1356 | |||||
1357 | 55 | 113µs | 55 | 54µs | return $class_name # spent 54µs making 55 calls to Class::MOP::does_metaclass_exist, avg 985ns/call |
1358 | if Class::MOP::does_metaclass_exist($class_name); | ||||
1359 | |||||
1360 | # If the metaclass is a subclass of CMOP::Class which has had | ||||
1361 | # metaclass roles applied (via Moose), then we want to make sure | ||||
1362 | # that we preserve that anonymous class (see Fey::ORM for an | ||||
1363 | # example of where this matters). | ||||
1364 | 2 | 2µs | 2 | 19µs | my $meta_name = $meta->_real_ref_name; # spent 19µs making 2 calls to Class::MOP::Class::_real_ref_name, avg 9µs/call |
1365 | |||||
1366 | 2 | 5µs | 2 | 1.23ms | my $immutable_meta = $meta_name->create( # spent 1.23ms making 2 calls to Class::MOP::Class::create, avg 615µs/call |
1367 | $class_name, | ||||
1368 | superclasses => [ ref $self ], | ||||
1369 | ); | ||||
1370 | |||||
1371 | 2 | 6µs | 2 | 26.6ms | Class::MOP::MiniTrait::apply( $immutable_meta, $trait ); # spent 26.6ms making 2 calls to Class::MOP::MiniTrait::apply, avg 13.3ms/call |
1372 | |||||
1373 | 2 | 8µs | 2 | 0s | $immutable_meta->make_immutable( # spent 214µs making 2 calls to Class::MOP::Class::make_immutable, avg 107µs/call, recursion: max depth 1, sum of overlapping time 214µs |
1374 | inline_constructor => 0, | ||||
1375 | inline_accessors => 0, | ||||
1376 | ); | ||||
1377 | |||||
1378 | 2 | 6µs | return $class_name; | ||
1379 | } | ||||
1380 | |||||
1381 | sub _remove_inlined_code { | ||||
1382 | my $self = shift; | ||||
1383 | |||||
1384 | $self->remove_method( $_->name ) for $self->_inlined_methods; | ||||
1385 | |||||
1386 | delete $self->{__immutable}{inlined_methods}; | ||||
1387 | } | ||||
1388 | |||||
1389 | sub _inlined_methods { @{ $_[0]{__immutable}{inlined_methods} || [] } } | ||||
1390 | |||||
1391 | sub _add_inlined_method { | ||||
1392 | 32 | 7µs | my ( $self, $method ) = @_; | ||
1393 | |||||
1394 | 32 | 65µs | push @{ $self->{__immutable}{inlined_methods} ||= [] }, $method; | ||
1395 | } | ||||
1396 | |||||
1397 | # spent 94.2ms (331µs+93.9) within Class::MOP::Class::_initialize_immutable which was called 55 times, avg 1.71ms/call:
# 55 times (331µs+93.9ms) by Class::MOP::Class::make_immutable at line 1297, avg 1.71ms/call | ||||
1398 | 55 | 136µs | my ( $self, %args ) = @_; | ||
1399 | |||||
1400 | 55 | 46µs | $self->{__immutable}{options} = \%args; | ||
1401 | 55 | 149µs | 55 | 93.9ms | $self->_install_inlined_code(%args); # spent 93.9ms making 55 calls to Class::MOP::Class::_install_inlined_code, avg 1.71ms/call |
1402 | } | ||||
1403 | |||||
1404 | # spent 93.9ms (303µs+93.6) within Class::MOP::Class::_install_inlined_code which was called 55 times, avg 1.71ms/call:
# 55 times (303µs+93.6ms) by Class::MOP::Class::_initialize_immutable at line 1401, avg 1.71ms/call | ||||
1405 | 55 | 59µs | my ( $self, %args ) = @_; | ||
1406 | |||||
1407 | # FIXME | ||||
1408 | 55 | 67µs | 33 | 34.8ms | $self->_inline_accessors(%args) if $args{inline_accessors}; # spent 34.8ms making 33 calls to Class::MOP::Class::_inline_accessors, avg 1.05ms/call |
1409 | 55 | 68µs | 31 | 58.3ms | $self->_inline_constructor(%args) if $args{inline_constructor}; # spent 58.3ms making 31 calls to Class::MOP::Class::_inline_constructor, avg 1.88ms/call |
1410 | 55 | 97µs | 1 | 524µs | $self->_inline_destructor(%args) if $args{inline_destructor}; # spent 524µs making 1 call to Class::MOP::Class::_inline_destructor |
1411 | } | ||||
1412 | |||||
1413 | sub _rebless_as_mutable { | ||||
1414 | my $self = shift; | ||||
1415 | |||||
1416 | bless $self, $self->_get_mutable_metaclass_name; | ||||
1417 | |||||
1418 | return $self; | ||||
1419 | } | ||||
1420 | |||||
1421 | # spent 34.8ms (301µs+34.5) within Class::MOP::Class::_inline_accessors which was called 33 times, avg 1.05ms/call:
# 33 times (301µs+34.5ms) by Class::MOP::Class::_install_inlined_code at line 1408, avg 1.05ms/call | ||||
1422 | 33 | 5µs | my $self = shift; | ||
1423 | |||||
1424 | 33 | 80µs | 33 | 98µs | foreach my $attr_name ( $self->get_attribute_list ) { # spent 98µs making 33 calls to Class::MOP::Mixin::HasAttributes::get_attribute_list, avg 3µs/call |
1425 | 76 | 124µs | 152 | 34.4ms | $self->get_attribute($attr_name)->install_accessors(1); # spent 33.5ms making 75 calls to Class::MOP::Attribute::install_accessors, avg 447µs/call
# spent 720µs making 1 call to Moose::Meta::Attribute::install_accessors
# spent 169µs making 76 calls to Class::MOP::Mixin::HasAttributes::get_attribute, avg 2µs/call |
1426 | } | ||||
1427 | } | ||||
1428 | |||||
1429 | # spent 58.3ms (578µs+57.7) within Class::MOP::Class::_inline_constructor which was called 31 times, avg 1.88ms/call:
# 31 times (578µs+57.7ms) by Class::MOP::Class::_install_inlined_code at line 1409, avg 1.88ms/call | ||||
1430 | 31 | 60µs | my ( $self, %args ) = @_; | ||
1431 | |||||
1432 | 31 | 8µs | my $name = $args{constructor_name}; | ||
1433 | # A class may not even have a constructor, and that's okay. | ||||
1434 | 31 | 7µs | return unless defined $name; | ||
1435 | |||||
1436 | 31 | 30µs | 31 | 466µs | if ( $self->has_method($name) && !$args{replace_constructor} ) { # spent 466µs making 31 calls to Class::MOP::Mixin::HasMethods::has_method, avg 15µs/call |
1437 | my $class = $self->name; | ||||
1438 | warn "Not inlining a constructor for $class since it defines" | ||||
1439 | . " its own constructor.\n" | ||||
1440 | . "If you are certain you don't need to inline your" | ||||
1441 | . " constructor, specify inline_constructor => 0 in your" | ||||
1442 | . " call to $class->meta->make_immutable\n"; | ||||
1443 | return; | ||||
1444 | } | ||||
1445 | |||||
1446 | 31 | 9µs | my $constructor_class = $args{constructor_class}; | ||
1447 | |||||
1448 | { | ||||
1449 | 62 | 14µs | local $@; | ||
1450 | 31 | 43µs | 31 | 895µs | use_package_optimistically($constructor_class); # spent 895µs making 31 calls to Module::Runtime::use_package_optimistically, avg 29µs/call |
1451 | } | ||||
1452 | |||||
1453 | my $constructor = $constructor_class->new( | ||||
1454 | options => \%args, | ||||
1455 | metaclass => $self, | ||||
1456 | is_inline => 1, | ||||
1457 | package_name => $self->name, | ||||
1458 | name => $name, | ||||
1459 | definition_context => { | ||||
1460 | description => "constructor " . $self->name . "::" . $name, | ||||
1461 | file => $args{file}, | ||||
1462 | line => $args{line}, | ||||
1463 | }, | ||||
1464 | 31 | 196µs | 93 | 50.1ms | ); # spent 48.0ms making 30 calls to Class::MOP::Method::Constructor::new, avg 1.60ms/call
# spent 2.04ms making 1 call to Moose::Meta::Method::Constructor::new
# spent 16µs making 62 calls to Class::MOP::Package::name, avg 250ns/call |
1465 | |||||
1466 | 31 | 101µs | 31 | 2.03ms | if ( $args{replace_constructor} or $constructor->can_be_inlined ) { # spent 2.03ms making 31 calls to Class::MOP::Method::Inlined::can_be_inlined, avg 65µs/call |
1467 | 31 | 25µs | 31 | 4.18ms | $self->add_method( $name => $constructor ); # spent 4.18ms making 31 calls to Class::MOP::Mixin::HasMethods::add_method, avg 135µs/call |
1468 | 31 | 30µs | 31 | 58µs | $self->_add_inlined_method($constructor); # spent 58µs making 31 calls to Class::MOP::Class::_add_inlined_method, avg 2µs/call |
1469 | } | ||||
1470 | } | ||||
1471 | |||||
1472 | # spent 524µs (34+490) within Class::MOP::Class::_inline_destructor which was called:
# once (34µs+490µs) by Class::MOP::Class::_install_inlined_code at line 1410 | ||||
1473 | 1 | 3µs | my ( $self, %args ) = @_; | ||
1474 | |||||
1475 | ( exists $args{destructor_class} && defined $args{destructor_class} ) | ||||
1476 | 1 | 700ns | || $self->_throw_exception( NoDestructorClassSpecified => class_name => $self->name, | ||
1477 | params => \%args, | ||||
1478 | ); | ||||
1479 | |||||
1480 | 1 | 1µs | 1 | 11µs | if ( $self->has_method('DESTROY') && ! $args{replace_destructor} ) { # spent 11µs making 1 call to Class::MOP::Mixin::HasMethods::has_method |
1481 | my $class = $self->name; | ||||
1482 | warn "Not inlining a destructor for $class since it defines" | ||||
1483 | . " its own destructor.\n"; | ||||
1484 | return; | ||||
1485 | } | ||||
1486 | |||||
1487 | 1 | 500ns | my $destructor_class = $args{destructor_class}; | ||
1488 | |||||
1489 | { | ||||
1490 | 2 | 600ns | local $@; | ||
1491 | 1 | 900ns | 1 | 26µs | use_package_optimistically($destructor_class); # spent 26µs making 1 call to Module::Runtime::use_package_optimistically |
1492 | } | ||||
1493 | |||||
1494 | 1 | 3µs | 2 | 75µs | return unless $destructor_class->is_needed($self); # spent 74µs making 1 call to Moose::Meta::Method::Destructor::is_needed
# spent 600ns making 1 call to Class::MOP::Method::__ANON__[Class/MOP/Method.pm:16] |
1495 | |||||
1496 | my $destructor = $destructor_class->new( | ||||
1497 | options => \%args, | ||||
1498 | metaclass => $self, | ||||
1499 | package_name => $self->name, | ||||
1500 | name => 'DESTROY', | ||||
1501 | definition_context => { | ||||
1502 | description => "destructor " . $self->name . "::DESTROY", | ||||
1503 | file => $args{file}, | ||||
1504 | line => $args{line}, | ||||
1505 | }, | ||||
1506 | 1 | 8µs | 3 | 265µs | ); # spent 265µs making 1 call to Moose::Meta::Method::Destructor::new
# spent 400ns making 2 calls to Class::MOP::Package::name, avg 200ns/call |
1507 | |||||
1508 | 1 | 6µs | 1 | 71µs | if ( $args{replace_destructor} or $destructor->can_be_inlined ) { # spent 71µs making 1 call to Class::MOP::Method::Inlined::can_be_inlined |
1509 | 1 | 900ns | 1 | 41µs | $self->add_method( 'DESTROY' => $destructor ); # spent 41µs making 1 call to Class::MOP::Mixin::HasMethods::add_method |
1510 | 1 | 900ns | 1 | 1µs | $self->_add_inlined_method($destructor); # spent 1µs making 1 call to Class::MOP::Class::_add_inlined_method |
1511 | } | ||||
1512 | } | ||||
1513 | |||||
1514 | 1 | 5µs | 1; | ||
1515 | |||||
1516 | # ABSTRACT: Class Meta Object | ||||
1517 | |||||
1518 | __END__ | ||||
# spent 5.59ms (5.24+346µs) within Class::MOP::Class::CORE:sort which was called 62 times, avg 90µs/call:
# 31 times (3.95ms+172µs) by Class::MOP::Class::_inline_slot_initializers at line 593, avg 133µs/call
# 31 times (1.29ms+174µs) by Class::MOP::Class::_eval_environment at line 709, avg 47µs/call |