← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 21:39:01 2010
Reported on Wed Nov 17 22:04:47 2010

Filename/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Class.pm
StatementsExecuted 52847 statements in 636ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
31442413105ms367msClass::MOP::Class::::initializeClass::MOP::Class::initialize (recurses: max depth 1, inclusive time 5.19ms)
3616563.2ms147msClass::MOP::Class::::get_all_attributesClass::MOP::Class::get_all_attributes
1722142.8ms310msClass::MOP::Class::::_construct_instanceClass::MOP::Class::_construct_instance
5311137.6ms77.1msClass::MOP::Class::::_single_metaclass_can_be_made_compatibleClass::MOP::Class::_single_metaclass_can_be_made_compatible
2731127.2ms50.5msClass::MOP::Class::::_single_metaclass_is_compatibleClass::MOP::Class::_single_metaclass_is_compatible
7977223.6ms37.4msClass::MOP::Class::::linearized_isaClass::MOP::Class::linearized_isa
2116619.9ms185msClass::MOP::Class::::find_method_by_nameClass::MOP::Class::find_method_by_name
1342119.7ms267msClass::MOP::Class::::_check_metaclass_compatibilityClass::MOP::Class::_check_metaclass_compatibility (recurses: max depth 1, inclusive time 3.72ms)
1644315.4ms107msClass::MOP::Class::::find_next_method_by_nameClass::MOP::Class::find_next_method_by_name
2381115.3ms1.47sClass::MOP::Class::::_post_add_attributeClass::MOP::Class::_post_add_attribute
821114.1ms113msClass::MOP::Class::::_can_fix_metaclass_incompatibilityClass::MOP::Class::_can_fix_metaclass_incompatibility
1731112.8ms156msClass::MOP::Class::::_create_meta_instanceClass::MOP::Class::_create_meta_instance
81512512.4ms168msClass::MOP::Class::::get_meta_instanceClass::MOP::Class::get_meta_instance
981111.1ms236msClass::MOP::Class::::_construct_class_instanceClass::MOP::Class::_construct_class_instance (recurses: max depth 1, inclusive time 1.10ms)
2381110.5ms1.42sClass::MOP::Class::::__ANON__[:790]Class::MOP::Class::__ANON__[:790]
238119.82ms12.8msClass::MOP::Class::::invalidate_meta_instancesClass::MOP::Class::invalidate_meta_instances
77319.47ms147msClass::MOP::Class::::__ANON__[:967]Class::MOP::Class::__ANON__[:967]
55118.18ms535msClass::MOP::Class::::_inline_constructorClass::MOP::Class::_inline_constructor
75117.88ms242msClass::MOP::Class::::_immutable_metaclassClass::MOP::Class::_immutable_metaclass (recurses: max depth 1, inclusive time 1.05ms)
273117.23ms57.7msClass::MOP::Class::::_check_single_metaclass_compatibilityClass::MOP::Class::_check_single_metaclass_compatibility
138666.68ms202msClass::MOP::Class::::new_objectClass::MOP::Class::new_object
7530286.33ms1.10sClass::MOP::Class::::make_immutableClass::MOP::Class::make_immutable (recurses: max depth 1, inclusive time 1.75ms)
75225.86ms9.03msClass::MOP::Class::::_immutable_optionsClass::MOP::Class::_immutable_options
238115.67ms20.5msClass::MOP::Class::::_attach_attributeClass::MOP::Class::_attach_attribute
1115.25ms5.98msClass::MOP::Class::::BEGIN@7Class::MOP::Class::BEGIN@7
77225.21ms18.8msClass::MOP::Class::::find_attribute_by_nameClass::MOP::Class::find_attribute_by_name
48225.14ms38.3msClass::MOP::Class::::find_all_methods_by_nameClass::MOP::Class::find_all_methods_by_name
1115.08ms9.58msClass::MOP::Class::::BEGIN@10Class::MOP::Class::BEGIN@10
68114.91ms123msClass::MOP::Class::::_fix_metaclass_incompatibilityClass::MOP::Class::_fix_metaclass_incompatibility (recurses: max depth 1, inclusive time 2.48ms)
51334.64ms22.2msClass::MOP::Class::::class_precedence_listClass::MOP::Class::class_precedence_list (recurses: max depth 4, inclusive time 17.8ms)
1114.50ms8.94msClass::MOP::Class::::BEGIN@9Class::MOP::Class::BEGIN@9
75114.50ms838msClass::MOP::Class::::_install_inlined_codeClass::MOP::Class::_install_inlined_code
1114.20ms5.04msClass::MOP::Class::::BEGIN@8Class::MOP::Class::BEGIN@8
24114.17ms108msClass::MOP::Class::::_inline_destructorClass::MOP::Class::_inline_destructor
75114.12ms842msClass::MOP::Class::::_initialize_immutableClass::MOP::Class::_initialize_immutable
64113.91ms3.91msClass::MOP::Class::::_newClass::MOP::Class::_new
70223.77ms151msClass::MOP::Class::::add_around_method_modifierClass::MOP::Class::add_around_method_modifier
131413.74ms7.02msClass::MOP::Class::::_real_ref_nameClass::MOP::Class::_real_ref_name
75113.32ms245msClass::MOP::Class::::_rebless_as_immutableClass::MOP::Class::_rebless_as_immutable (recurses: max depth 1, inclusive time 1.17ms)
32113.07ms191msClass::MOP::Class::::_inline_accessorsClass::MOP::Class::_inline_accessors
238112.98ms2.98msClass::MOP::Class::::invalidate_meta_instanceClass::MOP::Class::invalidate_meta_instance
82112.91ms12.0msClass::MOP::Class::::_class_metaclass_can_be_made_compatibleClass::MOP::Class::_class_metaclass_can_be_made_compatible
150322.71ms2.71msClass::MOP::Class::::_base_metaclassesClass::MOP::Class::_base_metaclasses
36112.69ms15.0msClass::MOP::Class::::_superclasses_updatedClass::MOP::Class::_superclasses_updated
39112.21ms5.76msClass::MOP::Class::::_class_metaclass_is_compatibleClass::MOP::Class::_class_metaclass_is_compatible
55222.11ms11.9msClass::MOP::Class::::inline_create_instanceClass::MOP::Class::inline_create_instance
79211.86ms1.86msClass::MOP::Class::::_add_inlined_methodClass::MOP::Class::_add_inlined_method
1111.80ms2.11msClass::MOP::Class::::BEGIN@11Class::MOP::Class::BEGIN@11
10221.79ms135msClass::MOP::Class::::createClass::MOP::Class::create
8111.54ms27.5msClass::MOP::Class::::get_all_methodsClass::MOP::Class::get_all_methods
1111.22ms15.6msClass::MOP::Class::::BEGIN@16Class::MOP::Class::BEGIN@16
39111.08ms6.84msClass::MOP::Class::::_check_class_metaclass_compatibilityClass::MOP::Class::_check_class_metaclass_compatibility
10633715µs715µsClass::MOP::Class::::is_mutableClass::MOP::Class::is_mutable
9111651µs651µsClass::MOP::Class::::is_immutableClass::MOP::Class::is_immutable
3611594µs594µsClass::MOP::Class::::_superclass_metasClass::MOP::Class::_superclass_metas
3611419µs419µsClass::MOP::Class::::update_meta_instance_dependenciesClass::MOP::Class::update_meta_instance_dependencies
811386µs447msClass::MOP::Class::::create_anon_classClass::MOP::Class::create_anon_class
522286µs9.97msClass::MOP::Class::::add_before_method_modifierClass::MOP::Class::add_before_method_modifier
2111259µs259µsClass::MOP::Class::::reset_package_cache_flagClass::MOP::Class::reset_package_cache_flag
211117µs1.77msClass::MOP::Class::::add_after_method_modifierClass::MOP::Class::add_after_method_modifier
11182µs105µsClass::MOP::Class::::BEGIN@4Class::MOP::Class::BEGIN@4
11162µs353µsClass::MOP::Class::::BEGIN@14Class::MOP::Class::BEGIN@14
11162µs294µsClass::MOP::Class::::BEGIN@13Class::MOP::Class::BEGIN@13
11158µs255µsClass::MOP::Class::::BEGIN@15Class::MOP::Class::BEGIN@15
11154µs128µsClass::MOP::Class::::BEGIN@445Class::MOP::Class::BEGIN@445
11151µs125µsClass::MOP::Class::::BEGIN@467Class::MOP::Class::BEGIN@467
11145µs248µsClass::MOP::Class::::BEGIN@17Class::MOP::Class::BEGIN@17
11144µs110µsClass::MOP::Class::::BEGIN@480Class::MOP::Class::BEGIN@480
11142µs14.2msClass::MOP::Class::::BEGIN@24Class::MOP::Class::BEGIN@24
11140µs111µsClass::MOP::Class::::BEGIN@5Class::MOP::Class::BEGIN@5
11137µs177µsClass::MOP::Class::::BEGIN@18Class::MOP::Class::BEGIN@18
0000s0sClass::MOP::Class::::DESTROYClass::MOP::Class::DESTROY
0000s0sClass::MOP::Class::::__ANON__[:226]Class::MOP::Class::__ANON__[:226]
0000s0sClass::MOP::Class::::__ANON__[:794]Class::MOP::Class::__ANON__[:794]
0000s0sClass::MOP::Class::::_clone_instanceClass::MOP::Class::_clone_instance
0000s0sClass::MOP::Class::::_fix_class_metaclass_incompatibilityClass::MOP::Class::_fix_class_metaclass_incompatibility
0000s0sClass::MOP::Class::::_fix_single_metaclass_incompatibilityClass::MOP::Class::_fix_single_metaclass_incompatibility
0000s0sClass::MOP::Class::::_fixup_attributes_after_reblessClass::MOP::Class::_fixup_attributes_after_rebless
0000s0sClass::MOP::Class::::_force_rebless_instanceClass::MOP::Class::_force_rebless_instance
0000s0sClass::MOP::Class::::_inline_clear_mop_slotClass::MOP::Class::_inline_clear_mop_slot
0000s0sClass::MOP::Class::::_inline_get_mop_slotClass::MOP::Class::_inline_get_mop_slot
0000s0sClass::MOP::Class::::_inline_set_mop_slotClass::MOP::Class::_inline_set_mop_slot
0000s0sClass::MOP::Class::::_inlined_methodsClass::MOP::Class::_inlined_methods
0000s0sClass::MOP::Class::::_rebless_as_mutableClass::MOP::Class::_rebless_as_mutable
0000s0sClass::MOP::Class::::_remove_generated_metaobjectsClass::MOP::Class::_remove_generated_metaobjects
0000s0sClass::MOP::Class::::_remove_inlined_codeClass::MOP::Class::_remove_inlined_code
0000s0sClass::MOP::Class::::_restore_metaobjects_fromClass::MOP::Class::_restore_metaobjects_from
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::::clone_objectClass::MOP::Class::clone_object
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::::immutable_optionsClass::MOP::Class::immutable_options
0000s0sClass::MOP::Class::::inline_rebless_instanceClass::MOP::Class::inline_rebless_instance
0000s0sClass::MOP::Class::::is_anon_classClass::MOP::Class::is_anon_class
0000s0sClass::MOP::Class::::is_pristineClass::MOP::Class::is_pristine
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::::reinitializeClass::MOP::Class::reinitialize
0000s0sClass::MOP::Class::::remove_attributeClass::MOP::Class::remove_attribute
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
0000s0sClass::MOP::Class::::update_package_cache_flagClass::MOP::Class::update_package_cache_flag
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
43110µs2128µs
# spent 105µs (82+23) within Class::MOP::Class::BEGIN@4 which was called: # once (82µs+23µs) by Class::MOP::BEGIN@19 at line 4
use strict;
# spent 105µs making 1 call to Class::MOP::Class::BEGIN@4 # spent 23µs making 1 call to strict::import
53114µs2183µs
# spent 111µs (40+72) within Class::MOP::Class::BEGIN@5 which was called: # once (40µs+72µs) by Class::MOP::BEGIN@19 at line 5
use warnings;
# spent 111µs making 1 call to Class::MOP::Class::BEGIN@5 # spent 72µs making 1 call to warnings::import
6
73498µs15.98ms
# spent 5.98ms (5.25+733µs) within Class::MOP::Class::BEGIN@7 which was called: # once (5.25ms+733µs) by Class::MOP::BEGIN@19 at line 7
use Class::MOP::Instance;
# spent 5.98ms making 1 call to Class::MOP::Class::BEGIN@7
83494µs15.04ms
# spent 5.04ms (4.20+841µs) within Class::MOP::Class::BEGIN@8 which was called: # once (4.20ms+841µs) by Class::MOP::BEGIN@19 at line 8
use Class::MOP::Method::Wrapped;
# spent 5.04ms making 1 call to Class::MOP::Class::BEGIN@8
93485µs18.94ms
# spent 8.94ms (4.50+4.44) within Class::MOP::Class::BEGIN@9 which was called: # once (4.50ms+4.44ms) by Class::MOP::BEGIN@19 at line 9
use Class::MOP::Method::Accessor;
# spent 8.94ms making 1 call to Class::MOP::Class::BEGIN@9
103571µs19.58ms
# spent 9.58ms (5.08+4.50) within Class::MOP::Class::BEGIN@10 which was called: # once (5.08ms+4.50ms) by Class::MOP::BEGIN@19 at line 10
use Class::MOP::Method::Constructor;
# spent 9.58ms making 1 call to Class::MOP::Class::BEGIN@10
113698µs12.11ms
# spent 2.11ms (1.80+318µs) within Class::MOP::Class::BEGIN@11 which was called: # once (1.80ms+318µs) by Class::MOP::BEGIN@19 at line 11
use Class::MOP::MiniTrait;
# spent 2.11ms making 1 call to Class::MOP::Class::BEGIN@11
12
133195µs2526µs
# spent 294µs (62+232) within Class::MOP::Class::BEGIN@13 which was called: # once (62µs+232µs) by Class::MOP::BEGIN@19 at line 13
use Carp 'confess';
# spent 294µs making 1 call to Class::MOP::Class::BEGIN@13 # spent 232µs making 1 call to Exporter::import
143176µs2644µs
# spent 353µs (62+291) within Class::MOP::Class::BEGIN@14 which was called: # once (62µs+291µs) by Class::MOP::BEGIN@19 at line 14
use Scalar::Util 'blessed', 'reftype', 'weaken';
# spent 353µs making 1 call to Class::MOP::Class::BEGIN@14 # spent 291µs making 1 call to Exporter::import
153176µs2451µs
# spent 255µs (58+196) within Class::MOP::Class::BEGIN@15 which was called: # once (58µs+196µs) by Class::MOP::BEGIN@19 at line 15
use Sub::Name 'subname';
# spent 255µs making 1 call to Class::MOP::Class::BEGIN@15 # spent 196µs making 1 call to Exporter::import
163674µs216.4ms
# spent 15.6ms (1.22+14.4) within Class::MOP::Class::BEGIN@16 which was called: # once (1.22ms+14.4ms) by Class::MOP::BEGIN@19 at line 16
use Devel::GlobalDestruction 'in_global_destruction';
# spent 15.6ms making 1 call to Class::MOP::Class::BEGIN@16 # spent 815µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
173111µs2451µs
# spent 248µs (45+203) within Class::MOP::Class::BEGIN@17 which was called: # once (45µs+203µs) by Class::MOP::BEGIN@19 at line 17
use Try::Tiny;
# spent 248µs making 1 call to Class::MOP::Class::BEGIN@17 # spent 203µs making 1 call to Exporter::import
183228µs2316µs
# spent 177µs (37+140) within Class::MOP::Class::BEGIN@18 which was called: # once (37µs+140µs) by Class::MOP::BEGIN@19 at line 18
use List::MoreUtils 'all';
# spent 177µs making 1 call to Class::MOP::Class::BEGIN@18 # spent 140µs making 1 call to Exporter::import
19
2015µsour $VERSION = '1.11';
21187µs$VERSION = eval $VERSION;
# spent 13µs executing statements in string eval
2213µsour $AUTHORITY = 'cpan:STEVAN';
23
24114.2ms
# spent 14.2ms (42µs+14.2) within Class::MOP::Class::BEGIN@24 which was called: # once (42µs+14.2ms) by Class::MOP::BEGIN@19 at line 26
use base 'Class::MOP::Module',
# spent 14.2ms making 1 call to base::import
25 'Class::MOP::Mixin::HasAttributes',
2636.01ms114.2ms 'Class::MOP::Mixin::HasMethods';
# spent 14.2ms making 1 call to Class::MOP::Class::BEGIN@24
27
28# Creation
29
30
# spent 367ms (105+262) within Class::MOP::Class::initialize which was called 3144 times, avg 117µs/call: # 1294 times (40.7ms+11.0ms) by Class::MOP::Class::get_all_attributes at line 826, avg 40µs/call # 483 times (17.6ms+22.9ms) by Class::MOP::Class::__ANON__::SERIAL::1::meta or Class::MOP::Class::__ANON__::SERIAL::2::meta or Class::MOP::Class::__ANON__::SERIAL::5::meta or Class::MOP::Mixin::meta or Class::MOP::Object::meta or Data::Stream::Bulk::Cat::meta or Data::Stream::Bulk::Filter::meta or Data::Stream::Bulk::Nil::meta or Data::Visitor::meta or KiokuDB::Collapser::Buffer::meta or KiokuDB::Collapser::meta or KiokuDB::Entry::Skip::meta or KiokuDB::Entry::meta or KiokuDB::Error::MissingObjects::meta or KiokuDB::Error::UnknownObjects::meta or KiokuDB::Linker::meta or KiokuDB::LiveObjects::Scope::meta or KiokuDB::LiveObjects::TXNScope::meta or KiokuDB::LiveObjects::meta or KiokuDB::Reference::meta or KiokuDB::Stream::Objects::meta or KiokuDB::Thunk::meta or KiokuDB::TypeMap::Entry::Alias::meta or KiokuDB::TypeMap::Entry::Compiled::meta or KiokuDB::TypeMap::Entry::MOP::meta or KiokuDB::TypeMap::Resolver::meta or KiokuDB::TypeMap::Shadow::meta or KiokuDB::TypeMap::meta or KiokuDB::meta or Moose::Meta::Role::Application::RoleSummation::meta or Moose::Meta::Role::Application::ToClass::meta or Moose::Meta::Role::Application::ToInstance::meta or Moose::Meta::Role::Application::ToRole::meta or Moose::Meta::Role::Application::meta or Moose::Meta::Role::Composite::meta or Moose::Meta::Role::Method::Required::meta or Moose::Meta::Role::meta or Moose::Meta::TypeCoercion::Union::meta or Moose::Meta::TypeCoercion::meta or Moose::Meta::TypeConstraint::Class::meta or Moose::Meta::TypeConstraint::DuckType::meta or Moose::Meta::TypeConstraint::Enum::meta or Moose::Meta::TypeConstraint::Parameterizable::meta or Moose::Meta::TypeConstraint::Parameterized::meta or Moose::Meta::TypeConstraint::Registry::meta or Moose::Meta::TypeConstraint::Role::meta or Moose::Meta::TypeConstraint::Union::meta or Moose::Meta::TypeConstraint::meta at line 44 of Class/MOP/Method/Meta.pm, avg 84µs/call # 432 times (14.5ms+4.05ms) by Class::MOP::Class::find_method_by_name at line 1018, avg 43µs/call # 256 times (8.45ms+2.52ms) by Class::MOP::Class::find_next_method_by_name at line 1067, avg 43µs/call # 107 times (3.41ms+1.01ms) by Moose::Meta::Attribute::_new or Moose::Meta::Method::_new at line 4 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 41µs/call # 98 times (3.35ms+963µs) by Class::MOP::Class::find_all_methods_by_name at line 1050, avg 44µs/call # 82 times (2.72ms+2.34ms) by Class::MOP::Class::_fix_metaclass_incompatibility at line 310, avg 62µs/call # 79 times (2.40ms+667µs) by Class::MOP::Class::find_attribute_by_name at line 816, avg 39µs/call # 58 times (1.67ms+529µs) by Class::MOP::Attribute::has_value at line 282 of Class/MOP/Attribute.pm, avg 38µs/call # 49 times (1.56ms+507µs) by Class::MOP::Class::class_precedence_list at line 927, avg 42µs/call # 34 times (1.76ms+142ms) by Moose::Meta::Class::initialize at line 68 of Moose/Meta/Class.pm, avg 4.23ms/call # 33 times (1.33ms+26.7ms) by Class::MOP::Object::meta at line 18 of Class/MOP/Object.pm, avg 849µs/call # 29 times (818µs+258µs) by Class::MOP::Attribute::get_raw_value at line 274 of Class/MOP/Attribute.pm, avg 37µs/call # 26 times (814µs+8.51ms) by Class::MOP::Method::_new at line 54 of Class/MOP/Method.pm, avg 358µs/call # 19 times (983µs+11.0ms) by metaclass::import at line 45 of metaclass.pm, avg 630µs/call # 18 times (679µs+7.28ms) by Class::MOP::Mixin::meta at line 14 of Class/MOP/Mixin.pm, avg 442µs/call # 14 times (621µs+14.7ms) by Class::MOP::MiniTrait::apply at line 15 of Class/MOP/MiniTrait.pm, avg 1.09ms/call # 11 times (342µs+102µs) by Class::MOP::Attribute::set_initial_value at line 253 of Class/MOP/Attribute.pm, avg 40µs/call # 9 times (278µs+75µs) by Class::MOP::Class::get_all_methods at line 1029, avg 39µs/call # 7 times (324µs+3.75ms) by Moose::BEGIN@38 at line 11 of Moose/Meta/Attribute/Native.pm, avg 583µs/call # 2 times (87µs+1.17ms) by Class::MOP::Class::create at line 525, avg 629µs/call # 2 times (56µs+17µs) by Moose::Meta::Attribute::_weaken_value at line 568 of Moose/Meta/Attribute.pm, avg 37µs/call # once (40µs+12µs) by Moose::Object::new at line 26 of Moose/Object.pm # once (32µs+9µs) by Class::MOP::Attribute::_new at line 62 of Class/MOP/Attribute.pm
sub initialize {
3115720101ms my $class = shift;
32
33 my $package_name;
34
35 if ( @_ % 2 ) {
36 $package_name = shift;
37 } else {
38 my %options = @_;
39 $package_name = $options{package};
40 }
41
42 ($package_name && !ref($package_name))
43 || confess "You must pass a package name and it cannot be blessed";
44
453242266ms return Class::MOP::get_metaclass_by_name($package_name)
# spent 237ms making 98 calls to Class::MOP::Class::_construct_class_instance, avg 2.42ms/call, recursion: max depth 1, sum of overlapping time 1.10ms # spent 30.4ms making 3144 calls to Class::MOP::get_metaclass_by_name, avg 10µs/call
46 || $class->_construct_class_instance(package => $package_name, @_);
47}
48
49sub reinitialize {
50 my ( $class, @args ) = @_;
51 unshift @args, "package" if @args % 2;
52 my %options = @args;
53 my $old_metaclass = blessed($options{package})
54 ? $options{package}
55 : Class::MOP::get_metaclass_by_name($options{package});
56 $options{weaken} = Class::MOP::metaclass_is_weak($old_metaclass->name)
57 if !exists $options{weaken}
58 && blessed($old_metaclass)
59 && $old_metaclass->isa('Class::MOP::Class');
60 $old_metaclass->_remove_generated_metaobjects
61 if $old_metaclass && $old_metaclass->isa('Class::MOP::Class');
62 my $new_metaclass = $class->SUPER::reinitialize(%options);
63 $new_metaclass->_restore_metaobjects_from($old_metaclass)
64 if $old_metaclass && $old_metaclass->isa('Class::MOP::Class');
65 return $new_metaclass;
66}
67
68# NOTE: (meta-circularity)
69# this is a special form of _construct_instance
70# (see below), which is used to construct class
71# meta-object instances for any Class::MOP::*
72# class. All other classes will use the more
73# normal &construct_instance.
74
# spent 236ms (11.1+225) within Class::MOP::Class::_construct_class_instance which was called 98 times, avg 2.40ms/call: # 98 times (11.1ms+225ms) by Class::MOP::Class::initialize at line 45, avg 2.40ms/call
sub _construct_class_instance {
75121010.1ms my $class = shift;
76 my $options = @_ == 1 ? $_[0] : {@_};
77 my $package_name = $options->{package};
78 (defined $package_name && $package_name)
79 || confess "You must pass a package name";
80 # NOTE:
81 # return the metaclass if we have it cached,
82 # and it is still defined (it has not been
83 # reaped by DESTROY yet, which can happen
84 # annoyingly enough during global destruction)
85
8698800µs if (defined(my $meta = Class::MOP::get_metaclass_by_name($package_name))) {
# spent 800µs making 98 calls to Class::MOP::get_metaclass_by_name, avg 8µs/call
87 return $meta;
88 }
89
90 $class
918837µs = ref $class
# spent 837µs making 8 calls to Class::MOP::Class::_real_ref_name, avg 105µs/call
92 ? $class->_real_ref_name
93 : $class;
94
95 # now create the metaclass
96 my $meta;
97643.91ms if ($class eq 'Class::MOP::Class') {
# spent 3.91ms making 64 calls to Class::MOP::Class::_new, avg 61µs/call
98 $meta = $class->_new($options);
99 }
100 else {
101 # NOTE:
102 # it is safe to use meta here because
103 # class will always be a subclass of
104 # Class::MOP::Class, which defines meta
10568120ms $meta = $class->meta->_construct_instance($options)
# spent 118ms making 34 calls to Class::MOP::Class::_construct_instance, avg 3.46ms/call # spent 2.83ms making 34 calls to Class::MOP::Object::meta, avg 83µs/call
106 }
107
108 # and check the metaclass compatibility
1099894.8ms $meta->_check_metaclass_compatibility();
# spent 98.5ms making 98 calls to Class::MOP::Class::_check_metaclass_compatibility, avg 1.00ms/call, recursion: max depth 1, sum of overlapping time 3.72ms
110
111981.28ms Class::MOP::store_metaclass_by_name($package_name, $meta);
# spent 1.28ms making 98 calls to Class::MOP::store_metaclass_by_name, avg 13µs/call
112
113 # NOTE:
114 # we need to weaken any anon classes
115 # so that they can call DESTROY properly
116 Class::MOP::weaken_metaclass($package_name) if $options->{weaken};
117
118 $meta;
119}
120
121
# spent 7.02ms (3.74+3.28) within Class::MOP::Class::_real_ref_name which was called 131 times, avg 54µs/call: # 82 times (2.33ms+1.84ms) by Class::MOP::Class::_class_metaclass_can_be_made_compatible at line 355, avg 51µs/call # 39 times (1.08ms+811µs) by Class::MOP::Class::_class_metaclass_is_compatible at line 265, avg 48µs/call # 8 times (271µs+566µs) by Class::MOP::Class::_construct_class_instance at line 91, avg 105µs/call # 2 times (61µs+63µs) by Class::MOP::Class::_immutable_metaclass at line 1244, avg 62µs/call
sub _real_ref_name {
1222623.54ms my $self = shift;
123
124 # NOTE: we need to deal with the possibility of class immutability here,
125 # and then get the name of the class appropriately
1261713.28ms return $self->is_immutable
# spent 1.96ms making 38 calls to Class::MOP::Class::Immutable::Class::MOP::Class::is_immutable, avg 52µs/call # spent 651µs making 91 calls to Class::MOP::Class::is_immutable, avg 7µs/call # spent 558µs making 40 calls to Class::MOP::Class::Immutable::Trait::_get_mutable_metaclass_name, avg 14µs/call # spent 106µs making 2 calls to Class::MOP::Class::Immutable::Moose::Meta::Class::is_immutable, avg 53µs/call
127 ? $self->_get_mutable_metaclass_name()
128 : ref $self;
129}
130
131
# spent 3.91ms within Class::MOP::Class::_new which was called 64 times, avg 61µs/call: # 64 times (3.91ms+0s) by Class::MOP::Class::_construct_class_instance at line 97, avg 61µs/call
sub _new {
1322564.13ms my $class = shift;
133
134 return Class::MOP::Class->initialize($class)->new_object(@_)
135 if $class ne __PACKAGE__;
136
137 my $options = @_ == 1 ? $_[0] : {@_};
138
139 return bless {
140 # inherited from Class::MOP::Package
141 'package' => $options->{package},
142
143 # NOTE:
144 # since the following attributes will
145 # actually be loaded from the symbol
146 # table, and actually bypass the instance
147 # entirely, we can just leave these things
148 # listed here for reference, because they
149 # should not actually have a value associated
150 # with the slot.
151 'namespace' => \undef,
152 'methods' => {},
153
154 # inherited from Class::MOP::Module
155 'version' => \undef,
156 'authority' => \undef,
157
158 # defined in Class::MOP::Class
159 'superclasses' => \undef,
160
161 'attributes' => {},
162 'attribute_metaclass' =>
163 ( $options->{'attribute_metaclass'} || 'Class::MOP::Attribute' ),
164 'method_metaclass' =>
165 ( $options->{'method_metaclass'} || 'Class::MOP::Method' ),
166 'wrapped_method_metaclass' => (
167 $options->{'wrapped_method_metaclass'}
168 || 'Class::MOP::Method::Wrapped'
169 ),
170 'instance_metaclass' =>
171 ( $options->{'instance_metaclass'} || 'Class::MOP::Instance' ),
172 'immutable_trait' => (
173 $options->{'immutable_trait'}
174 || 'Class::MOP::Class::Immutable::Trait'
175 ),
176 'constructor_name' => ( $options->{constructor_name} || 'new' ),
177 'constructor_class' => (
178 $options->{constructor_class} || 'Class::MOP::Method::Constructor'
179 ),
180 'destructor_class' => $options->{destructor_class},
181 }, $class;
182}
183
18421332µs
# spent 259µs within Class::MOP::Class::reset_package_cache_flag which was called 21 times, avg 12µs/call: # 21 times (259µs+0s) by Moose::Meta::Role::Application::ToClass::apply_methods at line 190 of Moose/Meta/Role/Application/ToClass.pm, avg 12µs/call
sub reset_package_cache_flag { (shift)->{'_package_cache_flag'} = undef }
185sub update_package_cache_flag {
186 my $self = shift;
187 # NOTE:
188 # we can manually update the cache number
189 # since we are actually adding the method
190 # to our cache as well. This avoids us
191 # having to regenerate the method_map.
192 # - SL
193 $self->{'_package_cache_flag'} = Class::MOP::check_package_cache_flag($self->name);
194}
195
196## Metaclass compatibility
197{
198221µs my %base_metaclass = (
199 attribute_metaclass => 'Class::MOP::Attribute',
200 method_metaclass => 'Class::MOP::Method',
201 wrapped_method_metaclass => 'Class::MOP::Method::Wrapped',
202 instance_metaclass => 'Class::MOP::Instance',
203 constructor_class => 'Class::MOP::Method::Constructor',
204 destructor_class => 'Class::MOP::Method::Destructor',
205 );
206
2071503.39ms
# spent 2.71ms within Class::MOP::Class::_base_metaclasses which was called 150 times, avg 18µs/call: # 73 times (1.36ms+0s) by Moose::Meta::Class::_base_metaclasses at line 354 of Moose/Meta/Class.pm, avg 19µs/call # 43 times (796µs+0s) by Class::MOP::Class::_can_fix_metaclass_incompatibility at line 343, avg 19µs/call # 34 times (546µs+0s) by Class::MOP::Class::_check_metaclass_compatibility at line 218, avg 16µs/call
sub _base_metaclasses { %base_metaclass }
208}
209
210
# spent 267ms (19.7+247) within Class::MOP::Class::_check_metaclass_compatibility which was called 134 times, avg 1.99ms/call: # 98 times (4.89ms+89.9ms) by Class::MOP::Class::_construct_class_instance at line 109, avg 967µs/call # 36 times (14.8ms+157ms) by Class::MOP::Class::superclasses at line 857, avg 4.78ms/call
sub _check_metaclass_compatibility {
211132817.3ms my $self = shift;
212
21313434.3ms my @superclasses = $self->superclasses
# spent 19.7ms making 66 calls to Class::MOP::Class::superclasses, avg 299µs/call, recursion: max depth 1, sum of overlapping time 539µs # spent 23.6ms making 68 calls to Moose::Meta::Class::superclasses, avg 347µs/call, recursion: max depth 1, sum of overlapping time 8.45ms
214 or return;
215
21668123ms $self->_fix_metaclass_incompatibility(@superclasses);
# spent 125ms making 68 calls to Class::MOP::Class::_fix_metaclass_incompatibility, avg 1.84ms/call, recursion: max depth 1, sum of overlapping time 2.48ms
217
218687.95ms my %base_metaclass = $self->_base_metaclasses;
# spent 7.41ms making 34 calls to Moose::Meta::Class::_base_metaclasses, avg 218µs/call # spent 546µs making 34 calls to Class::MOP::Class::_base_metaclasses, avg 16µs/call
219
220 # this is always okay ...
221 return
222 if ref($self) eq 'Class::MOP::Class'
223 && all {
2244083.06ms2041.98ms my $meta = $self->$_;
# spent 345µs making 34 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 10µs/call # spent 339µs making 34 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 10µs/call # spent 338µs making 34 calls to Class::MOP::Class::destructor_class, avg 10µs/call # spent 322µs making 34 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 9µs/call # spent 322µs making 34 calls to Class::MOP::Class::instance_metaclass, avg 9µs/call # spent 311µs making 34 calls to Class::MOP::Class::constructor_class, avg 9µs/call
22511.17ms !defined($meta) || $meta eq $base_metaclass{$_};
226 }
227346.51ms keys %base_metaclass;
# spent 6.51ms making 34 calls to List::MoreUtils::all, avg 191µs/call
228
229 for my $superclass (@superclasses) {
230396.84ms $self->_check_class_metaclass_compatibility($superclass);
# spent 6.84ms making 39 calls to Class::MOP::Class::_check_class_metaclass_compatibility, avg 175µs/call
231 }
232
233 for my $metaclass_type ( keys %base_metaclass ) {
2342383.07ms next unless defined $self->$metaclass_type;
# spent 506µs making 34 calls to Moose::Meta::Class::constructor_class, avg 15µs/call # spent 475µs making 34 calls to Moose::Meta::Class::error_class, avg 14µs/call # spent 466µs making 34 calls to Moose::Meta::Class::destructor_class, avg 14µs/call # spent 424µs making 34 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 12µs/call # spent 407µs making 34 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 12µs/call # spent 397µs making 34 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 12µs/call # spent 391µs making 34 calls to Class::MOP::Class::instance_metaclass, avg 11µs/call
235 for my $superclass (@superclasses) {
23627357.7ms $self->_check_single_metaclass_compatibility( $metaclass_type,
# spent 57.7ms making 273 calls to Class::MOP::Class::_check_single_metaclass_compatibility, avg 211µs/call
237 $superclass );
238 }
239 }
240}
241
242
# spent 6.84ms (1.08+5.76) within Class::MOP::Class::_check_class_metaclass_compatibility which was called 39 times, avg 175µs/call: # 39 times (1.08ms+5.76ms) by Class::MOP::Class::_check_metaclass_compatibility at line 230, avg 175µs/call
sub _check_class_metaclass_compatibility {
2431171.04ms my $self = shift;
244 my ( $superclass_name ) = @_;
245
246395.76ms if (!$self->_class_metaclass_is_compatible($superclass_name)) {
# spent 5.76ms making 39 calls to Class::MOP::Class::_class_metaclass_is_compatible, avg 148µs/call
247 my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name);
248
249 my $super_meta_type = $super_meta->_real_ref_name;
250
251 confess "The metaclass of " . $self->name . " ("
252 . (ref($self)) . ")" . " is not compatible with "
253 . "the metaclass of its superclass, "
254 . $superclass_name . " (" . ($super_meta_type) . ")";
255 }
256}
257
258
# spent 5.76ms (2.21+3.54) within Class::MOP::Class::_class_metaclass_is_compatible which was called 39 times, avg 148µs/call: # 39 times (2.21ms+3.54ms) by Class::MOP::Class::_check_class_metaclass_compatibility at line 246, avg 148µs/call
sub _class_metaclass_is_compatible {
2591951.95ms my $self = shift;
260 my ( $superclass_name ) = @_;
261
26239406µs my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name)
# spent 406µs making 39 calls to Class::MOP::get_metaclass_by_name, avg 10µs/call
263 || return 1;
264
265391.89ms my $super_meta_name = $super_meta->_real_ref_name;
# spent 1.89ms making 39 calls to Class::MOP::Class::_real_ref_name, avg 48µs/call
266
267391.25ms return $self->_is_compatible_with($super_meta_name);
# spent 1.25ms making 39 calls to Class::MOP::Object::_is_compatible_with, avg 32µs/call
268}
269
270
# spent 57.7ms (7.23+50.5) within Class::MOP::Class::_check_single_metaclass_compatibility which was called 273 times, avg 211µs/call: # 273 times (7.23ms+50.5ms) by Class::MOP::Class::_check_metaclass_compatibility at line 236, avg 211µs/call
sub _check_single_metaclass_compatibility {
2718196.90ms my $self = shift;
272 my ( $metaclass_type, $superclass_name ) = @_;
273
27427350.5ms if (!$self->_single_metaclass_is_compatible($metaclass_type, $superclass_name)) {
# spent 50.5ms making 273 calls to Class::MOP::Class::_single_metaclass_is_compatible, avg 185µs/call
275 my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name);
276 my $metaclass_type_name = $metaclass_type;
277 $metaclass_type_name =~ s/_(?:meta)?class$//;
278 $metaclass_type_name =~ s/_/ /g;
279 confess "The $metaclass_type_name metaclass for "
280 . $self->name . " (" . ($self->$metaclass_type)
281 . ")" . " is not compatible with the "
282 . "$metaclass_type_name metaclass of its "
283 . "superclass, $superclass_name ("
284 . ($super_meta->$metaclass_type) . ")";
285 }
286}
287
288
# spent 50.5ms (27.2+23.2) within Class::MOP::Class::_single_metaclass_is_compatible which was called 273 times, avg 185µs/call: # 273 times (27.2ms+23.2ms) by Class::MOP::Class::_check_single_metaclass_compatibility at line 274, avg 185µs/call
sub _single_metaclass_is_compatible {
289184624.5ms my $self = shift;
290 my ( $metaclass_type, $superclass_name ) = @_;
291
2922732.33ms my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name)
# spent 2.33ms making 273 calls to Class::MOP::get_metaclass_by_name, avg 9µs/call
293 || return 1;
294
295 # for instance, Moose::Meta::Class has a error_class attribute, but
296 # Class::MOP::Class doesn't - this shouldn't be an error
2972731.72ms return 1 unless $super_meta->can($metaclass_type);
# spent 1.72ms making 273 calls to UNIVERSAL::can, avg 6µs/call
298 # for instance, Moose::Meta::Class has a destructor_class, but
299 # Class::MOP::Class doesn't - this shouldn't be an error
3002602.82ms return 1 unless defined $super_meta->$metaclass_type;
# spent 413µs making 39 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 11µs/call # spent 398µs making 39 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 10µs/call # spent 386µs making 39 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 10µs/call # spent 386µs making 39 calls to Class::MOP::Class::instance_metaclass, avg 10µs/call # spent 366µs making 26 calls to Moose::Meta::Class::constructor_class, avg 14µs/call # spent 311µs making 26 calls to Moose::Meta::Class::destructor_class, avg 12µs/call # spent 308µs making 26 calls to Moose::Meta::Class::error_class, avg 12µs/call # spent 128µs making 13 calls to Class::MOP::Class::constructor_class, avg 10µs/call # spent 121µs making 13 calls to Class::MOP::Class::destructor_class, avg 9µs/call
301 # if metaclass is defined in superclass but not here, it's not compatible
302 # this is a really odd case
3032472.61ms return 0 unless defined $self->$metaclass_type;
# spent 469µs making 39 calls to Moose::Meta::Class::constructor_class, avg 12µs/call # spent 442µs making 39 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 11µs/call # spent 384µs making 39 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 10µs/call # spent 364µs making 39 calls to Class::MOP::Class::instance_metaclass, avg 9µs/call # spent 360µs making 39 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 9µs/call # spent 296µs making 26 calls to Moose::Meta::Class::error_class, avg 11µs/call # spent 296µs making 26 calls to Moose::Meta::Class::destructor_class, avg 11µs/call
304
30574113.8ms return $self->$metaclass_type->_is_compatible_with($super_meta->$metaclass_type);
# spent 8.72ms making 247 calls to Class::MOP::Object::_is_compatible_with, avg 35µs/call # spent 770µs making 78 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 10µs/call # spent 759µs making 65 calls to Moose::Meta::Class::constructor_class, avg 12µs/call # spent 737µs making 78 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 9µs/call # spent 724µs making 78 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 9µs/call # spent 700µs making 78 calls to Class::MOP::Class::instance_metaclass, avg 9µs/call # spent 598µs making 52 calls to Moose::Meta::Class::error_class, avg 11µs/call # spent 590µs making 52 calls to Moose::Meta::Class::destructor_class, avg 11µs/call # spent 158µs making 13 calls to Class::MOP::Class::constructor_class, avg 12µs/call
306}
307
308
# spent 123ms (4.91+118) within Class::MOP::Class::_fix_metaclass_incompatibility which was called 68 times, avg 1.81ms/call: # 68 times (4.91ms+118ms) by Class::MOP::Class::_check_metaclass_compatibility at line 216, avg 1.81ms/call
sub _fix_metaclass_incompatibility {
3095044.54ms my $self = shift;
310825.06ms my @supers = map { Class::MOP::Class->initialize($_) } @_;
# spent 7.84ms making 82 calls to Class::MOP::Class::initialize, avg 96µs/call, recursion: max depth 1, sum of overlapping time 2.78ms
311
312 my $necessary = 0;
313 for my $super (@supers) {
31482113ms $necessary = 1
# spent 113ms making 82 calls to Class::MOP::Class::_can_fix_metaclass_incompatibility, avg 1.37ms/call
315 if $self->_can_fix_metaclass_incompatibility($super);
316 }
317 return unless $necessary;
318
319 for my $super (@supers) {
320 if (!$self->_class_metaclass_is_compatible($super->name)) {
321 $self->_fix_class_metaclass_incompatibility($super);
322 }
323 }
324
325 my %base_metaclass = $self->_base_metaclasses;
326 for my $metaclass_type (keys %base_metaclass) {
327 for my $super (@supers) {
328 if (!$self->_single_metaclass_is_compatible($metaclass_type, $super->name)) {
329 $self->_fix_single_metaclass_incompatibility(
330 $metaclass_type, $super
331 );
332 }
333 }
334 }
335}
336
337
# spent 113ms (14.1+98.6) within Class::MOP::Class::_can_fix_metaclass_incompatibility which was called 82 times, avg 1.37ms/call: # 82 times (14.1ms+98.6ms) by Class::MOP::Class::_fix_metaclass_incompatibility at line 314, avg 1.37ms/call
sub _can_fix_metaclass_incompatibility {
338102312.7ms my $self = shift;
339 my ($super_meta) = @_;
340
3418212.0ms return 1 if $self->_class_metaclass_can_be_made_compatible($super_meta);
# spent 12.0ms making 82 calls to Class::MOP::Class::_class_metaclass_can_be_made_compatible, avg 147µs/call
342
343829.41ms my %base_metaclass = $self->_base_metaclasses;
# spent 8.62ms making 39 calls to Moose::Meta::Class::_base_metaclasses, avg 221µs/call # spent 796µs making 43 calls to Class::MOP::Class::_base_metaclasses, avg 19µs/call
344 for my $metaclass_type (keys %base_metaclass) {
34553177.1ms return 1 if $self->_single_metaclass_can_be_made_compatible($super_meta, $metaclass_type);
# spent 77.1ms making 531 calls to Class::MOP::Class::_single_metaclass_can_be_made_compatible, avg 145µs/call
346 }
347
348 return;
349}
350
351
# spent 12.0ms (2.91+9.12) within Class::MOP::Class::_class_metaclass_can_be_made_compatible which was called 82 times, avg 147µs/call: # 82 times (2.91ms+9.12ms) by Class::MOP::Class::_can_fix_metaclass_incompatibility at line 341, avg 147µs/call
sub _class_metaclass_can_be_made_compatible {
3522462.78ms my $self = shift;
353 my ($super_meta) = @_;
354
3551649.12ms return $self->_can_be_made_compatible_with($super_meta->_real_ref_name);
# spent 4.95ms making 82 calls to Class::MOP::Object::_can_be_made_compatible_with, avg 60µs/call # spent 4.17ms making 82 calls to Class::MOP::Class::_real_ref_name, avg 51µs/call
356}
357
358
# spent 77.1ms (37.6+39.5) within Class::MOP::Class::_single_metaclass_can_be_made_compatible which was called 531 times, avg 145µs/call: # 531 times (37.6ms+39.5ms) by Class::MOP::Class::_can_fix_metaclass_incompatibility at line 345, avg 145µs/call
sub _single_metaclass_can_be_made_compatible {
359408437.4ms my $self = shift;
360 my ($super_meta, $metaclass_type) = @_;
361
3625315.79ms my $specific_meta = $self->$metaclass_type;
# spent 925µs making 82 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 11µs/call # spent 917µs making 82 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 11µs/call # spent 870µs making 82 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 11µs/call # spent 784µs making 82 calls to Class::MOP::Class::instance_metaclass, avg 10µs/call # spent 537µs making 39 calls to Moose::Meta::Class::error_class, avg 14µs/call # spent 515µs making 39 calls to Moose::Meta::Class::destructor_class, avg 13µs/call # spent 510µs making 39 calls to Moose::Meta::Class::constructor_class, avg 13µs/call # spent 384µs making 43 calls to Class::MOP::Class::constructor_class, avg 9µs/call # spent 343µs making 43 calls to Class::MOP::Class::destructor_class, avg 8µs/call
363
3645313.55ms return unless $super_meta->can($metaclass_type);
# spent 3.55ms making 531 calls to UNIVERSAL::can, avg 7µs/call
3655185.12ms my $super_specific_meta = $super_meta->$metaclass_type;
# spent 827µs making 82 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 10µs/call # spent 800µs making 82 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 10µs/call # spent 786µs making 82 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 10µs/call # spent 770µs making 82 calls to Class::MOP::Class::instance_metaclass, avg 9µs/call # spent 518µs making 56 calls to Class::MOP::Class::constructor_class, avg 9µs/call # spent 458µs making 56 calls to Class::MOP::Class::destructor_class, avg 8µs/call # spent 337µs making 26 calls to Moose::Meta::Class::error_class, avg 13µs/call # spent 314µs making 26 calls to Moose::Meta::Class::destructor_class, avg 12µs/call # spent 314µs making 26 calls to Moose::Meta::Class::constructor_class, avg 12µs/call
366
367 # for instance, Moose::Meta::Class has a destructor_class, but
368 # Class::MOP::Class doesn't - this shouldn't be an error
369 return unless defined $super_specific_meta;
370
371 # if metaclass is defined in superclass but not here, it's fixable
372 # this is a really odd case
373 return 1 unless defined $specific_meta;
374
37546225.0ms return 1 if $specific_meta->_can_be_made_compatible_with($super_specific_meta);
# spent 25.0ms making 462 calls to Class::MOP::Object::_can_be_made_compatible_with, avg 54µs/call
376}
377
378sub _fix_class_metaclass_incompatibility {
379 my $self = shift;
380 my ( $super_meta ) = @_;
381
382 if ($self->_class_metaclass_can_be_made_compatible($super_meta)) {
383 ($self->is_pristine)
384 || confess "Can't fix metaclass incompatibility for "
385 . $self->name
386 . " because it is not pristine.";
387
388 my $super_meta_name = $super_meta->_real_ref_name;
389
390 $self->_make_compatible_with($super_meta_name);
391 }
392}
393
394sub _fix_single_metaclass_incompatibility {
395 my $self = shift;
396 my ( $metaclass_type, $super_meta ) = @_;
397
398 if ($self->_single_metaclass_can_be_made_compatible($super_meta, $metaclass_type)) {
399 ($self->is_pristine)
400 || confess "Can't fix metaclass incompatibility for "
401 . $self->name
402 . " because it is not pristine.";
403
404 my $new_metaclass = $self->$metaclass_type
405 ? $self->$metaclass_type->_get_compatible_metaclass($super_meta->$metaclass_type)
406 : $super_meta->$metaclass_type;
407 $self->{$metaclass_type} = $new_metaclass;
408 }
409}
410
411sub _restore_metaobjects_from {
412 my $self = shift;
413 my ($old_meta) = @_;
414
415 $self->_restore_metamethods_from($old_meta);
416 $self->_restore_metaattributes_from($old_meta);
417}
418
419sub _remove_generated_metaobjects {
420 my $self = shift;
421
422 for my $attr (map { $self->get_attribute($_) } $self->get_attribute_list) {
423 $attr->remove_accessors;
424 }
425}
426
427## ANON classes
428
429{
430 # NOTE:
431 # this should be sufficient, if you have a
432 # use case where it is not, write a test and
433 # I will change it.
43426µs my $ANON_CLASS_SERIAL = 0;
435
436 # NOTE:
437 # we need a sufficiently annoying prefix
438 # this should suffice for now, this is
439 # used in a couple of places below, so
440 # need to put it up here for now.
44113µs my $ANON_CLASS_PREFIX = 'Class::MOP::Class::__ANON__::SERIAL::';
442
443 sub is_anon_class {
444 my $self = shift;
4453425µs2203µs
# spent 128µs (54+74) within Class::MOP::Class::BEGIN@445 which was called: # once (54µs+74µs) by Class::MOP::BEGIN@19 at line 445
no warnings 'uninitialized';
# spent 128µs making 1 call to Class::MOP::Class::BEGIN@445 # spent 74µs making 1 call to warnings::unimport
446 $self->name =~ /^$ANON_CLASS_PREFIX/o;
447 }
448
449
# spent 447ms (386µs+446) within Class::MOP::Class::create_anon_class which was called 8 times, avg 55.8ms/call: # 8 times (386µs+446ms) by Moose::Meta::Class::create_anon_class at line 111 of Moose/Meta/Class.pm, avg 55.8ms/call
sub create_anon_class {
45032359µs my ($class, %options) = @_;
451 $options{weaken} = 1 unless exists $options{weaken};
452 my $package_name = $ANON_CLASS_PREFIX . ++$ANON_CLASS_SERIAL;
4538446ms return $class->create($package_name, %options);
# spent 446ms making 8 calls to Moose::Meta::Class::create, avg 55.8ms/call
454 }
455
456 # NOTE:
457 # this will only get called for
458 # anon-classes, all other calls
459 # are assumed to occur during
460 # global destruction and so don't
461 # really need to be handled explicitly
462 sub DESTROY {
463 my $self = shift;
464
465 return if in_global_destruction(); # it'll happen soon anyway and this just makes things more complicated
466
4673298µs2199µs
# spent 125µs (51+74) within Class::MOP::Class::BEGIN@467 which was called: # once (51µs+74µs) by Class::MOP::BEGIN@19 at line 467
no warnings 'uninitialized';
# spent 125µs making 1 call to Class::MOP::Class::BEGIN@467 # spent 74µs making 1 call to warnings::unimport
468 my $name = $self->name;
469 return unless $name =~ /^$ANON_CLASS_PREFIX/o;
470
471 # Moose does a weird thing where it replaces the metaclass for
472 # class when fixing metaclass incompatibility. In that case,
473 # we don't want to clean out the namespace now. We can detect
474 # that because Moose will explicitly update the singleton
475 # cache in Class::MOP.
476 my $current_meta = Class::MOP::get_metaclass_by_name($name);
477 return if $current_meta ne $self;
478
479 my ($serial_id) = ($name =~ /^$ANON_CLASS_PREFIX(\d+)/o);
480314.2ms2175µs
# spent 110µs (44+66) within Class::MOP::Class::BEGIN@480 which was called: # once (44µs+66µs) by Class::MOP::BEGIN@19 at line 480
no strict 'refs';
# spent 110µs making 1 call to Class::MOP::Class::BEGIN@480 # spent 66µs making 1 call to strict::unimport
481 @{$name . '::ISA'} = ();
482 %{$name . '::'} = ();
483 delete ${$ANON_CLASS_PREFIX}{$serial_id . '::'};
484
485 Class::MOP::remove_metaclass_by_name($name);
486 }
487
488}
489
490# creating classes with MOP ...
491
492
# spent 135ms (1.79+134) within Class::MOP::Class::create which was called 10 times, avg 13.5ms/call: # 8 times (1.44ms+122ms) by Moose::Meta::Class::create at line 85 of Moose/Meta/Class.pm, avg 15.4ms/call # 2 times (355µs+11.6ms) by Class::MOP::Class::_immutable_metaclass at line 1246, avg 5.99ms/call
sub create {
4931701.70ms my ( $class, @args ) = @_;
494
495 unshift @args, 'package' if @args % 2 == 1;
496
497 my (%options) = @args;
498 my $package_name = $options{package};
499
500 (ref $options{superclasses} eq 'ARRAY')
501 || confess "You must pass an ARRAY ref of superclasses"
502 if exists $options{superclasses};
503
504 (ref $options{attributes} eq 'ARRAY')
505 || confess "You must pass an ARRAY ref of attributes"
506 if exists $options{attributes};
507
508 (ref $options{methods} eq 'HASH')
509 || confess "You must pass a HASH ref of methods"
510 if exists $options{methods};
511
512 $options{meta_name} = 'meta'
513 unless exists $options{meta_name};
514
515 my (%initialize_options) = @args;
516 delete @initialize_options{qw(
517 package
518 superclasses
519 attributes
520 methods
521 meta_name
522 version
523 authority
524 )};
5251035.5ms my $meta = $class->initialize( $package_name => %initialize_options );
# spent 34.2ms making 8 calls to Moose::Meta::Class::initialize, avg 4.28ms/call # spent 1.26ms making 2 calls to Class::MOP::Class::initialize, avg 629µs/call
526
527101.24ms $meta->_instantiate_module( $options{version}, $options{authority} );
# spent 1.24ms making 10 calls to Class::MOP::Module::_instantiate_module, avg 124µs/call
528
5291027.5ms $meta->_add_meta_method($options{meta_name})
# spent 27.5ms making 10 calls to Class::MOP::Mixin::HasMethods::_add_meta_method, avg 2.75ms/call
530 if defined $options{meta_name};
531
5321069.3ms $meta->superclasses(@{$options{superclasses}})
# spent 64.3ms making 8 calls to Moose::Meta::Class::superclasses, avg 8.04ms/call # spent 5.01ms making 2 calls to Class::MOP::Class::superclasses, avg 2.50ms/call
533 if exists $options{superclasses};
534 # NOTE:
535 # process attributes first, so that they can
536 # install accessors, but locally defined methods
537 # can then overwrite them. It is maybe a little odd, but
538 # I think this should be the order of things.
539 if (exists $options{attributes}) {
540 foreach my $attr (@{$options{attributes}}) {
541 $meta->add_attribute($attr);
542 }
543 }
544 if (exists $options{methods}) {
545 foreach my $method_name (keys %{$options{methods}}) {
546 $meta->add_method($method_name, $options{methods}->{$method_name});
547 }
548 }
549 return $meta;
550}
551
552## Attribute readers
553
554# NOTE:
555# all these attribute readers will be bootstrapped
556# away in the Class::MOP bootstrap section
557
55885112.0mssub instance_metaclass { $_[0]->{'instance_metaclass'} }
5591021.41mssub immutable_trait { $_[0]->{'immutable_trait'} }
5602102.80mssub constructor_class { $_[0]->{'constructor_class'} }
56175978µssub constructor_name { $_[0]->{'constructor_name'} }
5621972.34mssub destructor_class { $_[0]->{'destructor_class'} }
563
564# Instance Construction & Cloning
565
566
# spent 202ms (6.68+195) within Class::MOP::Class::new_object which was called 138 times, avg 1.46ms/call: # 102 times (4.81ms+132ms) by Moose::Meta::Method::_new at line 4 of (eval 74)[Class/MOP/Method/Generated.pm:53], avg 1.34ms/call # 26 times (1.34ms+30.9ms) by Class::MOP::Method::_new at line 54 of Class/MOP/Method.pm, avg 1.24ms/call # 6 times (289µs+24.0ms) by Moose::Meta::Class::new_object at line 256 of Moose/Meta/Class.pm, avg 4.05ms/call # 2 times (123µs+2.78ms) by Moose::Meta::TypeCoercion::new at line 34 of Moose/Meta/TypeCoercion.pm, avg 1.45ms/call # once (67µs+4.20ms) by Class::MOP::Attribute::_new at line 62 of Class/MOP/Attribute.pm # once (54µs+1.37ms) by Class::MOP::Object::_new at line 22 of Class/MOP/Object.pm
sub new_object {
5674149.57ms my $class = shift;
568
569 # NOTE:
570 # we need to protect the integrity of the
571 # Class::MOP::Class singletons here, so we
572 # delegate this to &construct_class_instance
573 # which will deal with the singletons
5742762.80ms return $class->_construct_class_instance(@_)
# spent 2.00ms making 138 calls to UNIVERSAL::isa, avg 14µs/call # spent 798µs making 138 calls to Class::MOP::Package::name, avg 6µs/call
575 if $class->name->isa('Class::MOP::Class');
576138192ms return $class->_construct_instance(@_);
# spent 192ms making 138 calls to Class::MOP::Class::_construct_instance, avg 1.39ms/call
577}
578
579
# spent 310ms (42.8+267) within Class::MOP::Class::_construct_instance which was called 172 times, avg 1.80ms/call: # 138 times (29.3ms+163ms) by Class::MOP::Class::new_object at line 576, avg 1.39ms/call # 34 times (13.5ms+104ms) by Class::MOP::Class::_construct_class_instance at line 105, avg 3.46ms/call
sub _construct_instance {
580299641.6ms my $class = shift;
581 my $params = @_ == 1 ? $_[0] : {@_};
58217214.2ms my $meta_instance = $class->get_meta_instance();
# spent 10.7ms making 117 calls to Class::MOP::Class::get_meta_instance, avg 91µs/call # spent 3.46ms making 55 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 63µs/call
583 # FIXME:
584 # the code below is almost certainly incorrect
585 # but this is foreign inheritance, so we might
586 # have to kludge it in the end.
587 my $instance;
5881721.30ms if (my $instance_class = blessed($params->{__INSTANCE__})) {
# spent 1.30ms making 172 calls to Scalar::Util::blessed, avg 8µs/call
589 ($instance_class eq $class->name)
590 || confess "Objects passed as the __INSTANCE__ parameter must "
591 . "already be blessed into the correct class, but "
592 . "$params->{__INSTANCE__} is not a " . $class->name;
593 $instance = $params->{__INSTANCE__};
594 }
595 elsif (exists $params->{__INSTANCE__}) {
596 confess "The __INSTANCE__ parameter must be a blessed reference, not "
597 . $params->{__INSTANCE__};
598 }
599 else {
60017212.7ms $instance = $meta_instance->create_instance();
# spent 12.7ms making 172 calls to Class::MOP::Instance::create_instance, avg 74µs/call
601 }
60217264.3ms foreach my $attr ($class->get_all_attributes()) {
# spent 59.4ms making 117 calls to Class::MOP::Class::get_all_attributes, avg 508µs/call # spent 4.89ms making 55 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 89µs/call
6031448169ms $attr->initialize_instance_slot($meta_instance, $instance, $params);
# spent 161ms making 1434 calls to Class::MOP::Attribute::initialize_instance_slot, avg 112µs/call # spent 7.88ms making 14 calls to Moose::Meta::Attribute::initialize_instance_slot, avg 563µs/call
604 }
6053445.43ms if (Class::MOP::metaclass_is_weak($class->name)) {
# spent 4.36ms making 172 calls to Class::MOP::metaclass_is_weak, avg 25µs/call # spent 1.07ms making 172 calls to Class::MOP::Package::name, avg 6µs/call
606 $meta_instance->_set_mop_slot($instance, $class);
607 }
608 return $instance;
609}
610
611
612
# spent 168ms (12.4+156) within Class::MOP::Class::get_meta_instance which was called 815 times, avg 206µs/call: # 196 times (2.74ms+24.4ms) by Moose::Meta::Attribute::inline_set at line 697 of Moose/Meta/Attribute.pm, avg 139µs/call # 195 times (3.76ms+83.9ms) by Class::MOP::Attribute::inline_get at line 411 of Class/MOP/Attribute.pm, avg 450µs/call # 126 times (1.62ms+8.55ms) by Class::MOP::Attribute::inline_set at line 419 of Class/MOP/Attribute.pm, avg 81µs/call # 117 times (1.65ms+9.04ms) by Class::MOP::Class::_construct_instance at line 582, avg 91µs/call # 62 times (811µs+0s) by Class::MOP::Attribute::inline_has at line 428 of Class/MOP/Attribute.pm, avg 13µs/call # 55 times (771µs+8.14ms) by Class::MOP::Class::inline_create_instance at line 634, avg 162µs/call # 29 times (399µs+609µs) by Class::MOP::Attribute::inline_clear at line 437 of Class/MOP/Attribute.pm, avg 35µs/call # 21 times (450µs+20.1ms) by Class::MOP::Class:::around at line 74 of Class/MOP/Class/Immutable/Trait.pm, avg 979µs/call # 9 times (113µs+0s) by Class::MOP::Attribute::set_initial_value at line 253 of Class/MOP/Attribute.pm, avg 13µs/call # 3 times (36µs+0s) by Class::MOP::Attribute::get_raw_value at line 274 of Class/MOP/Attribute.pm, avg 12µs/call # once (28µs+792µs) by Moose::Exporter::BEGIN@11 at line 684 of Class/MOP.pm # once (13µs+0s) by Class::MOP::Attribute::has_value at line 282 of Class/MOP/Attribute.pm
sub get_meta_instance {
613163014.3ms my $self = shift;
614173156ms $self->{'_meta_instance'} ||= $self->_create_meta_instance();
# spent 156ms making 173 calls to Class::MOP::Class::_create_meta_instance, avg 899µs/call
615}
616
617
# spent 156ms (12.8+143) within Class::MOP::Class::_create_meta_instance which was called 173 times, avg 899µs/call: # 173 times (12.8ms+143ms) by Class::MOP::Class::get_meta_instance at line 614, avg 899µs/call
sub _create_meta_instance {
61869211.6ms my $self = shift;
619
620519141ms my $instance = $self->instance_metaclass->new(
# spent 80.7ms making 173 calls to Class::MOP::Instance::new, avg 466µs/call # spent 52.0ms making 161 calls to Class::MOP::Class::get_all_attributes, avg 323µs/call # spent 6.77ms making 12 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 564µs/call # spent 1.62ms making 173 calls to Class::MOP::Class::instance_metaclass, avg 9µs/call
621 associated_metaclass => $self,
622 attributes => [ $self->get_all_attributes() ],
623 );
624
6251731.62ms $self->add_meta_instance_dependencies()
# spent 1.62ms making 173 calls to Class::MOP::Instance::is_dependent_on_superclasses, avg 9µs/call
626 if $instance->is_dependent_on_superclasses();
627
628 return $instance;
629}
630
631
# spent 11.9ms (2.11+9.76) within Class::MOP::Class::inline_create_instance which was called 55 times, avg 216µs/call: # 31 times (1.15ms+8.53ms) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 112 of Class/MOP/Method/Constructor.pm, avg 312µs/call # 24 times (960µs+1.23ms) by Moose::Meta::Method::Constructor::_generate_instance at line 132 of Moose/Meta/Method/Constructor.pm, avg 91µs/call
sub inline_create_instance {
6321101.84ms my $self = shift;
633
6341109.76ms return $self->get_meta_instance->inline_create_instance(@_);
# spent 8.91ms making 55 calls to Class::MOP::Class::get_meta_instance, avg 162µs/call # spent 847µs making 55 calls to Class::MOP::Instance::inline_create_instance, avg 15µs/call
635}
636
637sub inline_rebless_instance {
638 my $self = shift;
639
640 return $self->get_meta_instance->inline_rebless_instance_structure(@_);
641}
642
643sub _inline_get_mop_slot {
644 my $self = shift;
645
646 return $self->get_meta_instance->_inline_get_mop_slot(@_);
647}
648
649sub _inline_set_mop_slot {
650 my $self = shift;
651
652 return $self->get_meta_instance->_inline_set_mop_slot(@_);
653}
654
655sub _inline_clear_mop_slot {
656 my $self = shift;
657
658 return $self->get_meta_instance->_inline_clear_mop_slot(@_);
659}
660
661sub clone_object {
662 my $class = shift;
663 my $instance = shift;
664 (blessed($instance) && $instance->isa($class->name))
665 || confess "You must pass an instance of the metaclass (" . (ref $class ? $class->name : $class) . "), not ($instance)";
666
667 # NOTE:
668 # we need to protect the integrity of the
669 # Class::MOP::Class singletons here, they
670 # should not be cloned.
671 return $instance if $instance->isa('Class::MOP::Class');
672 $class->_clone_instance($instance, @_);
673}
674
675sub _clone_instance {
676 my ($class, $instance, %params) = @_;
677 (blessed($instance))
678 || confess "You can only clone instances, ($instance) is not a blessed instance";
679 my $meta_instance = $class->get_meta_instance();
680 my $clone = $meta_instance->clone_instance($instance);
681 foreach my $attr ($class->get_all_attributes()) {
682 if ( defined( my $init_arg = $attr->init_arg ) ) {
683 if (exists $params{$init_arg}) {
684 $attr->set_value($clone, $params{$init_arg});
685 }
686 }
687 }
688 return $clone;
689}
690
691sub _force_rebless_instance {
692 my ($self, $instance, %params) = @_;
693 my $old_metaclass = Class::MOP::class_of($instance);
694
695 $old_metaclass->rebless_instance_away($instance, $self, %params)
696 if $old_metaclass;
697
698 my $meta_instance = $self->get_meta_instance;
699
700 if (Class::MOP::metaclass_is_weak($old_metaclass->name)) {
701 $meta_instance->_clear_mop_slot($instance);
702 }
703
704 # rebless!
705 # we use $_[1] here because of t/306_rebless_overload.t regressions on 5.8.8
706 $meta_instance->rebless_instance_structure($_[1], $self);
707
708 $self->_fixup_attributes_after_rebless($instance, $old_metaclass, %params);
709
710 if (Class::MOP::metaclass_is_weak($self->name)) {
711 $meta_instance->_set_mop_slot($instance, $self);
712 }
713}
714
715sub rebless_instance {
716 my ($self, $instance, %params) = @_;
717 my $old_metaclass = Class::MOP::class_of($instance);
718
719 my $old_class = $old_metaclass ? $old_metaclass->name : blessed($instance);
720 $self->name->isa($old_class)
721 || confess "You may rebless only into a subclass of ($old_class), of which (". $self->name .") isn't.";
722
723 $self->_force_rebless_instance($_[1], %params);
724
725 return $instance;
726}
727
728sub rebless_instance_back {
729 my ( $self, $instance ) = @_;
730 my $old_metaclass = Class::MOP::class_of($instance);
731
732 my $old_class
733 = $old_metaclass ? $old_metaclass->name : blessed($instance);
734 $old_class->isa( $self->name )
735 || confess
736 "You may rebless only into a superclass of ($old_class), of which ("
737 . $self->name
738 . ") isn't.";
739
740 $self->_force_rebless_instance($_[1]);
741
742 return $instance;
743}
744
745sub rebless_instance_away {
746 # this intentionally does nothing, it is just a hook
747}
748
749sub _fixup_attributes_after_rebless {
750 my $self = shift;
751 my ($instance, $rebless_from, %params) = @_;
752 my $meta_instance = $self->get_meta_instance;
753
754 for my $attr ( $rebless_from->get_all_attributes ) {
755 next if $self->find_attribute_by_name( $attr->name );
756 $meta_instance->deinitialize_slot( $instance, $_ ) for $attr->slots;
757 }
758
759 foreach my $attr ( $self->get_all_attributes ) {
760 if ( $attr->has_value($instance) ) {
761 if ( defined( my $init_arg = $attr->init_arg ) ) {
762 $params{$init_arg} = $attr->get_value($instance)
763 unless exists $params{$init_arg};
764 }
765 else {
766 $attr->set_value($instance, $attr->get_value($instance));
767 }
768 }
769 }
770
771 foreach my $attr ($self->get_all_attributes) {
772 $attr->initialize_instance_slot($meta_instance, $instance, \%params);
773 }
774}
775
776
# spent 20.5ms (5.67+14.8) within Class::MOP::Class::_attach_attribute which was called 238 times, avg 86µs/call: # 238 times (5.67ms+14.8ms) by Class::MOP::Mixin::HasAttributes::add_attribute at line 28 of Class/MOP/Mixin/HasAttributes.pm, avg 86µs/call
sub _attach_attribute {
7774765.85ms my ($self, $attribute) = @_;
77823814.8ms $attribute->attach_to_class($self);
# spent 14.8ms making 238 calls to Class::MOP::Attribute::attach_to_class, avg 62µs/call
779}
780
781
# spent 1.47s (15.3ms+1.46) within Class::MOP::Class::_post_add_attribute which was called 238 times, avg 6.19ms/call: # 238 times (15.3ms+1.46s) by Class::MOP::Mixin::HasAttributes::add_attribute at line 45 of Class/MOP/Mixin/HasAttributes.pm, avg 6.19ms/call
sub _post_add_attribute {
78271413.9ms my ( $self, $attribute ) = @_;
783
78423812.8ms $self->invalidate_meta_instances;
# spent 12.8ms making 238 calls to Class::MOP::Class::invalidate_meta_instances, avg 54µs/call
785
786 # invalidate package flag here
787
# spent 1.42s (10.5ms+1.41) within Class::MOP::Class::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Class.pm:790] which was called 238 times, avg 5.96ms/call: # 238 times (10.5ms+1.41s) by Try::Tiny::try at line 76 of Try/Tiny.pm, avg 5.96ms/call
try {
78847610.5ms local $SIG{__DIE__};
7892381.41s $attribute->install_accessors;
# spent 879ms making 122 calls to Moose::Meta::Attribute::install_accessors, avg 7.21ms/call # spent 240ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::install_accessors # spent 163ms making 114 calls to Class::MOP::Attribute::install_accessors, avg 1.43ms/call # spent 125ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::install_accessors
790 }
791 catch {
792 $self->remove_attribute( $attribute->name );
793 die $_;
7944761.40s };
# spent 1.44s making 238 calls to Try::Tiny::try, avg 6.05ms/call, recursion: max depth 1, sum of overlapping time 46.3ms # spent 5.10ms making 238 calls to Try::Tiny::catch, avg 21µs/call
795}
796
797sub remove_attribute {
798 my $self = shift;
799
800 my $removed_attribute = $self->SUPER::remove_attribute(@_)
801 or return;
802
803 $self->invalidate_meta_instances;
804
805 $removed_attribute->remove_accessors;
806 $removed_attribute->detach_from_class;
807
808 return$removed_attribute;
809}
810
811
# spent 18.8ms (5.21+13.6) within Class::MOP::Class::find_attribute_by_name which was called 77 times, avg 244µs/call: # 75 times (4.96ms+13.0ms) by Class::MOP::Class::_immutable_metaclass at line 1223, avg 240µs/call # 2 times (254µs+514µs) by Moose::Meta::Class::_process_inherited_attribute at line 443 of Moose/Meta/Class.pm, avg 384µs/call
sub find_attribute_by_name {
8123124.59ms my ( $self, $attr_name ) = @_;
813
814774.65ms foreach my $class ( $self->linearized_isa ) {
# spent 4.39ms making 71 calls to Class::MOP::Class::Immutable::Class::MOP::Class::linearized_isa, avg 62µs/call # spent 261µs making 6 calls to Class::MOP::Class::linearized_isa, avg 44µs/call
815 # fetch the meta-class ...
816793.07ms my $meta = Class::MOP::Class->initialize($class);
# spent 3.07ms making 79 calls to Class::MOP::Class::initialize, avg 39µs/call
8171565.84ms return $meta->get_attribute($attr_name)
# spent 3.19ms making 79 calls to Class::MOP::Mixin::HasAttributes::has_attribute, avg 40µs/call # spent 2.65ms making 77 calls to Class::MOP::Mixin::HasAttributes::get_attribute, avg 34µs/call
818 if $meta->has_attribute($attr_name);
819 }
820
821 return;
822}
823
824
# spent 147ms (63.2+83.8) within Class::MOP::Class::get_all_attributes which was called 361 times, avg 407µs/call: # 161 times (22.9ms+29.1ms) by Class::MOP::Class::_create_meta_instance at line 620, avg 323µs/call # 117 times (25.1ms+34.4ms) by Class::MOP::Class::_construct_instance at line 602, avg 508µs/call # 55 times (8.43ms+10.9ms) by Class::MOP::Method::Constructor::_attributes at line 77 of Class/MOP/Method/Constructor.pm, avg 351µs/call # 16 times (2.91ms+5.06ms) by Class::MOP::Class:::around at line 68 of Class/MOP/Class/Immutable/Trait.pm, avg 498µs/call # 6 times (2.07ms+2.29ms) by Moose::Meta::Attribute::new at line 64 of Moose/Meta/Attribute.pm, avg 728µs/call # 6 times (1.77ms+2.09ms) by Moose::Meta::Class::new_object at line 258 of Moose/Meta/Class.pm, avg 643µs/call
sub get_all_attributes {
825367156.5ms my $self = shift;
826294982.8ms my %attrs = map { %{ Class::MOP::Class->initialize($_)->_attribute_map } }
# spent 52.7ms making 1294 calls to Class::MOP::Class::initialize, avg 41µs/call, recursion: max depth 1, sum of overlapping time 968µs # spent 16.0ms making 345 calls to Class::MOP::Class::linearized_isa, avg 46µs/call # spent 13.0ms making 1294 calls to Class::MOP::Mixin::HasAttributes::_attribute_map, avg 10µs/call # spent 1.97ms making 16 calls to Class::MOP::Class::Immutable::Class::MOP::Class::linearized_isa, avg 123µs/call
827 reverse $self->linearized_isa;
828 return values %attrs;
829}
830
831# Inheritance
832
833sub superclasses {
834134417.6ms my $self = shift;
835
83628250.4ms my $isa = $self->get_or_add_package_symbol(
# spent 50.4ms making 282 calls to Class::MOP::Package::get_or_add_package_symbol, avg 179µs/call
837 { sigil => '@', type => 'ARRAY', name => 'ISA' } );
838
839 if (@_) {
840 my @supers = @_;
841 @{$isa} = @supers;
842
843 # NOTE:
844 # on 5.8 and below, we need to call
845 # a method to get Perl to detect
846 # a cycle in the class hierarchy
84736231µs my $class = $self->name;
# spent 231µs making 36 calls to Class::MOP::Package::name, avg 6µs/call
84836286µs $class->isa($class);
# spent 286µs making 36 calls to UNIVERSAL::isa, avg 8µs/call
849
850 # NOTE:
851 # we need to check the metaclass
852 # compatibility here so that we can
853 # be sure that the superclass is
854 # not potentially creating an issues
855 # we don't know about
856
85736172ms $self->_check_metaclass_compatibility();
# spent 172ms making 36 calls to Class::MOP::Class::_check_metaclass_compatibility, avg 4.78ms/call
8583615.0ms $self->_superclasses_updated();
# spent 15.0ms making 36 calls to Class::MOP::Class::_superclasses_updated, avg 416µs/call
859 }
860
861 return @{$isa};
862}
863
864
# spent 15.0ms (2.69+12.3) within Class::MOP::Class::_superclasses_updated which was called 36 times, avg 416µs/call: # 36 times (2.69ms+12.3ms) by Class::MOP::Class::superclasses at line 858, avg 416µs/call
sub _superclasses_updated {
8651492.19ms my $self = shift;
86636419µs $self->update_meta_instance_dependencies();
# spent 419µs making 36 calls to Class::MOP::Class::update_meta_instance_dependencies, avg 12µs/call
867 # keep strong references to all our parents, so they don't disappear if
868 # they are anon classes and don't have any direct instances
869411.40ms $self->_superclass_metas(
# spent 1.40ms making 41 calls to Class::MOP::class_of, avg 34µs/call
87072594µs map { Class::MOP::class_of($_) } $self->superclasses
# spent 594µs making 36 calls to Class::MOP::Class::_superclass_metas, avg 17µs/call # spent 339µs making 2 calls to Class::MOP::Class::superclasses, avg 170µs/call, recursion: max depth 1, sum of overlapping time 339µs # spent 9.54ms making 34 calls to Moose::Meta::Class::superclasses, avg 281µs/call, recursion: max depth 1, sum of overlapping time 9.54ms
871 );
872}
873
874
# spent 594µs within Class::MOP::Class::_superclass_metas which was called 36 times, avg 17µs/call: # 36 times (594µs+0s) by Class::MOP::Class::_superclasses_updated at line 870, avg 17µs/call
sub _superclass_metas {
87572667µs my $self = shift;
876 $self->{_superclass_metas} = [@_];
877}
878
879sub subclasses {
880 my $self = shift;
881 my $super_class = $self->name;
882
883 return @{ $super_class->mro::get_isarev() };
884}
885
886sub direct_subclasses {
887 my $self = shift;
888 my $super_class = $self->name;
889
890 return grep {
891 grep {
892 $_ eq $super_class
893 } Class::MOP::Class->initialize($_)->superclasses
894 } $self->subclasses;
895}
896
897
# spent 37.4ms (23.6+13.7) within Class::MOP::Class::linearized_isa which was called 797 times, avg 47µs/call: # 345 times (10.3ms+5.76ms) by Class::MOP::Class::get_all_attributes at line 826, avg 46µs/call # 211 times (6.14ms+3.60ms) by Class::MOP::Class::find_method_by_name at line 1017, avg 46µs/call # 162 times (4.86ms+2.97ms) by Class::MOP::Class::find_next_method_by_name at line 1064, avg 48µs/call # 48 times (1.38ms+826µs) by Class::MOP::Class::find_all_methods_by_name at line 1048, avg 46µs/call # 17 times (563µs+318µs) by Class::MOP::Class:::around at line 50 of Class/MOP/Class/Immutable/Trait.pm, avg 52µs/call # 8 times (247µs+148µs) by Class::MOP::Class::get_all_methods at line 1028, avg 49µs/call # 6 times (170µs+91µs) by Class::MOP::Class::find_attribute_by_name at line 814, avg 44µs/call
sub linearized_isa {
89879739.9ms159413.7ms return @{ mro::get_linear_isa( (shift)->name ) };
# spent 9.48ms making 797 calls to mro::get_linear_isa, avg 12µs/call # spent 4.24ms making 797 calls to Class::MOP::Package::name, avg 5µs/call
899}
900
901
# spent 22.2ms (4.64+17.6) within Class::MOP::Class::class_precedence_list which was called 51 times, avg 435µs/call: # 21 times (2.26ms+20.0ms) by Moose::Meta::Class::excludes_role at line 239 of Moose/Meta/Class.pm, avg 1.06ms/call # 18 times (1.31ms+-1.31ms) by Class::MOP::Class::class_precedence_list at line 927, avg 0s/call # 12 times (1.07ms+-1.07ms) by Class::MOP::Class:::around at line 43 of Class/MOP/Class/Immutable/Trait.pm, avg 0s/call
sub class_precedence_list {
9023045.50ms my $self = shift;
90351271µs my $name = $self->name;
# spent 271µs making 51 calls to Class::MOP::Package::name, avg 5µs/call
904
90551261µs unless (Class::MOP::IS_RUNNING_ON_5_10()) {
# spent 261µs making 51 calls to Class::MOP::__ANON__, avg 5µs/call
906 # NOTE:
907 # We need to check for circular inheritance here
908 # if we are are not on 5.10, cause 5.8 detects it
909 # late. This will do nothing if all is well, and
910 # blow up otherwise. Yes, it's an ugly hack, better
911 # suggestions are welcome.
912 # - SL
913 ($name || return)->isa('This is a test for circular inheritance')
914 }
915
916 # if our mro is c3, we can
917 # just grab the linear_isa
91851597µs if (mro::get_mro($name) eq 'c3') {
# spent 597µs making 51 calls to mro::get_mro, avg 12µs/call
919 return @{ mro::get_linear_isa($name) }
920 }
921 else {
922 # NOTE:
923 # we can't grab the linear_isa for dfs
924 # since it has all the duplicates
925 # already removed.
926 return (
927988.98ms $name,
# spent 12.5ms making 30 calls to Class::MOP::Class::Immutable::Class::MOP::Class::class_precedence_list, avg 418µs/call, recursion: max depth 3, sum of overlapping time 6.58ms # spent 2.06ms making 49 calls to Class::MOP::Class::initialize, avg 42µs/call # spent 952µs making 1 call to Class::MOP::Class::Immutable::Moose::Meta::Class::class_precedence_list # spent 6.34ms making 18 calls to Class::MOP::Class::class_precedence_list, avg 352µs/call, recursion: max depth 2, sum of overlapping time 6.34ms
928 map {
9295112.3ms Class::MOP::Class->initialize($_)->class_precedence_list()
# spent 8.85ms making 34 calls to Moose::Meta::Class::superclasses, avg 260µs/call # spent 2.30ms making 11 calls to Class::MOP::Class::Immutable::Class::MOP::Class::superclasses, avg 209µs/call # spent 752µs making 5 calls to Class::MOP::Class::superclasses, avg 150µs/call # spent 391µs making 1 call to Class::MOP::Class::Immutable::Moose::Meta::Class::superclasses
930 } $self->superclasses()
931 );
932 }
933}
934
935## Methods
936
937{
93814µs
# spent 147ms (9.47+138) within Class::MOP::Class::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Class.pm:967] which was called 77 times, avg 1.91ms/call: # 70 times (8.68ms+128ms) by Class::MOP::Class::add_around_method_modifier at line 993, avg 1.95ms/call # 5 times (611µs+8.66ms) by Class::MOP::Class::add_before_method_modifier at line 973, avg 1.85ms/call # 2 times (177µs+1.31ms) by Class::MOP::Class::add_after_method_modifier at line 983, avg 744µs/call
my $fetch_and_prepare_method = sub {
9396719.06ms my ($self, $method_name) = @_;
94077998µs my $wrapped_metaclass = $self->wrapped_method_metaclass;
# spent 998µs making 77 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 13µs/call
941 # fetch it locally
9427717.7ms my $method = $self->get_method($method_name);
# spent 17.7ms making 77 calls to Class::MOP::Mixin::HasMethods::get_method, avg 230µs/call
943 # if we dont have local ...
944 unless ($method) {
945 # try to find the next method
9466657.6ms $method = $self->find_next_method_by_name($method_name);
# spent 57.6ms making 66 calls to Class::MOP::Class::find_next_method_by_name, avg 873µs/call
947 # die if it does not exist
948 (defined $method)
949 || confess "The method '$method_name' was not found in the inheritance hierarchy for " . $self->name;
950 # and now make sure to wrap it
951 # even if it is already wrapped
952 # because we need a new sub ref
95313222.7ms $method = $wrapped_metaclass->wrap($method,
# spent 22.3ms making 66 calls to Class::MOP::Method::Wrapped::wrap, avg 338µs/call # spent 373µs making 66 calls to Class::MOP::Package::name, avg 6µs/call
954 package_name => $self->name,
955 name => $method_name,
956 );
957 }
958 else {
959 # now make sure we wrap it properly
960292.97ms $method = $wrapped_metaclass->wrap($method,
# spent 2.79ms making 9 calls to Class::MOP::Method::Wrapped::wrap, avg 310µs/call # spent 134µs making 11 calls to UNIVERSAL::isa, avg 12µs/call # spent 47µs making 9 calls to Class::MOP::Package::name, avg 5µs/call
961 package_name => $self->name,
962 name => $method_name,
963 ) unless $method->isa($wrapped_metaclass);
964 }
9657736.0ms $self->add_method($method_name => $method);
# spent 36.0ms making 77 calls to Class::MOP::Mixin::HasMethods::add_method, avg 467µs/call
966 return $method;
967114µs };
968
969
# spent 9.97ms (286µs+9.68) within Class::MOP::Class::add_before_method_modifier which was called 5 times, avg 1.99ms/call: # 4 times (233µs+8.45ms) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 221 of Moose/Meta/Role/Application/ToClass.pm, avg 2.17ms/call # once (54µs+1.23ms) by Moose::Util::add_method_modifier at line 244 of Moose/Util.pm
sub add_before_method_modifier {
97020329µs my ($self, $method_name, $method_modifier) = @_;
971 (defined $method_name && length $method_name)
972 || confess "You must pass in a method name";
97359.27ms my $method = $fetch_and_prepare_method->($self, $method_name);
# spent 9.27ms making 5 calls to Class::MOP::Class::__ANON__[Class/MOP/Class.pm:967], avg 1.85ms/call
97410413µs $method->add_before_modifier(
# spent 352µs making 5 calls to Class::MOP::Method::Wrapped::add_before_modifier, avg 70µs/call # spent 61µs making 5 calls to Sub::Name::subname, avg 12µs/call
975 subname(':before' => $method_modifier)
976 );
977 }
978
979
# spent 1.77ms (117µs+1.66) within Class::MOP::Class::add_after_method_modifier which was called 2 times, avg 887µs/call: # 2 times (117µs+1.66ms) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 221 of Moose/Meta/Role/Application/ToClass.pm, avg 887µs/call
sub add_after_method_modifier {
9808132µs my ($self, $method_name, $method_modifier) = @_;
981 (defined $method_name && length $method_name)
982 || confess "You must pass in a method name";
98321.49ms my $method = $fetch_and_prepare_method->($self, $method_name);
# spent 1.49ms making 2 calls to Class::MOP::Class::__ANON__[Class/MOP/Class.pm:967], avg 744µs/call
9844168µs $method->add_after_modifier(
# spent 143µs making 2 calls to Class::MOP::Method::Wrapped::add_after_modifier, avg 72µs/call # spent 24µs making 2 calls to Sub::Name::subname, avg 12µs/call
985 subname(':after' => $method_modifier)
986 );
987 }
988
989
# spent 151ms (3.77+147) within Class::MOP::Class::add_around_method_modifier which was called 70 times, avg 2.16ms/call: # 46 times (2.46ms+99.7ms) by Class::MOP::MiniTrait::apply at line 21 of Class/MOP/MiniTrait.pm, avg 2.22ms/call # 24 times (1.31ms+47.6ms) by Moose::Meta::Role::Application::ToClass::apply_method_modifiers at line 221 of Moose/Meta/Role/Application/ToClass.pm, avg 2.04ms/call
sub add_around_method_modifier {
9902804.47ms my ($self, $method_name, $method_modifier) = @_;
991 (defined $method_name && length $method_name)
992 || confess "You must pass in a method name";
99370137ms my $method = $fetch_and_prepare_method->($self, $method_name);
# spent 137ms making 70 calls to Class::MOP::Class::__ANON__[Class/MOP/Class.pm:967], avg 1.95ms/call
99414010.6ms $method->add_around_modifier(
# spent 9.64ms making 70 calls to Class::MOP::Method::Wrapped::add_around_modifier, avg 138µs/call # spent 927µs making 70 calls to Sub::Name::subname, avg 13µs/call
995 subname(':around' => $method_modifier)
996 );
997 }
998
999 # NOTE:
1000 # the methods above used to be named like this:
1001 # ${pkg}::${method}:(before|after|around)
1002 # but this proved problematic when using one modifier
1003 # to wrap multiple methods (something which is likely
1004 # to happen pretty regularly IMO). So instead of naming
1005 # it like this, I have chosen to just name them purely
1006 # with their modifier names, like so:
1007 # :(before|after|around)
1008 # The fact is that in a stack trace, it will be fairly
1009 # evident from the context what method they are attached
1010 # to, and so don't need the fully qualified name.
1011}
1012
1013
# spent 185ms (19.9+165) within Class::MOP::Class::find_method_by_name which was called 211 times, avg 877µs/call: # 57 times (3.93ms+20.9ms) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 25 of Class/MOP/Mixin/HasMethods.pm, avg 436µs/call # 56 times (8.34ms+81.1ms) by Class::MOP::MiniTrait::apply at line 21 of Class/MOP/MiniTrait.pm, avg 1.60ms/call # 43 times (2.50ms+26.0ms) by Moose::Meta::Role::Application::ToClass::check_required_methods at line 64 of Moose/Meta/Role/Application/ToClass.pm, avg 664µs/call # 24 times (2.34ms+17.5ms) by Moose::Meta::Method::Constructor::_generate_BUILDARGS at line 146 of Moose/Meta/Method/Constructor.pm, avg 825µs/call # 24 times (2.32ms+17.0ms) by Moose::Meta::Method::Destructor::is_needed at line 62 of Moose/Meta/Method/Destructor.pm, avg 804µs/call # 7 times (481µs+2.63ms) by Moose::BEGIN@38 at line 14 of Moose/Meta/Attribute/Native.pm, avg 444µs/call
sub find_method_by_name {
1014156918.2ms my ($self, $method_name) = @_;
1015 (defined $method_name && length $method_name)
1016 || confess "You must define a method name to find";
10172119.74ms foreach my $class ($self->linearized_isa) {
# spent 9.74ms making 211 calls to Class::MOP::Class::linearized_isa, avg 46µs/call
1018864155ms my $method = Class::MOP::Class->initialize($class)->get_method($method_name);
# spent 137ms making 432 calls to Class::MOP::Mixin::HasMethods::get_method, avg 317µs/call # spent 18.6ms making 432 calls to Class::MOP::Class::initialize, avg 43µs/call
1019 return $method if defined $method;
1020 }
1021 return;
1022}
1023
1024
# spent 27.5ms (1.54+25.9) within Class::MOP::Class::get_all_methods which was called 8 times, avg 3.43ms/call: # 8 times (1.54ms+25.9ms) by Class::MOP::MiniTrait::apply at line 18 of Class/MOP/MiniTrait.pm, avg 3.43ms/call
sub get_all_methods {
1025591.72ms my $self = shift;
1026
1027 my %methods;
10288395µs for my $class ( reverse $self->linearized_isa ) {
# spent 395µs making 8 calls to Class::MOP::Class::linearized_isa, avg 49µs/call
10299353µs my $meta = Class::MOP::Class->initialize($class);
# spent 353µs making 9 calls to Class::MOP::Class::initialize, avg 39µs/call
1030
10316525.2ms $methods{ $_->name } = $_ for $meta->_get_local_methods;
# spent 24.9ms making 9 calls to Class::MOP::Mixin::HasMethods::_get_local_methods, avg 2.77ms/call # spent 251µs making 56 calls to Class::MOP::Method::name, avg 4µs/call
1032 }
1033
1034 return values %methods;
1035}
1036
1037sub get_all_method_names {
1038 my $self = shift;
1039 my %uniq;
1040 return grep { !$uniq{$_}++ } map { Class::MOP::Class->initialize($_)->get_method_list } $self->linearized_isa;
1041}
1042
1043
# spent 38.3ms (5.14+33.1) within Class::MOP::Class::find_all_methods_by_name which was called 48 times, avg 797µs/call: # 24 times (2.62ms+17.1ms) by Moose::Meta::Method::Constructor::_generate_BUILDALL at line 184 of Moose/Meta/Method/Constructor.pm, avg 820µs/call # 24 times (2.52ms+16.1ms) by Moose::Meta::Method::Destructor::_initialize_body at line 81 of Moose/Meta/Method/Destructor.pm, avg 774µs/call
sub find_all_methods_by_name {
10444364.62ms my ($self, $method_name) = @_;
1045 (defined $method_name && length $method_name)
1046 || confess "You must define a method name to find";
1047 my @methods;
1048482.21ms foreach my $class ($self->linearized_isa) {
# spent 2.21ms making 48 calls to Class::MOP::Class::linearized_isa, avg 46µs/call
1049 # fetch the meta-class ...
1050984.31ms my $meta = Class::MOP::Class->initialize($class);
# spent 4.31ms making 98 calls to Class::MOP::Class::initialize, avg 44µs/call
105110226.6ms push @methods => {
# spent 24.4ms making 98 calls to Class::MOP::Mixin::HasMethods::has_method, avg 249µs/call # spent 2.20ms making 4 calls to Class::MOP::Mixin::HasMethods::get_method, avg 551µs/call
1052 name => $method_name,
1053 class => $class,
1054 code => $meta->get_method($method_name)
1055 } if $meta->has_method($method_name);
1056 }
1057 return @methods;
1058}
1059
1060
# spent 107ms (15.4+92.0) within Class::MOP::Class::find_next_method_by_name which was called 164 times, avg 655µs/call: # 79 times (6.02ms+32.9ms) by Class::MOP::Method::Inlined::can_be_inlined at line 40 of Class/MOP/Method/Inlined.pm, avg 493µs/call # 66 times (7.81ms+49.8ms) by Class::MOP::Class::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Class.pm:967] at line 946, avg 873µs/call # 17 times (1.44ms+8.49ms) by Moose::Meta::Method::Overridden::new at line 23 of Moose/Meta/Method/Overridden.pm, avg 584µs/call # 2 times (141µs+727µs) by Class::MOP::Method::Inlined::_uninlined_body at line 20 of Class/MOP/Method/Inlined.pm, avg 434µs/call
sub find_next_method_by_name {
1061133514.2ms my ($self, $method_name) = @_;
1062 (defined $method_name && length $method_name)
1063 || confess "You must define a method name to find";
10641648.00ms my @cpl = $self->linearized_isa;
# spent 7.83ms making 162 calls to Class::MOP::Class::linearized_isa, avg 48µs/call # spent 166µs making 2 calls to Class::MOP::Class::Immutable::Moose::Meta::Class::linearized_isa, avg 83µs/call
1065 shift @cpl; # discard ourselves
1066 foreach my $class (@cpl) {
106751284.0ms my $method = Class::MOP::Class->initialize($class)->get_method($method_name);
# spent 73.0ms making 256 calls to Class::MOP::Mixin::HasMethods::get_method, avg 285µs/call # spent 11.0ms making 256 calls to Class::MOP::Class::initialize, avg 43µs/call
1068 return $method if defined $method;
1069 }
1070 return;
1071}
1072
1073
# spent 419µs within Class::MOP::Class::update_meta_instance_dependencies which was called 36 times, avg 12µs/call: # 36 times (419µs+0s) by Class::MOP::Class::_superclasses_updated at line 866, avg 12µs/call
sub update_meta_instance_dependencies {
107472580µs my $self = shift;
1075
1076 if ( $self->{meta_instance_dependencies} ) {
1077 return $self->add_meta_instance_dependencies;
1078 }
1079}
1080
1081sub add_meta_instance_dependencies {
1082 my $self = shift;
1083
1084 $self->remove_meta_instance_dependencies;
1085
1086 my @attrs = $self->get_all_attributes();
1087
1088 my %seen;
1089 my @classes = grep { not $seen{ $_->name }++ }
1090 map { $_->associated_class } @attrs;
1091
1092 foreach my $class (@classes) {
1093 $class->add_dependent_meta_instance($self);
1094 }
1095
1096 $self->{meta_instance_dependencies} = \@classes;
1097}
1098
1099sub remove_meta_instance_dependencies {
1100 my $self = shift;
1101
1102 if ( my $classes = delete $self->{meta_instance_dependencies} ) {
1103 foreach my $class (@$classes) {
1104 $class->remove_dependent_meta_instance($self);
1105 }
1106
1107 return $classes;
1108 }
1109
1110 return;
1111
1112}
1113
1114sub add_dependent_meta_instance {
1115 my ( $self, $metaclass ) = @_;
1116 push @{ $self->{dependent_meta_instances} }, $metaclass;
1117}
1118
1119sub remove_dependent_meta_instance {
1120 my ( $self, $metaclass ) = @_;
1121 my $name = $metaclass->name;
1122 @$_ = grep { $_->name ne $name } @$_
1123 for $self->{dependent_meta_instances};
1124}
1125
1126
# spent 12.8ms (9.82+2.98) within Class::MOP::Class::invalidate_meta_instances which was called 238 times, avg 54µs/call: # 238 times (9.82ms+2.98ms) by Class::MOP::Class::_post_add_attribute at line 784, avg 54µs/call
sub invalidate_meta_instances {
11277149.64ms my $self = shift;
1128 $_->invalidate_meta_instance()
11292382.98ms for $self, @{ $self->{dependent_meta_instances} };
# spent 2.98ms making 238 calls to Class::MOP::Class::invalidate_meta_instance, avg 13µs/call
1130}
1131
1132
# spent 2.98ms within Class::MOP::Class::invalidate_meta_instance which was called 238 times, avg 13µs/call: # 238 times (2.98ms+0s) by Class::MOP::Class::invalidate_meta_instances at line 1129, avg 13µs/call
sub invalidate_meta_instance {
11334763.86ms my $self = shift;
1134 undef $self->{_meta_instance};
1135}
1136
1137# check if we can reinitialize
1138sub is_pristine {
1139 my $self = shift;
1140
1141 # if any local attr is defined
1142 return if $self->get_attribute_list;
1143
1144 # or any non-declared methods
1145 for my $method ( map { $self->get_method($_) } $self->get_method_list ) {
1146 return if $method->isa("Class::MOP::Method::Generated");
1147 # FIXME do we need to enforce this too? return unless $method->isa( $self->method_metaclass );
1148 }
1149
1150 return 1;
1151}
1152
1153## Class closing
1154
11551061.27ms
# spent 715µs within Class::MOP::Class::is_mutable which was called 106 times, avg 7µs/call: # 75 times (519µs+0s) by Class::MOP::Class::make_immutable at line 1179, avg 7µs/call # 22 times (139µs+0s) by KiokuDB::BEGIN@4 at line 231 of Moose.pm, avg 6µs/call # 9 times (57µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 688 of Moose/Util/TypeConstraints.pm, avg 6µs/call
sub is_mutable { 1 }
1156911.03ms
# spent 651µs within Class::MOP::Class::is_immutable which was called 91 times, avg 7µs/call: # 91 times (651µs+0s) by Class::MOP::Class::_real_ref_name at line 126, avg 7µs/call
sub is_immutable { 0 }
1157
1158sub immutable_options { %{ $_[0]{__immutable}{options} || {} } }
1159
1160
# spent 9.03ms (5.86+3.17) within Class::MOP::Class::_immutable_options which was called 75 times, avg 120µs/call: # 51 times (3.81ms+1.91ms) by Class::MOP::Class::make_immutable at line 1180, avg 112µs/call # 24 times (2.05ms+1.27ms) by Moose::Meta::Class::_immutable_options at line 461 of Moose/Meta/Class.pm, avg 138µs/call
sub _immutable_options {
11611504.92ms my ( $self, @args ) = @_;
1162
1163 return (
11643003.17ms inline_accessors => 1,
# spent 758µs making 75 calls to Class::MOP::Class::constructor_name, avg 10µs/call # spent 493µs making 51 calls to Class::MOP::Class::immutable_trait, avg 10µs/call # spent 481µs making 51 calls to Class::MOP::Class::constructor_class, avg 9µs/call # spent 440µs making 51 calls to Class::MOP::Class::destructor_class, avg 9µs/call # spent 353µs making 24 calls to Moose::Meta::Class::immutable_trait, avg 15µs/call # spent 335µs making 24 calls to Moose::Meta::Class::destructor_class, avg 14µs/call # spent 312µs making 24 calls to Moose::Meta::Class::constructor_class, avg 13µs/call
1165 inline_constructor => 1,
1166 inline_destructor => 0,
1167 debug => 0,
1168 immutable_trait => $self->immutable_trait,
1169 constructor_name => $self->constructor_name,
1170 constructor_class => $self->constructor_class,
1171 destructor_class => $self->destructor_class,
1172 @args,
1173 );
1174}
1175
1176
# spent 1.10s (6.33ms+1.10) within Class::MOP::Class::make_immutable which was called 75 times, avg 14.7ms/call: # 22 times (1.99ms+307ms) by KiokuDB::BEGIN@4 at line 236 of Moose.pm, avg 14.0ms/call # 13 times (931µs+110ms) by Moose::Exporter::BEGIN@11 at line 699 of Class/MOP.pm, avg 8.50ms/call # 9 times (760µs+126ms) by Moose::Meta::Attribute::BEGIN@20 at line 693 of Moose/Util/TypeConstraints.pm, avg 14.1ms/call # 4 times (324µs+2.50ms) by Moose::Exporter::BEGIN@11 at line 724 of Class/MOP.pm, avg 705µs/call # 2 times (176µs+-176µs) by Class::MOP::Class::_immutable_metaclass at line 1253, avg 0s/call # once (129µs+132ms) by KiokuDB::Collapser::BEGIN@12 at line 304 of KiokuDB/Entry.pm # once (81µs+36.1ms) by KiokuDB::BEGIN@4 at line 268 of Moose.pm # once (85µs+26.4ms) by KiokuDB::Collapser::BEGIN@15 at line 231 of KiokuDB/Collapser/Buffer.pm # once (83µs+25.9ms) by main::BEGIN@0 at line 655 of KiokuDB.pm # once (98µs+24.7ms) by KiokuDB::BEGIN@13 at line 531 of KiokuDB/LiveObjects.pm # once (83µs+22.6ms) by KiokuDB::BEGIN@11 at line 396 of KiokuDB/Collapser.pm # once (96µs+18.9ms) by KiokuDB::TypeMap::Resolver::BEGIN@9 at line 484 of KiokuDB/TypeMap/Entry/MOP.pm # once (81µs+18.8ms) by KiokuDB::BEGIN@12 at line 381 of KiokuDB/Linker.pm # once (81µs+17.9ms) by KiokuDB::TypeMap::Entry::Std::BEGIN@6 at line 26 of KiokuDB/TypeMap/Entry/Compiled.pm # once (95µs+17.6ms) by KiokuDB::LiveObjects::BEGIN@14 at line 55 of KiokuDB/LiveObjects/TXNScope.pm # once (83µs+16.8ms) by KiokuDB::BEGIN@14 at line 171 of KiokuDB/TypeMap.pm # once (82µs+16.7ms) by KiokuDB::BEGIN@17 at line 79 of KiokuDB/Stream/Objects.pm # once (93µs+15.9ms) by KiokuDB::Collapser::BEGIN@14 at line 39 of KiokuDB/Reference.pm # once (82µs+15.8ms) by KiokuDB::LiveObjects::BEGIN@13 at line 60 of KiokuDB/LiveObjects/Scope.pm # once (83µs+15.3ms) by KiokuDB::Collapser::BEGIN@13 at line 27 of KiokuDB/Entry/Skip.pm # once (82µs+14.8ms) by KiokuDB::BEGIN@16 at line 117 of KiokuDB/TypeMap/Resolver.pm # once (82µs+14.6ms) by KiokuDB::TypeMap::Entry::MOP::BEGIN@9 at line 51 of KiokuDB/Thunk.pm # once (87µs+14.0ms) by KiokuDB::Linker::BEGIN@18 at line 37 of KiokuDB/Error/MissingObjects.pm # once (84µs+13.9ms) by KiokuDB::Collapser::BEGIN@16 at line 25 of KiokuDB/Error/UnknownObjects.pm # once (82µs+13.1ms) by KiokuDB::Collapser::BEGIN@18 at line 443 of Data/Visitor.pm # once (80µs+13.1ms) by Class::MOP::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP.pm:118] at line 38 of Data/Stream/Bulk/Filter.pm # once (81µs+11.8ms) by KiokuDB::BEGIN@15 at line 28 of KiokuDB/TypeMap/Shadow.pm # once (81µs+11.7ms) by KiokuDB::TypeMap::BEGIN@10 at line 14 of KiokuDB/TypeMap/Entry/Alias.pm # once (84µs+11.7ms) by Class::MOP::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP.pm:118] at line 51 of Data/Stream/Bulk/Cat.pm # once (79µs+11.3ms) by Class::MOP::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP.pm:118] at line 35 of Data/Stream/Bulk/Nil.pm
sub make_immutable {
11773755.75ms my ( $self, @args ) = @_;
1178
117975519µs if ( $self->is_mutable ) {
# spent 519µs making 75 calls to Class::MOP::Class::is_mutable, avg 7µs/call
1180150852ms $self->_initialize_immutable( $self->_immutable_options(@args) );
# spent 842ms making 75 calls to Class::MOP::Class::_initialize_immutable, avg 11.2ms/call # spent 5.71ms making 51 calls to Class::MOP::Class::_immutable_options, avg 112µs/call # spent 4.34ms making 24 calls to Moose::Meta::Class::_immutable_options, avg 181µs/call
118175245ms $self->_rebless_as_immutable(@args);
# spent 246ms making 75 calls to Class::MOP::Class::_rebless_as_immutable, avg 3.28ms/call, recursion: max depth 1, sum of overlapping time 1.17ms
1182 return $self;
1183 }
1184 else {
1185 return;
1186 }
1187}
1188
1189sub make_mutable {
1190 my $self = shift;
1191
1192 if ( $self->is_immutable ) {
1193 my @args = $self->immutable_options;
1194 $self->_rebless_as_mutable();
1195 $self->_remove_inlined_code(@args);
1196 delete $self->{__immutable};
1197 return $self;
1198 }
1199 else {
1200 return;
1201 }
1202}
1203
1204
# spent 245ms (3.32+241) within Class::MOP::Class::_rebless_as_immutable which was called 75 times, avg 3.26ms/call: # 75 times (3.32ms+241ms) by Class::MOP::Class::make_immutable at line 1181, avg 3.26ms/call
sub _rebless_as_immutable {
12052253.22ms my ( $self, @args ) = @_;
1206
1207 $self->{__immutable}{original_class} = ref $self;
1208
120975242ms bless $self => $self->_immutable_metaclass(@args);
# spent 243ms making 75 calls to Class::MOP::Class::_immutable_metaclass, avg 3.23ms/call, recursion: max depth 1, sum of overlapping time 1.05ms
1210}
1211
1212
# spent 242ms (7.88+234) within Class::MOP::Class::_immutable_metaclass which was called 75 times, avg 3.22ms/call: # 75 times (7.88ms+234ms) by Class::MOP::Class::_rebless_as_immutable at line 1209, avg 3.22ms/call
sub _immutable_metaclass {
12136108.67ms my ( $self, %args ) = @_;
1214
1215 if ( my $class = $args{immutable_metaclass} ) {
1216 return $class;
1217 }
1218
121975829µs my $trait = $args{immutable_trait} = $self->immutable_trait
# spent 497µs making 51 calls to Class::MOP::Class::immutable_trait, avg 10µs/call # spent 332µs making 24 calls to Moose::Meta::Class::immutable_trait, avg 14µs/call
1220 || confess "no immutable trait specified for $self";
1221
1222756.31ms my $meta = $self->meta;
# spent 6.31ms making 75 calls to Class::MOP::Object::meta, avg 84µs/call
12237518.0ms my $meta_attr = $meta->find_attribute_by_name("immutable_trait");
# spent 18.0ms making 75 calls to Class::MOP::Class::find_attribute_by_name, avg 240µs/call
1224
1225 my $class_name;
1226
1227751.28ms if ( $meta_attr and $trait eq $meta_attr->default ) {
# spent 1.28ms making 75 calls to Class::MOP::Mixin::AttributeCore::default, avg 17µs/call
1228 # if the trait is the same as the default we try and pick a
1229 # predictable name for the immutable metaclass
1230 $class_name = 'Class::MOP::Class::Immutable::' . ref($self);
1231 }
1232 else {
1233 $class_name = join '::', 'Class::MOP::Class::Immutable::CustomTrait',
1234 $trait, 'ForMetaClass', ref($self);
1235 }
1236
1237751.39ms return $class_name
# spent 1.39ms making 75 calls to Class::MOP::is_class_loaded, avg 18µs/call
1238 if Class::MOP::is_class_loaded($class_name);
1239
1240 # If the metaclass is a subclass of CMOP::Class which has had
1241 # metaclass roles applied (via Moose), then we want to make sure
1242 # that we preserve that anonymous class (see Fey::ORM for an
1243 # example of where this matters).
12442125µs my $meta_name = $meta->_real_ref_name;
# spent 125µs making 2 calls to Class::MOP::Class::_real_ref_name, avg 62µs/call
1245
1246212.0ms my $immutable_meta = $meta_name->create(
# spent 12.0ms making 2 calls to Class::MOP::Class::create, avg 5.99ms/call
1247 $class_name,
1248 superclasses => [ ref $self ],
1249 );
1250
12512193ms Class::MOP::MiniTrait::apply( $immutable_meta, $trait );
# spent 193ms making 2 calls to Class::MOP::MiniTrait::apply, avg 96.5ms/call
1252
125320s $immutable_meta->make_immutable(
# spent 1.75ms making 2 calls to Class::MOP::Class::make_immutable, avg 877µs/call, recursion: max depth 1, sum of overlapping time 1.75ms
1254 inline_constructor => 0,
1255 inline_accessors => 0,
1256 );
1257
1258 return $class_name;
1259}
1260
1261sub _remove_inlined_code {
1262 my $self = shift;
1263
1264 $self->remove_method( $_->name ) for $self->_inlined_methods;
1265
1266 delete $self->{__immutable}{inlined_methods};
1267}
1268
1269sub _inlined_methods { @{ $_[0]{__immutable}{inlined_methods} || [] } }
1270
1271
# spent 1.86ms within Class::MOP::Class::_add_inlined_method which was called 79 times, avg 24µs/call: # 55 times (1.41ms+0s) by Class::MOP::Class::_inline_constructor at line 1340, avg 26µs/call # 24 times (444µs+0s) by Class::MOP::Class::_inline_destructor at line 1373, avg 18µs/call
sub _add_inlined_method {
12721581.98ms my ( $self, $method ) = @_;
1273
1274 push @{ $self->{__immutable}{inlined_methods} ||= [] }, $method;
1275}
1276
1277
# spent 842ms (4.12+838) within Class::MOP::Class::_initialize_immutable which was called 75 times, avg 11.2ms/call: # 75 times (4.12ms+838ms) by Class::MOP::Class::make_immutable at line 1180, avg 11.2ms/call
sub _initialize_immutable {
12782254.04ms my ( $self, %args ) = @_;
1279
1280 $self->{__immutable}{options} = \%args;
128175838ms $self->_install_inlined_code(%args);
# spent 838ms making 75 calls to Class::MOP::Class::_install_inlined_code, avg 11.2ms/call
1282}
1283
1284
# spent 838ms (4.50+833) within Class::MOP::Class::_install_inlined_code which was called 75 times, avg 11.2ms/call: # 75 times (4.50ms+833ms) by Class::MOP::Class::_initialize_immutable at line 1281, avg 11.2ms/call
sub _install_inlined_code {
12853004.54ms my ( $self, %args ) = @_;
1286
1287 # FIXME
128832191ms $self->_inline_accessors(%args) if $args{inline_accessors};
# spent 191ms making 32 calls to Class::MOP::Class::_inline_accessors, avg 5.97ms/call
128955535ms $self->_inline_constructor(%args) if $args{inline_constructor};
# spent 535ms making 55 calls to Class::MOP::Class::_inline_constructor, avg 9.72ms/call
129024108ms $self->_inline_destructor(%args) if $args{inline_destructor};
# spent 108ms making 24 calls to Class::MOP::Class::_inline_destructor, avg 4.49ms/call
1291}
1292
1293sub _rebless_as_mutable {
1294 my $self = shift;
1295
1296 bless $self, $self->_get_mutable_metaclass_name;
1297
1298 return $self;
1299}
1300
1301
# spent 191ms (3.07+188) within Class::MOP::Class::_inline_accessors which was called 32 times, avg 5.97ms/call: # 32 times (3.07ms+188ms) by Class::MOP::Class::_install_inlined_code at line 1288, avg 5.97ms/call
sub _inline_accessors {
13021322.74ms my $self = shift;
1303
1304321.16ms foreach my $attr_name ( $self->get_attribute_list ) {
# spent 1.16ms making 32 calls to Class::MOP::Mixin::HasAttributes::get_attribute_list, avg 36µs/call
1305136187ms $self->get_attribute($attr_name)->install_accessors(1);
# spent 178ms making 67 calls to Class::MOP::Attribute::install_accessors, avg 2.65ms/call # spent 6.65ms making 1 call to Moose::Meta::Attribute::install_accessors # spent 2.77ms making 68 calls to Class::MOP::Mixin::HasAttributes::get_attribute, avg 41µs/call
1306 }
1307}
1308
1309
# spent 535ms (8.18+526) within Class::MOP::Class::_inline_constructor which was called 55 times, avg 9.72ms/call: # 55 times (8.18ms+526ms) by Class::MOP::Class::_install_inlined_code at line 1289, avg 9.72ms/call
sub _inline_constructor {
13105508.05ms my ( $self, %args ) = @_;
1311
1312 my $name = $args{constructor_name};
1313 # A class may not even have a constructor, and that's okay.
1314 return unless defined $name;
1315
13165517.1ms if ( $self->has_method($name) && !$args{replace_constructor} ) {
# spent 17.1ms making 55 calls to Class::MOP::Mixin::HasMethods::has_method, avg 311µs/call
1317 my $class = $self->name;
1318 warn "Not inlining a constructor for $class since it defines"
1319 . " its own constructor.\n"
1320 . "If you are certain you don't need to inline your"
1321 . " constructor, specify inline_constructor => 0 in your"
1322 . " call to $class->meta->make_immutable\n";
1323 return;
1324 }
1325
1326 my $constructor_class = $args{constructor_class};
1327
13285512.2ms Class::MOP::load_class($constructor_class);
# spent 13.2ms making 55 calls to Class::MOP::load_class, avg 241µs/call, recursion: max depth 1, sum of overlapping time 1.01ms
1329
1330110427ms my $constructor = $constructor_class->new(
# spent 232ms making 24 calls to Moose::Meta::Method::Constructor::new, avg 9.67ms/call # spent 195ms making 31 calls to Class::MOP::Method::Constructor::new, avg 6.29ms/call # spent 368µs making 55 calls to Class::MOP::Package::name, avg 7µs/call
1331 options => \%args,
1332 metaclass => $self,
1333 is_inline => 1,
1334 package_name => $self->name,
1335 name => $name,
1336 );
1337
13385541.0ms if ( $args{replace_constructor} or $constructor->can_be_inlined ) {
# spent 41.0ms making 55 calls to Class::MOP::Method::Inlined::can_be_inlined, avg 746µs/call
13395526.1ms $self->add_method( $name => $constructor );
# spent 26.1ms making 55 calls to Class::MOP::Mixin::HasMethods::add_method, avg 475µs/call
1340551.41ms $self->_add_inlined_method($constructor);
# spent 1.41ms making 55 calls to Class::MOP::Class::_add_inlined_method, avg 26µs/call
1341 }
1342}
1343
1344
# spent 108ms (4.17+104) within Class::MOP::Class::_inline_destructor which was called 24 times, avg 4.49ms/call: # 24 times (4.17ms+104ms) by Class::MOP::Class::_install_inlined_code at line 1290, avg 4.49ms/call
sub _inline_destructor {
13452403.94ms my ( $self, %args ) = @_;
1346
1347 ( exists $args{destructor_class} && defined $args{destructor_class} )
1348 || confess "The 'inline_destructor' option is present, but "
1349 . "no destructor class was specified";
1350
1351247.50ms if ( $self->has_method('DESTROY') && ! $args{replace_destructor} ) {
# spent 7.50ms making 24 calls to Class::MOP::Mixin::HasMethods::has_method, avg 312µs/call
1352 my $class = $self->name;
1353 warn "Not inlining a destructor for $class since it defines"
1354 . " its own destructor.\n";
1355 return;
1356 }
1357
1358 my $destructor_class = $args{destructor_class};
1359
1360245.04ms Class::MOP::load_class($destructor_class);
# spent 6.03ms making 24 calls to Class::MOP::load_class, avg 251µs/call, recursion: max depth 1, sum of overlapping time 986µs
1361
13622420.9ms return unless $destructor_class->is_needed($self);
# spent 20.9ms making 24 calls to Moose::Meta::Method::Destructor::is_needed, avg 872µs/call
1363
13644841.2ms my $destructor = $destructor_class->new(
# spent 41.1ms making 24 calls to Moose::Meta::Method::Destructor::new, avg 1.71ms/call # spent 142µs making 24 calls to Class::MOP::Package::name, avg 6µs/call
1365 options => \%args,
1366 metaclass => $self,
1367 package_name => $self->name,
1368 name => 'DESTROY'
1369 );
1370
13712414.4ms if ( $args{replace_destructor} or $destructor->can_be_inlined ) {
# spent 14.4ms making 24 calls to Class::MOP::Method::Inlined::can_be_inlined, avg 600µs/call
13722413.1ms $self->add_method( 'DESTROY' => $destructor );
# spent 13.1ms making 24 calls to Class::MOP::Mixin::HasMethods::add_method, avg 545µs/call
137324444µs $self->_add_inlined_method($destructor);
# spent 444µs making 24 calls to Class::MOP::Class::_add_inlined_method, avg 18µs/call
1374 }
1375}
1376
1377123µs1;
1378
1379__END__