← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/bin/epoll_server.pl
  Run on Wed Jan 5 05:34:33 2011
Reported on Wed Jan 5 05:35:55 2011

File /usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP/Class.pm
Statements Executed 52269
Statement Execution Time 607ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
5127584.6ms179msClass::MOP::Class::::get_all_attributesClass::MOP::Class::get_all_attributes
2323301865.4ms429msClass::MOP::Class::::initializeClass::MOP::Class::initialize
2062149.8ms434msClass::MOP::Class::::_construct_instanceClass::MOP::Class::_construct_instance
2141133.4ms146msClass::MOP::Class::::_clone_instanceClass::MOP::Class::_clone_instance
124310428.5ms43.2msClass::MOP::Class::::linearized_isaClass::MOP::Class::linearized_isa
2023228.3ms51.4msClass::MOP::Class::::_check_metaclass_compatibilityClass::MOP::Class::_check_metaclass_compatibility
4703323.5ms152msClass::MOP::Class::::superclassesClass::MOP::Class::superclasses
1595418.0ms59.2msClass::MOP::Class::::find_attribute_by_nameClass::MOP::Class::find_attribute_by_name
2164317.2ms60.9msClass::MOP::Class::::class_precedence_listClass::MOP::Class::class_precedence_list
1916617.0ms124msClass::MOP::Class::::find_method_by_nameClass::MOP::Class::find_method_by_name
1844315.4ms81.5msClass::MOP::Class::::find_next_method_by_nameClass::MOP::Class::find_next_method_by_name
1361115.2ms351msClass::MOP::Class::::_construct_class_instanceClass::MOP::Class::_construct_class_instance
2341114.3ms715msClass::MOP::Class::::_post_add_attributeClass::MOP::Class::_post_add_attribute
3584213.0ms17.0msClass::MOP::Class::::is_anon_classClass::MOP::Class::is_anon_class
128213411.9ms11.9msClass::MOP::Class::::instance_metaclassClass::MOP::Class::instance_metaclass
2141111.0ms162msClass::MOP::Class::::clone_objectClass::MOP::Class::clone_object
1053110.7ms142msClass::MOP::Class::::__ANON__[:678]Class::MOP::Class::__ANON__[:678]
77119.98ms251msClass::MOP::Class::::_immutable_metaclassClass::MOP::Class::_immutable_metaclass
236219.55ms11.7msClass::MOP::Class::::invalidate_meta_instancesClass::MOP::Class::invalidate_meta_instances
56118.72ms406msClass::MOP::Class::::_inline_constructorClass::MOP::Class::_inline_constructor
158118.47ms120msClass::MOP::Class::::_create_meta_instanceClass::MOP::Class::_create_meta_instance
234117.49ms663msClass::MOP::Class::::__ANON__[:515]Class::MOP::Class::__ANON__[:515]
63336.81ms46.2msClass::MOP::Class::::find_all_methods_by_nameClass::MOP::Class::find_all_methods_by_name
27115.93ms81.8msClass::MOP::Class::::_inline_destructorClass::MOP::Class::_inline_destructor
5011265.83ms126msClass::MOP::Class::::get_meta_instanceClass::MOP::Class::get_meta_instance
77225.38ms8.12msClass::MOP::Class::::_immutable_optionsClass::MOP::Class::_immutable_options
7732285.37ms921msClass::MOP::Class::::make_immutableClass::MOP::Class::make_immutable
32114.85ms159msClass::MOP::Class::::_inline_accessorsClass::MOP::Class::_inline_accessors
1114.53ms14.2msClass::MOP::Class::::BEGIN@9Class::MOP::Class::BEGIN@9
1114.40ms6.45msClass::MOP::Class::::BEGIN@7Class::MOP::Class::BEGIN@7
77114.38ms651msClass::MOP::Class::::_install_inlined_codeClass::MOP::Class::_install_inlined_code
129444.30ms188msClass::MOP::Class::::new_objectClass::MOP::Class::new_object
77114.29ms655msClass::MOP::Class::::_initialize_immutableClass::MOP::Class::_initialize_immutable
1114.26ms15.2msClass::MOP::Class::::BEGIN@8Class::MOP::Class::BEGIN@8
234114.20ms16.4msClass::MOP::Class::::_attach_attributeClass::MOP::Class::_attach_attribute
1113.78ms8.49msClass::MOP::Class::::BEGIN@10Class::MOP::Class::BEGIN@10
77113.29ms254msClass::MOP::Class::::_rebless_as_immutableClass::MOP::Class::_rebless_as_immutable
59113.20ms3.20msClass::MOP::Class::::_newClass::MOP::Class::_new
87443.15ms126msClass::MOP::Class::::add_around_method_modifierClass::MOP::Class::add_around_method_modifier
236112.19ms2.19msClass::MOP::Class::::invalidate_meta_instanceClass::MOP::Class::invalidate_meta_instance
11221.71ms60.4msClass::MOP::Class::::createClass::MOP::Class::create
233851.53ms1.53msClass::MOP::Class::::is_immutableClass::MOP::Class::is_immutable
373221.51ms1.51msClass::MOP::Class::::CORE:matchClass::MOP::Class::CORE:match (opcode)
82211.34ms1.34msClass::MOP::Class::::_add_inlined_methodClass::MOP::Class::_add_inlined_method
66111.13ms1.80msClass::MOP::Class::::_superclasses_updatedClass::MOP::Class::_superclasses_updated
311984µs31.9msClass::MOP::Class::::get_all_methodsClass::MOP::Class::get_all_methods
111967µs34.7msClass::MOP::Class::::BEGIN@15Class::MOP::Class::BEGIN@15
10021945µs945µsClass::MOP::Class::::immutable_traitClass::MOP::Class::immutable_trait
7711827µs827µsClass::MOP::Class::::constructor_nameClass::MOP::Class::constructor_name
37322760µs760µsClass::MOP::Class::::CORE:regcompClass::MOP::Class::CORE:regcomp (opcode)
1455734µs27.2msClass::MOP::Class::::add_before_method_modifierClass::MOP::Class::add_before_method_modifier
6611674µs674µsClass::MOP::Class::::update_meta_instance_dependenciesClass::MOP::Class::update_meta_instance_dependencies
10833597µs597µsClass::MOP::Class::::is_mutableClass::MOP::Class::is_mutable
1533507µs704µsClass::MOP::Class::::DESTROYClass::MOP::Class::DESTROY
5011351µs351µsClass::MOP::Class::::constructor_classClass::MOP::Class::constructor_class
711334µs6.65msClass::MOP::Class::::is_pristineClass::MOP::Class::is_pristine
5011311µs311µsClass::MOP::Class::::destructor_classClass::MOP::Class::destructor_class
2611294µs294µsClass::MOP::Class::::reset_package_cache_flagClass::MOP::Class::reset_package_cache_flag
811284µs293msClass::MOP::Class::::create_anon_classClass::MOP::Class::create_anon_class
422177µs5.37msClass::MOP::Class::::add_after_method_modifierClass::MOP::Class::add_after_method_modifier
211120µs1.71msClass::MOP::Class::::remove_attributeClass::MOP::Class::remove_attribute
161193µs93µsClass::MOP::Class::::immutable_optionsClass::MOP::Class::immutable_options
11156µs70µsClass::MOP::Class::::BEGIN@4Class::MOP::Class::BEGIN@4
11140µs1.61msClass::MOP::Class::::BEGIN@16Class::MOP::Class::BEGIN@16
21134µs46µsClass::MOP::Class::::update_package_cache_flagClass::MOP::Class::update_package_cache_flag
11134µs85µsClass::MOP::Class::::BEGIN@223Class::MOP::Class::BEGIN@223
11134µs11.7msClass::MOP::Class::::BEGIN@22Class::MOP::Class::BEGIN@22
11132µs419µsClass::MOP::Class::::BEGIN@13Class::MOP::Class::BEGIN@13
11132µs100µsClass::MOP::Class::::BEGIN@5Class::MOP::Class::BEGIN@5
11132µs136µsClass::MOP::Class::::BEGIN@244Class::MOP::Class::BEGIN@244
11132µs77µsClass::MOP::Class::::BEGIN@257Class::MOP::Class::BEGIN@257
11131µs134µsClass::MOP::Class::::BEGIN@14Class::MOP::Class::BEGIN@14
11131µs140µsClass::MOP::Class::::BEGIN@12Class::MOP::Class::BEGIN@12
0000s0sClass::MOP::Class::::__ANON__[:305]Class::MOP::Class::__ANON__[:305]
0000s0sClass::MOP::Class::::__ANON__[:519]Class::MOP::Class::__ANON__[:519]
0000s0sClass::MOP::Class::::_inlined_methodsClass::MOP::Class::_inlined_methods
0000s0sClass::MOP::Class::::_rebless_as_mutableClass::MOP::Class::_rebless_as_mutable
0000s0sClass::MOP::Class::::_remove_inlined_codeClass::MOP::Class::_remove_inlined_code
0000s0sClass::MOP::Class::::add_dependent_meta_instanceClass::MOP::Class::add_dependent_meta_instance
0000s0sClass::MOP::Class::::add_meta_instance_dependenciesClass::MOP::Class::add_meta_instance_dependencies
0000s0sClass::MOP::Class::::direct_subclassesClass::MOP::Class::direct_subclasses
0000s0sClass::MOP::Class::::get_all_method_namesClass::MOP::Class::get_all_method_names
0000s0sClass::MOP::Class::::make_mutableClass::MOP::Class::make_mutable
0000s0sClass::MOP::Class::::rebless_instanceClass::MOP::Class::rebless_instance
0000s0sClass::MOP::Class::::rebless_instance_awayClass::MOP::Class::rebless_instance_away
0000s0sClass::MOP::Class::::rebless_instance_backClass::MOP::Class::rebless_instance_back
0000s0sClass::MOP::Class::::remove_dependent_meta_instanceClass::MOP::Class::remove_dependent_meta_instance
0000s0sClass::MOP::Class::::remove_meta_instance_dependenciesClass::MOP::Class::remove_meta_instance_dependencies
0000s0sClass::MOP::Class::::subclassesClass::MOP::Class::subclasses
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Class::MOP::Class;
3
4385µs285µs
# spent 70µs (56+14) within Class::MOP::Class::BEGIN@4 which was called # once (56µs+14µs) by Class::MOP::BEGIN@18 at line 4
use strict;
# spent 70µs making 1 call to Class::MOP::Class::BEGIN@4 # spent 14µs making 1 call to strict::import
5393µs2168µs
# spent 100µs (32+68) within Class::MOP::Class::BEGIN@5 which was called # once (32µs+68µs) by Class::MOP::BEGIN@18 at line 5
use warnings;
# spent 100µs making 1 call to Class::MOP::Class::BEGIN@5 # spent 68µs making 1 call to warnings::import
6
73366µs16.45ms
# spent 6.45ms (4.40+2.05) within Class::MOP::Class::BEGIN@7 which was called # once (4.40ms+2.05ms) by Class::MOP::BEGIN@18 at line 7
use Class::MOP::Instance;
# spent 6.45ms making 1 call to Class::MOP::Class::BEGIN@7
83353µs115.2ms
# spent 15.2ms (4.26+11.0) within Class::MOP::Class::BEGIN@8 which was called # once (4.26ms+11.0ms) by Class::MOP::BEGIN@18 at line 8
use Class::MOP::Method::Wrapped;
# spent 15.2ms making 1 call to Class::MOP::Class::BEGIN@8
93454µs114.2ms
# spent 14.2ms (4.53+9.68) within Class::MOP::Class::BEGIN@9 which was called # once (4.53ms+9.68ms) by Class::MOP::BEGIN@18 at line 9
use Class::MOP::Method::Accessor;
# spent 14.2ms making 1 call to Class::MOP::Class::BEGIN@9
103397µs18.49ms
# spent 8.49ms (3.78+4.71) within Class::MOP::Class::BEGIN@10 which was called # once (3.78ms+4.71ms) by Class::MOP::BEGIN@18 at line 10
use Class::MOP::Method::Constructor;
# spent 8.49ms making 1 call to Class::MOP::Class::BEGIN@10
11
12393µs2249µs
# spent 140µs (31+109) within Class::MOP::Class::BEGIN@12 which was called # once (31µs+109µs) by Class::MOP::BEGIN@18 at line 12
use Carp 'confess';
# spent 140µs making 1 call to Class::MOP::Class::BEGIN@12 # spent 109µs making 1 call to Exporter::import
13399µs2806µs
# spent 419µs (32+387) within Class::MOP::Class::BEGIN@13 which was called # once (32µs+387µs) by Class::MOP::BEGIN@18 at line 13
use Scalar::Util 'blessed', 'reftype', 'weaken';
# spent 419µs making 1 call to Class::MOP::Class::BEGIN@13 # spent 387µs making 1 call to Exporter::import
14392µs2236µs
# spent 134µs (31+103) within Class::MOP::Class::BEGIN@14 which was called # once (31µs+103µs) by Class::MOP::BEGIN@18 at line 14
use Sub::Name 'subname';
# spent 134µs making 1 call to Class::MOP::Class::BEGIN@14 # spent 103µs making 1 call to Exporter::import
153558µs235.4ms
# spent 34.7ms (967µs+33.7) within Class::MOP::Class::BEGIN@15 which was called # once (967µs+33.7ms) by Class::MOP::BEGIN@18 at line 15
use Devel::GlobalDestruction 'in_global_destruction';
# spent 34.7ms making 1 call to Class::MOP::Class::BEGIN@15 # spent 677µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
163363µs23.18ms
# spent 1.61ms (40µs+1.57) within Class::MOP::Class::BEGIN@16 which was called # once (40µs+1.57ms) by Class::MOP::BEGIN@18 at line 16
use Try::Tiny;
# spent 1.61ms making 1 call to Class::MOP::Class::BEGIN@16 # spent 1.57ms making 1 call to Exporter::import
17
1813µsour $VERSION = '1.00';
19157µs$VERSION = eval $VERSION;
2012µsour $AUTHORITY = 'cpan:STEVAN';
21
2232.59ms223.3ms
# spent 11.7ms (34µs+11.6) within Class::MOP::Class::BEGIN@22 which was called # once (34µs+11.6ms) by Class::MOP::BEGIN@18 at line 22
use base 'Class::MOP::Module', 'Class::MOP::Mixin::HasAttributes';
# spent 11.7ms making 1 call to Class::MOP::Class::BEGIN@22 # spent 11.6ms making 1 call to base::import
23
24# Creation
25
26
# spent 429ms (65.4+364) within Class::MOP::Class::initialize which was called 2323 times, avg 185µs/call: # 537 times (16.0ms+6.41ms) by Class::MOP::Object::meta at line 17 of Class/MOP/Object.pm, avg 42µs/call # 441 times (10.9ms+3.02ms) by Class::MOP::Attribute::set_raw_value at line 264 of Class/MOP/Attribute.pm, avg 32µs/call # 295 times (9.75ms+2.04ms) by Class::MOP::Class::get_all_attributes at line 551, avg 40µs/call # 175 times (4.65ms+1.51ms) by Class::MOP::Class::find_method_by_name at line 729, avg 35µs/call # 151 times (3.93ms+1.02ms) by Class::MOP::Class::find_attribute_by_name at line 541, avg 33µs/call # 115 times (2.83ms+627µs) by Class::MOP::Attribute::get_raw_value at line 272 of Class/MOP/Attribute.pm, avg 30µs/call # 112 times (3.27ms+771µs) by Class::MOP::Class::find_next_method_by_name at line 779, avg 36µs/call # 77 times (3.11ms+334ms) by Moose::Meta::Class::initialize at line 62 of Moose/Meta/Class.pm, avg 4.38ms/call # 66 times (1.16ms+368µ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 23µs/call # 60 times (722µs+186µs) by Class::MOP::Attribute::has_value at line 280 of Class/MOP/Attribute.pm, avg 15µs/call # 55 times (2.42ms+515µ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 53µs/call # 43 times (907µs+499µs) by Moose::Util::MetaRole::_make_new_class at line 144 of Moose/Util/MetaRole.pm, avg 33µs/call # 40 times (1.07ms+1.68ms) by Class::MOP::Mixin::meta at line 14 of Class/MOP/Mixin.pm, avg 69µs/call # 23 times (336µs+91µs) by Class::MOP::Attribute::set_initial_value at line 251 of Class/MOP/Attribute.pm, avg 19µs/call # 22 times (636µs+257µs) by Class::MOP::Class::class_precedence_list at line 638, avg 41µs/call # 19 times (697µs+7.44ms) by metaclass::import at line 43 of metaclass.pm, avg 428µs/call # 17 times (648µs+114µ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 45µs/call # 17 times (486µs+132µ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, avg 36µs/call # 13 times (473µs+109µs) by namespace::autoclean::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/namespace/autoclean.pm:53] at line 40 of namespace/autoclean.pm, avg 45µs/call # 12 times (336µs+54µs) by Moose::Object::new at line 25 of Moose/Object.pm, avg 32µs/call # 7 times (282µs+1.81ms) by Moose::BEGIN@37 at line 11 of Moose/Meta/Attribute/Native.pm, avg 299µs/call # 6 times (102µs+29µs) by Class::MOP::Method::Wrapped::_new at line 101 of Class/MOP/Method/Wrapped.pm, avg 22µs/call # 5 times (106µs+27µs) by Class::MOP::Class::get_all_methods at line 740, avg 27µs/call # 3 times (144µs+472µs) by Class::MOP::Class::_immutable_metaclass at line 967, avg 205µs/call # 3 times (131µs+20µs) by Moose::Meta::Role::_new at line 4 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 50µs/call # 3 times (72µs+21µs) by Moose::Meta::Role::Application::ToClass::_new at line 4 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 31µs/call # 2 times (68µs+556µs) by Class::MOP::Class::create at line 298, avg 312µs/call # 2 times (113µs+204µs) by Class::MOP::Method::_new at line 54 of Class/MOP/Method.pm, avg 159µs/call # once (37µs+10µs) by Moose::Meta::Role::Application::ToRole::_new at line 4 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm # once (23µs+6µs) by Class::MOP::Attribute::_new at line 62 of Class/MOP/Attribute.pm
sub initialize {
271161559.9ms my $class = shift;
28
29 my $package_name;
30
31 if ( @_ % 2 ) {
32 $package_name = shift;
33 } else {
34 my %options = @_;
35 $package_name = $options{package};
36 }
37
38 ($package_name && !ref($package_name))
39 || confess "You must pass a package name and it cannot be blessed";
40
41 return Class::MOP::get_metaclass_by_name($package_name)
# spent 391ms making 136 calls to Class::MOP::Class::_construct_class_instance, avg 2.88ms/call, recursion: max depth 1, time 40.2ms # spent 16.4ms making 2323 calls to Class::MOP::get_metaclass_by_name, avg 7µ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 351ms (15.2+336) within Class::MOP::Class::_construct_class_instance which was called 136 times, avg 2.58ms/call: # 136 times (15.2ms+336ms) by Class::MOP::Class::initialize at line 41, avg 2.58ms/call
sub _construct_class_instance {
52170913.4ms my $class = shift;
53 my $options = @_ == 1 ? $_[0] : {@_};
54 my $package_name = $options->{package};
55 (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 if (defined(my $meta = Class::MOP::get_metaclass_by_name($package_name))) {
# spent 976µs making 136 calls to Class::MOP::get_metaclass_by_name, avg 7µs/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 $class = (ref($class)
# spent 630µs making 7 calls to Class::MOP::Class::Immutable::Class::MOP::Class::__ANON__::SERIAL::5::is_immutable, avg 90µs/call # spent 116µs making 7 calls to Class::MOP::Class::Immutable::Trait::_get_mutable_metaclass_name, avg 17µs/call # spent 17µs making 3 calls to Class::MOP::Class::is_immutable, avg 6µs/call
72 ? ($class->is_immutable
73 ? $class->_get_mutable_metaclass_name()
74 : ref($class))
75 : $class);
76
77 # now create the metaclass
78 my $meta;
79 if ($class eq 'Class::MOP::Class') {
# spent 3.20ms making 59 calls to Class::MOP::Class::_new, avg 54µ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 $meta = $class->meta->_construct_instance($options)
# spent 253ms making 77 calls to Class::MOP::Class::_construct_instance, avg 3.28ms/call # spent 4.55ms making 62 calls to Class::MOP::Object::meta, avg 73µs/call # spent 580µs making 15 calls to Class::MOP::Class::__ANON__::SERIAL::5::meta, avg 39µs/call
88 }
89
90 # and check the metaclass compatibility
91 $meta->_check_metaclass_compatibility();
# spent 102ms making 77 calls to Moose::Meta::Class::_check_metaclass_compatibility, avg 1.33ms/call, recursion: max depth 2, time 20.3ms # spent 2.08ms making 59 calls to Class::MOP::Class::_check_metaclass_compatibility, avg 35µs/call
92
93 Class::MOP::store_metaclass_by_name($package_name, $meta);
# spent 1.14ms making 136 calls to Class::MOP::store_metaclass_by_name, avg 8µs/call
94
95 # NOTE:
96 # we need to weaken any anon classes
97 # so that they can call DESTROY properly
98 Class::MOP::weaken_metaclass($package_name) if $meta->is_anon_class;
# spent 7.65ms making 136 calls to Class::MOP::Class::is_anon_class, avg 56µs/call # spent 163µs making 8 calls to Class::MOP::weaken_metaclass, avg 20µs/call
99
100 $meta;
101}
102
103
# spent 3.20ms within Class::MOP::Class::_new which was called 59 times, avg 54µs/call: # 59 times (3.20ms+0s) by Class::MOP::Class::_construct_class_instance at line 79, avg 54µs/call
sub _new {
1042363.56ms my $class = shift;
105
106 return Class::MOP::Class->initialize($class)->new_object(@_)
107 if $class ne __PACKAGE__;
108
109 my $options = @_ == 1 ? $_[0] : {@_};
110
111 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
15626485µs
# spent 294µs within Class::MOP::Class::reset_package_cache_flag which was called 26 times, avg 11µs/call: # 26 times (294µs+0s) by Moose::Meta::Role::Application::ToClass::apply_methods at line 187 of Moose/Meta/Role/Application/ToClass.pm, avg 11µs/call
sub reset_package_cache_flag { (shift)->{'_package_cache_flag'} = undef }
157
# spent 46µs (34+12) within Class::MOP::Class::update_package_cache_flag which was called 2 times, avg 23µs/call: # 2 times (34µs+12µs) by Class::MOP::Mixin::HasMethods::remove_method at line 144 of Class/MOP/Mixin/HasMethods.pm, avg 23µs/call
sub update_package_cache_flag {
158450µs 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);
# spent 8µs making 2 calls to mro::get_pkg_gen, avg 4µs/call # spent 4µs making 2 calls to Class::MOP::Package::name, avg 2µs/call
166}
167
168
# spent 51.4ms (28.3+23.1) within Class::MOP::Class::_check_metaclass_compatibility which was called 202 times, avg 254µs/call: # 141 times (26.8ms+22.4ms) by Moose::Meta::Class::_check_metaclass_compatibility at line 108 of Moose/Meta/Class.pm, avg 349µs/call # 59 times (1.44ms+635µs) by Class::MOP::Class::_construct_class_instance at line 91, avg 35µs/call # 2 times (43µs+16µs) by Class::MOP::Class::superclasses at line 579, avg 29µs/call
sub _check_metaclass_compatibility {
169202327.6ms my $self = shift;
170
171 # this is always okay ...
172 return if ref($self) eq 'Class::MOP::Class' &&
# spent 651µs making 61 calls to Class::MOP::Class::instance_metaclass, avg 11µs/call
173 $self->instance_metaclass eq 'Class::MOP::Instance';
174
175 my @class_list = $self->linearized_isa;
# spent 4.98ms making 141 calls to Class::MOP::Class::linearized_isa, avg 35µs/call
176 shift @class_list; # shift off $self->name
177
178 foreach my $superclass_name (@class_list) {
179 my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name) || next;
# spent 2.01ms making 299 calls to Class::MOP::get_metaclass_by_name, avg 7µ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 my $super_meta_type
# spent 3.50ms making 89 calls to Class::MOP::Class::Immutable::Moose::Meta::Class::is_immutable, avg 39µs/call # spent 1.32ms making 47 calls to Class::MOP::Class::Immutable::Class::MOP::Class::is_immutable, avg 28µs/call # spent 1.24ms making 164 calls to Class::MOP::Class::Immutable::Trait::_get_mutable_metaclass_name, avg 8µs/call # spent 1.01ms making 28 calls to Class::MOP::Class::Immutable::Class::MOP::Class::__ANON__::SERIAL::5::is_immutable, avg 36µs/call # spent 971µs making 135 calls to Class::MOP::Class::is_immutable, avg 7µs/call
186 = $super_meta->is_immutable
187 ? $super_meta->_get_mutable_metaclass_name()
188 : ref($super_meta);
189
190 ($self->isa($super_meta_type))
# spent 1.58ms making 299 calls to UNIVERSAL::isa, avg 5µs/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 ($self->instance_metaclass->isa($super_meta->instance_metaclass))
# spent 4.03ms making 598 calls to Class::MOP::Class::instance_metaclass, avg 7µs/call # spent 1.80ms making 299 calls to UNIVERSAL::isa, avg 6µ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.
21225µs 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.
21913µs my $ANON_CLASS_PREFIX = 'Class::MOP::Class::__ANON__::SERIAL::';
220
221
# spent 17.0ms (13.0+4.08) within Class::MOP::Class::is_anon_class which was called 358 times, avg 48µs/call: # 206 times (6.45ms+2.43ms) by Class::MOP::Class::_construct_instance at line 368, avg 43µs/call # 136 times (6.10ms+1.55ms) by Class::MOP::Class::_construct_class_instance at line 98, avg 56µs/call # 9 times (271µs+68µs) by Moose::Meta::Class::reinitialize at line 163 of Moose/Meta/Class.pm, avg 38µs/call # 7 times (142µs+41µs) by Moose::Meta::Class::_reinitialize_with at line 436 of Moose/Meta/Class.pm, avg 26µs/call
sub is_anon_class {
22271617.2ms my $self = shift;
2233405µs2136µs
# spent 85µs (34+51) within Class::MOP::Class::BEGIN@223 which was called # once (34µs+51µs) by Class::MOP::BEGIN@18 at line 223
no warnings 'uninitialized';
# spent 85µs making 1 call to Class::MOP::Class::BEGIN@223 # spent 51µs making 1 call to warnings::unimport
224 $self->name =~ /^$ANON_CLASS_PREFIX/o;
# spent 1.88ms making 358 calls to Class::MOP::Package::name, avg 5µs/call # spent 1.49ms making 358 calls to Class::MOP::Class::CORE:match, avg 4µs/call # spent 719µs making 358 calls to Class::MOP::Class::CORE:regcomp, avg 2µs/call
225 }
226
227
# spent 293ms (284µs+293) within Class::MOP::Class::create_anon_class which was called 8 times, avg 36.7ms/call: # 8 times (284µs+293ms) by Moose::Meta::Class::create_anon_class at line 125 of Moose/Meta/Class.pm, avg 36.7ms/call
sub create_anon_class {
22824272µs my ($class, %options) = @_;
229 my $package_name = $ANON_CLASS_PREFIX . ++$ANON_CLASS_SERIAL;
230 return $class->create($package_name, %options);
# spent 293ms making 8 calls to Moose::Meta::Class::create, avg 36.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 704µs (507+197) within Class::MOP::Class::DESTROY which was called 15 times, avg 47µs/call: # 7 times (234µs+100µs) by MooseX::MethodAttributes::init_meta at line 39 of MooseX/MethodAttributes.pm, avg 48µs/call # 7 times (233µs+81µs) by Moose::Meta::Class::_reinitialize_with at line 406 of Moose/Meta/Class.pm, avg 45µs/call # once (40µs+15µs) by Moose::Util::_apply_all_roles at line 86 of Moose/Util.pm
sub DESTROY {
24060894µs my $self = shift;
241
242 return if in_global_destruction(); # it'll happen soon anyway and this just makes things more complicated
# spent 81µs making 15 calls to Devel::GlobalDestruction::in_global_destruction, avg 5µs/call
243
2443290µs2240µs
# spent 136µs (32+104) within Class::MOP::Class::BEGIN@244 which was called # once (32µs+104µs) by Class::MOP::BEGIN@18 at line 244
no warnings 'uninitialized';
# spent 136µs making 1 call to Class::MOP::Class::BEGIN@244 # spent 104µs making 1 call to warnings::unimport
245 my $name = $self->name;
# spent 54µs making 15 calls to Class::MOP::Package::name, avg 4µs/call
246 return unless $name =~ /^$ANON_CLASS_PREFIX/o;
# spent 41µs making 15 calls to Class::MOP::Class::CORE:regcomp, avg 3µs/call # spent 21µs making 15 calls to Class::MOP::Class::CORE:match, avg 1µs/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);
257316.9ms2123µs
# spent 77µs (32+46) within Class::MOP::Class::BEGIN@257 which was called # once (32µs+46µs) by Class::MOP::BEGIN@18 at line 257
no strict 'refs';
# spent 77µs making 1 call to Class::MOP::Class::BEGIN@257 # spent 46µ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 60.4ms (1.71+58.7) within Class::MOP::Class::create which was called 11 times, avg 5.49ms/call: # 9 times (1.26ms+55.8ms) by Moose::Meta::Class::create at line 92 of Moose/Meta/Class.pm, avg 6.34ms/call # 2 times (448µs+2.95ms) by Class::MOP::Class::_immutable_metaclass at line 961, avg 1.70ms/call
sub create {
2701761.61ms my ( $class, @args ) = @_;
271
272 unshift @args, 'package' if @args % 2 == 1;
273
274 my (%options) = @args;
275 my $package_name = $options{package};
276
277 (ref $options{superclasses} eq 'ARRAY')
278 || confess "You must pass an ARRAY ref of superclasses"
279 if exists $options{superclasses};
280
281 (ref $options{attributes} eq 'ARRAY')
282 || confess "You must pass an ARRAY ref of attributes"
283 if exists $options{attributes};
284
285 (ref $options{methods} eq 'HASH')
286 || confess "You must pass a HASH ref of methods"
287 if exists $options{methods};
288
289 my (%initialize_options) = @args;
290 delete @initialize_options{qw(
291 package
292 superclasses
293 attributes
294 methods
295 version
296 authority
297 )};
298 my $meta = $class->initialize( $package_name => %initialize_options );
# spent 36.8ms making 9 calls to Moose::Meta::Class::initialize, avg 4.08ms/call # spent 624µs making 2 calls to Class::MOP::Class::initialize, avg 312µs/call
299
300 $meta->_instantiate_module( $options{version}, $options{authority} );
# spent 1.44ms making 11 calls to Class::MOP::Module::_instantiate_module, avg 131µs/call
301
302 # FIXME totally lame
303 $meta->add_method('meta' => sub {
304681.14ms681.60ms $class->initialize(ref($_[0]) || $_[0]);
# spent 1.95ms making 68 calls to Moose::Meta::Class::initialize, avg 29µs/call, recursion: max depth 2, time 351µs
305 });
# spent 2.28ms making 11 calls to Class::MOP::Mixin::HasMethods::add_method, avg 208µs/call
306
307 $meta->superclasses(@{$options{superclasses}})
# spent 16.1ms making 9 calls to Moose::Meta::Class::superclasses, avg 1.79ms/call # spent 1.48ms making 2 calls to Class::MOP::Class::superclasses, avg 742µs/call
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 if (exists $options{attributes}) {
315 foreach my $attr (@{$options{attributes}}) {
316 $meta->add_attribute($attr);
317 }
318 }
319 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 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
333128216.0ms
# spent 11.9ms within Class::MOP::Class::instance_metaclass which was called 1282 times, avg 9µs/call: # 598 times (4.03ms+0s) by Class::MOP::Class::_check_metaclass_compatibility at line 198, avg 7µs/call # 250 times (3.02ms+0s) by Moose::Meta::Class::_superclass_meta_is_compatible at line 378 of Moose/Meta/Class.pm, avg 12µs/call # 158 times (1.32ms+0s) by Class::MOP::Class::_create_meta_instance at line 390, avg 8µs/call # 84 times (607µs+0s) by Class::MOP::Attribute::_process_accessors at line 320 of Class/MOP/Attribute.pm, avg 7µs/call # 61 times (651µs+0s) by Class::MOP::Class::_check_metaclass_compatibility at line 172, avg 11µs/call # 52 times (401µs+0s) by Class::MOP::Method::Accessor::_generate_reader_method_inline at line 155 of Class/MOP/Method/Accessor.pm, avg 8µs/call # 23 times (1.22ms+0s) by Class::MOP::Method::Accessor::_generate_predicate_method_inline at line 190 of Class/MOP/Method/Accessor.pm, avg 53µs/call # 15 times (388µs+0s) by Class::MOP::Method::Accessor::_generate_accessor_method_inline at line 136 of Class/MOP/Method/Accessor.pm, avg 26µs/call # 14 times (97µs+0s) by List::MoreUtils::all at line 407 of Moose/Meta/Class.pm, avg 7µs/call # 9 times (58µs+0s) by Moose::Meta::Class::reinitialize at line 151 of Moose/Meta/Class.pm, avg 6µs/call # 8 times (58µs+0s) by Class::MOP::Method::Accessor::_generate_clearer_method_inline at line 207 of Class/MOP/Method/Accessor.pm, avg 7µs/call # 7 times (42µs+0s) by Moose::Meta::Class::_reinitialize_with at line 418 of Moose/Meta/Class.pm, avg 6µs/call # 3 times (20µs+0s) by Class::MOP::Method::Accessor::_generate_writer_method_inline at line 173 of Class/MOP/Method/Accessor.pm, avg 7µs/call
sub instance_metaclass { $_[0]->{'instance_metaclass'} }
3341001.57ms
# spent 945µs within Class::MOP::Class::immutable_trait which was called 100 times, avg 9µs/call: # 50 times (485µs+0s) by Class::MOP::Class::_immutable_options at line 876, avg 10µs/call # 50 times (460µs+0s) by Class::MOP::Class::_immutable_metaclass at line 931, avg 9µs/call
sub immutable_trait { $_[0]->{'immutable_trait'} }
33550791µs
# spent 351µs within Class::MOP::Class::constructor_class which was called 50 times, avg 7µs/call: # 50 times (351µs+0s) by Class::MOP::Class::_immutable_options at line 876, avg 7µs/call
sub constructor_class { $_[0]->{'constructor_class'} }
33677857µs
# spent 827µs within Class::MOP::Class::constructor_name which was called 77 times, avg 11µs/call: # 77 times (827µs+0s) by Class::MOP::Class::_immutable_options at line 876, avg 11µs/call
sub constructor_name { $_[0]->{'constructor_name'} }
33750432µs
# spent 311µs within Class::MOP::Class::destructor_class which was called 50 times, avg 6µs/call: # 50 times (311µs+0s) by Class::MOP::Class::_immutable_options at line 876, avg 6µs/call
sub destructor_class { $_[0]->{'destructor_class'} }
338
339# Instance Construction & Cloning
340
341
# spent 188ms (4.30+183) within Class::MOP::Class::new_object which was called 129 times, avg 1.45ms/call: # 125 times (3.89ms+168ms) by Moose::Meta::Class::new_object at line 255 of Moose/Meta/Class.pm, avg 1.37ms/call # 2 times (250µs+10.1ms) by Class::MOP::Method::_new at line 54 of Class/MOP/Method.pm, avg 5.20ms/call # once (47µs+3.82ms) by Class::MOP::Attribute::_new at line 62 of Class/MOP/Attribute.pm # once (109µs+1.61ms) by Class::MOP::Object::_new at line 21 of Class/MOP/Object.pm
sub new_object {
3423876.16ms 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 return $class->_construct_class_instance(@_)
# spent 1.08ms making 129 calls to UNIVERSAL::isa, avg 8µs/call # spent 809µs making 129 calls to Class::MOP::Package::name, avg 6µs/call
350 if $class->name->isa('Class::MOP::Class');
351 return $class->_construct_instance(@_);
# spent 181ms making 129 calls to Class::MOP::Class::_construct_instance, avg 1.41ms/call
352}
353
354
# spent 434ms (49.8+384) within Class::MOP::Class::_construct_instance which was called 206 times, avg 2.11ms/call: # 129 times (24.5ms+157ms) by Class::MOP::Class::new_object at line 351, avg 1.41ms/call # 77 times (25.3ms+228ms) by Class::MOP::Class::_construct_class_instance at line 87, avg 3.28ms/call
sub _construct_instance {
355432345.5ms my $class = shift;
356 my $params = @_ == 1 ? $_[0] : {@_};
357 my $meta_instance = $class->get_meta_instance();
# spent 19.8ms making 144 calls to Class::MOP::Class::get_meta_instance, avg 138µs/call # spent 3.43ms making 61 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 56µs/call # spent 35µs making 1 call to Class::MOP::Class::Immutable::Moose::Meta::Class::get_meta_instance
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 my $instance = $params->{__INSTANCE__} || $meta_instance->create_instance();
# spent 16.5ms making 206 calls to Class::MOP::Instance::create_instance, avg 80µs/call
363 foreach my $attr ($class->get_all_attributes()) {
# spent 53.5ms making 144 calls to Class::MOP::Class::get_all_attributes, avg 372µs/call # spent 4.83ms making 61 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 79µs/call # spent 164µs making 1 call to Class::MOP::Class::Immutable::Moose::Meta::Class::get_all_attributes
364 $attr->initialize_instance_slot($meta_instance, $instance, $params);
# spent 256ms making 2506 calls to Class::MOP::Attribute::initialize_instance_slot, avg 102µs/call # spent 20.8ms making 153 calls to Moose::Meta::Attribute::initialize_instance_slot, avg 136µs/call
365 }
366 # NOTE:
367 # this will only work for a HASH instance type
368 if ($class->is_anon_class) {
# spent 8.88ms making 206 calls to Class::MOP::Class::is_anon_class, avg 43µs/call
369 (reftype($instance) eq 'HASH')
# spent 793µs making 111 calls to Scalar::Util::reftype, avg 7µ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 $instance->{'__MOP__'} = $class;
377 }
378 return $instance;
379}
380
381
382
# spent 126ms (5.83+120) within Class::MOP::Class::get_meta_instance which was called 501 times, avg 251µs/call: # 144 times (1.23ms+18.6ms) by Class::MOP::Class::_construct_instance at line 357, avg 138µs/call # 105 times (1.64ms+54.1ms) by Moose::Meta::Method::Accessor::_inline_store at line 218 of Moose/Meta/Method/Accessor.pm, avg 531µs/call # 104 times (1.01ms+12.7ms) by Moose::Meta::Method::Accessor::_inline_get at line 252 of Moose/Meta/Method/Accessor.pm, avg 132µs/call # 56 times (1.17ms+32.8ms) by Class::MOP::Method::Constructor::_meta_instance at line 77 of Class/MOP/Method/Constructor.pm, avg 606µs/call # 25 times (211µs+0s) by Class::MOP::Attribute::get_raw_value at line 272 of Class/MOP/Attribute.pm, avg 8µs/call # 21 times (221µs+0s) by Moose::Meta::Method::Accessor::_inline_has at line 270 of Moose/Meta/Method/Accessor.pm, avg 11µs/call # 21 times (114µs+0s) by Class::MOP::Attribute::set_initial_value at line 251 of Class/MOP/Attribute.pm, avg 5µs/call # 10 times (82µs+0s) by Class::MOP::Attribute::set_raw_value at line 264 of Class/MOP/Attribute.pm, avg 8µs/call # 7 times (48µs+0s) by Class::MOP::Class:::around at line 74 of Class/MOP/Class/Immutable/Trait.pm, avg 7µs/call # 6 times (69µs+528µs) by Class::MOP::Class::_clone_instance at line 419, avg 100µs/call # once (21µs+1.00ms) by Moose::Exporter::BEGIN@11 at line 663 of Class/MOP.pm # once (10µs+0s) by Class::MOP::Attribute::has_value at line 280 of Class/MOP/Attribute.pm
sub get_meta_instance {
38310027.06ms my $self = shift;
384 $self->{'_meta_instance'} ||= $self->_create_meta_instance();
# spent 120ms making 158 calls to Class::MOP::Class::_create_meta_instance, avg 758µs/call
385}
386
387
# spent 120ms (8.47+111) within Class::MOP::Class::_create_meta_instance which was called 158 times, avg 758µs/call: # 158 times (8.47ms+111ms) by Class::MOP::Class::get_meta_instance at line 384, avg 758µs/call
sub _create_meta_instance {
3886327.30ms my $self = shift;
389
390 my $instance = $self->instance_metaclass->new(
# spent 60.5ms making 158 calls to Class::MOP::Instance::new, avg 383µs/call # spent 48.6ms making 158 calls to Class::MOP::Class::get_all_attributes, avg 307µs/call # spent 1.32ms making 158 calls to Class::MOP::Class::instance_metaclass, avg 8µs/call
391 associated_metaclass => $self,
392 attributes => [ $self->get_all_attributes() ],
393 );
394
395 $self->add_meta_instance_dependencies()
# spent 854µs making 158 calls to Class::MOP::Instance::is_dependent_on_superclasses, avg 5µs/call
396 if $instance->is_dependent_on_superclasses();
397
398 return $instance;
399}
400
401
# spent 162ms (11.0+151) within Class::MOP::Class::clone_object which was called 214 times, avg 755µs/call: # 214 times (11.0ms+151ms) by Class::MOP::Method::clone at line 538 of Class/MOP.pm, avg 755µs/call
sub clone_object {
402107014.0ms my $class = shift;
403 my $instance = shift;
404 (blessed($instance) && $instance->isa($class->name))
# spent 1.01ms making 214 calls to Scalar::Util::blessed, avg 5µs/call # spent 934µs making 214 calls to UNIVERSAL::isa, avg 4µs/call # spent 777µs making 214 calls to Class::MOP::Package::name, avg 4µs/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 return $instance if $instance->isa('Class::MOP::Class');
# spent 1.52ms making 214 calls to UNIVERSAL::isa, avg 7µs/call
412 $class->_clone_instance($instance, @_);
# spent 146ms making 214 calls to Class::MOP::Class::_clone_instance, avg 684µs/call
413}
414
415
# spent 146ms (33.4+113) within Class::MOP::Class::_clone_instance which was called 214 times, avg 684µs/call: # 214 times (33.4ms+113ms) by Class::MOP::Class::clone_object at line 412, avg 684µs/call
sub _clone_instance {
416235433.2ms my ($class, $instance, %params) = @_;
417 (blessed($instance))
# spent 929µs making 214 calls to Scalar::Util::blessed, avg 4µs/call
418 || confess "You can only clone instances, ($instance) is not a blessed instance";
419 my $meta_instance = $class->get_meta_instance();
# spent 11.0ms making 208 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 53µs/call # spent 597µs making 6 calls to Class::MOP::Class::get_meta_instance, avg 100µs/call
420 my $clone = $meta_instance->clone_instance($instance);
# spent 11.5ms making 214 calls to Class::MOP::Instance::clone_instance, avg 54µs/call
421 foreach my $attr ($class->get_all_attributes()) {
# spent 13.2ms making 208 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 64µs/call # spent 1.32ms making 6 calls to Class::MOP::Class::get_all_attributes, avg 220µs/call
422 if ( defined( my $init_arg = $attr->init_arg ) ) {
# spent 66.1ms making 410 calls to Class::MOP::Attribute::set_value, avg 161µs/call # spent 8.25ms making 1070 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 8µs/call
423 if (exists $params{$init_arg}) {
424 $attr->set_value($clone, $params{$init_arg});
425 }
426 }
427 }
428 return $clone;
429}
430
431sub 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
468sub 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
497sub rebless_instance_away {
498 # this intentionally does nothing, it is just a hook
499}
500
501
# spent 16.4ms (4.20+12.2) within Class::MOP::Class::_attach_attribute which was called 234 times, avg 70µs/call: # 234 times (4.20ms+12.2ms) by Class::MOP::Mixin::HasAttributes::add_attribute at line 28 of Class/MOP/Mixin/HasAttributes.pm, avg 70µs/call
sub _attach_attribute {
5024684.46ms my ($self, $attribute) = @_;
503 $attribute->attach_to_class($self);
# spent 12.2ms making 234 calls to Class::MOP::Attribute::attach_to_class, avg 52µs/call
504}
505
506
# spent 715ms (14.3+701) within Class::MOP::Class::_post_add_attribute which was called 234 times, avg 3.06ms/call: # 234 times (14.3ms+701ms) by Class::MOP::Mixin::HasAttributes::add_attribute at line 45 of Class/MOP/Mixin/HasAttributes.pm, avg 3.06ms/call
sub _post_add_attribute {
50770212.9ms my ( $self, $attribute ) = @_;
508
509 $self->invalidate_meta_instances;
# spent 11.7ms making 234 calls to Class::MOP::Class::invalidate_meta_instances, avg 50µs/call
510
511 # invalidate package flag here
512
# spent 663ms (7.49+655) within Class::MOP::Class::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP/Class.pm:515] which was called 234 times, avg 2.83ms/call: # 234 times (7.49ms+655ms) by Try::Tiny::try at line 76 of Try/Tiny.pm, avg 2.83ms/call
try {
5134687.38ms local $SIG{__DIE__};
514 $attribute->install_accessors;
# spent 519ms making 120 calls to Moose::Meta::Attribute::install_accessors, avg 4.32ms/call # spent 136ms making 114 calls to Class::MOP::Attribute::install_accessors, avg 1.19ms/call
515 }
516 catch {
517 $self->remove_attribute( $attribute->name );
518 die $_;
519 };
# spent 680ms making 234 calls to Try::Tiny::try, avg 2.91ms/call, recursion: max depth 2, time 214ms # spent 8.68ms making 234 calls to Try::Tiny::catch, avg 37µs/call
520}
521
522
# spent 1.71ms (120µs+1.59) within Class::MOP::Class::remove_attribute which was called 2 times, avg 856µs/call: # 2 times (120µs+1.59ms) by Class::MOP::Mixin::HasAttributes::add_attribute at line 32 of Class/MOP/Mixin/HasAttributes.pm, avg 856µs/call
sub remove_attribute {
52312101µs my $self = shift;
524
525 my $removed_attribute = $self->SUPER::remove_attribute(@_)
# spent 50µs making 2 calls to Class::MOP::Mixin::HasAttributes::remove_attribute, avg 25µs/call
526 or return;
527
528 $self->invalidate_meta_instances;
# spent 59µs making 2 calls to Class::MOP::Class::invalidate_meta_instances, avg 30µs/call
529
530 $removed_attribute->remove_accessors;
# spent 1.39ms making 2 calls to Moose::Meta::Attribute::remove_accessors, avg 694µs/call
531 $removed_attribute->detach_from_class;
# spent 94µs making 2 calls to Class::MOP::Attribute::detach_from_class, avg 47µs/call
532
533 return$removed_attribute;
534}
535
536
# spent 59.2ms (18.0+41.2) within Class::MOP::Class::find_attribute_by_name which was called 159 times, avg 373µs/call: # 77 times (5.71ms+13.9ms) by Class::MOP::Class::_immutable_metaclass at line 935, avg 255µs/call # 50 times (9.49ms+21.5ms) by Moose::Util::MetaRole::_make_new_metaclass at line 104 of Moose/Util/MetaRole.pm, avg 620µs/call # 15 times (1.51ms+3.28ms) by MooseX::Emulate::Class::Accessor::Fast::mk_accessors at line 111 of MooseX/Emulate/Class/Accessor/Fast.pm, avg 320µs/call # 15 times (1.21ms+2.43ms) by MooseX::Emulate::Class::Accessor::Fast::mk_accessors at line 119 of MooseX/Emulate/Class/Accessor/Fast.pm, avg 243µs/call # 2 times (89µs+114µs) by Moose::Meta::Class::_process_inherited_attribute at line 612 of Moose/Meta/Class.pm, avg 102µs/call
sub find_attribute_by_name {
537133115.6ms my ( $self, $attr_name ) = @_;
538
539 foreach my $class ( $self->linearized_isa ) {
# spent 4.81ms making 87 calls to Class::MOP::Class::Immutable::Class::MOP::Class::linearized_isa, avg 55µs/call # spent 2.86ms making 72 calls to Class::MOP::Class::linearized_isa, avg 40µs/call
540 # fetch the meta-class ...
541 my $meta = $self->initialize($class);
# spent 9.26ms making 328 calls to Moose::Meta::Class::initialize, avg 28µs/call # spent 4.95ms making 151 calls to Class::MOP::Class::initialize, avg 33µs/call
542 return $meta->get_attribute($attr_name)
# spent 15.8ms making 479 calls to Class::MOP::Mixin::HasAttributes::has_attribute, avg 33µs/call # spent 3.53ms making 104 calls to Class::MOP::Mixin::HasAttributes::get_attribute, avg 34µs/call
543 if $meta->has_attribute($attr_name);
544 }
545
546 return;
547}
548
549
# spent 179ms (84.6+94.9) within Class::MOP::Class::get_all_attributes which was called 512 times, avg 351µs/call: # 158 times (20.9ms+27.7ms) by Class::MOP::Class::_create_meta_instance at line 390, avg 307µs/call # 144 times (24.8ms+28.7ms) by Class::MOP::Class::_construct_instance at line 363, avg 372µs/call # 124 times (23.3ms+22.0ms) by Moose::Meta::Class::new_object at line 257 of Moose/Meta/Class.pm, avg 365µs/call # 56 times (8.17ms+9.14ms) by Class::MOP::Method::Constructor::_attributes at line 82 of Class/MOP/Method/Constructor.pm, avg 309µs/call # 18 times (5.75ms+5.07ms) by Moose::Meta::Attribute::new at line 59 of Moose/Meta/Attribute.pm, avg 601µs/call # 6 times (943µs+1.74ms) by Class::MOP::Class:::around at line 68 of Class/MOP/Class/Immutable/Trait.pm, avg 447µs/call # 6 times (730µs+589µs) by Class::MOP::Class::_clone_instance at line 421, avg 220µs/call
sub get_all_attributes {
550604276.3ms my $self = shift;
551 my %attrs = map { %{ $self->initialize($_)->_attribute_map } }
# spent 49.3ms making 1958 calls to Moose::Meta::Class::initialize, avg 25µs/call, recursion: max depth 2, time 3.81ms # spent 16.8ms making 506 calls to Class::MOP::Class::linearized_isa, avg 33µs/call # spent 15.5ms making 2253 calls to Class::MOP::Mixin::HasAttributes::_attribute_map, avg 7µs/call # spent 12.7ms making 295 calls to Class::MOP::Class::initialize, avg 43µs/call, recursion: max depth 1, time 875µs # spent 451µs making 4 calls to Class::MOP::Class::Immutable::Class::MOP::Class::linearized_isa, avg 113µs/call # spent 128µs making 2 calls to Class::MOP::Class::Immutable::Moose::Meta::Class::linearized_isa, avg 64µs/call
552 reverse $self->linearized_isa;
553 return values %attrs;
554}
555
556# Inheritance
557
558
# spent 152ms (23.5+129) within Class::MOP::Class::superclasses which was called 470 times, avg 324µs/call: # 448 times (22.1ms+126ms) by Moose::Meta::Class::superclasses at line 289 of Moose/Meta/Class.pm, avg 332µs/call # 20 times (629µs+1.79ms) by Class::MOP::Class:::around at line 27 of Class/MOP/Class/Immutable/Trait.pm, avg 121µs/call # 2 times (794µs+690µs) by Class::MOP::Class::create at line 307, avg 742µs/call
sub superclasses {
559227624.1ms my $self = shift;
560 my $var_spec = { sigil => '@', type => 'ARRAY', name => 'ISA' };
561 if (@_) {
562 my @supers = @_;
563 @{$self->get_package_symbol($var_spec)} = @supers;
# spent 3.92ms making 66 calls to Class::MOP::Package::get_package_symbol, avg 59µ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 my $class = $self->name;
# spent 307µs making 66 calls to Class::MOP::Package::name, avg 5µs/call
570 $class->isa($class);
# spent 871µs making 66 calls to UNIVERSAL::isa, avg 13µ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 $self->_check_metaclass_compatibility();
# spent 103ms making 64 calls to Moose::Meta::Class::_check_metaclass_compatibility, avg 1.60ms/call # spent 59µs making 2 calls to Class::MOP::Class::_check_metaclass_compatibility, avg 29µs/call
580 $self->_superclasses_updated();
# spent 1.80ms making 66 calls to Class::MOP::Class::_superclasses_updated, avg 27µs/call
581 }
582 @{$self->get_package_symbol($var_spec)};
# spent 25.1ms making 470 calls to Class::MOP::Package::get_package_symbol, avg 54µs/call
583}
584
585
# spent 1.80ms (1.13+674µs) within Class::MOP::Class::_superclasses_updated which was called 66 times, avg 27µs/call: # 66 times (1.13ms+674µs) by Class::MOP::Class::superclasses at line 580, avg 27µs/call
sub _superclasses_updated {
5861321.09ms my $self = shift;
587 $self->update_meta_instance_dependencies();
# spent 674µs making 66 calls to Class::MOP::Class::update_meta_instance_dependencies, avg 10µs/call
588}
589
590sub subclasses {
591 my $self = shift;
592 my $super_class = $self->name;
593
594 return @{ $super_class->mro::get_isarev() };
595}
596
597sub 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 43.2ms (28.5+14.7) within Class::MOP::Class::linearized_isa which was called 1243 times, avg 35µs/call: # 506 times (10.8ms+5.98ms) by Class::MOP::Class::get_all_attributes at line 551, avg 33µs/call # 191 times (4.18ms+2.19ms) by Class::MOP::Class::find_method_by_name at line 728, avg 33µs/call # 162 times (3.74ms+2.21ms) by Class::MOP::Class::find_next_method_by_name at line 776, avg 37µs/call # 141 times (3.45ms+1.53ms) by Class::MOP::Class::_check_metaclass_compatibility at line 175, avg 35µs/call # 85 times (2.04ms+770µs) by Catalyst::Component::__config_accessor or Catalyst::Component::__plugins_accessor or Catalyst::Controller::__action_class_accessor or Catalyst::Controller::__dispatch_steps_accessor or Catalyst::_dispatcher_class_accessor or Catalyst::_log_accessor or Catalyst::_setup_finished_accessor or Catalyst::_stats_class_accessor at line 32 of Catalyst/ClassData.pm, avg 33µs/call # 72 times (1.87ms+993µs) by Class::MOP::Class::find_attribute_by_name at line 539, avg 40µs/call # 62 times (1.09ms+659µs) by Class::MOP::Class::find_all_methods_by_name at line 760, avg 28µs/call # 14 times (1.11ms+242µs) by Class::MOP::Class:::around at line 50 of Class/MOP/Class/Immutable/Trait.pm, avg 97µs/call # 7 times (176µs+73µs) by MooseX::MethodAttributes::Role::Meta::Class::get_all_methods_with_attributes at line 47 of MooseX/MethodAttributes/Role/Meta/Class.pm, avg 36µs/call # 3 times (47µs+33µs) by Class::MOP::Class::get_all_methods at line 739, avg 27µs/call
sub linearized_isa {
609124345.6ms248614.7ms return @{ mro::get_linear_isa( (shift)->name ) };
# spent 9.59ms making 1243 calls to mro::get_linear_isa, avg 8µs/call # spent 5.09ms making 1243 calls to Class::MOP::Package::name, avg 4µs/call
610}
611
612
# spent 60.9ms (17.2+43.7) within Class::MOP::Class::class_precedence_list which was called 216 times, avg 282µs/call: # 129 times (11.7ms+28.3ms) by Moose::Meta::Class::does_role at line 218 of Moose/Meta/Class.pm, avg 310µs/call # 37 times (1.56ms+-1.56ms) by Class::MOP::Class::class_precedence_list at line 638, avg 0s/call # 26 times (2.28ms+18.6ms) by Moose::Meta::Class::excludes_role at line 238 of Moose/Meta/Class.pm, avg 803µs/call # 24 times (1.60ms+-1.60ms) by Class::MOP::Class:::around at line 43 of Class/MOP/Class/Immutable/Trait.pm, avg 0s/call
sub class_precedence_list {
613128220.3ms my $self = shift;
614 my $name = $self->name;
# spent 1.01ms making 216 calls to Class::MOP::Package::name, avg 5µs/call
615
616 unless (Class::MOP::IS_RUNNING_ON_5_10()) {
# spent 765µs making 216 calls to Class::MOP::__ANON__, avg 4µs/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 if (mro::get_mro($name) eq 'c3') {
# spent 2.07ms making 216 calls to mro::get_mro, avg 10µs/call # spent 99µs making 3 calls to mro::get_linear_isa, avg 33µ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 $name,
# spent 22.8ms making 151 calls to Class::MOP::Class::Immutable::Class::MOP::Class::class_precedence_list, avg 151µs/call, recursion: max depth 4, time 8.72ms # spent 4.42ms making 183 calls to Moose::Meta::Class::initialize, avg 24µs/call # spent 1.69ms making 9 calls to Class::MOP::Class::Immutable::Moose::Meta::Class::class_precedence_list, avg 187µs/call, recursion: max depth 1, time 282µs # spent 928µs making 8 calls to Class::MOP::Class::Immutable::Class::MOP::Class::__ANON__::SERIAL::5::class_precedence_list, avg 116µs/call # spent 894µs making 22 calls to Class::MOP::Class::initialize, avg 41µs/call # spent 6.90ms making 37 calls to Class::MOP::Class::class_precedence_list, avg 187µs/call, recursion: max depth 2, time 6.90ms
639 map {
640 $self->initialize($_)->class_precedence_list()
# spent 21.5ms making 190 calls to Moose::Meta::Class::superclasses, avg 113µs/call, recursion: max depth 2, time 728µs # spent 3.56ms making 20 calls to Class::MOP::Class::Immutable::Class::MOP::Class::superclasses, avg 178µs/call # spent 408µs making 2 calls to Class::MOP::Class::Immutable::Moose::Meta::Class::superclasses, avg 204µs/call # spent 240µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::__ANON__::SERIAL::5::superclasses
641 } $self->superclasses()
642 );
643 }
644}
645
646## Methods
647
648{
64913µs
# spent 142ms (10.7+131) within Class::MOP::Class::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP/Class.pm:678] which was called 105 times, avg 1.35ms/call: # 87 times (9.01ms+103ms) by Class::MOP::Class::add_around_method_modifier at line 704, avg 1.28ms/call # 14 times (1.14ms+23.9ms) by Class::MOP::Class::add_before_method_modifier at line 684, avg 1.79ms/call # 4 times (535µs+4.29ms) by Class::MOP::Class::add_after_method_modifier at line 694, avg 1.21ms/call
my $fetch_and_prepare_method = sub {
6508939.34ms my ($self, $method_name) = @_;
651 my $wrapped_metaclass = $self->wrapped_method_metaclass;
# spent 967µs making 105 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 9µs/call
652 # fetch it locally
653 my $method = $self->get_method($method_name);
# spent 14.2ms making 105 calls to Class::MOP::Mixin::HasMethods::get_method, avg 136µs/call
654 # if we dont have local ...
655 unless ($method) {
656 # try to find the next method
657 $method = $self->find_next_method_by_name($method_name);
# spent 48.1ms making 79 calls to Class::MOP::Class::find_next_method_by_name, avg 609µs/call
658 # die if it does not exist
659 (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 $method = $wrapped_metaclass->wrap($method,
# spent 21.9ms making 75 calls to Class::MOP::Method::Wrapped::wrap, avg 292µs/call # spent 8.40ms making 4 calls to Class::MOP::Class::__ANON__::SERIAL::6::wrap, avg 2.10ms/call # spent 307µs making 79 calls to Class::MOP::Package::name, avg 4µs/call
665 package_name => $self->name,
666 name => $method_name,
667 );
668 }
669 else {
670 # now make sure we wrap it properly
671 $method = $wrapped_metaclass->wrap($method,
# spent 7.94ms making 23 calls to Class::MOP::Method::Wrapped::wrap, avg 345µs/call # spent 2.52ms making 2 calls to Class::MOP::Class::__ANON__::SERIAL::6::wrap, avg 1.26ms/call # spent 364µs making 26 calls to UNIVERSAL::isa, avg 14µs/call # spent 92µs making 25 calls to Class::MOP::Package::name, avg 4µs/call
672 package_name => $self->name,
673 name => $method_name,
674 ) unless $method->isa($wrapped_metaclass);
675 }
676 $self->add_method($method_name => $method);
# spent 26.1ms making 105 calls to Class::MOP::Mixin::HasMethods::add_method, avg 248µs/call
677 return $method;
678113µs };
679
680
# spent 27.2ms (734µs+26.5) within Class::MOP::Class::add_before_method_modifier which was called 14 times, avg 1.95ms/call: # 5 times (195µs+4.94ms) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 744 of Catalyst/Dispatcher.pm, avg 1.03ms/call # 4 times (237µs+5.47ms) by Moose::Util::add_method_modifier at line 229 of Moose/Util.pm, avg 1.43ms/call # 3 times (238µs+14.6ms) by Class::MOP::Class:::around at line 76 of MooseX/MethodAttributes/Role/Meta/Class.pm, avg 4.95ms/call # once (43µs+1.01ms) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 218 of Moose/Meta/Role/Application/ToClass.pm # once (21µs+456µs) by Catalyst::BEGIN@11 at line 123 of Catalyst/Log.pm
sub add_before_method_modifier {
68156693µs my ($self, $method_name, $method_modifier) = @_;
682 (defined $method_name && length $method_name)
683 || confess "You must pass in a method name";
684 my $method = $fetch_and_prepare_method->($self, $method_name);
# spent 25.0ms making 14 calls to Class::MOP::Class::__ANON__[Class/MOP/Class.pm:678], avg 1.79ms/call
685 $method->add_before_modifier(
# spent 1.29ms making 14 calls to Class::MOP::Method::Wrapped::add_before_modifier, avg 92µs/call # spent 163µs making 14 calls to Sub::Name::subname, avg 12µs/call
686 subname(':before' => $method_modifier)
687 );
688 }
689
690
# spent 5.37ms (177µs+5.19) within Class::MOP::Class::add_after_method_modifier which was called 4 times, avg 1.34ms/call: # 3 times (136µs+4.18ms) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 218 of Moose/Meta/Role/Application/ToClass.pm, avg 1.44ms/call # once (41µs+1.01ms) by Moose::Util::add_method_modifier at line 229 of Moose/Util.pm
sub add_after_method_modifier {
69116391µs my ($self, $method_name, $method_modifier) = @_;
692 (defined $method_name && length $method_name)
693 || confess "You must pass in a method name";
694 my $method = $fetch_and_prepare_method->($self, $method_name);
# spent 4.83ms making 4 calls to Class::MOP::Class::__ANON__[Class/MOP/Class.pm:678], avg 1.21ms/call
695 $method->add_after_modifier(
# spent 221µs making 4 calls to Class::MOP::Method::Wrapped::add_after_modifier, avg 55µs/call # spent 140µs making 4 calls to Sub::Name::subname, avg 35µs/call
696 subname(':after' => $method_modifier)
697 );
698 }
699
700
# spent 126ms (3.15+123) within Class::MOP::Class::add_around_method_modifier which was called 87 times, avg 1.45ms/call: # 55 times (1.83ms+77.0ms) by Class::MOP::Class::_immutable_metaclass at line 970, avg 1.43ms/call # 19 times (896µs+26.2ms) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 218 of Moose/Meta/Role/Application/ToClass.pm, avg 1.42ms/call # 10 times (347µs+10.5ms) by Moose::Util::add_method_modifier at line 229 of Moose/Util.pm, avg 1.09ms/call # 3 times (81µs+9.07ms) by Class::MOP::Class:::around at line 76 of MooseX/MethodAttributes/Role/Meta/Class.pm, avg 3.05ms/call
sub add_around_method_modifier {
7013484.60ms my ($self, $method_name, $method_modifier) = @_;
702 (defined $method_name && length $method_name)
703 || confess "You must pass in a method name";
704 my $method = $fetch_and_prepare_method->($self, $method_name);
# spent 112ms making 87 calls to Class::MOP::Class::__ANON__[Class/MOP/Class.pm:678], avg 1.28ms/call
705 $method->add_around_modifier(
# spent 9.51ms making 87 calls to Class::MOP::Method::Wrapped::add_around_modifier, avg 109µs/call # spent 1.52ms making 87 calls to Sub::Name::subname, avg 17µ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 124ms (17.0+107) within Class::MOP::Class::find_method_by_name which was called 191 times, avg 651µs/call: # 65 times (4.15ms+22.8ms) by MooseX::MethodAttributes::Role::Meta::Class::get_nearest_methods_with_attributes at line 58 of MooseX/MethodAttributes/Role/Meta/Class.pm, avg 414µs/call # 64 times (8.37ms+55.8ms) by Class::MOP::Class::_immutable_metaclass at line 970, avg 1.00ms/call # 27 times (2.05ms+12.1ms) by Moose::Meta::Method::Destructor::is_needed at line 62 of Moose/Meta/Method/Destructor.pm, avg 524µs/call # 25 times (1.75ms+11.4ms) by Moose::Meta::Method::Constructor::_generate_BUILDARGS at line 135 of Moose/Meta/Method/Constructor.pm, avg 525µs/call # 7 times (340µs+2.22ms) by Moose::BEGIN@37 at line 14 of Moose/Meta/Attribute/Native.pm, avg 366µs/call # 3 times (302µs+3.16ms) by Moose::Meta::Role::Application::ToClass::check_required_methods at line 64 of Moose/Meta/Role/Application/ToClass.pm, avg 1.15ms/call
sub find_method_by_name {
725175216.4ms my ($self, $method_name) = @_;
726 (defined $method_name && length $method_name)
727 || confess "You must define a method name to find";
728 foreach my $class ($self->linearized_isa) {
# spent 6.37ms making 191 calls to Class::MOP::Class::linearized_isa, avg 33µs/call
729 my $method = $self->initialize($class)->get_method($method_name);
# spent 87.3ms making 581 calls to Class::MOP::Mixin::HasMethods::get_method, avg 150µs/call # spent 7.62ms making 406 calls to Moose::Meta::Class::initialize, avg 19µs/call # spent 6.16ms making 175 calls to Class::MOP::Class::initialize, avg 35µs/call
730 return $method if defined $method;
731 }
732 return;
733}
734
735
# spent 31.9ms (984µs+31.0) within Class::MOP::Class::get_all_methods which was called 3 times, avg 10.6ms/call: # 3 times (984µs+31.0ms) by Class::MOP::Class::_immutable_metaclass at line 967, avg 10.6ms/call
sub get_all_methods {
736271.04ms my $self = shift;
737
738 my %methods;
739 for my $class ( reverse $self->linearized_isa ) {
# spent 80µs making 3 calls to Class::MOP::Class::linearized_isa, avg 27µs/call
740 my $meta = $self->initialize($class);
# spent 133µs making 5 calls to Class::MOP::Class::initialize, avg 27µs/call
741
742 $methods{$_} = $meta->get_method($_)
743 for $meta->get_method_list;
# spent 22.9ms making 5 calls to Class::MOP::Mixin::HasMethods::get_method_list, avg 4.58ms/call # spent 7.84ms making 64 calls to Class::MOP::Mixin::HasMethods::get_method, avg 122µs/call
744 }
745
746 return values %methods;
747}
748
749sub 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 46.2ms (6.81+39.4) within Class::MOP::Class::find_all_methods_by_name which was called 63 times, avg 734µs/call: # 26 times (2.34ms+12.9ms) by Moose::Meta::Method::Destructor::_initialize_body at line 81 of Moose/Meta/Method/Destructor.pm, avg 585µs/call # 25 times (2.92ms+17.4ms) by Moose::Meta::Method::Constructor::_generate_BUILDALL at line 153 of Moose/Meta/Method/Constructor.pm, avg 814µs/call # 12 times (1.55ms+9.13ms) by Moose::Object::BUILDALL at line 53 of Moose/Object.pm, avg 890µs/call
sub find_all_methods_by_name {
7567335.57ms my ($self, $method_name) = @_;
757 (defined $method_name && length $method_name)
758 || confess "You must define a method name to find";
759 my @methods;
760 foreach my $class ($self->linearized_isa) {
# spent 1.75ms making 62 calls to Class::MOP::Class::linearized_isa, avg 28µs/call # spent 20µs making 1 call to Class::MOP::Class::Immutable::Moose::Meta::Class::linearized_isa
761 # fetch the meta-class ...
762 my $meta = $self->initialize($class);
# spent 5.25ms making 209 calls to Moose::Meta::Class::initialize, avg 25µs/call
763 push @methods => {
# spent 27.8ms making 209 calls to Class::MOP::Mixin::HasMethods::has_method, avg 133µs/call # spent 4.58ms making 38 calls to Class::MOP::Mixin::HasMethods::get_method, avg 120µ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 return @methods;
770}
771
772
# spent 81.5ms (15.4+66.1) within Class::MOP::Class::find_next_method_by_name which was called 184 times, avg 443µs/call: # 81 times (5.57ms+20.5ms) by Class::MOP::Method::Inlined::can_be_inlined at line 40 of Class/MOP/Method/Inlined.pm, avg 322µs/call # 79 times (8.39ms+39.7ms) by Class::MOP::Class::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP/Class.pm:678] at line 657, avg 609µs/call # 22 times (1.40ms+5.52ms) by Class::MOP::Method::Inlined::_uninlined_body at line 20 of Class/MOP/Method/Inlined.pm, avg 314µs/call # 2 times (61µs+331µs) by Moose::Meta::Method::Overridden::new at line 23 of Moose/Meta/Method/Overridden.pm, avg 196µs/call
sub find_next_method_by_name {
773155112.5ms my ($self, $method_name) = @_;
774 (defined $method_name && length $method_name)
775 || confess "You must define a method name to find";
776 my @cpl = $self->linearized_isa;
# spent 5.95ms making 162 calls to Class::MOP::Class::linearized_isa, avg 37µs/call # spent 1.93ms making 22 calls to Class::MOP::Class::Immutable::Moose::Meta::Class::linearized_isa, avg 88µs/call
777 shift @cpl; # discard ourselves
778 foreach my $class (@cpl) {
779 my $method = $self->initialize($class)->get_method($method_name);
# spent 49.3ms making 314 calls to Class::MOP::Mixin::HasMethods::get_method, avg 157µs/call # spent 4.84ms making 202 calls to Moose::Meta::Class::initialize, avg 24µs/call # spent 4.04ms making 112 calls to Class::MOP::Class::initialize, avg 36µs/call
780 return $method if defined $method;
781 }
782 return;
783}
784
785
# spent 674µs within Class::MOP::Class::update_meta_instance_dependencies which was called 66 times, avg 10µs/call: # 66 times (674µs+0s) by Class::MOP::Class::_superclasses_updated at line 587, avg 10µs/call
sub update_meta_instance_dependencies {
786132818µs my $self = shift;
787
788 if ( $self->{meta_instance_dependencies} ) {
789 return $self->add_meta_instance_dependencies;
790 }
791}
792
793sub 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
811sub 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
826sub add_dependent_meta_instance {
827 my ( $self, $metaclass ) = @_;
828 push @{ $self->{dependent_meta_instances} }, $metaclass;
829}
830
831sub 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 11.7ms (9.55+2.19) within Class::MOP::Class::invalidate_meta_instances which was called 236 times, avg 50µs/call: # 234 times (9.50ms+2.18ms) by Class::MOP::Class::_post_add_attribute at line 509, avg 50µs/call # 2 times (50µs+10µs) by Class::MOP::Class::remove_attribute at line 528, avg 30µs/call
sub invalidate_meta_instances {
8397089.59ms my $self = shift;
840 $_->invalidate_meta_instance()
841 for $self, @{ $self->{dependent_meta_instances} };
# spent 2.19ms making 236 calls to Class::MOP::Class::invalidate_meta_instance, avg 9µs/call
842}
843
844
# spent 2.19ms within Class::MOP::Class::invalidate_meta_instance which was called 236 times, avg 9µs/call: # 236 times (2.19ms+0s) by Class::MOP::Class::invalidate_meta_instances at line 841, avg 9µs/call
sub invalidate_meta_instance {
8454723.27ms my $self = shift;
846 undef $self->{_meta_instance};
847}
848
849# check if we can reinitialize
850
# spent 6.65ms (334µs+6.31) within Class::MOP::Class::is_pristine which was called 7 times, avg 949µs/call: # 7 times (334µs+6.31ms) by Moose::Meta::Class::_fix_one_incompatible_metaclass at line 358 of Moose/Meta/Class.pm, avg 949µs/call
sub is_pristine {
85128300µs my $self = shift;
852
853 # if any local attr is defined
854 return if $self->get_attribute_list;
# spent 329µs making 7 calls to Class::MOP::Mixin::HasAttributes::get_attribute_list, avg 47µs/call
855
856 # or any non-declared methods
857 for my $method ( map { $self->get_method($_) } $self->get_method_list ) {
# spent 5.98ms making 7 calls to Class::MOP::Mixin::HasMethods::get_method_list, avg 855µs/call
858 return if $method->isa("Class::MOP::Method::Generated");
859 # FIXME do we need to enforce this too? return unless $method->isa( $self->method_metaclass );
860 }
861
862 return 1;
863}
864
865## Class closing
866
8671081.41ms
# spent 597µs within Class::MOP::Class::is_mutable which was called 108 times, avg 6µs/call: # 77 times (443µs+0s) by Class::MOP::Class::make_immutable at line 891, avg 6µs/call # 22 times (106µs+0s) by Catalyst::Engine::HTTP::BEGIN@3 at line 239 of Moose.pm, avg 5µs/call # 9 times (47µs+0s) by Moose::Meta::Attribute::BEGIN@18 at line 631 of Moose/Util/TypeConstraints.pm, avg 5µs/call
sub is_mutable { 1 }
8682331.96ms
# spent 1.53ms within Class::MOP::Class::is_immutable which was called 233 times, avg 7µs/call: # 135 times (971µs+0s) by Class::MOP::Class::_check_metaclass_compatibility at line 185, avg 7µs/call # 72 times (456µs+0s) by Moose::Meta::Class::_superclass_meta_is_compatible at line 373 of Moose/Meta/Class.pm, avg 6µs/call # 16 times (47µs+0s) by Catalyst::ClassData::mk_classdata at line 51 of Catalyst/ClassData.pm, avg 3µs/call # 3 times (18µs+0s) by MooseX::Emulate::Class::Accessor::Fast::mk_accessors at line 106 of MooseX/Emulate/Class/Accessor/Fast.pm, avg 6µs/call # 3 times (17µs+0s) by Class::MOP::Class::_construct_class_instance at line 71, avg 6µs/call # 2 times (12µs+0s) by Class::MOP::Class::_immutable_metaclass at line 956, avg 6µs/call # once (6µs+0s) by Catalyst::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/Catalyst.pm:1189] at line 1172 of Catalyst.pm # once (5µs+0s) by Catalyst::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/Catalyst.pm:1189] at line 1187 of Catalyst.pm
sub is_immutable { 0 }
869
87016124µs
# spent 93µs within Class::MOP::Class::immutable_options which was called 16 times, avg 6µs/call: # 16 times (93µs+0s) by Catalyst::ClassData::mk_classdata at line 52 of Catalyst/ClassData.pm, avg 6µs/call
sub immutable_options { %{ $_[0]{__immutable}{options} || {} } }
871
872
# spent 8.12ms (5.38+2.74) within Class::MOP::Class::_immutable_options which was called 77 times, avg 105µs/call: # 50 times (3.38ms+1.72ms) by Class::MOP::Class::make_immutable at line 892, avg 102µs/call # 27 times (2.01ms+1.02ms) by Moose::Meta::Class::_immutable_options at line 74 of Moose/Meta/Class.pm, avg 112µs/call
sub _immutable_options {
8731544.44ms my ( $self, @args ) = @_;
874
875 return (
876 inline_accessors => 1,
# spent 827µs making 77 calls to Class::MOP::Class::constructor_name, avg 11µs/call # spent 485µs making 50 calls to Class::MOP::Class::immutable_trait, avg 10µs/call # spent 351µs making 50 calls to Class::MOP::Class::constructor_class, avg 7µs/call # spent 311µs making 50 calls to Class::MOP::Class::destructor_class, avg 6µs/call # spent 279µs making 27 calls to Moose::Meta::Class::immutable_trait, avg 10µs/call # spent 258µs making 27 calls to Moose::Meta::Class::constructor_class, avg 10µs/call # spent 228µs making 27 calls to Moose::Meta::Class::destructor_class, avg 8µ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 921ms (5.37+916) within Class::MOP::Class::make_immutable which was called 77 times, avg 12.0ms/call: # 22 times (1.75ms+242ms) by Catalyst::Engine::HTTP::BEGIN@3 at line 244 of Moose.pm, avg 11.1ms/call # 12 times (727µs+94.0ms) by Moose::Exporter::BEGIN@11 at line 678 of Class/MOP.pm, avg 7.89ms/call # 9 times (609µs+112ms) by Moose::Meta::Attribute::BEGIN@18 at line 636 of Moose/Util/TypeConstraints.pm, avg 12.5ms/call # 4 times (476µs+2.57ms) by Moose::Exporter::BEGIN@11 at line 701 of Class/MOP.pm, avg 762µs/call # 3 times (170µs+-170µs) by Class::MOP::Class::_immutable_metaclass at line 979, avg 0s/call # once (88µs+100ms) by Catalyst::BEGIN@8 at line 52 of Catalyst/Exception.pm # once (81µs+53.4ms) by Catalyst::BEGIN@16 at line 425 of Catalyst/Controller.pm # once (58µs+34.7ms) by Catalyst::Engine::HTTP::BEGIN@3 at line 276 of Moose.pm # once (89µs+23.5ms) by Catalyst::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/Catalyst.pm:1189] at line 1187 of Catalyst.pm # once (72µs+17.2ms) by base::import at line 36 of Catalyst/Model.pm # once (102µs+16.6ms) by Catalyst::BEGIN@12 at line 700 of Catalyst/Request.pm # once (62µs+16.6ms) by Catalyst::Plugin::ConfigLoader::BEGIN@8 at line 283 of Data/Visitor/Callback.pm # once (60µs+15.7ms) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 749 of Catalyst/Dispatcher.pm # once (65µs+15.6ms) by Catalyst::BEGIN@14 at line 224 of Catalyst/Response.pm # once (61µs+14.0ms) by Catalyst::Dispatcher::BEGIN@9 at line 91 of Catalyst/Action.pm # once (67µs+13.9ms) by Data::Visitor::Callback::BEGIN@6 at line 443 of Data/Visitor.pm # once (54µs+13.5ms) by Catalyst::BEGIN@8 at line 67 of Catalyst/Exception.pm # once (65µs+13.1ms) by Catalyst::BEGIN@13 at line 179 of Catalyst/Request/Upload.pm # once (62µs+11.5ms) by Catalyst::Utils::ensure_class_loaded at line 163 of Catalyst/Stats.pm # once (65µs+11.2ms) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 156 of Catalyst/Component.pm # once (60µs+11.2ms) by base::import at line 61 of Catalyst/View.pm # once (62µs+11.0ms) by Catalyst::Dispatcher::BEGIN@10 at line 49 of Catalyst/ActionContainer.pm # once (58µs+10.5ms) by Catalyst::Dispatcher::BEGIN@11 at line 74 of Catalyst/DispatchType/Default.pm # once (46µs+9.45ms) by Catalyst::Dispatcher::BEGIN@12 at line 105 of Catalyst/DispatchType/Index.pm # once (59µs+9.23ms) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 89 of Catalyst/DispatchType.pm # once (115µs+8.97ms) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 15 of MooseX/MethodAttributes/Inheritable.pm # once (31µs+8.16ms) by Epoll::BEGIN@17 at line 3197 of Catalyst.pm # once (32µs+7.66ms) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 182 of Catalyst/DispatchType/Regex.pm # once (37µs+6.22ms) by Catalyst::BEGIN@9 at line 12 of Catalyst/Exception/Detach.pm # once (32µs+5.92ms) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 164 of Catalyst/DispatchType/Path.pm # once (31µs+5.12ms) by Catalyst::BEGIN@10 at line 12 of Catalyst/Exception/Go.pm # once (31µs+1.69ms) by Catalyst::BEGIN@11 at line 127 of Catalyst/Log.pm
sub make_immutable {
8893854.77ms my ( $self, @args ) = @_;
890
891 if ( $self->is_mutable ) {
# spent 443µs making 77 calls to Class::MOP::Class::is_mutable, avg 6µs/call
892 $self->_initialize_immutable( $self->_immutable_options(@args) );
# spent 655ms making 77 calls to Class::MOP::Class::_initialize_immutable, avg 8.51ms/call # spent 5.10ms making 50 calls to Class::MOP::Class::_immutable_options, avg 102µs/call # spent 3.81ms making 27 calls to Moose::Meta::Class::_immutable_options, avg 141µs/call
893 $self->_rebless_as_immutable(@args);
# spent 255ms making 77 calls to Class::MOP::Class::_rebless_as_immutable, avg 3.32ms/call, recursion: max depth 1, time 1.43ms
894 return $self;
895 }
896 else {
897 return;
898 }
899}
900
901sub 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 254ms (3.29+251) within Class::MOP::Class::_rebless_as_immutable which was called 77 times, avg 3.30ms/call: # 77 times (3.29ms+251ms) by Class::MOP::Class::make_immutable at line 893, avg 3.30ms/call
sub _rebless_as_immutable {
9172313.23ms my ( $self, @args ) = @_;
918
919 $self->{__immutable}{original_class} = ref $self;
920
921 bless $self => $self->_immutable_metaclass(@args);
# spent 252ms making 77 calls to Class::MOP::Class::_immutable_metaclass, avg 3.27ms/call, recursion: max depth 1, time 1.22ms
922}
923
924
# spent 251ms (9.98+241) within Class::MOP::Class::_immutable_metaclass which was called 77 times, avg 3.26ms/call: # 77 times (9.98ms+241ms) by Class::MOP::Class::_rebless_as_immutable at line 921, avg 3.26ms/call
sub _immutable_metaclass {
92577110.0ms my ( $self, %args ) = @_;
926
927 if ( my $class = $args{immutable_metaclass} ) {
928 return $class;
929 }
930
931 my $trait = $args{immutable_trait} = $self->immutable_trait
# spent 460µs making 50 calls to Class::MOP::Class::immutable_trait, avg 9µs/call # spent 234µs making 27 calls to Moose::Meta::Class::immutable_trait, avg 9µs/call
932 || confess "no immutable trait specified for $self";
933
934 my $meta = $self->meta;
# spent 6.67ms making 75 calls to Class::MOP::Object::meta, avg 89µs/call # spent 116µs making 2 calls to Class::MOP::Class::__ANON__::SERIAL::5::meta, avg 58µs/call
935 my $meta_attr = $meta->find_attribute_by_name("immutable_trait");
# spent 19.6ms making 77 calls to Class::MOP::Class::find_attribute_by_name, avg 255µs/call
936
937 my $class_name;
938
939 if ( $meta_attr and $trait eq $meta_attr->default ) {
# spent 1.17ms making 77 calls to Class::MOP::Mixin::AttributeCore::default, avg 15µ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 return $class_name
# spent 1.09ms making 77 calls to Class::MOP::is_class_loaded, avg 14µ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 my $meta_name
# spent 38µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::is_immutable # spent 12µs making 2 calls to Class::MOP::Class::is_immutable, avg 6µs/call # spent 10µs making 1 call to Class::MOP::Class::Immutable::Trait::_get_mutable_metaclass_name
957 = $meta->is_immutable
958 ? $meta->_get_mutable_metaclass_name
959 : ref $meta;
960
961 my $immutable_meta = $meta_name->create(
# spent 6.78ms making 1 call to Moose::Meta::Class::create # spent 3.40ms making 2 calls to Class::MOP::Class::create, avg 1.70ms/call
962 $class_name,
963 superclasses => [ ref $self ],
964 );
965
966 Class::MOP::load_class($trait);
# spent 5.29ms making 3 calls to Class::MOP::load_class, avg 1.76ms/call
967 for my $meth ( Class::MOP::Class->initialize($trait)->get_all_methods ) {
# spent 31.9ms making 3 calls to Class::MOP::Class::get_all_methods, avg 10.6ms/call # spent 616µs making 3 calls to Class::MOP::Class::initialize, avg 205µs/call
968 my $meth_name = $meth->name;
# spent 302µs making 64 calls to Class::MOP::Method::name, avg 5µs/call
969
970 if ( $immutable_meta->find_method_by_name( $meth_name ) ) {
# spent 78.8ms making 55 calls to Class::MOP::Class::add_around_method_modifier, avg 1.43ms/call # spent 64.2ms making 64 calls to Class::MOP::Class::find_method_by_name, avg 1.00ms/call # spent 257µs making 55 calls to Class::MOP::Method::body, avg 5µs/call
971 $immutable_meta->add_around_method_modifier( $meth_name, $meth->body );
972 }
973 else {
974 $immutable_meta->add_method( $meth_name, $meth->clone );
# spent 10.9ms making 9 calls to Class::MOP::Mixin::HasMethods::add_method, avg 1.21ms/call # spent 6.09ms making 9 calls to Class::MOP::Method::clone, avg 677µs/call
975 }
976 }
977
978 $immutable_meta->make_immutable(
979 inline_constructor => 0,
# spent 4.06ms making 3 calls to Class::MOP::Class::make_immutable, avg 1.35ms/call, recursion: max depth 1, time 4.06ms
980 inline_accessors => 0,
981 );
982
983 return $class_name;
984}
985
986sub _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
994sub _inlined_methods { @{ $_[0]{__immutable}{inlined_methods} || [] } }
995
996
# spent 1.34ms within Class::MOP::Class::_add_inlined_method which was called 82 times, avg 16µs/call: # 56 times (1.05ms+0s) by Class::MOP::Class::_inline_constructor at line 1065, avg 19µs/call # 26 times (292µs+0s) by Class::MOP::Class::_inline_destructor at line 1098, avg 11µs/call
sub _add_inlined_method {
9971641.69ms my ( $self, $method ) = @_;
998
999 push @{ $self->{__immutable}{inlined_methods} ||= [] }, $method;
1000}
1001
1002
# spent 655ms (4.29+651) within Class::MOP::Class::_initialize_immutable which was called 77 times, avg 8.51ms/call: # 77 times (4.29ms+651ms) by Class::MOP::Class::make_immutable at line 892, avg 8.51ms/call
sub _initialize_immutable {
10032313.95ms my ( $self, %args ) = @_;
1004
1005 $self->{__immutable}{options} = \%args;
1006 $self->_install_inlined_code(%args);
# spent 651ms making 77 calls to Class::MOP::Class::_install_inlined_code, avg 8.45ms/call
1007}
1008
1009
# spent 651ms (4.38+647) within Class::MOP::Class::_install_inlined_code which was called 77 times, avg 8.45ms/call: # 77 times (4.38ms+647ms) by Class::MOP::Class::_initialize_immutable at line 1006, avg 8.45ms/call
sub _install_inlined_code {
10103084.64ms my ( $self, %args ) = @_;
1011
1012 # FIXME
1013 $self->_inline_accessors(%args) if $args{inline_accessors};
# spent 159ms making 32 calls to Class::MOP::Class::_inline_accessors, avg 4.97ms/call
1014 $self->_inline_constructor(%args) if $args{inline_constructor};
# spent 406ms making 56 calls to Class::MOP::Class::_inline_constructor, avg 7.24ms/call
1015 $self->_inline_destructor(%args) if $args{inline_destructor};
# spent 81.8ms making 27 calls to Class::MOP::Class::_inline_destructor, avg 3.03ms/call
1016}
1017
1018sub _rebless_as_mutable {
1019 my $self = shift;
1020
1021 bless $self, $self->_get_mutable_metaclass_name;
1022
1023 return $self;
1024}
1025
1026
# spent 159ms (4.85+154) within Class::MOP::Class::_inline_accessors which was called 32 times, avg 4.97ms/call: # 32 times (4.85ms+154ms) by Class::MOP::Class::_install_inlined_code at line 1013, avg 4.97ms/call
sub _inline_accessors {
10271324.44ms my $self = shift;
1028
1029 foreach my $attr_name ( $self->get_attribute_list ) {
# spent 1.04ms making 32 calls to Class::MOP::Mixin::HasAttributes::get_attribute_list, avg 33µs/call
1030 $self->get_attribute($attr_name)->install_accessors(1);
# spent 143ms making 67 calls to Class::MOP::Attribute::install_accessors, avg 2.14ms/call # spent 7.64ms making 1 call to Moose::Meta::Attribute::install_accessors # spent 2.33ms making 68 calls to Class::MOP::Mixin::HasAttributes::get_attribute, avg 34µs/call
1031 }
1032}
1033
1034
# spent 406ms (8.72+397) within Class::MOP::Class::_inline_constructor which was called 56 times, avg 7.24ms/call: # 56 times (8.72ms+397ms) by Class::MOP::Class::_install_inlined_code at line 1014, avg 7.24ms/call
sub _inline_constructor {
10355606.14ms my ( $self, %args ) = @_;
1036
1037 my $name = $args{constructor_name};
1038 # A class may not even have a constructor, and that's okay.
1039 return unless defined $name;
1040
1041 if ( $self->has_method($name) && !$args{replace_constructor} ) {
# spent 12.1ms making 56 calls to Class::MOP::Mixin::HasMethods::has_method, avg 216µ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 my $constructor_class = $args{constructor_class};
1052
1053 Class::MOP::load_class($constructor_class);
# spent 9.68ms making 56 calls to Class::MOP::load_class, avg 173µs/call, recursion: max depth 2, time 2.02ms
1054
1055 my $constructor = $constructor_class->new(
# spent 165ms making 25 calls to Moose::Meta::Method::Constructor::new, avg 6.62ms/call # spent 155ms making 31 calls to Class::MOP::Method::Constructor::new, avg 5.01ms/call # spent 272µs making 56 calls to Class::MOP::Package::name, avg 5µs/call
1056 options => \%args,
1057 metaclass => $self,
1058 is_inline => 1,
1059 package_name => $self->name,
1060 name => $name,
1061 );
1062
1063 if ( $args{replace_constructor} or $constructor->can_be_inlined ) {
# spent 36.5ms making 55 calls to Class::MOP::Method::Inlined::can_be_inlined, avg 663µs/call
1064 $self->add_method( $name => $constructor );
# spent 16.7ms making 56 calls to Class::MOP::Mixin::HasMethods::add_method, avg 299µs/call
1065 $self->_add_inlined_method($constructor);
# spent 1.05ms making 56 calls to Class::MOP::Class::_add_inlined_method, avg 19µs/call
1066 }
1067}
1068
1069
# spent 81.8ms (5.93+75.9) within Class::MOP::Class::_inline_destructor which was called 27 times, avg 3.03ms/call: # 27 times (5.93ms+75.9ms) by Class::MOP::Class::_install_inlined_code at line 1015, avg 3.03ms/call
sub _inline_destructor {
10702665.67ms my ( $self, %args ) = @_;
1071
1072 ( 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 if ( $self->has_method('DESTROY') && ! $args{replace_destructor} ) {
# spent 4.15ms making 27 calls to Class::MOP::Mixin::HasMethods::has_method, avg 154µ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 my $destructor_class = $args{destructor_class};
1084
1085 Class::MOP::load_class($destructor_class);
# spent 3.98ms making 27 calls to Class::MOP::load_class, avg 147µs/call, recursion: max depth 2, time 1.93ms
1086
1087 return unless $destructor_class->is_needed($self);
# spent 15.4ms making 27 calls to Moose::Meta::Method::Destructor::is_needed, avg 572µs/call
1088
1089 my $destructor = $destructor_class->new(
# spent 36.0ms making 26 calls to Moose::Meta::Method::Destructor::new, avg 1.38ms/call # spent 211µs making 26 calls to Class::MOP::Package::name, avg 8µs/call
1090 options => \%args,
1091 metaclass => $self,
1092 package_name => $self->name,
1093 name => 'DESTROY'
1094 );
1095
1096 if ( $args{replace_destructor} or $destructor->can_be_inlined ) {
# spent 10.1ms making 26 calls to Class::MOP::Method::Inlined::can_be_inlined, avg 390µs/call
1097 $self->add_method( 'DESTROY' => $destructor );
# spent 5.66ms making 26 calls to Class::MOP::Mixin::HasMethods::add_method, avg 218µs/call
1098 $self->_add_inlined_method($destructor);
# spent 292µs making 26 calls to Class::MOP::Class::_add_inlined_method, avg 11µs/call
1099 }
1100}
1101
1102116µs1;
1103
1104__END__
1105
1106=pod
1107
1108=head1 NAME
1109
1110Class::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
1148The Class Protocol is the largest and most complex part of the
1149Class::MOP meta-object protocol. It controls the introspection and
1150manipulation of Perl 5 classes, and it can create them as well. The
1151best way to understand what this module can do is to read the
1152documentation for each of its methods.
1153
1154=head1 INHERITANCE
1155
1156C<Class::MOP::Class> is a subclass of L<Class::MOP::Module>.
1157
1158=head1 METHODS
1159
1160=head2 Class construction
1161
1162These methods all create new C<Class::MOP::Class> objects. These
1163objects can represent existing classes or they can be used to create
1164new classes from scratch.
1165
1166The metaclass object for a given class is a singleton. If you attempt
1167to create a metaclass for the same class twice, you will just get the
1168existing object.
1169
1170=over 4
1171
1172=item B<< Class::MOP::Class->create($package_name, %options) >>
1173
1174This method creates a new C<Class::MOP::Class> object with the given
1175package name. It accepts a number of options:
1176
1177=over 8
1178
1179=item * version
1180
1181An optional version number for the newly created package.
1182
1183=item * authority
1184
1185An optional authority for the newly created package.
1186
1187=item * superclasses
1188
1189An optional array reference of superclass names.
1190
1191=item * methods
1192
1193An optional hash reference of methods for the class. The keys of the
1194hash reference are method names and values are subroutine references.
1195
1196=item * attributes
1197
1198An optional array reference of L<Class::MOP::Attribute> objects.
1199
1200=back
1201
1202=item B<< Class::MOP::Class->create_anon_class(%options) >>
1203
1204This method works just like C<< Class::MOP::Class->create >> but it
1205creates an "anonymous" class. In fact, the class does have a name, but
1206that name is a unique name generated internally by this module.
1207
1208It accepts the same C<superclasses>, C<methods>, and C<attributes>
1209parameters that C<create> accepts.
1210
1211Anonymous classes are destroyed once the metaclass they are attached
1212to goes out of scope, and will be removed from Perl's internal symbol
1213table.
1214
1215All instances of an anonymous class keep a special reference to the
1216metaclass object, which prevents the metaclass from going out of scope
1217while any instances exist.
1218
1219This only works if the instance is based on a hash reference, however.
1220
1221=item B<< Class::MOP::Class->initialize($package_name, %options) >>
1222
1223This method will initialize a C<Class::MOP::Class> object for the
1224named package. Unlike C<create>, this method I<will not> create a new
1225class.
1226
1227The purpose of this method is to retrieve a C<Class::MOP::Class>
1228object for introspecting an existing class.
1229
1230If an existing C<Class::MOP::Class> object exists for the named
1231package, it will be returned, and any options provided will be
1232ignored!
1233
1234If the object does not yet exist, it will be created.
1235
1236The valid options that can be passed to this method are
1237C<attribute_metaclass>, C<method_metaclass>,
1238C<wrapped_method_metaclass>, and C<instance_metaclass>. These are all
1239optional, and default to the appropriate class in the C<Class::MOP>
1240distribution.
1241
1242=back
1243
1244=head2 Object instance construction and cloning
1245
1246These methods are all related to creating and/or cloning object
1247instances.
1248
1249=over 4
1250
1251=item B<< $metaclass->clone_object($instance, %params) >>
1252
1253This method clones an existing object instance. Any parameters you
1254provide are will override existing attribute values in the object.
1255
1256This is a convenience method for cloning an object instance, then
1257blessing it into the appropriate package.
1258
1259You 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
1268This method changes the class of C<$instance> to the metaclass's class.
1269
1270You can only rebless an instance into a subclass of its current
1271class. If you pass any additional parameters, these will be treated
1272like constructor parameters and used to initialize the object's
1273attributes. Any existing attributes that are already set will be
1274overwritten.
1275
1276Before reblessing the instance, this method will call
1277C<rebless_instance_away> on the instance's current metaclass. This method
1278will be passed the instance, the new metaclass, and any parameters
1279specified to C<rebless_instance>. By default, C<rebless_instance_away>
1280does nothing; it is merely a hook.
1281
1282=item B<< $metaclass->rebless_instance_back($instance) >>
1283
1284Does the same thing as C<rebless_instance>, except that you can only
1285rebless an instance into one of its superclasses. Any attributes that
1286do not exist in the superclass will be deinitialized.
1287
1288This is a much more dangerous operation than C<rebless_instance>,
1289especially when multiple inheritance is involved, so use this carefully!
1290
1291=item B<< $metaclass->new_object(%params) >>
1292
1293This method is used to create a new object of the metaclass's
1294class. Any parameters you provide are used to initialize the
1295instance's attributes. A special C<__INSTANCE__> key can be passed to
1296provide an already generated instance, rather than having Class::MOP
1297generate it for you. This is mostly useful for using Class::MOP with
1298foreign classes which generate instances using their own constructors.
1299
1300=item B<< $metaclass->instance_metaclass >>
1301
1302Returns the class name of the instance metaclass. See
1303L<Class::MOP::Instance> for more information on the instance
1304metaclass.
1305
1306=item B<< $metaclass->get_meta_instance >>
1307
1308Returns an instance of the C<instance_metaclass> to be used in the
1309construction of a new instance of the class.
1310
1311=back
1312
1313=head2 Informational predicates
1314
1315These are a few predicate methods for asking information about the
1316class itself.
1317
1318=over 4
1319
1320=item B<< $metaclass->is_anon_class >>
1321
1322This returns true if the class was created by calling C<<
1323Class::MOP::Class->create_anon_class >>.
1324
1325=item B<< $metaclass->is_mutable >>
1326
1327This returns true if the class is still mutable.
1328
1329=item B<< $metaclass->is_immutable >>
1330
1331This returns true if the class has been made immutable.
1332
1333=item B<< $metaclass->is_pristine >>
1334
1335A class is I<not> pristine if it has non-inherited attributes or if it
1336has any generated methods.
1337
1338=back
1339
1340=head2 Inheritance Relationships
1341
1342=over 4
1343
1344=item B<< $metaclass->superclasses(@superclasses) >>
1345
1346This is a read-write accessor which represents the superclass
1347relationships of the metaclass's class.
1348
1349This is basically sugar around getting and setting C<@ISA>.
1350
1351=item B<< $metaclass->class_precedence_list >>
1352
1353This returns a list of all of the class's ancestor classes. The
1354classes are returned in method dispatch order.
1355
1356=item B<< $metaclass->linearized_isa >>
1357
1358This returns a list based on C<class_precedence_list> but with all
1359duplicates removed.
1360
1361=item B<< $metaclass->subclasses >>
1362
1363This returns a list of all subclasses for this class, even indirect
1364subclasses.
1365
1366=item B<< $metaclass->direct_subclasses >>
1367
1368This returns a list of immediate subclasses for this class, which does not
1369include indirect subclasses.
1370
1371=back
1372
1373=head2 Method introspection
1374
1375See L<Class::MOP::Package/Method introspection and creation> for
1376methods that operate only on the current class. Class::MOP::Class adds
1377introspection capabilities that take inheritance into account.
1378
1379=over 4
1380
1381=item B<< $metaclass->get_all_methods >>
1382
1383This will traverse the inheritance hierarchy and return a list of all
1384the L<Class::MOP::Method> objects for this class and its parents.
1385
1386=item B<< $metaclass->find_method_by_name($method_name) >>
1387
1388This will return a L<Class::MOP::Method> for the specified
1389C<$method_name>. If the class does not have the specified method, it
1390returns C<undef>
1391
1392Unlike C<get_method>, this method I<will> look for the named method in
1393superclasses.
1394
1395=item B<< $metaclass->get_all_method_names >>
1396
1397This will return a list of method I<names> for all of this class's
1398methods, including inherited methods.
1399
1400=item B<< $metaclass->find_all_methods_by_name($method_name) >>
1401
1402This method looks for the named method in the class and all of its
1403parents. It returns every matching method it finds in the inheritance
1404tree, so it returns a list of methods.
1405
1406Each method is returned as a hash reference with three keys. The keys
1407are C<name>, C<class>, and C<code>. The C<code> key has a
1408L<Class::MOP::Method> object as its value.
1409
1410The list of methods is distinct.
1411
1412=item B<< $metaclass->find_next_method_by_name($method_name) >>
1413
1414This method returns the first method in any superclass matching the
1415given name. It is effectively the method that C<SUPER::$method_name>
1416would dispatch to.
1417
1418=back
1419
1420=head2 Attribute introspection and creation
1421
1422Because Perl 5 does not have a core concept of attributes in classes,
1423we can only return information about attributes which have been added
1424via this class's methods. We cannot discover information about
1425attributes which are defined in terms of "regular" Perl 5 methods.
1426
1427=over 4
1428
1429=item B<< $metaclass->get_attribute($attribute_name) >>
1430
1431This will return a L<Class::MOP::Attribute> for the specified
1432C<$attribute_name>. If the class does not have the specified
1433attribute, it returns C<undef>.
1434
1435NOTE that get_attribute does not search superclasses, for that you
1436need to use C<find_attribute_by_name>.
1437
1438=item B<< $metaclass->has_attribute($attribute_name) >>
1439
1440Returns a boolean indicating whether or not the class defines the
1441named attribute. It does not include attributes inherited from parent
1442classes.
1443
1444=item B<< $metaclass->get_attribute_list >>
1445
1446This will return a list of attributes I<names> for all attributes
1447defined in this class.
1448
1449=item B<< $metaclass->get_all_attributes >>
1450
1451This will traverse the inheritance hierarchy and return a list of all
1452the L<Class::MOP::Attribute> objects for this class and its parents.
1453
1454=item B<< $metaclass->find_attribute_by_name($attribute_name) >>
1455
1456This will return a L<Class::MOP::Attribute> for the specified
1457C<$attribute_name>. If the class does not have the specified
1458attribute, it returns C<undef>.
1459
1460Unlike C<get_attribute>, this attribute I<will> look for the named
1461attribute in superclasses.
1462
1463=item B<< $metaclass->add_attribute(...) >>
1464
1465This method accepts either an existing L<Class::MOP::Attribute>
1466object or parameters suitable for passing to that class's C<new>
1467method.
1468
1469The attribute provided will be added to the class.
1470
1471Any accessor methods defined by the attribute will be added to the
1472class when the attribute is added.
1473
1474If an attribute of the same name already exists, the old attribute
1475will be removed first.
1476
1477=item B<< $metaclass->remove_attribute($attribute_name) >>
1478
1479This will remove the named attribute from the class, and
1480L<Class::MOP::Attribute> object.
1481
1482Removing an attribute also removes any accessor methods defined by the
1483attribute.
1484
1485However, note that removing an attribute will only affect I<future>
1486object instances created for this class, not existing instances.
1487
1488=item B<< $metaclass->attribute_metaclass >>
1489
1490Returns the class name of the attribute metaclass for this class. By
1491default, this is L<Class::MOP::Attribute>.
1492
1493=back
1494
1495=head2 Class Immutability
1496
1497Making a class immutable "freezes" the class definition. You can no
1498longer call methods which alter the class, such as adding or removing
1499methods or attributes.
1500
1501Making a class immutable lets us optimize the class by inlining some
1502methods, and also allows us to optimize some methods on the metaclass
1503object itself.
1504
1505After immutabilization, the metaclass object will cache most informational
1506methods that returns information about methods or attributes. Methods which
1507would alter the class, such as C<add_attribute> and C<add_method>, will
1508throw an error on an immutable metaclass object.
1509
1510The immutabilization system in L<Moose> takes much greater advantage
1511of the inlining features than Class::MOP itself does.
1512
1513=over 4
1514
1515=item B<< $metaclass->make_immutable(%options) >>
1516
1517This method will create an immutable transformer and use it to make
1518the class and its metaclass object immutable.
1519
1520This 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
1530These are all booleans indicating whether the specified method(s)
1531should be inlined.
1532
1533By default, accessors and the constructor are inlined, but not the
1534destructor.
1535
1536=item * immutable_trait
1537
1538The name of a class which will be used as a parent class for the
1539metaclass object being made immutable. This "trait" implements the
1540post-immutability functionality of the metaclass (but not the
1541transformation itself).
1542
1543This defaults to L<Class::MOP::Class::Immutable::Trait>.
1544
1545=item * constructor_name
1546
1547This is the constructor method name. This defaults to "new".
1548
1549=item * constructor_class
1550
1551The name of the method metaclass for constructors. It will be used to
1552generate the inlined constructor. This defaults to
1553"Class::MOP::Method::Constructor".
1554
1555=item * replace_constructor
1556
1557This is a boolean indicating whether an existing constructor should be
1558replaced when inlining a constructor. This defaults to false.
1559
1560=item * destructor_class
1561
1562The name of the method metaclass for destructors. It will be used to
1563generate the inlined destructor. This defaults to
1564"Class::MOP::Method::Denstructor".
1565
1566=item * replace_destructor
1567
1568This is a boolean indicating whether an existing destructor should be
1569replaced when inlining a destructor. This defaults to false.
1570
1571=back
1572
1573=item B<< $metaclass->immutable_options >>
1574
1575Returns a hash of the options used when making the class immutable, including
1576both 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
1578a class mutable and then restore immutability as it was before.
1579
1580=item B<< $metaclass->make_mutable >>
1581
1582Calling this method reverse the immutabilization transformation.
1583
1584=back
1585
1586=head2 Method Modifiers
1587
1588Method modifiers are hooks which allow a method to be wrapped with
1589I<before>, I<after> and I<around> method modifiers. Every time a
1590method is called, its modifiers are also called.
1591
1592A class can modify its own methods, as well as methods defined in
1593parent classes.
1594
1595=head3 How method modifiers work?
1596
1597Method modifiers work by wrapping the original method and then
1598replacing it in the class's symbol table. The wrappers will handle
1599calling all the modifiers in the appropriate order and preserving the
1600calling context for the original method.
1601
1602The return values of C<before> and C<after> modifiers are
1603ignored. This is because their purpose is B<not> to filter the input
1604and output of the primary method (this is done with an I<around>
1605modifier).
1606
1607This may seem like an odd restriction to some, but doing this allows
1608for simple code to be added at the beginning or end of a method call
1609without altering the function of the wrapped method or placing any
1610extra responsibility on the code of the modifier.
1611
1612Of course if you have more complex needs, you can use the C<around>
1613modifier which allows you to change both the parameters passed to the
1614wrapped method, as well as its return value.
1615
1616Before and around modifiers are called in last-defined-first-called
1617order, while after modifiers are called in first-defined-first-called
1618order. 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
1632Of course there is a performance cost associated with method
1633modifiers, but we have made every effort to make that cost directly
1634proportional to the number of modifier features you use.
1635
1636The wrapping method does its best to B<only> do as much work as it
1637absolutely needs to. In order to do this we have moved some of the
1638performance costs to set-up time, where they are easier to amortize.
1639
1640All 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
1648These numbers may seem daunting, but you must remember, every feature
1649comes with some cost. To put things in perspective, just doing a
1650simple C<AUTOLOAD> which does nothing but extract the name of the
1651method called and return it costs about 400% over a normal method
1652call.
1653
1654=over 4
1655
1656=item B<< $metaclass->add_before_method_modifier($method_name, $code) >>
1657
1658This wraps the specified method with the supplied subroutine
1659reference. The modifier will be called as a method itself, and will
1660receive the same arguments as are passed to the method.
1661
1662When the modifier exits, the wrapped method will be called.
1663
1664The return value of the modifier will be ignored.
1665
1666=item B<< $metaclass->add_after_method_modifier($method_name, $code) >>
1667
1668This wraps the specified method with the supplied subroutine
1669reference. The modifier will be called as a method itself, and will
1670receive the same arguments as are passed to the method.
1671
1672When the wrapped methods exits, the modifier will be called.
1673
1674The return value of the modifier will be ignored.
1675
1676=item B<< $metaclass->add_around_method_modifier($method_name, $code) >>
1677
1678This wraps the specified method with the supplied subroutine
1679reference.
1680
1681The first argument passed to the modifier will be a subroutine
1682reference to the wrapped method. The second argument is the object,
1683and after that come any arguments passed when the method is called.
1684
1685The around modifier can choose to call the original method, as well as
1686what arguments to pass if it does so.
1687
1688The 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
1698This will return a L<Class::MOP::Class> instance for this class.
1699
1700It should also be noted that L<Class::MOP> will actually bootstrap
1701this module by installing a number of attribute meta-objects into its
1702metaclass.
1703
1704=back
1705
1706=head1 AUTHORS
1707
1708Stevan Little E<lt>stevan@iinteractive.comE<gt>
1709
1710=head1 COPYRIGHT AND LICENSE
1711
1712Copyright 2006-2010 by Infinity Interactive, Inc.
1713
1714L<http://www.iinteractive.com>
1715
1716This library is free software; you can redistribute it and/or modify
1717it under the same terms as Perl itself.
1718
1719=cut
# spent 1.51ms within Class::MOP::Class::CORE:match which was called 373 times, avg 4µs/call: # 358 times (1.49ms+0s) by Class::MOP::Class::is_anon_class at line 224 of Class/MOP/Class.pm, avg 4µs/call # 15 times (21µs+0s) by Class::MOP::Class::DESTROY at line 246 of Class/MOP/Class.pm, avg 1µs/call
sub Class::MOP::Class::CORE:match; # xsub
# spent 760µs within Class::MOP::Class::CORE:regcomp which was called 373 times, avg 2µs/call: # 358 times (719µs+0s) by Class::MOP::Class::is_anon_class at line 224 of Class/MOP/Class.pm, avg 2µs/call # 15 times (41µs+0s) by Class::MOP::Class::DESTROY at line 246 of Class/MOP/Class.pm, avg 3µs/call
sub Class::MOP::Class::CORE:regcomp; # xsub