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