File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP/Class.pm |
Statements Executed | 33684 |
Statement Execution Time | 65.1ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
284 | 7 | 5 | 8.82ms | 17.5ms | get_all_attributes | Class::MOP::Class::
1894 | 26 | 14 | 8.53ms | 34.2ms | initialize | Class::MOP::Class::
97 | 2 | 1 | 4.94ms | 105ms | _construct_instance | Class::MOP::Class::
154 | 1 | 1 | 4.46ms | 17.0ms | _clone_instance | Class::MOP::Class::
705 | 8 | 2 | 3.52ms | 5.15ms | linearized_isa | Class::MOP::Class::
139 | 3 | 2 | 2.67ms | 4.85ms | _check_metaclass_compatibility | Class::MOP::Class::
180 | 3 | 3 | 2.65ms | 15.2ms | superclasses | Class::MOP::Class::
201 | 1 | 1 | 2.20ms | 111ms | _post_add_attribute | Class::MOP::Class::
135 | 2 | 2 | 2.09ms | 10.6ms | find_next_method_by_name | Class::MOP::Class::
158 | 4 | 2 | 2.00ms | 5.98ms | find_attribute_by_name | Class::MOP::Class::
100 | 3 | 1 | 1.88ms | 22.1ms | __ANON__[:678] | Class::MOP::Class::
91 | 1 | 1 | 1.83ms | 23.6ms | _construct_class_instance | Class::MOP::Class::
86 | 5 | 5 | 1.80ms | 13.3ms | find_method_by_name | Class::MOP::Class::
57 | 1 | 1 | 1.75ms | 42.4ms | _immutable_metaclass | Class::MOP::Class::
124 | 1 | 1 | 1.54ms | 22.0ms | _create_meta_instance | Class::MOP::Class::
154 | 1 | 1 | 1.54ms | 19.0ms | clone_object | Class::MOP::Class::
201 | 1 | 1 | 1.37ms | 1.65ms | invalidate_meta_instances | Class::MOP::Class::
595 | 13 | 6 | 1.28ms | 23.2ms | get_meta_instance | Class::MOP::Class::
201 | 1 | 1 | 1.24ms | 105ms | __ANON__[:515] | Class::MOP::Class::
1 | 1 | 1 | 1.08ms | 2.82ms | BEGIN@9 | Class::MOP::Class::
191 | 4 | 2 | 1.06ms | 1.29ms | is_anon_class | Class::MOP::Class::
1 | 1 | 1 | 971µs | 1.42ms | BEGIN@7 | Class::MOP::Class::
730 | 13 | 4 | 916µs | 916µs | instance_metaclass | Class::MOP::Class::
37 | 1 | 1 | 912µs | 41.5ms | _inline_constructor | Class::MOP::Class::
57 | 12 | 10 | 866µs | 120ms | make_immutable | Class::MOP::Class::
1 | 1 | 1 | 859µs | 1.82ms | BEGIN@8 | Class::MOP::Class::
1 | 1 | 1 | 812µs | 1.68ms | BEGIN@10 | Class::MOP::Class::
65 | 5 | 5 | 747µs | 88.9ms | new_object | Class::MOP::Class::
57 | 2 | 2 | 741µs | 1.08ms | _immutable_options | Class::MOP::Class::
201 | 1 | 1 | 674µs | 2.45ms | _attach_attribute | Class::MOP::Class::
59 | 1 | 1 | 627µs | 627µs | _new | Class::MOP::Class::
57 | 1 | 1 | 578µs | 75.6ms | _initialize_immutable | Class::MOP::Class::
57 | 1 | 1 | 560µs | 75.1ms | _install_inlined_code | Class::MOP::Class::
65 | 2 | 2 | 497µs | 17.4ms | add_around_method_modifier | Class::MOP::Class::
57 | 1 | 1 | 485µs | 42.8ms | _rebless_as_immutable | Class::MOP::Class::
27 | 3 | 3 | 468µs | 1.66ms | class_precedence_list | Class::MOP::Class::
32 | 1 | 1 | 449µs | 28.6ms | _inline_accessors | Class::MOP::Class::
201 | 1 | 1 | 279µs | 279µs | invalidate_meta_instance | Class::MOP::Class::
3 | 1 | 1 | 263µs | 5.32ms | get_all_methods | Class::MOP::Class::
1 | 1 | 1 | 255µs | 6.89ms | BEGIN@15 | Class::MOP::Class::
7 | 1 | 1 | 254µs | 4.33ms | _inline_destructor | Class::MOP::Class::
5 | 2 | 2 | 218µs | 4.96ms | create | Class::MOP::Class::
12 | 2 | 2 | 209µs | 1.13ms | find_all_methods_by_name | Class::MOP::Class::
48 | 1 | 1 | 198µs | 285µs | _superclasses_updated | Class::MOP::Class::
22 | 2 | 2 | 186µs | 4.54ms | add_after_method_modifier | Class::MOP::Class::
100 | 2 | 1 | 133µs | 133µs | immutable_trait | Class::MOP::Class::
43 | 2 | 1 | 131µs | 131µs | _add_inlined_method | Class::MOP::Class::
13 | 1 | 1 | 119µs | 2.95ms | add_before_method_modifier | Class::MOP::Class::
193 | 2 | 2 | 98µs | 98µs | CORE:match (opcode) | Class::MOP::Class::
48 | 1 | 1 | 87µs | 87µs | update_meta_instance_dependencies | Class::MOP::Class::
76 | 4 | 2 | 83µs | 83µs | is_immutable | Class::MOP::Class::
57 | 1 | 1 | 80µs | 80µs | constructor_name | Class::MOP::Class::
88 | 3 | 3 | 68µs | 68µs | is_mutable | Class::MOP::Class::
50 | 1 | 1 | 55µs | 55µs | constructor_class | Class::MOP::Class::
1 | 1 | 1 | 43µs | 687µs | is_pristine | Class::MOP::Class::
50 | 1 | 1 | 42µs | 42µs | destructor_class | Class::MOP::Class::
13 | 1 | 1 | 35µs | 35µs | reset_package_cache_flag | Class::MOP::Class::
2 | 2 | 2 | 33µs | 66µs | DESTROY | Class::MOP::Class::
2 | 1 | 1 | 32µs | 29.3ms | create_anon_class | Class::MOP::Class::
2 | 2 | 2 | 26µs | 26µs | CORE:regcomp (opcode) | Class::MOP::Class::
1 | 1 | 1 | 14µs | 17µs | BEGIN@4 | Class::MOP::Class::
1 | 1 | 1 | 9µs | 25µs | BEGIN@5 | Class::MOP::Class::
1 | 1 | 1 | 9µs | 20µs | BEGIN@223 | Class::MOP::Class::
1 | 1 | 1 | 9µs | 50µs | BEGIN@16 | Class::MOP::Class::
1 | 1 | 1 | 9µs | 19µs | BEGIN@244 | Class::MOP::Class::
1 | 1 | 1 | 8µs | 2.26ms | BEGIN@22 | Class::MOP::Class::
1 | 1 | 1 | 7µs | 19µs | BEGIN@257 | Class::MOP::Class::
1 | 1 | 1 | 7µs | 31µs | BEGIN@12 | Class::MOP::Class::
1 | 1 | 1 | 6µs | 35µs | BEGIN@13 | Class::MOP::Class::
1 | 1 | 1 | 6µs | 27µs | BEGIN@14 | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | __ANON__[:305] | Class::MOP::Class::
0 | 0 | 0 | 0s | 0s | __ANON__[:519] | 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_inlined_code | 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 | 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 | 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 | 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::
0 | 0 | 0 | 0s | 0s | update_package_cache_flag | Class::MOP::Class::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | package Class::MOP::Class; | ||||
3 | |||||
4 | 3 | 19µs | 2 | 20µs | # spent 17µs (14+3) within Class::MOP::Class::BEGIN@4 which was called
# once (14µs+3µs) by Class::MOP::BEGIN@18 at line 4 # spent 17µs making 1 call to Class::MOP::Class::BEGIN@4
# spent 3µs making 1 call to strict::import |
5 | 3 | 19µs | 2 | 40µs | # spent 25µs (9+16) within Class::MOP::Class::BEGIN@5 which was called
# once (9µs+16µs) by Class::MOP::BEGIN@18 at line 5 # spent 25µs making 1 call to Class::MOP::Class::BEGIN@5
# spent 16µs making 1 call to warnings::import |
6 | |||||
7 | 3 | 95µs | 1 | 1.42ms | # spent 1.42ms (971µs+451µs) within Class::MOP::Class::BEGIN@7 which was called
# once (971µs+451µs) by Class::MOP::BEGIN@18 at line 7 # spent 1.42ms making 1 call to Class::MOP::Class::BEGIN@7 |
8 | 3 | 100µs | 1 | 1.82ms | # spent 1.82ms (859µs+959µs) within Class::MOP::Class::BEGIN@8 which was called
# once (859µs+959µs) by Class::MOP::BEGIN@18 at line 8 # spent 1.82ms making 1 call to Class::MOP::Class::BEGIN@8 |
9 | 3 | 100µs | 1 | 2.82ms | # spent 2.82ms (1.08+1.74) within Class::MOP::Class::BEGIN@9 which was called
# once (1.08ms+1.74ms) by Class::MOP::BEGIN@18 at line 9 # spent 2.82ms making 1 call to Class::MOP::Class::BEGIN@9 |
10 | 3 | 104µs | 1 | 1.68ms | # spent 1.68ms (812µs+866µs) within Class::MOP::Class::BEGIN@10 which was called
# once (812µs+866µs) by Class::MOP::BEGIN@18 at line 10 # spent 1.68ms making 1 call to Class::MOP::Class::BEGIN@10 |
11 | |||||
12 | 3 | 23µs | 2 | 56µs | # spent 31µs (7+25) within Class::MOP::Class::BEGIN@12 which was called
# once (7µs+25µs) by Class::MOP::BEGIN@18 at line 12 # spent 31µs making 1 call to Class::MOP::Class::BEGIN@12
# spent 25µs making 1 call to Exporter::import |
13 | 3 | 22µs | 2 | 63µs | # spent 35µs (6+29) within Class::MOP::Class::BEGIN@13 which was called
# once (6µs+29µs) by Class::MOP::BEGIN@18 at line 13 # spent 35µs making 1 call to Class::MOP::Class::BEGIN@13
# spent 28µs making 1 call to Exporter::import |
14 | 3 | 20µs | 2 | 48µs | # spent 27µs (6+21) within Class::MOP::Class::BEGIN@14 which was called
# once (6µs+21µs) by Class::MOP::BEGIN@18 at line 14 # spent 27µs making 1 call to Class::MOP::Class::BEGIN@14
# spent 21µs making 1 call to Exporter::import |
15 | 3 | 113µs | 2 | 7.02ms | # spent 6.89ms (255µs+6.63) within Class::MOP::Class::BEGIN@15 which was called
# once (255µs+6.63ms) by Class::MOP::BEGIN@18 at line 15 # spent 6.89ms making 1 call to Class::MOP::Class::BEGIN@15
# spent 135µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
16 | 3 | 45µs | 2 | 91µs | # spent 50µs (9+41) within Class::MOP::Class::BEGIN@16 which was called
# once (9µs+41µs) by Class::MOP::BEGIN@18 at line 16 # spent 50µs making 1 call to Class::MOP::Class::BEGIN@16
# spent 41µs making 1 call to Exporter::import |
17 | |||||
18 | 1 | 800ns | our $VERSION = '0.98'; | ||
19 | 1 | 14µs | $VERSION = eval $VERSION; | ||
20 | 1 | 400ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
21 | |||||
22 | 3 | 466µs | 2 | 4.51ms | # spent 2.26ms (8µs+2.25) within Class::MOP::Class::BEGIN@22 which was called
# once (8µs+2.25ms) by Class::MOP::BEGIN@18 at line 22 # spent 2.26ms making 1 call to Class::MOP::Class::BEGIN@22
# spent 2.25ms making 1 call to base::import |
23 | |||||
24 | # Creation | ||||
25 | |||||
26 | # spent 34.2ms (8.53+25.6) within Class::MOP::Class::initialize which was called 1894 times, avg 18µs/call:
# 388 times (1.80ms+1.03ms) by Class::MOP::Object::meta at line 17 of Class/MOP/Object.pm, avg 7µs/call
# 335 times (1.63ms+446µs) by Class::MOP::Attribute::set_initial_value at line 251 of Class/MOP/Attribute.pm, avg 6µs/call
# 300 times (1.12ms+267µs) by Class::MOP::Class::get_all_attributes at line 551, avg 5µs/call
# 290 times (1.07ms+305µs) by Class::MOP::Attribute::set_raw_value at line 264 of Class/MOP/Attribute.pm, avg 5µs/call
# 175 times (705µs+229µs) by Class::MOP::Class::find_method_by_name at line 729, avg 5µs/call
# 112 times (450µs+136µs) by Class::MOP::Class::find_next_method_by_name at line 779, avg 5µs/call
# 56 times (212µs+49µs) by Class::MOP::Class::find_attribute_by_name at line 541, avg 5µs/call
# 43 times (203µs+99µs) by 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 50 of metaclass.pm, avg 7µs/call
# 40 times (211µs+303µs) by Class::MOP::Mixin::meta at line 14 of Class/MOP/Mixin.pm, avg 13µs/call
# 37 times (420µs+132µs) by Moose::Object::new at line 25 of Moose/Object.pm, avg 15µs/call
# 32 times (275µs+21.3ms) by Moose::Meta::Class::initialize at line 62 of Moose/Meta/Class.pm, avg 674µs/call
# 19 times (129µs+782µs) by metaclass::import at line 43 of metaclass.pm, avg 48µs/call
# 14 times (56µs+16µs) by Class::MOP::Class::class_precedence_list at line 638, avg 5µs/call
# 11 times (39µs+12µs) by Moose::Meta::Attribute::_weaken_value at line 489 of Moose/Meta/Attribute.pm, avg 5µs/call
# 9 times (39µs+13µs) by Moose::Meta::Method::_new at line 3 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 6µs/call
# 7 times (46µs+260µs) by Moose::BEGIN@37 at line 11 of Moose/Meta/Attribute/Native.pm, avg 44µs/call
# 6 times (22µs+6µs) by Class::MOP::Attribute::get_raw_value at line 272 of Class/MOP/Attribute.pm, avg 5µs/call
# 5 times (23µs+6µs) by Class::MOP::Class::get_all_methods at line 740, avg 6µs/call
# 3 times (19µs+78µs) by Class::MOP::Class::_immutable_metaclass at line 967, avg 32µs/call
# 3 times (16µs+5µs) by Moose::Meta::Attribute::_new at line 4 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 7µs/call
# 2 times (15µs+114µs) by Class::MOP::Class::create at line 298, avg 65µs/call
# 2 times (11µs+37µs) by Class::MOP::Method::_new at line 54 of Class/MOP/Method.pm, avg 24µs/call
# 2 times (9µs+2µs) by Class::MOP::Attribute::has_value at line 280 of Class/MOP/Attribute.pm, avg 6µs/call
# once (7µs+1µs) by Moose::Util::MetaRole::_make_new_class at line 144 of Moose/Util/MetaRole.pm
# once (6µs+2µs) by Moose::Meta::Method::Accessor::_new at line 3 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm
# once (5µs+1µs) by Class::MOP::Attribute::_new at line 62 of Class/MOP/Attribute.pm | ||||
27 | 1894 | 568µs | my $class = shift; | ||
28 | |||||
29 | 1894 | 175µs | my $package_name; | ||
30 | |||||
31 | 1894 | 1.19ms | if ( @_ % 2 ) { | ||
32 | $package_name = shift; | ||||
33 | } else { | ||||
34 | my %options = @_; | ||||
35 | $package_name = $options{package}; | ||||
36 | } | ||||
37 | |||||
38 | 1894 | 355µs | ($package_name && !ref($package_name)) | ||
39 | || confess "You must pass a package name and it cannot be blessed"; | ||||
40 | |||||
41 | 1894 | 5.02ms | 1985 | 25.9ms | return Class::MOP::get_metaclass_by_name($package_name) # spent 23.6ms making 91 calls to Class::MOP::Class::_construct_class_instance, avg 260µs/call
# spent 2.29ms making 1894 calls to Class::MOP::get_metaclass_by_name, avg 1µs/call |
42 | || $class->_construct_class_instance(package => $package_name, @_); | ||||
43 | } | ||||
44 | |||||
45 | # NOTE: (meta-circularity) | ||||
46 | # this is a special form of _construct_instance | ||||
47 | # (see below), which is used to construct class | ||||
48 | # meta-object instances for any Class::MOP::* | ||||
49 | # class. All other classes will use the more | ||||
50 | # normal &construct_instance. | ||||
51 | # spent 23.6ms (1.83+21.8) within Class::MOP::Class::_construct_class_instance which was called 91 times, avg 260µs/call:
# 91 times (1.83ms+21.8ms) by Class::MOP::Class::initialize at line 41, avg 260µs/call | ||||
52 | 91 | 35µs | my $class = shift; | ||
53 | 91 | 214µs | my $options = @_ == 1 ? $_[0] : {@_}; | ||
54 | 91 | 44µs | my $package_name = $options->{package}; | ||
55 | 91 | 28µs | (defined $package_name && $package_name) | ||
56 | || confess "You must pass a package name"; | ||||
57 | # NOTE: | ||||
58 | # return the metaclass if we have it cached, | ||||
59 | # and it is still defined (it has not been | ||||
60 | # reaped by DESTROY yet, which can happen | ||||
61 | # annoyingly enough during global destruction) | ||||
62 | |||||
63 | 91 | 90µs | 91 | 79µs | if (defined(my $meta = Class::MOP::get_metaclass_by_name($package_name))) { # spent 79µs making 91 calls to Class::MOP::get_metaclass_by_name, avg 869ns/call |
64 | return $meta; | ||||
65 | } | ||||
66 | |||||
67 | # NOTE: | ||||
68 | # we need to deal with the possibility | ||||
69 | # of class immutability here, and then | ||||
70 | # get the name of the class appropriately | ||||
71 | 91 | 39µs | 5 | 13µs | $class = (ref($class) # spent 7µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::__ANON__::SERIAL::1::is_immutable
# spent 4µs making 3 calls to Class::MOP::Class::is_immutable, avg 2µs/call
# spent 2µs making 1 call to Class::MOP::Class::Immutable::Trait::_get_mutable_metaclass_name |
72 | ? ($class->is_immutable | ||||
73 | ? $class->_get_mutable_metaclass_name() | ||||
74 | : ref($class)) | ||||
75 | : $class); | ||||
76 | |||||
77 | # now create the metaclass | ||||
78 | 91 | 9µs | my $meta; | ||
79 | 91 | 130µs | 59 | 627µs | if ($class eq 'Class::MOP::Class') { # spent 627µs making 59 calls to Class::MOP::Class::_new, avg 11µs/call |
80 | $meta = $class->_new($options); | ||||
81 | } | ||||
82 | else { | ||||
83 | # NOTE: | ||||
84 | # it is safe to use meta here because | ||||
85 | # class will always be a subclass of | ||||
86 | # Class::MOP::Class, which defines meta | ||||
87 | 32 | 136µs | 64 | 17.8ms | $meta = $class->meta->_construct_instance($options) # spent 17.4ms making 32 calls to Class::MOP::Class::_construct_instance, avg 544µs/call
# spent 380µs making 30 calls to Class::MOP::Object::meta, avg 13µs/call
# spent 23µs making 2 calls to Class::MOP::Class::__ANON__::SERIAL::1::meta, avg 11µs/call |
88 | } | ||||
89 | |||||
90 | # and check the metaclass compatibility | ||||
91 | 91 | 157µs | 91 | 2.34ms | $meta->_check_metaclass_compatibility(); # spent 2.29ms making 32 calls to Moose::Meta::Class::_check_metaclass_compatibility, avg 72µs/call, recursion: max depth 1, time 260µs
# spent 306µs making 59 calls to Class::MOP::Class::_check_metaclass_compatibility, avg 5µs/call |
92 | |||||
93 | 91 | 104µs | 91 | 165µs | Class::MOP::store_metaclass_by_name($package_name, $meta); # spent 165µs making 91 calls to Class::MOP::store_metaclass_by_name, avg 2µs/call |
94 | |||||
95 | # NOTE: | ||||
96 | # we need to weaken any anon classes | ||||
97 | # so that they can call DESTROY properly | ||||
98 | 91 | 124µs | 93 | 526µs | Class::MOP::weaken_metaclass($package_name) if $meta->is_anon_class; # spent 512µs making 91 calls to Class::MOP::Class::is_anon_class, avg 6µs/call
# spent 14µs making 2 calls to Class::MOP::weaken_metaclass, avg 7µs/call |
99 | |||||
100 | 91 | 272µs | $meta; | ||
101 | } | ||||
102 | |||||
103 | # spent 627µs within Class::MOP::Class::_new which was called 59 times, avg 11µs/call:
# 59 times (627µs+0s) by Class::MOP::Class::_construct_class_instance at line 79, avg 11µs/call | ||||
104 | 59 | 15µs | my $class = shift; | ||
105 | |||||
106 | 59 | 12µs | return Class::MOP::Class->initialize($class)->new_object(@_) | ||
107 | if $class ne __PACKAGE__; | ||||
108 | |||||
109 | 59 | 20µs | my $options = @_ == 1 ? $_[0] : {@_}; | ||
110 | |||||
111 | 59 | 621µs | return bless { | ||
112 | # inherited from Class::MOP::Package | ||||
113 | 'package' => $options->{package}, | ||||
114 | |||||
115 | # NOTE: | ||||
116 | # since the following attributes will | ||||
117 | # actually be loaded from the symbol | ||||
118 | # table, and actually bypass the instance | ||||
119 | # entirely, we can just leave these things | ||||
120 | # listed here for reference, because they | ||||
121 | # should not actually have a value associated | ||||
122 | # with the slot. | ||||
123 | 'namespace' => \undef, | ||||
124 | 'methods' => {}, | ||||
125 | |||||
126 | # inherited from Class::MOP::Module | ||||
127 | 'version' => \undef, | ||||
128 | 'authority' => \undef, | ||||
129 | |||||
130 | # defined in Class::MOP::Class | ||||
131 | 'superclasses' => \undef, | ||||
132 | |||||
133 | 'attributes' => {}, | ||||
134 | 'attribute_metaclass' => | ||||
135 | ( $options->{'attribute_metaclass'} || 'Class::MOP::Attribute' ), | ||||
136 | 'method_metaclass' => | ||||
137 | ( $options->{'method_metaclass'} || 'Class::MOP::Method' ), | ||||
138 | 'wrapped_method_metaclass' => ( | ||||
139 | $options->{'wrapped_method_metaclass'} | ||||
140 | || 'Class::MOP::Method::Wrapped' | ||||
141 | ), | ||||
142 | 'instance_metaclass' => | ||||
143 | ( $options->{'instance_metaclass'} || 'Class::MOP::Instance' ), | ||||
144 | 'immutable_trait' => ( | ||||
145 | $options->{'immutable_trait'} | ||||
146 | || 'Class::MOP::Class::Immutable::Trait' | ||||
147 | ), | ||||
148 | 'constructor_name' => ( $options->{constructor_name} || 'new' ), | ||||
149 | 'constructor_class' => ( | ||||
150 | $options->{constructor_class} || 'Class::MOP::Method::Constructor' | ||||
151 | ), | ||||
152 | 'destructor_class' => $options->{destructor_class}, | ||||
153 | }, $class; | ||||
154 | } | ||||
155 | |||||
156 | 13 | 54µs | # spent 35µs within Class::MOP::Class::reset_package_cache_flag which was called 13 times, avg 3µs/call:
# 13 times (35µs+0s) by Moose::Meta::Role::Application::ToClass::apply_methods at line 187 of Moose/Meta/Role/Application/ToClass.pm, avg 3µs/call | ||
157 | sub update_package_cache_flag { | ||||
158 | my $self = shift; | ||||
159 | # NOTE: | ||||
160 | # we can manually update the cache number | ||||
161 | # since we are actually adding the method | ||||
162 | # to our cache as well. This avoids us | ||||
163 | # having to regenerate the method_map. | ||||
164 | # - SL | ||||
165 | $self->{'_package_cache_flag'} = Class::MOP::check_package_cache_flag($self->name); | ||||
166 | } | ||||
167 | |||||
168 | # spent 4.85ms (2.67+2.18) within Class::MOP::Class::_check_metaclass_compatibility which was called 139 times, avg 35µs/call:
# 78 times (2.43ms+2.10ms) by Moose::Meta::Class::_check_metaclass_compatibility at line 108 of Moose/Meta/Class.pm, avg 58µs/call
# 59 times (231µs+75µs) by Class::MOP::Class::_construct_class_instance at line 91, avg 5µs/call
# 2 times (8µs+3µs) by Class::MOP::Class::superclasses at line 579, avg 5µs/call | ||||
169 | 139 | 42µs | my $self = shift; | ||
170 | |||||
171 | # this is always okay ... | ||||
172 | 139 | 222µs | 61 | 78µs | return if ref($self) eq 'Class::MOP::Class' && # spent 78µs making 61 calls to Class::MOP::Class::instance_metaclass, avg 1µs/call |
173 | $self->instance_metaclass eq 'Class::MOP::Instance'; | ||||
174 | |||||
175 | 78 | 177µs | 78 | 523µs | my @class_list = $self->linearized_isa; # spent 523µs making 78 calls to Class::MOP::Class::linearized_isa, avg 7µs/call |
176 | 78 | 20µs | shift @class_list; # shift off $self->name | ||
177 | |||||
178 | 78 | 208µs | foreach my $superclass_name (@class_list) { | ||
179 | 129 | 144µs | 129 | 175µs | my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name) || next; # spent 175µs making 129 calls to Class::MOP::get_metaclass_by_name, avg 1µs/call |
180 | |||||
181 | # NOTE: | ||||
182 | # we need to deal with the possibility | ||||
183 | # of class immutability here, and then | ||||
184 | # get the name of the class appropriately | ||||
185 | 129 | 295µs | 219 | 836µs | my $super_meta_type # spent 595µs making 88 calls to Class::MOP::Class::Immutable::Class::MOP::Class::is_immutable, avg 7µs/call
# spent 189µs making 90 calls to Class::MOP::Class::Immutable::Trait::_get_mutable_metaclass_name, avg 2µs/call
# spent 31µs making 39 calls to Class::MOP::Class::is_immutable, avg 790ns/call
# spent 22µs making 2 calls to Class::MOP::Class::Immutable::Class::MOP::Class::__ANON__::SERIAL::1::is_immutable, avg 11µs/call |
186 | = $super_meta->is_immutable | ||||
187 | ? $super_meta->_get_mutable_metaclass_name() | ||||
188 | : ref($super_meta); | ||||
189 | |||||
190 | 129 | 328µs | 129 | 95µs | ($self->isa($super_meta_type)) # spent 95µs making 129 calls to UNIVERSAL::isa, avg 737ns/call |
191 | || confess "The metaclass of " . $self->name . " (" | ||||
192 | . (ref($self)) . ")" . " is not compatible with the " . | ||||
193 | "metaclass of its superclass, ".$superclass_name . " (" | ||||
194 | . ($super_meta_type) . ")"; | ||||
195 | # NOTE: | ||||
196 | # we also need to check that instance metaclasses | ||||
197 | # are compatibile in the same the class. | ||||
198 | 129 | 710µs | 387 | 472µs | ($self->instance_metaclass->isa($super_meta->instance_metaclass)) # spent 328µs making 258 calls to Class::MOP::Class::instance_metaclass, avg 1µs/call
# spent 144µs making 129 calls to UNIVERSAL::isa, avg 1µs/call |
199 | || confess "The instance metaclass for " . $self->name . " (" . ($self->instance_metaclass) . ")" . | ||||
200 | " is not compatible with the " . | ||||
201 | "instance metaclass of its superclass, " . $superclass_name . " (" . ($super_meta->instance_metaclass) . ")"; | ||||
202 | } | ||||
203 | } | ||||
204 | |||||
205 | ## ANON classes | ||||
206 | |||||
207 | { | ||||
208 | # NOTE: | ||||
209 | # this should be sufficient, if you have a | ||||
210 | # use case where it is not, write a test and | ||||
211 | # I will change it. | ||||
212 | 2 | 600ns | my $ANON_CLASS_SERIAL = 0; | ||
213 | |||||
214 | # NOTE: | ||||
215 | # we need a sufficiently annoying prefix | ||||
216 | # this should suffice for now, this is | ||||
217 | # used in a couple of places below, so | ||||
218 | # need to put it up here for now. | ||||
219 | 1 | 500ns | my $ANON_CLASS_PREFIX = 'Class::MOP::Class::__ANON__::SERIAL::'; | ||
220 | |||||
221 | # spent 1.29ms (1.06+229µs) within Class::MOP::Class::is_anon_class which was called 191 times, avg 7µs/call:
# 97 times (641µs+117µs) by Class::MOP::Class::_construct_instance at line 368, avg 8µs/call
# 91 times (404µs+109µs) by Class::MOP::Class::_construct_class_instance at line 98, avg 6µs/call
# 2 times (12µs+2µs) by Moose::Meta::Class::reinitialize at line 163 of Moose/Meta/Class.pm, avg 7µs/call
# once (8µs+1µs) by Moose::Meta::Class::_reinitialize_with at line 436 of Moose/Meta/Class.pm | ||||
222 | 191 | 67µs | my $self = shift; | ||
223 | 3 | 91µs | 2 | 32µs | # spent 20µs (9+11) within Class::MOP::Class::BEGIN@223 which was called
# once (9µs+11µs) by Class::MOP::BEGIN@18 at line 223 # spent 20µs making 1 call to Class::MOP::Class::BEGIN@223
# spent 11µs making 1 call to warnings::unimport |
224 | 191 | 1.32ms | 383 | 229µs | $self->name =~ /^$ANON_CLASS_PREFIX/o; # spent 123µs making 191 calls to Class::MOP::Package::name, avg 646ns/call
# spent 97µs making 191 calls to Class::MOP::Class::CORE:match, avg 508ns/call
# spent 8µs making 1 call to Class::MOP::Class::CORE:regcomp |
225 | } | ||||
226 | |||||
227 | # spent 29.3ms (32µs+29.2) within Class::MOP::Class::create_anon_class which was called 2 times, avg 14.6ms/call:
# 2 times (32µs+29.2ms) by Moose::Meta::Class::create_anon_class at line 125 of Moose/Meta/Class.pm, avg 14.6ms/call | ||||
228 | 2 | 4µs | my ($class, %options) = @_; | ||
229 | 2 | 4µs | my $package_name = $ANON_CLASS_PREFIX . ++$ANON_CLASS_SERIAL; | ||
230 | 2 | 23µs | 2 | 29.2ms | return $class->create($package_name, %options); # spent 29.2ms making 2 calls to Moose::Meta::Class::create, avg 14.6ms/call |
231 | } | ||||
232 | |||||
233 | # NOTE: | ||||
234 | # this will only get called for | ||||
235 | # anon-classes, all other calls | ||||
236 | # are assumed to occur during | ||||
237 | # global destruction and so don't | ||||
238 | # really need to be handled explicitly | ||||
239 | # spent 66µs (33+33) within Class::MOP::Class::DESTROY which was called 2 times, avg 33µs/call:
# once (17µs+28µs) by Moose::Util::MetaRole::apply_metaroles at line 25 of MooseX/ClassAttribute.pm
# once (16µs+4µs) by Moose::Meta::Class::_reinitialize_with at line 406 of Moose/Meta/Class.pm | ||||
240 | 2 | 1µs | my $self = shift; | ||
241 | |||||
242 | 2 | 23µs | 2 | 13µs | return if in_global_destruction(); # it'll happen soon anyway and this just makes things more complicated # spent 13µs making 2 calls to Devel::GlobalDestruction::in_global_destruction, avg 6µs/call |
243 | |||||
244 | 3 | 75µs | 2 | 29µs | # spent 19µs (9+10) within Class::MOP::Class::BEGIN@244 which was called
# once (9µs+10µs) by Class::MOP::BEGIN@18 at line 244 # spent 19µs making 1 call to Class::MOP::Class::BEGIN@244
# spent 10µs making 1 call to warnings::unimport |
245 | 2 | 9µs | 2 | 2µs | my $name = $self->name; # spent 2µs making 2 calls to Class::MOP::Package::name, avg 900ns/call |
246 | 2 | 39µs | 3 | 18µs | return unless $name =~ /^$ANON_CLASS_PREFIX/o; # spent 18µs making 1 call to Class::MOP::Class::CORE:regcomp
# spent 600ns making 2 calls to Class::MOP::Class::CORE:match, avg 300ns/call |
247 | |||||
248 | # Moose does a weird thing where it replaces the metaclass for | ||||
249 | # class when fixing metaclass incompatibility. In that case, | ||||
250 | # we don't want to clean out the namespace now. We can detect | ||||
251 | # that because Moose will explicitly update the singleton | ||||
252 | # cache in Class::MOP. | ||||
253 | my $current_meta = Class::MOP::get_metaclass_by_name($name); | ||||
254 | return if $current_meta ne $self; | ||||
255 | |||||
256 | my ($serial_id) = ($name =~ /^$ANON_CLASS_PREFIX(\d+)/o); | ||||
257 | 3 | 2.85ms | 2 | 30µs | # spent 19µs (7+11) within Class::MOP::Class::BEGIN@257 which was called
# once (7µs+11µs) by Class::MOP::BEGIN@18 at line 257 # spent 19µs making 1 call to Class::MOP::Class::BEGIN@257
# spent 11µs making 1 call to strict::unimport |
258 | @{$name . '::ISA'} = (); | ||||
259 | %{$name . '::'} = (); | ||||
260 | delete ${$ANON_CLASS_PREFIX}{$serial_id . '::'}; | ||||
261 | |||||
262 | Class::MOP::remove_metaclass_by_name($name); | ||||
263 | } | ||||
264 | |||||
265 | } | ||||
266 | |||||
267 | # creating classes with MOP ... | ||||
268 | |||||
269 | # spent 4.96ms (218µs+4.75) within Class::MOP::Class::create which was called 5 times, avg 993µs/call:
# 3 times (127µs+4.27ms) by Moose::Meta::Class::create at line 92 of Moose/Meta/Class.pm, avg 1.46ms/call
# 2 times (91µs+480µs) by Class::MOP::Class::_immutable_metaclass at line 961, avg 285µs/call | ||||
270 | 5 | 10µs | my ( $class, @args ) = @_; | ||
271 | |||||
272 | 5 | 11µs | unshift @args, 'package' if @args % 2 == 1; | ||
273 | |||||
274 | 5 | 8µs | my (%options) = @args; | ||
275 | 5 | 4µs | my $package_name = $options{package}; | ||
276 | |||||
277 | 5 | 8µs | (ref $options{superclasses} eq 'ARRAY') | ||
278 | || confess "You must pass an ARRAY ref of superclasses" | ||||
279 | if exists $options{superclasses}; | ||||
280 | |||||
281 | 5 | 3µs | (ref $options{attributes} eq 'ARRAY') | ||
282 | || confess "You must pass an ARRAY ref of attributes" | ||||
283 | if exists $options{attributes}; | ||||
284 | |||||
285 | 5 | 3µs | (ref $options{methods} eq 'HASH') | ||
286 | || confess "You must pass a HASH ref of methods" | ||||
287 | if exists $options{methods}; | ||||
288 | |||||
289 | 5 | 5µs | my (%initialize_options) = @args; | ||
290 | 5 | 10µs | delete @initialize_options{qw( | ||
291 | package | ||||
292 | superclasses | ||||
293 | attributes | ||||
294 | methods | ||||
295 | version | ||||
296 | authority | ||||
297 | )}; | ||||
298 | 5 | 12µs | 5 | 2.27ms | my $meta = $class->initialize( $package_name => %initialize_options ); # spent 2.14ms making 3 calls to Moose::Meta::Class::initialize, avg 714µs/call
# spent 129µs making 2 calls to Class::MOP::Class::initialize, avg 65µs/call |
299 | |||||
300 | 5 | 38µs | 5 | 139µs | $meta->_instantiate_module( $options{version}, $options{authority} ); # spent 139µs making 5 calls to Class::MOP::Module::_instantiate_module, avg 28µs/call |
301 | |||||
302 | # FIXME totally lame | ||||
303 | $meta->add_method('meta' => sub { | ||||
304 | 4 | 22µs | 4 | 12µs | $class->initialize(ref($_[0]) || $_[0]); # spent 22µs making 4 calls to Moose::Meta::Class::initialize, avg 6µs/call, recursion: max depth 1, time 10µs |
305 | 5 | 33µs | 5 | 190µs | }); # spent 190µs making 5 calls to Class::MOP::Mixin::HasMethods::add_method, avg 38µs/call |
306 | |||||
307 | 5 | 16µs | 5 | 204µs | $meta->superclasses(@{$options{superclasses}}) # spent 204µs making 2 calls to Class::MOP::Class::superclasses, avg 102µs/call
# spent 1.94ms making 3 calls to Moose::Meta::Class::superclasses, avg 647µs/call, recursion: max depth 1, time 1.94ms |
308 | if exists $options{superclasses}; | ||||
309 | # NOTE: | ||||
310 | # process attributes first, so that they can | ||||
311 | # install accessors, but locally defined methods | ||||
312 | # can then overwrite them. It is maybe a little odd, but | ||||
313 | # I think this should be the order of things. | ||||
314 | 5 | 4µs | if (exists $options{attributes}) { | ||
315 | foreach my $attr (@{$options{attributes}}) { | ||||
316 | $meta->add_attribute($attr); | ||||
317 | } | ||||
318 | } | ||||
319 | 5 | 3µs | if (exists $options{methods}) { | ||
320 | foreach my $method_name (keys %{$options{methods}}) { | ||||
321 | $meta->add_method($method_name, $options{methods}->{$method_name}); | ||||
322 | } | ||||
323 | } | ||||
324 | 5 | 22µs | return $meta; | ||
325 | } | ||||
326 | |||||
327 | ## Attribute readers | ||||
328 | |||||
329 | # NOTE: | ||||
330 | # all these attribute readers will be bootstrapped | ||||
331 | # away in the Class::MOP bootstrap section | ||||
332 | |||||
333 | 730 | 1.54ms | # spent 916µs within Class::MOP::Class::instance_metaclass which was called 730 times, avg 1µs/call:
# 258 times (328µs+0s) by Class::MOP::Class::_check_metaclass_compatibility at line 198, avg 1µs/call
# 124 times (158µs+0s) by Class::MOP::Class::_create_meta_instance at line 390, avg 1µs/call
# 94 times (140µs+0s) by Moose::Meta::Class::_superclass_meta_is_compatible at line 378 of Moose/Meta/Class.pm, avg 1µs/call
# 84 times (83µs+0s) by Class::MOP::Attribute::_process_accessors at line 320 of Class/MOP/Attribute.pm, avg 987ns/call
# 61 times (78µs+0s) by Class::MOP::Class::_check_metaclass_compatibility at line 172, avg 1µs/call
# 52 times (53µs+0s) by Class::MOP::Method::Accessor::_generate_reader_method_inline at line 155 of Class/MOP/Method/Accessor.pm, avg 1µs/call
# 31 times (34µs+0s) by Class::MOP::Method::Accessor::_generate_predicate_method_inline at line 190 of Class/MOP/Method/Accessor.pm, avg 1µs/call
# 15 times (29µs+0s) by Class::MOP::Method::Accessor::_generate_accessor_method_inline at line 136 of Class/MOP/Method/Accessor.pm, avg 2µs/call
# 3 times (3µs+0s) by Class::MOP::Method::Accessor::_generate_clearer_method_inline at line 207 of Class/MOP/Method/Accessor.pm, avg 1µs/call
# 3 times (3µs+0s) by Class::MOP::Method::Accessor::_generate_writer_method_inline at line 173 of Class/MOP/Method/Accessor.pm, avg 967ns/call
# 2 times (3µs+0s) by List::MoreUtils::all at line 407 of Moose/Meta/Class.pm, avg 2µs/call
# 2 times (2µs+0s) by Moose::Meta::Class::reinitialize at line 151 of Moose/Meta/Class.pm, avg 1µs/call
# once (1µs+0s) by Moose::Meta::Class::_reinitialize_with at line 418 of Moose/Meta/Class.pm | ||
334 | 100 | 216µs | sub immutable_trait { $_[0]->{'immutable_trait'} } | ||
335 | 50 | 87µs | # spent 55µs within Class::MOP::Class::constructor_class which was called 50 times, avg 1µs/call:
# 50 times (55µs+0s) by Class::MOP::Class::_immutable_options at line 876, avg 1µs/call | ||
336 | 57 | 111µs | # spent 80µs within Class::MOP::Class::constructor_name which was called 57 times, avg 1µs/call:
# 57 times (80µs+0s) by Class::MOP::Class::_immutable_options at line 876, avg 1µs/call | ||
337 | 50 | 71µs | # spent 42µs within Class::MOP::Class::destructor_class which was called 50 times, avg 832ns/call:
# 50 times (42µs+0s) by Class::MOP::Class::_immutable_options at line 876, avg 832ns/call | ||
338 | |||||
339 | # Instance Construction & Cloning | ||||
340 | |||||
341 | # spent 88.9ms (747µs+88.2) within Class::MOP::Class::new_object which was called 65 times, avg 1.37ms/call:
# 50 times (613µs+84.3ms) by Moose::Meta::Class::new_object at line 255 of Moose/Meta/Class.pm, avg 1.70ms/call
# 11 times (83µs+1.99ms) by Moose::Meta::TypeCoercion::new at line 34 of Moose/Meta/TypeCoercion.pm, avg 188µs/call
# 2 times (20µs+955µs) by Class::MOP::Method::_new at line 54 of Class/MOP/Method.pm, avg 488µs/call
# once (17µs+613µs) by Class::MOP::Attribute::_new at line 62 of Class/MOP/Attribute.pm
# once (13µs+290µs) by Class::MOP::Object::_new at line 21 of Class/MOP/Object.pm | ||||
342 | 65 | 25µs | my $class = shift; | ||
343 | |||||
344 | # NOTE: | ||||
345 | # we need to protect the integrity of the | ||||
346 | # Class::MOP::Class singletons here, so we | ||||
347 | # delegate this to &construct_class_instance | ||||
348 | # which will deal with the singletons | ||||
349 | 65 | 776µs | 130 | 342µs | return $class->_construct_class_instance(@_) # spent 232µs making 65 calls to UNIVERSAL::isa, avg 4µs/call
# spent 111µs making 65 calls to Class::MOP::Package::name, avg 2µs/call |
350 | if $class->name->isa('Class::MOP::Class'); | ||||
351 | 65 | 287µs | 65 | 87.8ms | return $class->_construct_instance(@_); # spent 87.8ms making 65 calls to Class::MOP::Class::_construct_instance, avg 1.35ms/call |
352 | } | ||||
353 | |||||
354 | # spent 105ms (4.94+100) within Class::MOP::Class::_construct_instance which was called 97 times, avg 1.08ms/call:
# 65 times (2.93ms+84.9ms) by Class::MOP::Class::new_object at line 351, avg 1.35ms/call
# 32 times (2.01ms+15.4ms) by Class::MOP::Class::_construct_class_instance at line 87, avg 544µs/call | ||||
355 | 97 | 32µs | my $class = shift; | ||
356 | 97 | 73µs | my $params = @_ == 1 ? $_[0] : {@_}; | ||
357 | 97 | 207µs | 97 | 2.36ms | my $meta_instance = $class->get_meta_instance(); # spent 1.93ms making 57 calls to Class::MOP::Class::get_meta_instance, avg 34µs/call
# spent 422µs making 40 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 11µs/call |
358 | # FIXME: | ||||
359 | # the code below is almost certainly incorrect | ||||
360 | # but this is foreign inheritance, so we might | ||||
361 | # have to kludge it in the end. | ||||
362 | 97 | 302µs | 97 | 1.78ms | my $instance = $params->{__INSTANCE__} || $meta_instance->create_instance(); # spent 1.78ms making 97 calls to Class::MOP::Instance::create_instance, avg 18µs/call |
363 | 97 | 323µs | 97 | 4.88ms | foreach my $attr ($class->get_all_attributes()) { # spent 4.25ms making 57 calls to Class::MOP::Class::get_all_attributes, avg 75µs/call
# spent 627µs making 40 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 16µs/call |
364 | 1199 | 1.86ms | 1199 | 90.5ms | $attr->initialize_instance_slot($meta_instance, $instance, $params); # spent 75.7ms making 415 calls to Moose::Meta::Attribute::initialize_instance_slot, avg 182µs/call
# spent 14.8ms making 784 calls to Class::MOP::Attribute::initialize_instance_slot, avg 19µs/call |
365 | } | ||||
366 | # NOTE: | ||||
367 | # this will only work for a HASH instance type | ||||
368 | 97 | 226µs | 97 | 758µs | if ($class->is_anon_class) { # spent 758µs making 97 calls to Class::MOP::Class::is_anon_class, avg 8µs/call |
369 | 3 | 14µs | 3 | 5µs | (reftype($instance) eq 'HASH') # spent 5µs making 3 calls to Scalar::Util::reftype, avg 2µs/call |
370 | || confess "Currently only HASH based instances are supported with instance of anon-classes"; | ||||
371 | # NOTE: | ||||
372 | # At some point we should make this official | ||||
373 | # as a reserved slot name, but right now I am | ||||
374 | # going to keep it here. | ||||
375 | # my $RESERVED_MOP_SLOT = '__MOP__'; | ||||
376 | 3 | 4µs | $instance->{'__MOP__'} = $class; | ||
377 | } | ||||
378 | 97 | 238µs | return $instance; | ||
379 | } | ||||
380 | |||||
381 | |||||
382 | # spent 23.2ms (1.28+22.0) within Class::MOP::Class::get_meta_instance which was called 595 times, avg 39µs/call:
# 324 times (539µs+0s) by Class::MOP::Attribute::set_initial_value at line 251 of Class/MOP/Attribute.pm, avg 2µs/call
# 89 times (290µs+13.9ms) by Moose::Meta::Method::Accessor::_inline_get at line 252 of Moose/Meta/Method/Accessor.pm, avg 159µs/call
# 57 times (182µs+1.75ms) by Class::MOP::Class::_construct_instance at line 357, avg 34µs/call
# 42 times (95µs+2.45ms) by Moose::Meta::Method::Accessor::_inline_store at line 218 of Moose/Meta/Method/Accessor.pm, avg 61µs/call
# 37 times (101µs+3.45ms) by Class::MOP::Method::Constructor::_meta_instance at line 77 of Class/MOP/Method/Constructor.pm, avg 96µs/call
# 22 times (28µs+0s) by Moose::Meta::Method::Accessor::_inline_has at line 270 of Moose/Meta/Method/Accessor.pm, avg 1µs/call
# 6 times (10µs+100µs) by Class::MOP::Class::_clone_instance at line 419, avg 18µs/call
# 6 times (14µs+0s) by Class::MOP::Class:::around at line 74 of Class/MOP/Class/Immutable/Trait.pm, avg 2µs/call
# 6 times (8µs+0s) by Class::MOP::Attribute::set_raw_value at line 264 of Class/MOP/Attribute.pm, avg 1µs/call
# 3 times (4µs+0s) by Class::MOP::Attribute::get_raw_value at line 272 of Class/MOP/Attribute.pm, avg 1µs/call
# once (6µs+196µs) by Moose::Exporter::BEGIN@11 at line 663 of Class/MOP.pm
# once (3µs+109µs) by Moose::Meta::Method::Accessor::_inline_get_old_value_for_trigger at line 232 of Moose/Meta/Method/Accessor.pm
# once (2µs+0s) by Class::MOP::Attribute::has_value at line 280 of Class/MOP/Attribute.pm | ||||
383 | 595 | 153µs | my $self = shift; | ||
384 | 595 | 1.49ms | 124 | 22.0ms | $self->{'_meta_instance'} ||= $self->_create_meta_instance(); # spent 22.0ms making 124 calls to Class::MOP::Class::_create_meta_instance, avg 177µs/call |
385 | } | ||||
386 | |||||
387 | # spent 22.0ms (1.54+20.4) within Class::MOP::Class::_create_meta_instance which was called 124 times, avg 177µs/call:
# 124 times (1.54ms+20.4ms) by Class::MOP::Class::get_meta_instance at line 384, avg 177µs/call | ||||
388 | 124 | 20µs | my $self = shift; | ||
389 | |||||
390 | 124 | 698µs | 372 | 20.3ms | my $instance = $self->instance_metaclass->new( # spent 12.6ms making 124 calls to Class::MOP::Instance::new, avg 101µs/call
# spent 7.55ms making 124 calls to Class::MOP::Class::get_all_attributes, avg 61µs/call
# spent 158µs making 124 calls to Class::MOP::Class::instance_metaclass, avg 1µs/call |
391 | associated_metaclass => $self, | ||||
392 | attributes => [ $self->get_all_attributes() ], | ||||
393 | ); | ||||
394 | |||||
395 | 124 | 171µs | 124 | 122µs | $self->add_meta_instance_dependencies() # spent 122µs making 124 calls to Class::MOP::Instance::is_dependent_on_superclasses, avg 981ns/call |
396 | if $instance->is_dependent_on_superclasses(); | ||||
397 | |||||
398 | 124 | 241µs | return $instance; | ||
399 | } | ||||
400 | |||||
401 | # spent 19.0ms (1.54+17.5) within Class::MOP::Class::clone_object which was called 154 times, avg 123µs/call:
# 154 times (1.54ms+17.5ms) by Class::MOP::Method::clone at line 538 of Class/MOP.pm, avg 123µs/call | ||||
402 | 154 | 37µs | my $class = shift; | ||
403 | 154 | 23µs | my $instance = shift; | ||
404 | 154 | 980µs | 462 | 264µs | (blessed($instance) && $instance->isa($class->name)) # spent 108µs making 154 calls to UNIVERSAL::isa, avg 699ns/call
# spent 81µs making 154 calls to Scalar::Util::blessed, avg 525ns/call
# spent 75µs making 154 calls to Class::MOP::Package::name, avg 488ns/call |
405 | || confess "You must pass an instance of the metaclass (" . (ref $class ? $class->name : $class) . "), not ($instance)"; | ||||
406 | |||||
407 | # NOTE: | ||||
408 | # we need to protect the integrity of the | ||||
409 | # Class::MOP::Class singletons here, they | ||||
410 | # should not be cloned. | ||||
411 | 154 | 405µs | 154 | 180µs | return $instance if $instance->isa('Class::MOP::Class'); # spent 180µs making 154 calls to UNIVERSAL::isa, avg 1µs/call |
412 | 154 | 405µs | 154 | 17.0ms | $class->_clone_instance($instance, @_); # spent 17.0ms making 154 calls to Class::MOP::Class::_clone_instance, avg 111µs/call |
413 | } | ||||
414 | |||||
415 | # spent 17.0ms (4.46+12.6) within Class::MOP::Class::_clone_instance which was called 154 times, avg 111µs/call:
# 154 times (4.46ms+12.6ms) by Class::MOP::Class::clone_object at line 412, avg 111µs/call | ||||
416 | 154 | 211µs | my ($class, $instance, %params) = @_; | ||
417 | 154 | 330µs | 154 | 75µs | (blessed($instance)) # spent 75µs making 154 calls to Scalar::Util::blessed, avg 488ns/call |
418 | || confess "You can only clone instances, ($instance) is not a blessed instance"; | ||||
419 | 154 | 184µs | 154 | 1.34ms | my $meta_instance = $class->get_meta_instance(); # spent 1.23ms making 148 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 8µs/call
# spent 110µs making 6 calls to Class::MOP::Class::get_meta_instance, avg 18µs/call |
420 | 154 | 252µs | 154 | 1.44ms | my $clone = $meta_instance->clone_instance($instance); # spent 1.44ms making 154 calls to Class::MOP::Instance::clone_instance, avg 9µs/call |
421 | 154 | 304µs | 154 | 1.48ms | foreach my $attr ($class->get_all_attributes()) { # spent 1.25ms making 148 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 8µs/call
# spent 228µs making 6 calls to Class::MOP::Class::get_all_attributes, avg 38µs/call |
422 | 770 | 1.52ms | 1060 | 8.22ms | if ( defined( my $init_arg = $attr->init_arg ) ) { # spent 7.31ms making 290 calls to Class::MOP::Attribute::set_value, avg 25µs/call
# spent 911µs making 770 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 1µs/call |
423 | if (exists $params{$init_arg}) { | ||||
424 | $attr->set_value($clone, $params{$init_arg}); | ||||
425 | } | ||||
426 | } | ||||
427 | } | ||||
428 | 154 | 381µs | return $clone; | ||
429 | } | ||||
430 | |||||
431 | sub rebless_instance { | ||||
432 | my ($self, $instance, %params) = @_; | ||||
433 | |||||
434 | my $old_metaclass = Class::MOP::class_of($instance); | ||||
435 | |||||
436 | my $old_class = $old_metaclass ? $old_metaclass->name : blessed($instance); | ||||
437 | $self->name->isa($old_class) | ||||
438 | || confess "You may rebless only into a subclass of ($old_class), of which (". $self->name .") isn't."; | ||||
439 | |||||
440 | $old_metaclass->rebless_instance_away($instance, $self, %params) | ||||
441 | if $old_metaclass; | ||||
442 | |||||
443 | my $meta_instance = $self->get_meta_instance(); | ||||
444 | |||||
445 | # rebless! | ||||
446 | # we use $_[1] here because of t/306_rebless_overload.t regressions on 5.8.8 | ||||
447 | $meta_instance->rebless_instance_structure($_[1], $self); | ||||
448 | |||||
449 | foreach my $attr ( $self->get_all_attributes ) { | ||||
450 | if ( $attr->has_value($instance) ) { | ||||
451 | if ( defined( my $init_arg = $attr->init_arg ) ) { | ||||
452 | $params{$init_arg} = $attr->get_value($instance) | ||||
453 | unless exists $params{$init_arg}; | ||||
454 | } | ||||
455 | else { | ||||
456 | $attr->set_value($instance, $attr->get_value($instance)); | ||||
457 | } | ||||
458 | } | ||||
459 | } | ||||
460 | |||||
461 | foreach my $attr ($self->get_all_attributes) { | ||||
462 | $attr->initialize_instance_slot($meta_instance, $instance, \%params); | ||||
463 | } | ||||
464 | |||||
465 | $instance; | ||||
466 | } | ||||
467 | |||||
468 | sub rebless_instance_back { | ||||
469 | my ( $self, $instance ) = @_; | ||||
470 | |||||
471 | my $old_metaclass = Class::MOP::class_of($instance); | ||||
472 | |||||
473 | my $old_class | ||||
474 | = $old_metaclass ? $old_metaclass->name : blessed($instance); | ||||
475 | $old_class->isa( $self->name ) | ||||
476 | || confess | ||||
477 | "You may rebless only into a superclass of ($old_class), of which (" | ||||
478 | . $self->name | ||||
479 | . ") isn't."; | ||||
480 | |||||
481 | $old_metaclass->rebless_instance_away( $instance, $self ) | ||||
482 | if $old_metaclass; | ||||
483 | |||||
484 | my $meta_instance = $self->get_meta_instance; | ||||
485 | |||||
486 | # we use $_[1] here because of t/306_rebless_overload.t regressions on 5.8.8 | ||||
487 | $meta_instance->rebless_instance_structure( $_[1], $self ); | ||||
488 | |||||
489 | for my $attr ( $old_metaclass->get_all_attributes ) { | ||||
490 | next if $self->has_attribute( $attr->name ); | ||||
491 | $meta_instance->deinitialize_slot( $instance, $_ ) for $attr->slots; | ||||
492 | } | ||||
493 | |||||
494 | return $instance; | ||||
495 | } | ||||
496 | |||||
497 | sub rebless_instance_away { | ||||
498 | # this intentionally does nothing, it is just a hook | ||||
499 | } | ||||
500 | |||||
501 | # spent 2.45ms (674µs+1.77) within Class::MOP::Class::_attach_attribute which was called 201 times, avg 12µs/call:
# 201 times (674µs+1.77ms) by Class::MOP::Mixin::HasAttributes::add_attribute at line 28 of Class/MOP/Mixin/HasAttributes.pm, avg 12µs/call | ||||
502 | 201 | 89µs | my ($self, $attribute) = @_; | ||
503 | 201 | 523µs | 201 | 1.77ms | $attribute->attach_to_class($self); # spent 1.77ms making 201 calls to Class::MOP::Attribute::attach_to_class, avg 9µs/call |
504 | } | ||||
505 | |||||
506 | # spent 111ms (2.20+109) within Class::MOP::Class::_post_add_attribute which was called 201 times, avg 554µs/call:
# 201 times (2.20ms+109ms) by Class::MOP::Mixin::HasAttributes::add_attribute at line 45 of Class/MOP/Mixin/HasAttributes.pm, avg 554µs/call | ||||
507 | 201 | 81µs | my ( $self, $attribute ) = @_; | ||
508 | |||||
509 | 201 | 240µs | 201 | 1.65ms | $self->invalidate_meta_instances; # spent 1.65ms making 201 calls to Class::MOP::Class::invalidate_meta_instances, avg 8µs/call |
510 | |||||
511 | # invalidate package flag here | ||||
512 | # spent 105ms (1.24+103) within Class::MOP::Class::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP/Class.pm:515] which was called 201 times, avg 520µs/call:
# 201 times (1.24ms+103ms) by Try::Tiny::try at line 76 of Try/Tiny.pm, avg 520µs/call | ||||
513 | 201 | 405µs | local $SIG{__DIE__}; | ||
514 | 201 | 749µs | 201 | 103ms | $attribute->install_accessors; # spent 73.5ms making 85 calls to Moose::Meta::Attribute::install_accessors, avg 865µs/call
# spent 20.0ms making 114 calls to Class::MOP::Attribute::install_accessors, avg 176µs/call
# spent 9.77ms making 2 calls to MooseX::AttributeHelpers::Collection::Hash::install_accessors, avg 4.89ms/call |
515 | } | ||||
516 | catch { | ||||
517 | $self->remove_attribute( $attribute->name ); | ||||
518 | die $_; | ||||
519 | 201 | 1.45ms | 402 | 38.1ms | }; # spent 107ms making 201 calls to Try::Tiny::try, avg 532µs/call, recursion: max depth 1, time 69.5ms
# spent 666µs making 201 calls to Try::Tiny::catch, avg 3µs/call |
520 | } | ||||
521 | |||||
522 | sub remove_attribute { | ||||
523 | my $self = shift; | ||||
524 | |||||
525 | my $removed_attribute = $self->SUPER::remove_attribute(@_) | ||||
526 | or return; | ||||
527 | |||||
528 | $self->invalidate_meta_instances; | ||||
529 | |||||
530 | $removed_attribute->remove_accessors; | ||||
531 | $removed_attribute->detach_from_class; | ||||
532 | |||||
533 | return$removed_attribute; | ||||
534 | } | ||||
535 | |||||
536 | # spent 5.98ms (2.00+3.98) within Class::MOP::Class::find_attribute_by_name which was called 158 times, avg 38µs/call:
# 79 times (966µs+1.85ms) by SimpleDB::Class::Item::stringify_values at line 613 of ../lib/SimpleDB/Class/Item.pm, avg 36µs/call
# 57 times (635µs+1.39ms) by Class::MOP::Class::_immutable_metaclass at line 935, avg 35µs/call
# 18 times (311µs+575µs) by SimpleDB::Class::Item::stringify_value at line 574 of ../lib/SimpleDB/Class/Item.pm, avg 49µs/call
# 4 times (86µs+176µs) by SimpleDB::Class::Item::parse_value at line 541 of ../lib/SimpleDB/Class/Item.pm, avg 66µs/call | ||||
537 | 158 | 102µs | my ( $self, $attr_name ) = @_; | ||
538 | |||||
539 | 158 | 260µs | 158 | 1.37ms | foreach my $class ( $self->linearized_isa ) { # spent 877µs making 106 calls to Class::MOP::Class::linearized_isa, avg 8µs/call
# spent 493µs making 52 calls to Class::MOP::Class::Immutable::Class::MOP::Class::linearized_isa, avg 9µs/call |
540 | # fetch the meta-class ... | ||||
541 | 161 | 190µs | 161 | 765µs | my $meta = $self->initialize($class); # spent 503µs making 105 calls to Moose::Meta::Class::initialize, avg 5µs/call
# spent 262µs making 56 calls to Class::MOP::Class::initialize, avg 5µs/call |
542 | 161 | 844µs | 319 | 1.85ms | return $meta->get_attribute($attr_name) # spent 1.02ms making 161 calls to Class::MOP::Mixin::HasAttributes::has_attribute, avg 6µs/call
# spent 827µs making 158 calls to Class::MOP::Mixin::HasAttributes::get_attribute, avg 5µs/call |
543 | if $meta->has_attribute($attr_name); | ||||
544 | } | ||||
545 | |||||
546 | return; | ||||
547 | } | ||||
548 | |||||
549 | # spent 17.5ms (8.82+8.69) within Class::MOP::Class::get_all_attributes which was called 284 times, avg 62µs/call:
# 124 times (3.81ms+3.74ms) by Class::MOP::Class::_create_meta_instance at line 390, avg 61µs/call
# 57 times (2.18ms+2.07ms) by Class::MOP::Class::_construct_instance at line 363, avg 75µs/call
# 50 times (1.39ms+1.32ms) by Moose::Meta::Class::new_object at line 257 of Moose/Meta/Class.pm, avg 54µs/call
# 37 times (876µs+902µs) by Class::MOP::Method::Constructor::_attributes at line 82 of Class/MOP/Method/Constructor.pm, avg 48µs/call
# 6 times (217µs+279µs) by Class::MOP::Class:::around at line 68 of Class/MOP/Class/Immutable/Trait.pm, avg 83µs/call
# 6 times (93µs+135µs) by Class::MOP::Class::_clone_instance at line 421, avg 38µs/call
# 4 times (250µs+240µs) by Moose::Meta::Attribute::new at line 59 of Moose/Meta/Attribute.pm, avg 123µs/call | ||||
550 | 284 | 61µs | my $self = shift; | ||
551 | 2486 | 5.13ms | 2486 | 8.51ms | my %attrs = map { %{ $self->initialize($_)->_attribute_map } } # spent 3.66ms making 801 calls to Moose::Meta::Class::initialize, avg 5µs/call, recursion: max depth 1, time 70µs
# spent 2.12ms making 278 calls to Class::MOP::Class::linearized_isa, avg 8µs/call
# spent 1.49ms making 300 calls to Class::MOP::Class::initialize, avg 5µs/call, recursion: max depth 1, time 103µs
# spent 1.29ms making 1101 calls to Class::MOP::Mixin::HasAttributes::_attribute_map, avg 1µs/call
# spent 133µs making 6 calls to Class::MOP::Class::Immutable::Class::MOP::Class::linearized_isa, avg 22µs/call |
552 | reverse $self->linearized_isa; | ||||
553 | 284 | 1.11ms | return values %attrs; | ||
554 | } | ||||
555 | |||||
556 | # Inheritance | ||||
557 | |||||
558 | # spent 15.2ms (2.65+12.6) within Class::MOP::Class::superclasses which was called 180 times, avg 84µs/call:
# 166 times (2.46ms+12.3ms) by Moose::Meta::Class::superclasses at line 289 of Moose/Meta/Class.pm, avg 89µs/call
# 12 times (69µs+147µs) by Class::MOP::Class:::around at line 27 of Class/MOP/Class/Immutable/Trait.pm, avg 18µs/call
# 2 times (114µs+90µs) by Class::MOP::Class::create at line 307, avg 102µs/call | ||||
559 | 180 | 39µs | my $self = shift; | ||
560 | 180 | 312µs | my $var_spec = { sigil => '@', type => 'ARRAY', name => 'ISA' }; | ||
561 | 180 | 43µs | if (@_) { | ||
562 | 48 | 31µs | my @supers = @_; | ||
563 | 48 | 662µs | 48 | 450µs | @{$self->get_package_symbol($var_spec)} = @supers; # spent 450µs making 48 calls to Class::MOP::Package::get_package_symbol, avg 9µs/call |
564 | |||||
565 | # NOTE: | ||||
566 | # on 5.8 and below, we need to call | ||||
567 | # a method to get Perl to detect | ||||
568 | # a cycle in the class hierarchy | ||||
569 | 48 | 168µs | 48 | 41µs | my $class = $self->name; # spent 41µs making 48 calls to Class::MOP::Package::name, avg 846ns/call |
570 | 48 | 363µs | 48 | 58µs | $class->isa($class); # spent 58µs making 48 calls to UNIVERSAL::isa, avg 1µs/call |
571 | |||||
572 | # NOTE: | ||||
573 | # we need to check the metaclass | ||||
574 | # compatibility here so that we can | ||||
575 | # be sure that the superclass is | ||||
576 | # not potentially creating an issues | ||||
577 | # we don't know about | ||||
578 | |||||
579 | 48 | 77µs | 48 | 10.5ms | $self->_check_metaclass_compatibility(); # spent 10.5ms making 46 calls to Moose::Meta::Class::_check_metaclass_compatibility, avg 229µs/call
# spent 11µs making 2 calls to Class::MOP::Class::_check_metaclass_compatibility, avg 5µs/call |
580 | 48 | 101µs | 48 | 285µs | $self->_superclasses_updated(); # spent 285µs making 48 calls to Class::MOP::Class::_superclasses_updated, avg 6µs/call |
581 | } | ||||
582 | 180 | 716µs | 180 | 1.85ms | @{$self->get_package_symbol($var_spec)}; # spent 1.85ms making 180 calls to Class::MOP::Package::get_package_symbol, avg 10µs/call |
583 | } | ||||
584 | |||||
585 | # spent 285µs (198+87) within Class::MOP::Class::_superclasses_updated which was called 48 times, avg 6µs/call:
# 48 times (198µs+87µs) by Class::MOP::Class::superclasses at line 580, avg 6µs/call | ||||
586 | 48 | 15µs | my $self = shift; | ||
587 | 48 | 153µs | 48 | 87µs | $self->update_meta_instance_dependencies(); # spent 87µs making 48 calls to Class::MOP::Class::update_meta_instance_dependencies, avg 2µs/call |
588 | } | ||||
589 | |||||
590 | sub subclasses { | ||||
591 | my $self = shift; | ||||
592 | my $super_class = $self->name; | ||||
593 | |||||
594 | return @{ $super_class->mro::get_isarev() }; | ||||
595 | } | ||||
596 | |||||
597 | sub direct_subclasses { | ||||
598 | my $self = shift; | ||||
599 | my $super_class = $self->name; | ||||
600 | |||||
601 | return grep { | ||||
602 | grep { | ||||
603 | $_ eq $super_class | ||||
604 | } Class::MOP::Class->initialize($_)->superclasses | ||||
605 | } $self->subclasses; | ||||
606 | } | ||||
607 | |||||
608 | # spent 5.15ms (3.52+1.63) within Class::MOP::Class::linearized_isa which was called 705 times, avg 7µs/call:
# 278 times (1.46ms+662µs) by Class::MOP::Class::get_all_attributes at line 551, avg 8µs/call
# 135 times (606µs+281µs) by Class::MOP::Class::find_next_method_by_name at line 776, avg 7µs/call
# 106 times (580µs+297µs) by Class::MOP::Class::find_attribute_by_name at line 539, avg 8µs/call
# 86 times (395µs+194µs) by Class::MOP::Class::find_method_by_name at line 728, avg 7µs/call
# 78 times (372µs+151µs) by Class::MOP::Class::_check_metaclass_compatibility at line 175, avg 7µs/call
# 12 times (54µs+24µs) by Class::MOP::Class::find_all_methods_by_name at line 760, avg 6µs/call
# 7 times (41µs+14µs) by Class::MOP::Class:::around at line 50 of Class/MOP/Class/Immutable/Trait.pm, avg 8µs/call
# 3 times (14µs+8µs) by Class::MOP::Class::get_all_methods at line 739, avg 7µs/call | ||||
609 | 705 | 5.83ms | 1410 | 1.63ms | return @{ mro::get_linear_isa( (shift)->name ) }; # spent 1.22ms making 705 calls to mro::get_linear_isa, avg 2µs/call
# spent 413µs making 705 calls to Class::MOP::Package::name, avg 586ns/call |
610 | } | ||||
611 | |||||
612 | # spent 1.66ms (468µs+1.19) within Class::MOP::Class::class_precedence_list which was called 27 times, avg 61µs/call:
# 13 times (282µs+1.38ms) by Moose::Meta::Class::excludes_role at line 238 of Moose/Meta/Class.pm, avg 128µs/call
# 12 times (169µs+-169µs) by Class::MOP::Class:::around at line 43 of Class/MOP/Class/Immutable/Trait.pm, avg 0s/call
# 2 times (17µs+-17µs) by Class::MOP::Class::class_precedence_list at line 638, avg 0s/call | ||||
613 | 27 | 7µs | my $self = shift; | ||
614 | 27 | 82µs | 27 | 15µs | my $name = $self->name; # spent 15µs making 27 calls to Class::MOP::Package::name, avg 563ns/call |
615 | |||||
616 | 27 | 76µs | 27 | 21µs | unless (Class::MOP::IS_RUNNING_ON_5_10()) { # spent 21µs making 27 calls to Class::MOP::__ANON__, avg 793ns/call |
617 | # NOTE: | ||||
618 | # We need to check for circular inheritance here | ||||
619 | # if we are are not on 5.10, cause 5.8 detects it | ||||
620 | # late. This will do nothing if all is well, and | ||||
621 | # blow up otherwise. Yes, it's an ugly hack, better | ||||
622 | # suggestions are welcome. | ||||
623 | # - SL | ||||
624 | ($name || return)->isa('This is a test for circular inheritance') | ||||
625 | } | ||||
626 | |||||
627 | # if our mro is c3, we can | ||||
628 | # just grab the linear_isa | ||||
629 | 27 | 108µs | 27 | 51µs | if (mro::get_mro($name) eq 'c3') { # spent 51µs making 27 calls to mro::get_mro, avg 2µs/call |
630 | return @{ mro::get_linear_isa($name) } | ||||
631 | } | ||||
632 | else { | ||||
633 | # NOTE: | ||||
634 | # we can't grab the linear_isa for dfs | ||||
635 | # since it has all the duplicates | ||||
636 | # already removed. | ||||
637 | return ( | ||||
638 | 27 | 84µs | 54 | 1.02ms | $name, # spent 2.23ms making 25 calls to Class::MOP::Class::Immutable::Class::MOP::Class::class_precedence_list, avg 89µs/call, recursion: max depth 5, time 1.36ms
# spent 71µs making 14 calls to Class::MOP::Class::initialize, avg 5µs/call
# spent 68µs making 13 calls to Moose::Meta::Class::initialize, avg 5µs/call
# spent 56µs making 2 calls to Class::MOP::Class::class_precedence_list, avg 28µs/call, recursion: max depth 1, time 56µs |
639 | map { | ||||
640 | 27 | 117µs | 27 | 322µs | $self->initialize($_)->class_precedence_list() # spent 322µs making 12 calls to Class::MOP::Class::Immutable::Class::MOP::Class::superclasses, avg 27µs/call
# spent 359µs making 15 calls to Moose::Meta::Class::superclasses, avg 24µs/call, recursion: max depth 1, time 359µs |
641 | } $self->superclasses() | ||||
642 | ); | ||||
643 | } | ||||
644 | } | ||||
645 | |||||
646 | ## Methods | ||||
647 | |||||
648 | { | ||||
649 | 1 | 200ns | # spent 22.1ms (1.88+20.2) within Class::MOP::Class::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP/Class.pm:678] which was called 100 times, avg 221µs/call:
# 65 times (1.17ms+14.3ms) by Class::MOP::Class::add_around_method_modifier at line 704, avg 237µs/call
# 22 times (401µs+3.64ms) by Class::MOP::Class::add_after_method_modifier at line 694, avg 184µs/call
# 13 times (315µs+2.32ms) by Class::MOP::Class::add_before_method_modifier at line 684, avg 202µs/call | ||
650 | 100 | 43µs | my ($self, $method_name) = @_; | ||
651 | 100 | 165µs | 100 | 149µs | my $wrapped_metaclass = $self->wrapped_method_metaclass; # spent 149µs making 100 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 1µs/call |
652 | # fetch it locally | ||||
653 | 100 | 101µs | 100 | 2.45ms | my $method = $self->get_method($method_name); # spent 2.45ms making 100 calls to Class::MOP::Mixin::HasMethods::get_method, avg 24µs/call |
654 | # if we dont have local ... | ||||
655 | 100 | 53µs | unless ($method) { | ||
656 | # try to find the next method | ||||
657 | 92 | 138µs | 92 | 7.87ms | $method = $self->find_next_method_by_name($method_name); # spent 7.87ms making 92 calls to Class::MOP::Class::find_next_method_by_name, avg 86µs/call |
658 | # die if it does not exist | ||||
659 | 92 | 11µs | (defined $method) | ||
660 | || confess "The method '$method_name' was not found in the inheritance hierarchy for " . $self->name; | ||||
661 | # and now make sure to wrap it | ||||
662 | # even if it is already wrapped | ||||
663 | # because we need a new sub ref | ||||
664 | 92 | 386µs | 184 | 4.76ms | $method = $wrapped_metaclass->wrap($method, # spent 4.70ms making 92 calls to Class::MOP::Method::Wrapped::wrap, avg 51µs/call
# spent 60µs making 92 calls to Class::MOP::Package::name, avg 648ns/call |
665 | package_name => $self->name, | ||||
666 | name => $method_name, | ||||
667 | ); | ||||
668 | } | ||||
669 | else { | ||||
670 | # now make sure we wrap it properly | ||||
671 | 8 | 91µs | 24 | 645µs | $method = $wrapped_metaclass->wrap($method, # spent 622µs making 8 calls to Class::MOP::Method::Wrapped::wrap, avg 78µs/call
# spent 19µs making 8 calls to UNIVERSAL::isa, avg 2µs/call
# spent 4µs making 8 calls to Class::MOP::Package::name, avg 512ns/call |
672 | package_name => $self->name, | ||||
673 | name => $method_name, | ||||
674 | ) unless $method->isa($wrapped_metaclass); | ||||
675 | } | ||||
676 | 100 | 211µs | 100 | 4.33ms | $self->add_method($method_name => $method); # spent 4.33ms making 100 calls to Class::MOP::Mixin::HasMethods::add_method, avg 43µs/call |
677 | 100 | 250µs | return $method; | ||
678 | 1 | 2µs | }; | ||
679 | |||||
680 | # spent 2.95ms (119µs+2.83) within Class::MOP::Class::add_before_method_modifier which was called 13 times, avg 227µs/call:
# 13 times (119µs+2.83ms) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 218 of Moose/Meta/Role/Application/ToClass.pm, avg 227µs/call | ||||
681 | 13 | 8µs | my ($self, $method_name, $method_modifier) = @_; | ||
682 | 13 | 4µs | (defined $method_name && length $method_name) | ||
683 | || confess "You must pass in a method name"; | ||||
684 | 13 | 25µs | 13 | 2.63ms | my $method = $fetch_and_prepare_method->($self, $method_name); # spent 2.63ms making 13 calls to Class::MOP::Class::__ANON__[Class/MOP/Class.pm:678], avg 202µs/call |
685 | 13 | 115µs | 26 | 200µs | $method->add_before_modifier( # spent 156µs making 13 calls to Class::MOP::Method::Wrapped::add_before_modifier, avg 12µs/call
# spent 44µs making 13 calls to Sub::Name::subname, avg 3µs/call |
686 | subname(':before' => $method_modifier) | ||||
687 | ); | ||||
688 | } | ||||
689 | |||||
690 | # spent 4.54ms (186µs+4.35) within Class::MOP::Class::add_after_method_modifier which was called 22 times, avg 206µs/call:
# 20 times (164µs+3.89ms) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 218 of Moose/Meta/Role/Application/ToClass.pm, avg 203µs/call
# 2 times (22µs+460µs) by SimpleDB::Class::Item::belongs_to at line 289 of ../lib/SimpleDB/Class/Item.pm, avg 241µs/call | ||||
691 | 22 | 13µs | my ($self, $method_name, $method_modifier) = @_; | ||
692 | 22 | 9µs | (defined $method_name && length $method_name) | ||
693 | || confess "You must pass in a method name"; | ||||
694 | 22 | 23µs | 22 | 4.04ms | my $method = $fetch_and_prepare_method->($self, $method_name); # spent 4.04ms making 22 calls to Class::MOP::Class::__ANON__[Class/MOP/Class.pm:678], avg 184µs/call |
695 | 22 | 164µs | 44 | 313µs | $method->add_after_modifier( # spent 259µs making 22 calls to Class::MOP::Method::Wrapped::add_after_modifier, avg 12µs/call
# spent 54µs making 22 calls to Sub::Name::subname, avg 2µs/call |
696 | subname(':after' => $method_modifier) | ||||
697 | ); | ||||
698 | } | ||||
699 | |||||
700 | # spent 17.4ms (497µs+16.9) within Class::MOP::Class::add_around_method_modifier which was called 65 times, avg 267µs/call:
# 55 times (417µs+13.9ms) by Class::MOP::Class::_immutable_metaclass at line 970, avg 260µs/call
# 10 times (80µs+2.96ms) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 218 of Moose/Meta/Role/Application/ToClass.pm, avg 304µs/call | ||||
701 | 65 | 37µs | my ($self, $method_name, $method_modifier) = @_; | ||
702 | 65 | 16µs | (defined $method_name && length $method_name) | ||
703 | || confess "You must pass in a method name"; | ||||
704 | 65 | 84µs | 65 | 15.4ms | my $method = $fetch_and_prepare_method->($self, $method_name); # spent 15.4ms making 65 calls to Class::MOP::Class::__ANON__[Class/MOP/Class.pm:678], avg 237µs/call |
705 | 65 | 464µs | 130 | 1.44ms | $method->add_around_modifier( # spent 1.28ms making 65 calls to Class::MOP::Method::Wrapped::add_around_modifier, avg 20µs/call
# spent 158µs making 65 calls to Sub::Name::subname, avg 2µs/call |
706 | subname(':around' => $method_modifier) | ||||
707 | ); | ||||
708 | } | ||||
709 | |||||
710 | # NOTE: | ||||
711 | # the methods above used to be named like this: | ||||
712 | # ${pkg}::${method}:(before|after|around) | ||||
713 | # but this proved problematic when using one modifier | ||||
714 | # to wrap multiple methods (something which is likely | ||||
715 | # to happen pretty regularly IMO). So instead of naming | ||||
716 | # it like this, I have chosen to just name them purely | ||||
717 | # with their modifier names, like so: | ||||
718 | # :(before|after|around) | ||||
719 | # The fact is that in a stack trace, it will be fairly | ||||
720 | # evident from the context what method they are attached | ||||
721 | # to, and so don't need the fully qualified name. | ||||
722 | } | ||||
723 | |||||
724 | # spent 13.3ms (1.80+11.5) within Class::MOP::Class::find_method_by_name which was called 86 times, avg 154µs/call:
# 64 times (1.45ms+9.58ms) by Class::MOP::Class::_immutable_metaclass at line 970, avg 172µs/call
# 7 times (132µs+884µs) by Moose::Meta::Method::Destructor::is_needed at line 62 of Moose/Meta/Method/Destructor.pm, avg 145µs/call
# 7 times (73µs+321µs) by Moose::BEGIN@37 at line 14 of Moose/Meta/Attribute/Native.pm, avg 56µs/call
# 6 times (115µs+593µs) by Moose::Meta::Method::Constructor::_generate_BUILDARGS at line 135 of Moose/Meta/Method/Constructor.pm, avg 118µs/call
# 2 times (26µs+91µs) by Moose::Meta::Role::Application::ToClass::check_required_methods at line 64 of Moose/Meta/Role/Application/ToClass.pm, avg 58µs/call | ||||
725 | 86 | 37µs | my ($self, $method_name) = @_; | ||
726 | 86 | 31µs | (defined $method_name && length $method_name) | ||
727 | || confess "You must define a method name to find"; | ||||
728 | 86 | 132µs | 86 | 589µs | foreach my $class ($self->linearized_isa) { # spent 589µs making 86 calls to Class::MOP::Class::linearized_isa, avg 7µs/call |
729 | 325 | 618µs | 650 | 10.9ms | my $method = $self->initialize($class)->get_method($method_name); # spent 9.30ms making 325 calls to Class::MOP::Mixin::HasMethods::get_method, avg 29µs/call
# spent 934µs making 175 calls to Class::MOP::Class::initialize, avg 5µs/call
# spent 649µs making 150 calls to Moose::Meta::Class::initialize, avg 4µs/call |
730 | 325 | 257µs | return $method if defined $method; | ||
731 | } | ||||
732 | 17 | 33µs | return; | ||
733 | } | ||||
734 | |||||
735 | # spent 5.32ms (263µs+5.06) within Class::MOP::Class::get_all_methods which was called 3 times, avg 1.77ms/call:
# 3 times (263µs+5.06ms) by Class::MOP::Class::_immutable_metaclass at line 967, avg 1.77ms/call | ||||
736 | 3 | 2µs | my $self = shift; | ||
737 | |||||
738 | 3 | 900ns | my %methods; | ||
739 | 3 | 8µs | 3 | 22µs | for my $class ( reverse $self->linearized_isa ) { # spent 22µs making 3 calls to Class::MOP::Class::linearized_isa, avg 7µs/call |
740 | 5 | 7µs | 5 | 29µs | my $meta = $self->initialize($class); # spent 29µs making 5 calls to Class::MOP::Class::initialize, avg 6µs/call |
741 | |||||
742 | $methods{$_} = $meta->get_method($_) | ||||
743 | 10 | 149µs | 69 | 5.01ms | for $meta->get_method_list; # spent 3.68ms making 5 calls to Class::MOP::Mixin::HasMethods::get_method_list, avg 735µs/call
# spent 1.33ms making 64 calls to Class::MOP::Mixin::HasMethods::get_method, avg 21µs/call |
744 | } | ||||
745 | |||||
746 | 3 | 29µs | return values %methods; | ||
747 | } | ||||
748 | |||||
749 | sub get_all_method_names { | ||||
750 | my $self = shift; | ||||
751 | my %uniq; | ||||
752 | return grep { !$uniq{$_}++ } map { $self->initialize($_)->get_method_list } $self->linearized_isa; | ||||
753 | } | ||||
754 | |||||
755 | # spent 1.13ms (209µs+918µs) within Class::MOP::Class::find_all_methods_by_name which was called 12 times, avg 94µs/call:
# 6 times (126µs+509µs) by Moose::Meta::Method::Constructor::_generate_BUILDALL at line 153 of Moose/Meta/Method/Constructor.pm, avg 106µs/call
# 6 times (83µs+409µs) by Moose::Meta::Method::Destructor::_initialize_body at line 81 of Moose/Meta/Method/Destructor.pm, avg 82µs/call | ||||
756 | 12 | 10µs | my ($self, $method_name) = @_; | ||
757 | 12 | 6µs | (defined $method_name && length $method_name) | ||
758 | || confess "You must define a method name to find"; | ||||
759 | 12 | 2µs | my @methods; | ||
760 | 12 | 24µs | 12 | 78µs | foreach my $class ($self->linearized_isa) { # spent 78µs making 12 calls to Class::MOP::Class::linearized_isa, avg 6µs/call |
761 | # fetch the meta-class ... | ||||
762 | 24 | 28µs | 24 | 115µs | my $meta = $self->initialize($class); # spent 115µs making 24 calls to Moose::Meta::Class::initialize, avg 5µs/call |
763 | 24 | 42µs | 24 | 726µs | push @methods => { # spent 726µs making 24 calls to Class::MOP::Mixin::HasMethods::has_method, avg 30µs/call |
764 | name => $method_name, | ||||
765 | class => $class, | ||||
766 | code => $meta->get_method($method_name) | ||||
767 | } if $meta->has_method($method_name); | ||||
768 | } | ||||
769 | 12 | 33µs | return @methods; | ||
770 | } | ||||
771 | |||||
772 | # spent 10.6ms (2.09+8.52) within Class::MOP::Class::find_next_method_by_name which was called 135 times, avg 79µs/call:
# 92 times (1.57ms+6.30ms) by Class::MOP::Class::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP/Class.pm:678] at line 657, avg 86µs/call
# 43 times (516µs+2.21ms) by Class::MOP::Method::Inlined::can_be_inlined at line 40 of Class/MOP/Method/Inlined.pm, avg 63µs/call | ||||
773 | 135 | 69µs | my ($self, $method_name) = @_; | ||
774 | 135 | 45µs | (defined $method_name && length $method_name) | ||
775 | || confess "You must define a method name to find"; | ||||
776 | 135 | 398µs | 135 | 887µs | my @cpl = $self->linearized_isa; # spent 887µs making 135 calls to Class::MOP::Class::linearized_isa, avg 7µs/call |
777 | 135 | 37µs | shift @cpl; # discard ourselves | ||
778 | 135 | 81µs | foreach my $class (@cpl) { | ||
779 | 233 | 476µs | 466 | 7.63ms | my $method = $self->initialize($class)->get_method($method_name); # spent 6.49ms making 233 calls to Class::MOP::Mixin::HasMethods::get_method, avg 28µs/call
# spent 586µs making 112 calls to Class::MOP::Class::initialize, avg 5µs/call
# spent 549µs making 121 calls to Moose::Meta::Class::initialize, avg 5µs/call |
780 | 233 | 413µs | return $method if defined $method; | ||
781 | } | ||||
782 | 3 | 6µs | return; | ||
783 | } | ||||
784 | |||||
785 | # spent 87µs within Class::MOP::Class::update_meta_instance_dependencies which was called 48 times, avg 2µs/call:
# 48 times (87µs+0s) by Class::MOP::Class::_superclasses_updated at line 587, avg 2µs/call | ||||
786 | 48 | 9µs | my $self = shift; | ||
787 | |||||
788 | 48 | 118µs | if ( $self->{meta_instance_dependencies} ) { | ||
789 | return $self->add_meta_instance_dependencies; | ||||
790 | } | ||||
791 | } | ||||
792 | |||||
793 | sub add_meta_instance_dependencies { | ||||
794 | my $self = shift; | ||||
795 | |||||
796 | $self->remove_meta_instance_dependencies; | ||||
797 | |||||
798 | my @attrs = $self->get_all_attributes(); | ||||
799 | |||||
800 | my %seen; | ||||
801 | my @classes = grep { not $seen{ $_->name }++ } | ||||
802 | map { $_->associated_class } @attrs; | ||||
803 | |||||
804 | foreach my $class (@classes) { | ||||
805 | $class->add_dependent_meta_instance($self); | ||||
806 | } | ||||
807 | |||||
808 | $self->{meta_instance_dependencies} = \@classes; | ||||
809 | } | ||||
810 | |||||
811 | sub remove_meta_instance_dependencies { | ||||
812 | my $self = shift; | ||||
813 | |||||
814 | if ( my $classes = delete $self->{meta_instance_dependencies} ) { | ||||
815 | foreach my $class (@$classes) { | ||||
816 | $class->remove_dependent_meta_instance($self); | ||||
817 | } | ||||
818 | |||||
819 | return $classes; | ||||
820 | } | ||||
821 | |||||
822 | return; | ||||
823 | |||||
824 | } | ||||
825 | |||||
826 | sub add_dependent_meta_instance { | ||||
827 | my ( $self, $metaclass ) = @_; | ||||
828 | push @{ $self->{dependent_meta_instances} }, $metaclass; | ||||
829 | } | ||||
830 | |||||
831 | sub remove_dependent_meta_instance { | ||||
832 | my ( $self, $metaclass ) = @_; | ||||
833 | my $name = $metaclass->name; | ||||
834 | @$_ = grep { $_->name ne $name } @$_ | ||||
835 | for $self->{dependent_meta_instances}; | ||||
836 | } | ||||
837 | |||||
838 | # spent 1.65ms (1.37+279µs) within Class::MOP::Class::invalidate_meta_instances which was called 201 times, avg 8µs/call:
# 201 times (1.37ms+279µs) by Class::MOP::Class::_post_add_attribute at line 509, avg 8µs/call | ||||
839 | 201 | 46µs | my $self = shift; | ||
840 | $_->invalidate_meta_instance() | ||||
841 | 402 | 1.18ms | 201 | 279µs | for $self, @{ $self->{dependent_meta_instances} }; # spent 279µs making 201 calls to Class::MOP::Class::invalidate_meta_instance, avg 1µs/call |
842 | } | ||||
843 | |||||
844 | # spent 279µs within Class::MOP::Class::invalidate_meta_instance which was called 201 times, avg 1µs/call:
# 201 times (279µs+0s) by Class::MOP::Class::invalidate_meta_instances at line 841, avg 1µs/call | ||||
845 | 201 | 26µs | my $self = shift; | ||
846 | 201 | 431µs | undef $self->{_meta_instance}; | ||
847 | } | ||||
848 | |||||
849 | # check if we can reinitialize | ||||
850 | # spent 687µs (43+644) within Class::MOP::Class::is_pristine which was called
# once (43µs+644µs) by Moose::Meta::Class::_fix_one_incompatible_metaclass at line 358 of Moose/Meta/Class.pm | ||||
851 | 1 | 600ns | my $self = shift; | ||
852 | |||||
853 | # if any local attr is defined | ||||
854 | 1 | 8µs | 1 | 7µs | return if $self->get_attribute_list; # spent 7µs making 1 call to Class::MOP::Mixin::HasAttributes::get_attribute_list |
855 | |||||
856 | # or any non-declared methods | ||||
857 | 2 | 20µs | 2 | 636µs | for my $method ( map { $self->get_method($_) } $self->get_method_list ) { # spent 615µs making 1 call to Class::MOP::Mixin::HasMethods::get_method_list
# spent 21µs making 1 call to Class::MOP::Mixin::HasMethods::get_method |
858 | 1 | 6µs | 1 | 2µs | return if $method->isa("Class::MOP::Method::Generated"); # spent 2µs making 1 call to UNIVERSAL::isa |
859 | # FIXME do we need to enforce this too? return unless $method->isa( $self->method_metaclass ); | ||||
860 | } | ||||
861 | |||||
862 | 1 | 4µs | return 1; | ||
863 | } | ||||
864 | |||||
865 | ## Class closing | ||||
866 | |||||
867 | 88 | 136µs | # spent 68µs within Class::MOP::Class::is_mutable which was called 88 times, avg 770ns/call:
# 57 times (49µs+0s) by Class::MOP::Class::make_immutable at line 891, avg 863ns/call
# 22 times (13µs+0s) by Foo::BEGIN@3 at line 239 of Moose.pm, avg 568ns/call
# 9 times (6µs+0s) by Moose::Meta::Attribute::BEGIN@18 at line 631 of Moose/Util/TypeConstraints.pm, avg 678ns/call | ||
868 | 76 | 152µs | # spent 83µs within Class::MOP::Class::is_immutable which was called 76 times, avg 1µs/call:
# 39 times (31µs+0s) by Class::MOP::Class::_check_metaclass_compatibility at line 185, avg 790ns/call
# 32 times (45µs+0s) by Moose::Meta::Class::_superclass_meta_is_compatible at line 373 of Moose/Meta/Class.pm, avg 1µs/call
# 3 times (4µs+0s) by Class::MOP::Class::_construct_class_instance at line 71, avg 2µs/call
# 2 times (2µs+0s) by Class::MOP::Class::_immutable_metaclass at line 956, avg 1µs/call | ||
869 | |||||
870 | sub immutable_options { %{ $_[0]{__immutable}{options} || {} } } | ||||
871 | |||||
872 | # spent 1.08ms (741µs+335µs) within Class::MOP::Class::_immutable_options which was called 57 times, avg 19µs/call:
# 50 times (568µs+233µs) by Class::MOP::Class::make_immutable at line 892, avg 16µs/call
# 7 times (173µs+102µs) by Moose::Meta::Class::_immutable_options at line 74 of Moose/Meta/Class.pm, avg 39µs/call | ||||
873 | 57 | 63µs | my ( $self, @args ) = @_; | ||
874 | |||||
875 | return ( | ||||
876 | 57 | 510µs | 228 | 335µs | inline_accessors => 1, # spent 80µs making 57 calls to Class::MOP::Class::constructor_name, avg 1µs/call
# spent 76µs making 50 calls to Class::MOP::Class::immutable_trait, avg 2µs/call
# spent 55µs making 50 calls to Class::MOP::Class::constructor_class, avg 1µs/call
# spent 42µs making 50 calls to Class::MOP::Class::destructor_class, avg 832ns/call
# spent 32µs making 7 calls to Moose::Meta::Class::immutable_trait, avg 5µs/call
# spent 26µs making 7 calls to Moose::Meta::Class::constructor_class, avg 4µs/call
# spent 24µs making 7 calls to Moose::Meta::Class::destructor_class, avg 3µs/call |
877 | inline_constructor => 1, | ||||
878 | inline_destructor => 0, | ||||
879 | debug => 0, | ||||
880 | immutable_trait => $self->immutable_trait, | ||||
881 | constructor_name => $self->constructor_name, | ||||
882 | constructor_class => $self->constructor_class, | ||||
883 | destructor_class => $self->destructor_class, | ||||
884 | @args, | ||||
885 | ); | ||||
886 | } | ||||
887 | |||||
888 | # spent 120ms (866µs+119) within Class::MOP::Class::make_immutable which was called 57 times, avg 2.10ms/call:
# 22 times (296µs+35.1ms) by Foo::BEGIN@3 at line 244 of Moose.pm, avg 1.61ms/call
# 12 times (148µs+13.4ms) by Moose::Exporter::BEGIN@11 at line 678 of Class/MOP.pm, avg 1.13ms/call
# 9 times (125µs+22.0ms) by Moose::Meta::Attribute::BEGIN@18 at line 636 of Moose/Util/TypeConstraints.pm, avg 2.45ms/call
# 4 times (47µs+357µs) by Moose::Exporter::BEGIN@11 at line 701 of Class/MOP.pm, avg 101µs/call
# 3 times (61µs+-61µs) by Class::MOP::Class::_immutable_metaclass at line 979, avg 0s/call
# once (33µs+16.5ms) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 451 of ../lib/SimpleDB/Class.pm
# once (39µs+15.3ms) by SimpleDB::Class::BEGIN@139 at line 449 of ../lib/SimpleDB/Class/Cache.pm
# once (12µs+4.63ms) by Foo::BEGIN@3 at line 276 of Moose.pm
# once (27µs+3.85ms) by SimpleDB::Class::Domain::BEGIN@19 at line 521 of ../lib/SimpleDB/Class/ResultSet.pm
# once (34µs+2.74ms) by SimpleDB::Class::Domain::BEGIN@18 at line 404 of ../lib/SimpleDB/Class/SQL.pm
# once (21µs+2.60ms) by SimpleDB::Class::BEGIN@140 at line 340 of SimpleDB/Client.pm
# once (23µs+2.48ms) by SimpleDB::Class::BEGIN@141 at line 459 of ../lib/SimpleDB/Class/Domain.pm | ||||
889 | 57 | 77µs | my ( $self, @args ) = @_; | ||
890 | |||||
891 | 57 | 76µs | 57 | 49µs | if ( $self->is_mutable ) { # spent 49µs making 57 calls to Class::MOP::Class::is_mutable, avg 863ns/call |
892 | 57 | 279µs | 114 | 76.8ms | $self->_initialize_immutable( $self->_immutable_options(@args) ); # spent 75.6ms making 57 calls to Class::MOP::Class::_initialize_immutable, avg 1.33ms/call
# spent 801µs making 50 calls to Class::MOP::Class::_immutable_options, avg 16µs/call
# spent 351µs making 7 calls to Moose::Meta::Class::_immutable_options, avg 50µs/call |
893 | 57 | 106µs | 57 | 42.8ms | $self->_rebless_as_immutable(@args); # spent 43.1ms making 57 calls to Class::MOP::Class::_rebless_as_immutable, avg 756µs/call, recursion: max depth 1, time 302µs |
894 | 57 | 151µs | return $self; | ||
895 | } | ||||
896 | else { | ||||
897 | return; | ||||
898 | } | ||||
899 | } | ||||
900 | |||||
901 | sub make_mutable { | ||||
902 | my $self = shift; | ||||
903 | |||||
904 | if ( $self->is_immutable ) { | ||||
905 | my @args = $self->immutable_options; | ||||
906 | $self->_rebless_as_mutable(); | ||||
907 | $self->_remove_inlined_code(@args); | ||||
908 | delete $self->{__immutable}; | ||||
909 | return $self; | ||||
910 | } | ||||
911 | else { | ||||
912 | return; | ||||
913 | } | ||||
914 | } | ||||
915 | |||||
916 | # spent 42.8ms (485µs+42.3) within Class::MOP::Class::_rebless_as_immutable which was called 57 times, avg 751µs/call:
# 57 times (485µs+42.3ms) by Class::MOP::Class::make_immutable at line 893, avg 751µs/call | ||||
917 | 57 | 71µs | my ( $self, @args ) = @_; | ||
918 | |||||
919 | 57 | 55µs | $self->{__immutable}{original_class} = ref $self; | ||
920 | |||||
921 | 57 | 332µs | 57 | 42.4ms | bless $self => $self->_immutable_metaclass(@args); # spent 42.6ms making 57 calls to Class::MOP::Class::_immutable_metaclass, avg 748µs/call, recursion: max depth 1, time 258µs |
922 | } | ||||
923 | |||||
924 | # spent 42.4ms (1.75+40.6) within Class::MOP::Class::_immutable_metaclass which was called 57 times, avg 743µs/call:
# 57 times (1.75ms+40.6ms) by Class::MOP::Class::_rebless_as_immutable at line 921, avg 743µs/call | ||||
925 | 57 | 68µs | my ( $self, %args ) = @_; | ||
926 | |||||
927 | 57 | 25µs | if ( my $class = $args{immutable_metaclass} ) { | ||
928 | return $class; | ||||
929 | } | ||||
930 | |||||
931 | 57 | 85µs | 57 | 73µs | my $trait = $args{immutable_trait} = $self->immutable_trait # spent 56µs making 50 calls to Class::MOP::Class::immutable_trait, avg 1µs/call
# spent 16µs making 7 calls to Moose::Meta::Class::immutable_trait, avg 2µs/call |
932 | || confess "no immutable trait specified for $self"; | ||||
933 | |||||
934 | 57 | 81µs | 57 | 644µs | my $meta = $self->meta; # spent 630µs making 56 calls to Class::MOP::Object::meta, avg 11µs/call
# spent 14µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::1::meta |
935 | 57 | 125µs | 57 | 2.02ms | my $meta_attr = $meta->find_attribute_by_name("immutable_trait"); # spent 2.02ms making 57 calls to Class::MOP::Class::find_attribute_by_name, avg 35µs/call |
936 | |||||
937 | 57 | 6µs | my $class_name; | ||
938 | |||||
939 | 57 | 136µs | 57 | 126µs | if ( $meta_attr and $trait eq $meta_attr->default ) { # spent 126µs making 57 calls to Class::MOP::Mixin::AttributeCore::default, avg 2µs/call |
940 | # if the trait is the same as the default we try and pick a | ||||
941 | # predictable name for the immutable metaclass | ||||
942 | $class_name = 'Class::MOP::Class::Immutable::' . ref($self); | ||||
943 | } | ||||
944 | else { | ||||
945 | $class_name = join '::', 'Class::MOP::Class::Immutable::CustomTrait', | ||||
946 | $trait, 'ForMetaClass', ref($self); | ||||
947 | } | ||||
948 | |||||
949 | 57 | 424µs | 57 | 164µs | return $class_name # spent 164µs making 57 calls to Class::MOP::is_class_loaded, avg 3µs/call |
950 | if Class::MOP::is_class_loaded($class_name); | ||||
951 | |||||
952 | # If the metaclass is a subclass of CMOP::Class which has had | ||||
953 | # metaclass roles applied (via Moose), then we want to make sure | ||||
954 | # that we preserve that anonymous class (see Fey::ORM for an | ||||
955 | # example of where this matters). | ||||
956 | 3 | 12µs | 4 | 18µs | my $meta_name # spent 12µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::is_immutable
# spent 3µs making 1 call to Class::MOP::Class::Immutable::Trait::_get_mutable_metaclass_name
# spent 2µs making 2 calls to Class::MOP::Class::is_immutable, avg 1µs/call |
957 | = $meta->is_immutable | ||||
958 | ? $meta->_get_mutable_metaclass_name | ||||
959 | : ref $meta; | ||||
960 | |||||
961 | 3 | 13µs | 3 | 2.06ms | my $immutable_meta = $meta_name->create( # spent 1.49ms making 1 call to Moose::Meta::Class::create
# spent 571µs making 2 calls to Class::MOP::Class::create, avg 285µs/call |
962 | $class_name, | ||||
963 | superclasses => [ ref $self ], | ||||
964 | ); | ||||
965 | |||||
966 | 3 | 5µs | 3 | 822µs | Class::MOP::load_class($trait); # spent 887µs making 3 calls to Class::MOP::load_class, avg 296µs/call, recursion: max depth 1, time 66µs |
967 | 3 | 18µs | 6 | 5.42ms | for my $meth ( Class::MOP::Class->initialize($trait)->get_all_methods ) { # spent 5.32ms making 3 calls to Class::MOP::Class::get_all_methods, avg 1.77ms/call
# spent 97µs making 3 calls to Class::MOP::Class::initialize, avg 32µs/call |
968 | 64 | 191µs | 64 | 47µs | my $meth_name = $meth->name; # spent 47µs making 64 calls to Class::MOP::Method::name, avg 742ns/call |
969 | |||||
970 | 64 | 346µs | 174 | 25.4ms | if ( $immutable_meta->find_method_by_name( $meth_name ) ) { # spent 14.3ms making 55 calls to Class::MOP::Class::add_around_method_modifier, avg 260µs/call
# spent 11.0ms making 64 calls to Class::MOP::Class::find_method_by_name, avg 172µs/call
# spent 38µs making 55 calls to Class::MOP::Method::body, avg 684ns/call |
971 | $immutable_meta->add_around_method_modifier( $meth_name, $meth->body ); | ||||
972 | } | ||||
973 | else { | ||||
974 | 9 | 25µs | 18 | 2.93ms | $immutable_meta->add_method( $meth_name, $meth->clone ); # spent 1.80ms making 9 calls to Class::MOP::Mixin::HasMethods::add_method, avg 200µs/call
# spent 1.13ms making 9 calls to Class::MOP::Method::clone, avg 126µs/call |
975 | } | ||||
976 | } | ||||
977 | |||||
978 | $immutable_meta->make_immutable( | ||||
979 | 3 | 10µs | 3 | 0s | inline_constructor => 0, # spent 1.10ms making 3 calls to Class::MOP::Class::make_immutable, avg 368µs/call, recursion: max depth 1, time 1.10ms |
980 | inline_accessors => 0, | ||||
981 | ); | ||||
982 | |||||
983 | 3 | 12µs | return $class_name; | ||
984 | } | ||||
985 | |||||
986 | sub _remove_inlined_code { | ||||
987 | my $self = shift; | ||||
988 | |||||
989 | $self->remove_method( $_->name ) for $self->_inlined_methods; | ||||
990 | |||||
991 | delete $self->{__immutable}{inlined_methods}; | ||||
992 | } | ||||
993 | |||||
994 | sub _inlined_methods { @{ $_[0]{__immutable}{inlined_methods} || [] } } | ||||
995 | |||||
996 | sub _add_inlined_method { | ||||
997 | 43 | 20µs | my ( $self, $method ) = @_; | ||
998 | |||||
999 | 43 | 134µs | push @{ $self->{__immutable}{inlined_methods} ||= [] }, $method; | ||
1000 | } | ||||
1001 | |||||
1002 | # spent 75.6ms (578µs+75.1) within Class::MOP::Class::_initialize_immutable which was called 57 times, avg 1.33ms/call:
# 57 times (578µs+75.1ms) by Class::MOP::Class::make_immutable at line 892, avg 1.33ms/call | ||||
1003 | 57 | 201µs | my ( $self, %args ) = @_; | ||
1004 | |||||
1005 | 57 | 92µs | $self->{__immutable}{options} = \%args; | ||
1006 | 57 | 262µs | 57 | 75.1ms | $self->_install_inlined_code(%args); # spent 75.1ms making 57 calls to Class::MOP::Class::_install_inlined_code, avg 1.32ms/call |
1007 | } | ||||
1008 | |||||
1009 | # spent 75.1ms (560µs+74.5) within Class::MOP::Class::_install_inlined_code which was called 57 times, avg 1.32ms/call:
# 57 times (560µs+74.5ms) by Class::MOP::Class::_initialize_immutable at line 1006, avg 1.32ms/call | ||||
1010 | 57 | 136µs | my ( $self, %args ) = @_; | ||
1011 | |||||
1012 | # FIXME | ||||
1013 | 57 | 92µs | 32 | 28.6ms | $self->_inline_accessors(%args) if $args{inline_accessors}; # spent 28.6ms making 32 calls to Class::MOP::Class::_inline_accessors, avg 894µs/call |
1014 | 57 | 111µs | 37 | 41.5ms | $self->_inline_constructor(%args) if $args{inline_constructor}; # spent 41.5ms making 37 calls to Class::MOP::Class::_inline_constructor, avg 1.12ms/call |
1015 | 57 | 181µs | 7 | 4.33ms | $self->_inline_destructor(%args) if $args{inline_destructor}; # spent 4.33ms making 7 calls to Class::MOP::Class::_inline_destructor, avg 619µs/call |
1016 | } | ||||
1017 | |||||
1018 | sub _rebless_as_mutable { | ||||
1019 | my $self = shift; | ||||
1020 | |||||
1021 | bless $self, $self->_get_mutable_metaclass_name; | ||||
1022 | |||||
1023 | return $self; | ||||
1024 | } | ||||
1025 | |||||
1026 | # spent 28.6ms (449µs+28.2) within Class::MOP::Class::_inline_accessors which was called 32 times, avg 894µs/call:
# 32 times (449µs+28.2ms) by Class::MOP::Class::_install_inlined_code at line 1013, avg 894µs/call | ||||
1027 | 32 | 7µs | my $self = shift; | ||
1028 | |||||
1029 | 32 | 106µs | 32 | 177µs | foreach my $attr_name ( $self->get_attribute_list ) { # spent 177µs making 32 calls to Class::MOP::Mixin::HasAttributes::get_attribute_list, avg 6µs/call |
1030 | 68 | 185µs | 136 | 28.0ms | $self->get_attribute($attr_name)->install_accessors(1); # spent 26.5ms making 67 calls to Class::MOP::Attribute::install_accessors, avg 396µs/call
# spent 1.10ms making 1 call to Moose::Meta::Attribute::install_accessors
# spent 352µs making 68 calls to Class::MOP::Mixin::HasAttributes::get_attribute, avg 5µs/call |
1031 | } | ||||
1032 | } | ||||
1033 | |||||
1034 | # spent 41.5ms (912µs+40.6) within Class::MOP::Class::_inline_constructor which was called 37 times, avg 1.12ms/call:
# 37 times (912µs+40.6ms) by Class::MOP::Class::_install_inlined_code at line 1014, avg 1.12ms/call | ||||
1035 | 37 | 77µs | my ( $self, %args ) = @_; | ||
1036 | |||||
1037 | 37 | 14µs | my $name = $args{constructor_name}; | ||
1038 | # A class may not even have a constructor, and that's okay. | ||||
1039 | 37 | 6µs | return unless defined $name; | ||
1040 | |||||
1041 | 37 | 63µs | 37 | 1.26ms | if ( $self->has_method($name) && !$args{replace_constructor} ) { # spent 1.26ms making 37 calls to Class::MOP::Mixin::HasMethods::has_method, avg 34µs/call |
1042 | my $class = $self->name; | ||||
1043 | warn "Not inlining a constructor for $class since it defines" | ||||
1044 | . " its own constructor.\n" | ||||
1045 | . "If you are certain you don't need to inline your" | ||||
1046 | . " constructor, specify inline_constructor => 0 in your" | ||||
1047 | . " call to $class->meta->make_immutable\n"; | ||||
1048 | return; | ||||
1049 | } | ||||
1050 | |||||
1051 | 37 | 18µs | my $constructor_class = $args{constructor_class}; | ||
1052 | |||||
1053 | 37 | 40µs | 37 | 897µs | Class::MOP::load_class($constructor_class); # spent 1.21ms making 37 calls to Class::MOP::load_class, avg 33µs/call, recursion: max depth 1, time 311µs |
1054 | |||||
1055 | 37 | 184µs | 74 | 32.9ms | my $constructor = $constructor_class->new( # spent 23.0ms making 31 calls to Class::MOP::Method::Constructor::new, avg 741µs/call
# spent 9.91ms making 6 calls to Moose::Meta::Method::Constructor::new, avg 1.65ms/call
# spent 25µs making 37 calls to Class::MOP::Package::name, avg 670ns/call |
1056 | options => \%args, | ||||
1057 | metaclass => $self, | ||||
1058 | is_inline => 1, | ||||
1059 | package_name => $self->name, | ||||
1060 | name => $name, | ||||
1061 | ); | ||||
1062 | |||||
1063 | 37 | 193µs | 37 | 3.45ms | if ( $args{replace_constructor} or $constructor->can_be_inlined ) { # spent 3.45ms making 37 calls to Class::MOP::Method::Inlined::can_be_inlined, avg 93µs/call |
1064 | 37 | 72µs | 37 | 1.69ms | $self->add_method( $name => $constructor ); # spent 1.69ms making 37 calls to Class::MOP::Mixin::HasMethods::add_method, avg 46µs/call |
1065 | 37 | 72µs | 37 | 119µs | $self->_add_inlined_method($constructor); # spent 119µs making 37 calls to Class::MOP::Class::_add_inlined_method, avg 3µs/call |
1066 | } | ||||
1067 | } | ||||
1068 | |||||
1069 | # spent 4.33ms (254µs+4.08) within Class::MOP::Class::_inline_destructor which was called 7 times, avg 619µs/call:
# 7 times (254µs+4.08ms) by Class::MOP::Class::_install_inlined_code at line 1015, avg 619µs/call | ||||
1070 | 7 | 25µs | my ( $self, %args ) = @_; | ||
1071 | |||||
1072 | 7 | 10µs | ( exists $args{destructor_class} && defined $args{destructor_class} ) | ||
1073 | || confess "The 'inline_destructor' option is present, but " | ||||
1074 | . "no destructor class was specified"; | ||||
1075 | |||||
1076 | 7 | 14µs | 7 | 259µs | if ( $self->has_method('DESTROY') && ! $args{replace_destructor} ) { # spent 259µs making 7 calls to Class::MOP::Mixin::HasMethods::has_method, avg 37µs/call |
1077 | my $class = $self->name; | ||||
1078 | warn "Not inlining a destructor for $class since it defines" | ||||
1079 | . " its own destructor.\n"; | ||||
1080 | return; | ||||
1081 | } | ||||
1082 | |||||
1083 | 7 | 6µs | my $destructor_class = $args{destructor_class}; | ||
1084 | |||||
1085 | 7 | 11µs | 7 | 0s | Class::MOP::load_class($destructor_class); # spent 282µs making 7 calls to Class::MOP::load_class, avg 40µs/call, recursion: max depth 1, time 282µs |
1086 | |||||
1087 | 7 | 36µs | 7 | 1.11ms | return unless $destructor_class->is_needed($self); # spent 1.11ms making 7 calls to Moose::Meta::Method::Destructor::is_needed, avg 159µs/call |
1088 | |||||
1089 | 6 | 38µs | 12 | 1.68ms | my $destructor = $destructor_class->new( # spent 1.68ms making 6 calls to Moose::Meta::Method::Destructor::new, avg 280µs/call
# spent 4µs making 6 calls to Class::MOP::Package::name, avg 633ns/call |
1090 | options => \%args, | ||||
1091 | metaclass => $self, | ||||
1092 | package_name => $self->name, | ||||
1093 | name => 'DESTROY' | ||||
1094 | ); | ||||
1095 | |||||
1096 | 6 | 36µs | 6 | 464µs | if ( $args{replace_destructor} or $destructor->can_be_inlined ) { # spent 464µs making 6 calls to Class::MOP::Method::Inlined::can_be_inlined, avg 77µs/call |
1097 | 6 | 14µs | 6 | 265µs | $self->add_method( 'DESTROY' => $destructor ); # spent 265µs making 6 calls to Class::MOP::Mixin::HasMethods::add_method, avg 44µs/call |
1098 | 6 | 9µs | 6 | 12µs | $self->_add_inlined_method($destructor); # spent 12µs making 6 calls to Class::MOP::Class::_add_inlined_method, avg 2µs/call |
1099 | } | ||||
1100 | } | ||||
1101 | |||||
1102 | 1 | 7µs | 1; | ||
1103 | |||||
1104 | __END__ | ||||
1105 | |||||
1106 | =pod | ||||
1107 | |||||
1108 | =head1 NAME | ||||
1109 | |||||
1110 | Class::MOP::Class - Class Meta Object | ||||
1111 | |||||
1112 | =head1 SYNOPSIS | ||||
1113 | |||||
1114 | # assuming that class Foo | ||||
1115 | # has been defined, you can | ||||
1116 | |||||
1117 | # use this for introspection ... | ||||
1118 | |||||
1119 | # add a method to Foo ... | ||||
1120 | Foo->meta->add_method( 'bar' => sub {...} ) | ||||
1121 | |||||
1122 | # get a list of all the classes searched | ||||
1123 | # the method dispatcher in the correct order | ||||
1124 | Foo->meta->class_precedence_list() | ||||
1125 | |||||
1126 | # remove a method from Foo | ||||
1127 | Foo->meta->remove_method('bar'); | ||||
1128 | |||||
1129 | # or use this to actually create classes ... | ||||
1130 | |||||
1131 | Class::MOP::Class->create( | ||||
1132 | 'Bar' => ( | ||||
1133 | version => '0.01', | ||||
1134 | superclasses => ['Foo'], | ||||
1135 | attributes => [ | ||||
1136 | Class::MOP::Attribute->new('$bar'), | ||||
1137 | Class::MOP::Attribute->new('$baz'), | ||||
1138 | ], | ||||
1139 | methods => { | ||||
1140 | calculate_bar => sub {...}, | ||||
1141 | construct_baz => sub {...} | ||||
1142 | } | ||||
1143 | ) | ||||
1144 | ); | ||||
1145 | |||||
1146 | =head1 DESCRIPTION | ||||
1147 | |||||
1148 | The Class Protocol is the largest and most complex part of the | ||||
1149 | Class::MOP meta-object protocol. It controls the introspection and | ||||
1150 | manipulation of Perl 5 classes, and it can create them as well. The | ||||
1151 | best way to understand what this module can do is to read the | ||||
1152 | documentation for each of its methods. | ||||
1153 | |||||
1154 | =head1 INHERITANCE | ||||
1155 | |||||
1156 | C<Class::MOP::Class> is a subclass of L<Class::MOP::Module>. | ||||
1157 | |||||
1158 | =head1 METHODS | ||||
1159 | |||||
1160 | =head2 Class construction | ||||
1161 | |||||
1162 | These methods all create new C<Class::MOP::Class> objects. These | ||||
1163 | objects can represent existing classes or they can be used to create | ||||
1164 | new classes from scratch. | ||||
1165 | |||||
1166 | The metaclass object for a given class is a singleton. If you attempt | ||||
1167 | to create a metaclass for the same class twice, you will just get the | ||||
1168 | existing object. | ||||
1169 | |||||
1170 | =over 4 | ||||
1171 | |||||
1172 | =item B<< Class::MOP::Class->create($package_name, %options) >> | ||||
1173 | |||||
1174 | This method creates a new C<Class::MOP::Class> object with the given | ||||
1175 | package name. It accepts a number of options: | ||||
1176 | |||||
1177 | =over 8 | ||||
1178 | |||||
1179 | =item * version | ||||
1180 | |||||
1181 | An optional version number for the newly created package. | ||||
1182 | |||||
1183 | =item * authority | ||||
1184 | |||||
1185 | An optional authority for the newly created package. | ||||
1186 | |||||
1187 | =item * superclasses | ||||
1188 | |||||
1189 | An optional array reference of superclass names. | ||||
1190 | |||||
1191 | =item * methods | ||||
1192 | |||||
1193 | An optional hash reference of methods for the class. The keys of the | ||||
1194 | hash reference are method names and values are subroutine references. | ||||
1195 | |||||
1196 | =item * attributes | ||||
1197 | |||||
1198 | An optional array reference of L<Class::MOP::Attribute> objects. | ||||
1199 | |||||
1200 | =back | ||||
1201 | |||||
1202 | =item B<< Class::MOP::Class->create_anon_class(%options) >> | ||||
1203 | |||||
1204 | This method works just like C<< Class::MOP::Class->create >> but it | ||||
1205 | creates an "anonymous" class. In fact, the class does have a name, but | ||||
1206 | that name is a unique name generated internally by this module. | ||||
1207 | |||||
1208 | It accepts the same C<superclasses>, C<methods>, and C<attributes> | ||||
1209 | parameters that C<create> accepts. | ||||
1210 | |||||
1211 | Anonymous classes are destroyed once the metaclass they are attached | ||||
1212 | to goes out of scope, and will be removed from Perl's internal symbol | ||||
1213 | table. | ||||
1214 | |||||
1215 | All instances of an anonymous class keep a special reference to the | ||||
1216 | metaclass object, which prevents the metaclass from going out of scope | ||||
1217 | while any instances exist. | ||||
1218 | |||||
1219 | This only works if the instance is based on a hash reference, however. | ||||
1220 | |||||
1221 | =item B<< Class::MOP::Class->initialize($package_name, %options) >> | ||||
1222 | |||||
1223 | This method will initialize a C<Class::MOP::Class> object for the | ||||
1224 | named package. Unlike C<create>, this method I<will not> create a new | ||||
1225 | class. | ||||
1226 | |||||
1227 | The purpose of this method is to retrieve a C<Class::MOP::Class> | ||||
1228 | object for introspecting an existing class. | ||||
1229 | |||||
1230 | If an existing C<Class::MOP::Class> object exists for the named | ||||
1231 | package, it will be returned, and any options provided will be | ||||
1232 | ignored! | ||||
1233 | |||||
1234 | If the object does not yet exist, it will be created. | ||||
1235 | |||||
1236 | The valid options that can be passed to this method are | ||||
1237 | C<attribute_metaclass>, C<method_metaclass>, | ||||
1238 | C<wrapped_method_metaclass>, and C<instance_metaclass>. These are all | ||||
1239 | optional, and default to the appropriate class in the C<Class::MOP> | ||||
1240 | distribution. | ||||
1241 | |||||
1242 | =back | ||||
1243 | |||||
1244 | =head2 Object instance construction and cloning | ||||
1245 | |||||
1246 | These methods are all related to creating and/or cloning object | ||||
1247 | instances. | ||||
1248 | |||||
1249 | =over 4 | ||||
1250 | |||||
1251 | =item B<< $metaclass->clone_object($instance, %params) >> | ||||
1252 | |||||
1253 | This method clones an existing object instance. Any parameters you | ||||
1254 | provide are will override existing attribute values in the object. | ||||
1255 | |||||
1256 | This is a convenience method for cloning an object instance, then | ||||
1257 | blessing it into the appropriate package. | ||||
1258 | |||||
1259 | You could implement a clone method in your class, using this method: | ||||
1260 | |||||
1261 | sub clone { | ||||
1262 | my ($self, %params) = @_; | ||||
1263 | $self->meta->clone_object($self, %params); | ||||
1264 | } | ||||
1265 | |||||
1266 | =item B<< $metaclass->rebless_instance($instance, %params) >> | ||||
1267 | |||||
1268 | This method changes the class of C<$instance> to the metaclass's class. | ||||
1269 | |||||
1270 | You can only rebless an instance into a subclass of its current | ||||
1271 | class. If you pass any additional parameters, these will be treated | ||||
1272 | like constructor parameters and used to initialize the object's | ||||
1273 | attributes. Any existing attributes that are already set will be | ||||
1274 | overwritten. | ||||
1275 | |||||
1276 | Before reblessing the instance, this method will call | ||||
1277 | C<rebless_instance_away> on the instance's current metaclass. This method | ||||
1278 | will be passed the instance, the new metaclass, and any parameters | ||||
1279 | specified to C<rebless_instance>. By default, C<rebless_instance_away> | ||||
1280 | does nothing; it is merely a hook. | ||||
1281 | |||||
1282 | =item B<< $metaclass->rebless_instance_back($instance) >> | ||||
1283 | |||||
1284 | Does the same thing as C<rebless_instance>, except that you can only | ||||
1285 | rebless an instance into one of its superclasses. Any attributes that | ||||
1286 | do not exist in the superclass will be deinitialized. | ||||
1287 | |||||
1288 | This is a much more dangerous operation than C<rebless_instance>, | ||||
1289 | especially when multiple inheritance is involved, so use this carefully! | ||||
1290 | |||||
1291 | =item B<< $metaclass->new_object(%params) >> | ||||
1292 | |||||
1293 | This method is used to create a new object of the metaclass's | ||||
1294 | class. Any parameters you provide are used to initialize the | ||||
1295 | instance's attributes. A special C<__INSTANCE__> key can be passed to | ||||
1296 | provide an already generated instance, rather than having Class::MOP | ||||
1297 | generate it for you. This is mostly useful for using Class::MOP with | ||||
1298 | foreign classes which generate instances using their own constructors. | ||||
1299 | |||||
1300 | =item B<< $metaclass->instance_metaclass >> | ||||
1301 | |||||
1302 | Returns the class name of the instance metaclass. See | ||||
1303 | L<Class::MOP::Instance> for more information on the instance | ||||
1304 | metaclass. | ||||
1305 | |||||
1306 | =item B<< $metaclass->get_meta_instance >> | ||||
1307 | |||||
1308 | Returns an instance of the C<instance_metaclass> to be used in the | ||||
1309 | construction of a new instance of the class. | ||||
1310 | |||||
1311 | =back | ||||
1312 | |||||
1313 | =head2 Informational predicates | ||||
1314 | |||||
1315 | These are a few predicate methods for asking information about the | ||||
1316 | class itself. | ||||
1317 | |||||
1318 | =over 4 | ||||
1319 | |||||
1320 | =item B<< $metaclass->is_anon_class >> | ||||
1321 | |||||
1322 | This returns true if the class was created by calling C<< | ||||
1323 | Class::MOP::Class->create_anon_class >>. | ||||
1324 | |||||
1325 | =item B<< $metaclass->is_mutable >> | ||||
1326 | |||||
1327 | This returns true if the class is still mutable. | ||||
1328 | |||||
1329 | =item B<< $metaclass->is_immutable >> | ||||
1330 | |||||
1331 | This returns true if the class has been made immutable. | ||||
1332 | |||||
1333 | =item B<< $metaclass->is_pristine >> | ||||
1334 | |||||
1335 | A class is I<not> pristine if it has non-inherited attributes or if it | ||||
1336 | has any generated methods. | ||||
1337 | |||||
1338 | =back | ||||
1339 | |||||
1340 | =head2 Inheritance Relationships | ||||
1341 | |||||
1342 | =over 4 | ||||
1343 | |||||
1344 | =item B<< $metaclass->superclasses(@superclasses) >> | ||||
1345 | |||||
1346 | This is a read-write accessor which represents the superclass | ||||
1347 | relationships of the metaclass's class. | ||||
1348 | |||||
1349 | This is basically sugar around getting and setting C<@ISA>. | ||||
1350 | |||||
1351 | =item B<< $metaclass->class_precedence_list >> | ||||
1352 | |||||
1353 | This returns a list of all of the class's ancestor classes. The | ||||
1354 | classes are returned in method dispatch order. | ||||
1355 | |||||
1356 | =item B<< $metaclass->linearized_isa >> | ||||
1357 | |||||
1358 | This returns a list based on C<class_precedence_list> but with all | ||||
1359 | duplicates removed. | ||||
1360 | |||||
1361 | =item B<< $metaclass->subclasses >> | ||||
1362 | |||||
1363 | This returns a list of all subclasses for this class, even indirect | ||||
1364 | subclasses. | ||||
1365 | |||||
1366 | =item B<< $metaclass->direct_subclasses >> | ||||
1367 | |||||
1368 | This returns a list of immediate subclasses for this class, which does not | ||||
1369 | include indirect subclasses. | ||||
1370 | |||||
1371 | =back | ||||
1372 | |||||
1373 | =head2 Method introspection | ||||
1374 | |||||
1375 | See L<Class::MOP::Package/Method introspection and creation> for | ||||
1376 | methods that operate only on the current class. Class::MOP::Class adds | ||||
1377 | introspection capabilities that take inheritance into account. | ||||
1378 | |||||
1379 | =over 4 | ||||
1380 | |||||
1381 | =item B<< $metaclass->get_all_methods >> | ||||
1382 | |||||
1383 | This will traverse the inheritance hierarchy and return a list of all | ||||
1384 | the L<Class::MOP::Method> objects for this class and its parents. | ||||
1385 | |||||
1386 | =item B<< $metaclass->find_method_by_name($method_name) >> | ||||
1387 | |||||
1388 | This will return a L<Class::MOP::Method> for the specified | ||||
1389 | C<$method_name>. If the class does not have the specified method, it | ||||
1390 | returns C<undef> | ||||
1391 | |||||
1392 | Unlike C<get_method>, this method I<will> look for the named method in | ||||
1393 | superclasses. | ||||
1394 | |||||
1395 | =item B<< $metaclass->get_all_method_names >> | ||||
1396 | |||||
1397 | This will return a list of method I<names> for all of this class's | ||||
1398 | methods, including inherited methods. | ||||
1399 | |||||
1400 | =item B<< $metaclass->find_all_methods_by_name($method_name) >> | ||||
1401 | |||||
1402 | This method looks for the named method in the class and all of its | ||||
1403 | parents. It returns every matching method it finds in the inheritance | ||||
1404 | tree, so it returns a list of methods. | ||||
1405 | |||||
1406 | Each method is returned as a hash reference with three keys. The keys | ||||
1407 | are C<name>, C<class>, and C<code>. The C<code> key has a | ||||
1408 | L<Class::MOP::Method> object as its value. | ||||
1409 | |||||
1410 | The list of methods is distinct. | ||||
1411 | |||||
1412 | =item B<< $metaclass->find_next_method_by_name($method_name) >> | ||||
1413 | |||||
1414 | This method returns the first method in any superclass matching the | ||||
1415 | given name. It is effectively the method that C<SUPER::$method_name> | ||||
1416 | would dispatch to. | ||||
1417 | |||||
1418 | =back | ||||
1419 | |||||
1420 | =head2 Attribute introspection and creation | ||||
1421 | |||||
1422 | Because Perl 5 does not have a core concept of attributes in classes, | ||||
1423 | we can only return information about attributes which have been added | ||||
1424 | via this class's methods. We cannot discover information about | ||||
1425 | attributes which are defined in terms of "regular" Perl 5 methods. | ||||
1426 | |||||
1427 | =over 4 | ||||
1428 | |||||
1429 | =item B<< $metaclass->get_attribute($attribute_name) >> | ||||
1430 | |||||
1431 | This will return a L<Class::MOP::Attribute> for the specified | ||||
1432 | C<$attribute_name>. If the class does not have the specified | ||||
1433 | attribute, it returns C<undef>. | ||||
1434 | |||||
1435 | NOTE that get_attribute does not search superclasses, for that you | ||||
1436 | need to use C<find_attribute_by_name>. | ||||
1437 | |||||
1438 | =item B<< $metaclass->has_attribute($attribute_name) >> | ||||
1439 | |||||
1440 | Returns a boolean indicating whether or not the class defines the | ||||
1441 | named attribute. It does not include attributes inherited from parent | ||||
1442 | classes. | ||||
1443 | |||||
1444 | =item B<< $metaclass->get_attribute_list >> | ||||
1445 | |||||
1446 | This will return a list of attributes I<names> for all attributes | ||||
1447 | defined in this class. | ||||
1448 | |||||
1449 | =item B<< $metaclass->get_all_attributes >> | ||||
1450 | |||||
1451 | This will traverse the inheritance hierarchy and return a list of all | ||||
1452 | the L<Class::MOP::Attribute> objects for this class and its parents. | ||||
1453 | |||||
1454 | =item B<< $metaclass->find_attribute_by_name($attribute_name) >> | ||||
1455 | |||||
1456 | This will return a L<Class::MOP::Attribute> for the specified | ||||
1457 | C<$attribute_name>. If the class does not have the specified | ||||
1458 | attribute, it returns C<undef>. | ||||
1459 | |||||
1460 | Unlike C<get_attribute>, this attribute I<will> look for the named | ||||
1461 | attribute in superclasses. | ||||
1462 | |||||
1463 | =item B<< $metaclass->add_attribute(...) >> | ||||
1464 | |||||
1465 | This method accepts either an existing L<Class::MOP::Attribute> | ||||
1466 | object or parameters suitable for passing to that class's C<new> | ||||
1467 | method. | ||||
1468 | |||||
1469 | The attribute provided will be added to the class. | ||||
1470 | |||||
1471 | Any accessor methods defined by the attribute will be added to the | ||||
1472 | class when the attribute is added. | ||||
1473 | |||||
1474 | If an attribute of the same name already exists, the old attribute | ||||
1475 | will be removed first. | ||||
1476 | |||||
1477 | =item B<< $metaclass->remove_attribute($attribute_name) >> | ||||
1478 | |||||
1479 | This will remove the named attribute from the class, and | ||||
1480 | L<Class::MOP::Attribute> object. | ||||
1481 | |||||
1482 | Removing an attribute also removes any accessor methods defined by the | ||||
1483 | attribute. | ||||
1484 | |||||
1485 | However, note that removing an attribute will only affect I<future> | ||||
1486 | object instances created for this class, not existing instances. | ||||
1487 | |||||
1488 | =item B<< $metaclass->attribute_metaclass >> | ||||
1489 | |||||
1490 | Returns the class name of the attribute metaclass for this class. By | ||||
1491 | default, this is L<Class::MOP::Attribute>. | ||||
1492 | |||||
1493 | =back | ||||
1494 | |||||
1495 | =head2 Class Immutability | ||||
1496 | |||||
1497 | Making a class immutable "freezes" the class definition. You can no | ||||
1498 | longer call methods which alter the class, such as adding or removing | ||||
1499 | methods or attributes. | ||||
1500 | |||||
1501 | Making a class immutable lets us optimize the class by inlining some | ||||
1502 | methods, and also allows us to optimize some methods on the metaclass | ||||
1503 | object itself. | ||||
1504 | |||||
1505 | After immutabilization, the metaclass object will cache most informational | ||||
1506 | methods that returns information about methods or attributes. Methods which | ||||
1507 | would alter the class, such as C<add_attribute> and C<add_method>, will | ||||
1508 | throw an error on an immutable metaclass object. | ||||
1509 | |||||
1510 | The immutabilization system in L<Moose> takes much greater advantage | ||||
1511 | of the inlining features than Class::MOP itself does. | ||||
1512 | |||||
1513 | =over 4 | ||||
1514 | |||||
1515 | =item B<< $metaclass->make_immutable(%options) >> | ||||
1516 | |||||
1517 | This method will create an immutable transformer and use it to make | ||||
1518 | the class and its metaclass object immutable. | ||||
1519 | |||||
1520 | This method accepts the following options: | ||||
1521 | |||||
1522 | =over 8 | ||||
1523 | |||||
1524 | =item * inline_accessors | ||||
1525 | |||||
1526 | =item * inline_constructor | ||||
1527 | |||||
1528 | =item * inline_destructor | ||||
1529 | |||||
1530 | These are all booleans indicating whether the specified method(s) | ||||
1531 | should be inlined. | ||||
1532 | |||||
1533 | By default, accessors and the constructor are inlined, but not the | ||||
1534 | destructor. | ||||
1535 | |||||
1536 | =item * immutable_trait | ||||
1537 | |||||
1538 | The name of a class which will be used as a parent class for the | ||||
1539 | metaclass object being made immutable. This "trait" implements the | ||||
1540 | post-immutability functionality of the metaclass (but not the | ||||
1541 | transformation itself). | ||||
1542 | |||||
1543 | This defaults to L<Class::MOP::Class::Immutable::Trait>. | ||||
1544 | |||||
1545 | =item * constructor_name | ||||
1546 | |||||
1547 | This is the constructor method name. This defaults to "new". | ||||
1548 | |||||
1549 | =item * constructor_class | ||||
1550 | |||||
1551 | The name of the method metaclass for constructors. It will be used to | ||||
1552 | generate the inlined constructor. This defaults to | ||||
1553 | "Class::MOP::Method::Constructor". | ||||
1554 | |||||
1555 | =item * replace_constructor | ||||
1556 | |||||
1557 | This is a boolean indicating whether an existing constructor should be | ||||
1558 | replaced when inlining a constructor. This defaults to false. | ||||
1559 | |||||
1560 | =item * destructor_class | ||||
1561 | |||||
1562 | The name of the method metaclass for destructors. It will be used to | ||||
1563 | generate the inlined destructor. This defaults to | ||||
1564 | "Class::MOP::Method::Denstructor". | ||||
1565 | |||||
1566 | =item * replace_destructor | ||||
1567 | |||||
1568 | This is a boolean indicating whether an existing destructor should be | ||||
1569 | replaced when inlining a destructor. This defaults to false. | ||||
1570 | |||||
1571 | =back | ||||
1572 | |||||
1573 | =item B<< $metaclass->immutable_options >> | ||||
1574 | |||||
1575 | Returns a hash of the options used when making the class immutable, including | ||||
1576 | both defaults and anything supplied by the user in the call to C<< | ||||
1577 | $metaclass->make_immutable >>. This is useful if you need to temporarily make | ||||
1578 | a class mutable and then restore immutability as it was before. | ||||
1579 | |||||
1580 | =item B<< $metaclass->make_mutable >> | ||||
1581 | |||||
1582 | Calling this method reverse the immutabilization transformation. | ||||
1583 | |||||
1584 | =back | ||||
1585 | |||||
1586 | =head2 Method Modifiers | ||||
1587 | |||||
1588 | Method modifiers are hooks which allow a method to be wrapped with | ||||
1589 | I<before>, I<after> and I<around> method modifiers. Every time a | ||||
1590 | method is called, its modifiers are also called. | ||||
1591 | |||||
1592 | A class can modify its own methods, as well as methods defined in | ||||
1593 | parent classes. | ||||
1594 | |||||
1595 | =head3 How method modifiers work? | ||||
1596 | |||||
1597 | Method modifiers work by wrapping the original method and then | ||||
1598 | replacing it in the class's symbol table. The wrappers will handle | ||||
1599 | calling all the modifiers in the appropriate order and preserving the | ||||
1600 | calling context for the original method. | ||||
1601 | |||||
1602 | The return values of C<before> and C<after> modifiers are | ||||
1603 | ignored. This is because their purpose is B<not> to filter the input | ||||
1604 | and output of the primary method (this is done with an I<around> | ||||
1605 | modifier). | ||||
1606 | |||||
1607 | This may seem like an odd restriction to some, but doing this allows | ||||
1608 | for simple code to be added at the beginning or end of a method call | ||||
1609 | without altering the function of the wrapped method or placing any | ||||
1610 | extra responsibility on the code of the modifier. | ||||
1611 | |||||
1612 | Of course if you have more complex needs, you can use the C<around> | ||||
1613 | modifier which allows you to change both the parameters passed to the | ||||
1614 | wrapped method, as well as its return value. | ||||
1615 | |||||
1616 | Before and around modifiers are called in last-defined-first-called | ||||
1617 | order, while after modifiers are called in first-defined-first-called | ||||
1618 | order. So the call tree might looks something like this: | ||||
1619 | |||||
1620 | before 2 | ||||
1621 | before 1 | ||||
1622 | around 2 | ||||
1623 | around 1 | ||||
1624 | primary | ||||
1625 | around 1 | ||||
1626 | around 2 | ||||
1627 | after 1 | ||||
1628 | after 2 | ||||
1629 | |||||
1630 | =head3 What is the performance impact? | ||||
1631 | |||||
1632 | Of course there is a performance cost associated with method | ||||
1633 | modifiers, but we have made every effort to make that cost directly | ||||
1634 | proportional to the number of modifier features you use. | ||||
1635 | |||||
1636 | The wrapping method does its best to B<only> do as much work as it | ||||
1637 | absolutely needs to. In order to do this we have moved some of the | ||||
1638 | performance costs to set-up time, where they are easier to amortize. | ||||
1639 | |||||
1640 | All this said, our benchmarks have indicated the following: | ||||
1641 | |||||
1642 | simple wrapper with no modifiers 100% slower | ||||
1643 | simple wrapper with simple before modifier 400% slower | ||||
1644 | simple wrapper with simple after modifier 450% slower | ||||
1645 | simple wrapper with simple around modifier 500-550% slower | ||||
1646 | simple wrapper with all 3 modifiers 1100% slower | ||||
1647 | |||||
1648 | These numbers may seem daunting, but you must remember, every feature | ||||
1649 | comes with some cost. To put things in perspective, just doing a | ||||
1650 | simple C<AUTOLOAD> which does nothing but extract the name of the | ||||
1651 | method called and return it costs about 400% over a normal method | ||||
1652 | call. | ||||
1653 | |||||
1654 | =over 4 | ||||
1655 | |||||
1656 | =item B<< $metaclass->add_before_method_modifier($method_name, $code) >> | ||||
1657 | |||||
1658 | This wraps the specified method with the supplied subroutine | ||||
1659 | reference. The modifier will be called as a method itself, and will | ||||
1660 | receive the same arguments as are passed to the method. | ||||
1661 | |||||
1662 | When the modifier exits, the wrapped method will be called. | ||||
1663 | |||||
1664 | The return value of the modifier will be ignored. | ||||
1665 | |||||
1666 | =item B<< $metaclass->add_after_method_modifier($method_name, $code) >> | ||||
1667 | |||||
1668 | This wraps the specified method with the supplied subroutine | ||||
1669 | reference. The modifier will be called as a method itself, and will | ||||
1670 | receive the same arguments as are passed to the method. | ||||
1671 | |||||
1672 | When the wrapped methods exits, the modifier will be called. | ||||
1673 | |||||
1674 | The return value of the modifier will be ignored. | ||||
1675 | |||||
1676 | =item B<< $metaclass->add_around_method_modifier($method_name, $code) >> | ||||
1677 | |||||
1678 | This wraps the specified method with the supplied subroutine | ||||
1679 | reference. | ||||
1680 | |||||
1681 | The first argument passed to the modifier will be a subroutine | ||||
1682 | reference to the wrapped method. The second argument is the object, | ||||
1683 | and after that come any arguments passed when the method is called. | ||||
1684 | |||||
1685 | The around modifier can choose to call the original method, as well as | ||||
1686 | what arguments to pass if it does so. | ||||
1687 | |||||
1688 | The return value of the modifier is what will be seen by the caller. | ||||
1689 | |||||
1690 | =back | ||||
1691 | |||||
1692 | =head2 Introspection | ||||
1693 | |||||
1694 | =over 4 | ||||
1695 | |||||
1696 | =item B<< Class::MOP::Class->meta >> | ||||
1697 | |||||
1698 | This will return a L<Class::MOP::Class> instance for this class. | ||||
1699 | |||||
1700 | It should also be noted that L<Class::MOP> will actually bootstrap | ||||
1701 | this module by installing a number of attribute meta-objects into its | ||||
1702 | metaclass. | ||||
1703 | |||||
1704 | =back | ||||
1705 | |||||
1706 | =head1 AUTHORS | ||||
1707 | |||||
1708 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
1709 | |||||
1710 | =head1 COPYRIGHT AND LICENSE | ||||
1711 | |||||
1712 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
1713 | |||||
1714 | L<http://www.iinteractive.com> | ||||
1715 | |||||
1716 | This library is free software; you can redistribute it and/or modify | ||||
1717 | it under the same terms as Perl itself. | ||||
1718 | |||||
1719 | =cut | ||||
# spent 98µs within Class::MOP::Class::CORE:match which was called 193 times, avg 506ns/call:
# 191 times (97µs+0s) by Class::MOP::Class::is_anon_class at line 224 of Class/MOP/Class.pm, avg 508ns/call
# 2 times (600ns+0s) by Class::MOP::Class::DESTROY at line 246 of Class/MOP/Class.pm, avg 300ns/call | |||||
# spent 26µs within Class::MOP::Class::CORE:regcomp which was called 2 times, avg 13µs/call:
# once (18µs+0s) by Class::MOP::Class::DESTROY at line 246 of Class/MOP/Class.pm
# once (8µs+0s) by Class::MOP::Class::is_anon_class at line 224 of Class/MOP/Class.pm |