← Index
NYTProf Performance Profile   « line view »
For /home/ss5/perl5/perlbrew/perls/perl-5.22.0/bin/benchmarkanything-storage
  Run on Mon Jan 29 16:55:34 2018
Reported on Mon Jan 29 16:57:06 2018

Filename/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Class/MOP/Class.pm
StatementsExecuted 31569 statements in 44.7ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
152920125.78ms24.5msClass::MOP::Class::::initializeClass::MOP::Class::initialize (recurses: max depth 2, inclusive time 418µs)
1115.26ms6.59msClass::MOP::Class::::BEGIN@9Class::MOP::Class::BEGIN@9
62215.24ms5.59msClass::MOP::Class::::CORE:sortClass::MOP::Class::CORE:sort (opcode)
49114.94ms13.2msClass::MOP::Class::::_can_fix_metaclass_incompatibilityClass::MOP::Class::_can_fix_metaclass_incompatibility
282214.71ms14.0msClass::MOP::Class::::_inline_init_attr_from_defaultClass::MOP::Class::_inline_init_attr_from_default
131842.21ms4.18msClass::MOP::Class::::get_all_attributesClass::MOP::Class::get_all_attributes
294111.69ms7.47msClass::MOP::Class::::_single_metaclass_can_be_made_compatibleClass::MOP::Class::_single_metaclass_can_be_made_compatible
286221.46ms29.5msClass::MOP::Class::::_inline_slot_initializerClass::MOP::Class::_inline_slot_initializer
271111.16ms13.4msClass::MOP::Class::::_inline_init_attr_from_constructorClass::MOP::Class::_inline_init_attr_from_constructor
90551.12ms8.20msClass::MOP::Class::::find_method_by_nameClass::MOP::Class::find_method_by_name
30942878µs1.19msClass::MOP::Class::::linearized_isaClass::MOP::Class::linearized_isa
3521812µs4.97msClass::MOP::Class::::_construct_instanceClass::MOP::Class::_construct_instance
6911775µs18.1msClass::MOP::Class::::_construct_class_instanceClass::MOP::Class::_construct_class_instance (recurses: max depth 1, inclusive time 230µs)
111765µs834µsClass::MOP::Class::::BEGIN@7Class::MOP::Class::BEGIN@7
13511758µs40.5msClass::MOP::Class::::_post_add_attributeClass::MOP::Class::_post_add_attribute
28522752µs1.04msClass::MOP::Class::::_inline_default_valueClass::MOP::Class::_inline_default_value
7522686µs6.51msClass::MOP::Class::::find_next_method_by_nameClass::MOP::Class::find_next_method_by_name
111632µs708µsClass::MOP::Class::::BEGIN@8Class::MOP::Class::BEGIN@8
3111578µs58.3msClass::MOP::Class::::_inline_constructorClass::MOP::Class::_inline_constructor
5511568µs30.2msClass::MOP::Class::::_immutable_metaclassClass::MOP::Class::_immutable_metaclass (recurses: max depth 1, inclusive time 111µs)
7221565µs16.5msClass::MOP::Class::::_check_metaclass_compatibilityClass::MOP::Class::_check_metaclass_compatibility (recurses: max depth 1, inclusive time 182µs)
6711537µs537µsClass::MOP::Class::::_newClass::MOP::Class::_new
3111513µs35.2msClass::MOP::Class::::_inline_slot_initializersClass::MOP::Class::_inline_slot_initializers
5575513µs125msClass::MOP::Class::::make_immutableClass::MOP::Class::make_immutable (recurses: max depth 1, inclusive time 214µs)
4311483µs8.76msClass::MOP::Class::::__ANON__[:1082]Class::MOP::Class::__ANON__[:1082]
3122462µs2.97msClass::MOP::Class::::_eval_environmentClass::MOP::Class::_eval_environment
13511458µs37.0msClass::MOP::Class::::try {...} Class::MOP::Class::try {...}
13511425µs532µsClass::MOP::Class::::invalidate_meta_instancesClass::MOP::Class::invalidate_meta_instances
5211367µs4.20msClass::MOP::Class::::_create_meta_instanceClass::MOP::Class::_create_meta_instance
111365µs870µsClass::MOP::Class::::BEGIN@10Class::MOP::Class::BEGIN@10
5522356µs438µsClass::MOP::Class::::_immutable_optionsClass::MOP::Class::_immutable_options
5511345µs1.18msClass::MOP::Class::::find_attribute_by_nameClass::MOP::Class::find_attribute_by_name
5511331µs94.2msClass::MOP::Class::::_initialize_immutableClass::MOP::Class::_initialize_immutable
5511303µs93.9msClass::MOP::Class::::_install_inlined_codeClass::MOP::Class::_install_inlined_code
3111302µs37.1msClass::MOP::Class::::_inline_new_objectClass::MOP::Class::_inline_new_object
3311301µs34.8msClass::MOP::Class::::_inline_accessorsClass::MOP::Class::_inline_accessors
17441286µs955µsClass::MOP::Class::::_method_lookup_orderClass::MOP::Class::_method_lookup_order
324105276µs4.47msClass::MOP::Class::::get_meta_instanceClass::MOP::Class::get_meta_instance
3811274µs13.8msClass::MOP::Class::::_fix_metaclass_incompatibilityClass::MOP::Class::_fix_metaclass_incompatibility (recurses: max depth 1, inclusive time 104µs)
13511249µs928µsClass::MOP::Class::::_attach_attributeClass::MOP::Class::_attach_attribute
711232µs5.14msClass::MOP::Class::::get_all_methodsClass::MOP::Class::get_all_methods
3355211µs4.49msClass::MOP::Class::::new_objectClass::MOP::Class::new_object
4311210µs16.5msClass::MOP::Class::::add_around_method_modifierClass::MOP::Class::add_around_method_modifier
4911174µs736µsClass::MOP::Class::::_class_metaclass_can_be_made_compatibleClass::MOP::Class::_class_metaclass_can_be_made_compatible
5511171µs30.3msClass::MOP::Class::::_rebless_as_immutableClass::MOP::Class::_rebless_as_immutable (recurses: max depth 1, inclusive time 122µs)
111162µs198µsClass::MOP::Class::::BEGIN@11Class::MOP::Class::BEGIN@11
6141156µs473µsClass::MOP::Class::::_real_ref_nameClass::MOP::Class::_real_ref_name
3111136µs181µsClass::MOP::Class::::_inline_fallback_constructorClass::MOP::Class::_inline_fallback_constructor
8732120µs120µsClass::MOP::Class::::_base_metaclassesClass::MOP::Class::_base_metaclasses
13511107µs107µsClass::MOP::Class::::invalidate_meta_instanceClass::MOP::Class::invalidate_meta_instance
311198µs183µsClass::MOP::Class::::_inline_preserve_weak_metaclassesClass::MOP::Class::_inline_preserve_weak_metaclasses
311196µs775µsClass::MOP::Class::::_inline_create_instanceClass::MOP::Class::_inline_create_instance
311177µs853µsClass::MOP::Class::::_inline_generate_instanceClass::MOP::Class::_inline_generate_instance
322159µs59µsClass::MOP::Class::::_add_inlined_methodClass::MOP::Class::_add_inlined_method
61158µs77µsClass::MOP::Class::::_single_metaclass_is_compatibleClass::MOP::Class::_single_metaclass_is_compatible
21138µs1.23msClass::MOP::Class::::createClass::MOP::Class::create
301136µs36µsClass::MOP::Class::::_inline_paramsClass::MOP::Class::_inline_params
884336µs36µsClass::MOP::Class::::is_mutableClass::MOP::Class::is_mutable
301136µs36µsClass::MOP::Class::::_generate_fallback_constructorClass::MOP::Class::_generate_fallback_constructor
31134µs85µsClass::MOP::Class::::_superclasses_updatedClass::MOP::Class::_superclasses_updated
11134µs524µsClass::MOP::Class::::_inline_destructorClass::MOP::Class::_inline_destructor
22225µs104µsClass::MOP::Class::::find_all_methods_by_nameClass::MOP::Class::find_all_methods_by_name
381118µs18µsClass::MOP::Class::::is_immutableClass::MOP::Class::is_immutable
301113µs13µsClass::MOP::Class::::_inline_extra_initClass::MOP::Class::_inline_extra_init
61112µs89µsClass::MOP::Class::::_check_single_metaclass_compatibilityClass::MOP::Class::_check_single_metaclass_compatibility
1119µs10µsClass::MOP::Class::::BEGIN@4Class::MOP::Class::BEGIN@4
1119µs39µsClass::MOP::Class::::BEGIN@18Class::MOP::Class::BEGIN@18
1117µs12µsClass::MOP::Class::::_class_metaclass_is_compatibleClass::MOP::Class::_class_metaclass_is_compatible
3117µs7µsClass::MOP::Class::::_superclass_metasClass::MOP::Class::_superclass_metas
1116µs9µsClass::MOP::Class::::BEGIN@5Class::MOP::Class::BEGIN@5
1115µs17µsClass::MOP::Class::::_check_class_metaclass_compatibilityClass::MOP::Class::_check_class_metaclass_compatibility
1115µs23µsClass::MOP::Class::::BEGIN@13Class::MOP::Class::BEGIN@13
1115µs2.11msClass::MOP::Class::::BEGIN@20Class::MOP::Class::BEGIN@20
3114µs4µsClass::MOP::Class::::update_meta_instance_dependenciesClass::MOP::Class::update_meta_instance_dependencies
1114µs10µsClass::MOP::Class::::BEGIN@14Class::MOP::Class::BEGIN@14
1114µs16µsClass::MOP::Class::::BEGIN@15Class::MOP::Class::BEGIN@15
1114µs14µsClass::MOP::Class::::BEGIN@16Class::MOP::Class::BEGIN@16
1114µs19µsClass::MOP::Class::::BEGIN@17Class::MOP::Class::BEGIN@17
0000s0sClass::MOP::Class::::__ANON__[:210]Class::MOP::Class::__ANON__[:210]
0000s0sClass::MOP::Class::::__ANON__[:900]Class::MOP::Class::__ANON__[:900]
0000s0sClass::MOP::Class::::__ANON__[:904]Class::MOP::Class::__ANON__[:904]
0000s0sClass::MOP::Class::::_anon_cache_keyClass::MOP::Class::_anon_cache_key
0000s0sClass::MOP::Class::::_anon_package_prefixClass::MOP::Class::_anon_package_prefix
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_rebless_instanceClass::MOP::Class::_inline_rebless_instance
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_after_method_modifierClass::MOP::Class::add_after_method_modifier
0000s0sClass::MOP::Class::::add_before_method_modifierClass::MOP::Class::add_before_method_modifier
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::::catch {...} Class::MOP::Class::catch {...}
0000s0sClass::MOP::Class::::class_precedence_listClass::MOP::Class::class_precedence_list
0000s0sClass::MOP::Class::::clone_objectClass::MOP::Class::clone_object
0000s0sClass::MOP::Class::::create_anon_classClass::MOP::Class::create_anon_class
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::::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
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Class::MOP::Class;
21800nsour $VERSION = '2.1605';
3
4214µs212µs
# spent 10µs (9+2) within Class::MOP::Class::BEGIN@4 which was called: # once (9µs+2µs) by Class::MOP::BEGIN@18 at line 4
use strict;
# spent 10µs making 1 call to Class::MOP::Class::BEGIN@4 # spent 2µs making 1 call to strict::import
5214µs212µs
# spent 9µs (6+3) within Class::MOP::Class::BEGIN@5 which was called: # once (6µs+3µs) by Class::MOP::BEGIN@18 at line 5
use warnings;
# spent 9µs making 1 call to Class::MOP::Class::BEGIN@5 # spent 3µs making 1 call to warnings::import
6
7263µs1834µs
# spent 834µs (765+69) within Class::MOP::Class::BEGIN@7 which was called: # once (765µs+69µs) by Class::MOP::BEGIN@18 at line 7
use Class::MOP::Instance;
# spent 834µs making 1 call to Class::MOP::Class::BEGIN@7
8270µs1708µs
# spent 708µs (632+76) within Class::MOP::Class::BEGIN@8 which was called: # once (632µs+76µs) by Class::MOP::BEGIN@18 at line 8
use Class::MOP::Method::Wrapped;
# spent 708µs making 1 call to Class::MOP::Class::BEGIN@8
9288µs16.59ms
# spent 6.59ms (5.26+1.33) within Class::MOP::Class::BEGIN@9 which was called: # once (5.26ms+1.33ms) by Class::MOP::BEGIN@18 at line 9
use Class::MOP::Method::Accessor;
# spent 6.59ms making 1 call to Class::MOP::Class::BEGIN@9
10270µs1870µs
# spent 870µs (365+505) within Class::MOP::Class::BEGIN@10 which was called: # once (365µs+505µs) by Class::MOP::BEGIN@18 at line 10
use Class::MOP::Method::Constructor;
# spent 870µs making 1 call to Class::MOP::Class::BEGIN@10
11265µs1198µs
# spent 198µs (162+36) within Class::MOP::Class::BEGIN@11 which was called: # once (162µs+36µs) by Class::MOP::BEGIN@18 at line 11
use Class::MOP::MiniTrait;
# spent 198µs making 1 call to Class::MOP::Class::BEGIN@11
12
13215µs242µs
# spent 23µs (5+18) within Class::MOP::Class::BEGIN@13 which was called: # once (5µs+18µs) by Class::MOP::BEGIN@18 at line 13
use Carp 'confess';
# spent 23µs making 1 call to Class::MOP::Class::BEGIN@13 # spent 18µs making 1 call to Exporter::import
14212µs216µs
# spent 10µs (4+6) within Class::MOP::Class::BEGIN@14 which was called: # once (4µs+6µs) by Class::MOP::BEGIN@18 at line 14
use Module::Runtime 'use_package_optimistically';
# spent 10µs making 1 call to Class::MOP::Class::BEGIN@14 # spent 6µs making 1 call to Module::Runtime::import
15212µs228µs
# spent 16µs (4+12) within Class::MOP::Class::BEGIN@15 which was called: # once (4µs+12µs) by Class::MOP::BEGIN@18 at line 15
use Scalar::Util 'blessed';
# spent 16µs making 1 call to Class::MOP::Class::BEGIN@15 # spent 12µs making 1 call to Exporter::import
16212µs225µs
# spent 14µs (4+11) within Class::MOP::Class::BEGIN@16 which was called: # once (4µs+11µs) by Class::MOP::BEGIN@18 at line 16
use Sub::Name 'subname';
# spent 14µs making 1 call to Class::MOP::Class::BEGIN@16 # spent 11µs making 1 call to Exporter::import
17215µs234µs
# spent 19µs (4+15) within Class::MOP::Class::BEGIN@17 which was called: # once (4µs+15µs) by Class::MOP::BEGIN@18 at line 17
use Try::Tiny;
# spent 19µs making 1 call to Class::MOP::Class::BEGIN@17 # spent 15µs making 1 call to Exporter::import
18333µs358µs
# spent 39µs (9+30) within Class::MOP::Class::BEGIN@18 which was called: # once (9µs+30µs) by Class::MOP::BEGIN@18 at line 18
use List::Util 1.33 'all';
# spent 39µs making 1 call to Class::MOP::Class::BEGIN@18 # spent 11µs making 1 call to UNIVERSAL::VERSION # spent 8µs making 1 call to List::Util::import
19
2013µs12.10ms
# spent 2.11ms (5µs+2.10) within Class::MOP::Class::BEGIN@20 which was called: # once (5µs+2.10ms) by Class::MOP::BEGIN@18 at line 23
use parent 'Class::MOP::Module',
# spent 2.10ms making 1 call to parent::import
21 'Class::MOP::Mixin::HasAttributes',
22 'Class::MOP::Mixin::HasMethods',
2313.44ms12.11ms 'Class::MOP::Mixin::HasOverloads';
# spent 2.11ms making 1 call to Class::MOP::Class::BEGIN@20
24
25# Creation
26
27
# spent 24.5ms (5.78+18.7) within Class::MOP::Class::initialize which was called 1529 times, avg 16µs/call: # 557 times (945µs+191µs) by Class::MOP::Class::get_all_attributes at line 936, avg 2µs/call # 345 times (649µs+340µs) by Class::MOP::Class::find_method_by_name at line 1133, avg 3µs/call # 195 times (3.17ms+2.02ms) by Class::MOP::Mixin::meta or Class::MOP::Object::meta or DBIx::MultiStatementDo::meta or Moose::Meta::Role::Application::RoleSummation::meta or Moose::Meta::Role::Application::ToClass::meta or Moose::Meta::Role::Application::ToInstance::meta or Moose::Meta::Role::Application::ToRole::meta or Moose::Meta::Role::Application::meta or Moose::Meta::Role::Composite::meta or Moose::Meta::Role::Method::Required::meta or Moose::Meta::Role::meta or Moose::Meta::TypeCoercion::Union::meta or Moose::Meta::TypeCoercion::meta or Moose::Meta::TypeConstraint::Class::meta or Moose::Meta::TypeConstraint::DuckType::meta or Moose::Meta::TypeConstraint::Enum::meta or Moose::Meta::TypeConstraint::Parameterizable::meta or Moose::Meta::TypeConstraint::Parameterized::meta or Moose::Meta::TypeConstraint::Registry::meta or Moose::Meta::TypeConstraint::Role::meta or Moose::Meta::TypeConstraint::Union::meta or Moose::Meta::TypeConstraint::meta at line 42 of Class/MOP/Method/Meta.pm, avg 27µs/call # 150 times (289µs+64µs) by Class::MOP::Class::find_next_method_by_name at line 1181, avg 2µs/call # 59 times (181µs+3.16ms) by Class::MOP::Mixin::meta at line 12 of Class/MOP/Mixin.pm, avg 57µs/call # 55 times (89µs+18µs) by Class::MOP::Class::find_attribute_by_name at line 926, avg 2µs/call # 49 times (112µs+-104µs) by Class::MOP::Class::_fix_metaclass_incompatibility at line 291, avg 169ns/call # 24 times (44µs+5.14ms) by Class::MOP::Method::_new at line 59 of Class/MOP/Method.pm, avg 216µs/call # 19 times (108µs+1.12ms) by metaclass::import at line 38 of metaclass.pm, avg 65µs/call # 15 times (26µs+7µs) by Class::MOP::Class::get_all_methods at line 1144, avg 2µs/call # 12 times (47µs+5.32ms) by Class::MOP::MiniTrait::apply at line 14 of Class/MOP/MiniTrait.pm, avg 447µs/call # 12 times (23µs+5µs) by Class::MOP::Attribute::has_value at line 332 of Class/MOP/Attribute.pm, avg 2µs/call # 12 times (22µs+5µs) by Class::MOP::Attribute::get_raw_value at line 311 of Class/MOP/Attribute.pm, avg 2µs/call # 7 times (22µs+223µs) by Moose::BEGIN@43 at line 12 of Moose/Meta/Attribute/Native.pm, avg 35µs/call # 6 times (16µs+231µs) by Class::MOP::Method::Accessor::_new at line 51 of Class/MOP/Method/Accessor.pm, avg 41µs/call # 6 times (11µs+2µs) by Class::MOP::Class::find_all_methods_by_name at line 1164, avg 2µs/call # 2 times (10µs+875µs) by Moose::Meta::Class::initialize at line 64 of Moose/Meta/Class.pm, avg 442µs/call # 2 times (7µs+114µs) by Class::MOP::Package::create at line 67 of Class/MOP/Package.pm, avg 60µs/call # once (2µs+500ns) by Class::MOP::Attribute::_new at line 69 of Class/MOP/Attribute.pm # once (2µs+500ns) by Moose::Meta::Method::_new at line 7 of (eval 33)[Eval/Closure.pm:142]
sub initialize {
281529191µs my $class = shift;
29
301529125µs my $package_name;
31
321529377µs if ( @_ % 2 ) {
33 $package_name = shift;
34 } else {
35 my %options = @_;
36 $package_name = $options{package};
37 }
38
391529209µs ($package_name && !ref($package_name))
40 || ($class||__PACKAGE__)->_throw_exception( InitializeTakesUnBlessedPackageName => package_name => $package_name );
4115292.23ms159818.9ms return Class::MOP::get_metaclass_by_name($package_name)
# spent 18.4ms making 69 calls to Class::MOP::Class::_construct_class_instance, avg 266µs/call, recursion: max depth 1, sum of overlapping time 230µs # spent 774µs making 1529 calls to Class::MOP::get_metaclass_by_name, avg 506ns/call
42 || $class->_construct_class_instance(package => $package_name, @_);
43}
44
45sub reinitialize {
46 my ( $class, @args ) = @_;
47 unshift @args, "package" if @args % 2;
48 my %options = @args;
49 my $old_metaclass = blessed($options{package})
50 ? $options{package}
51 : Class::MOP::get_metaclass_by_name($options{package});
52 $options{weaken} = Class::MOP::metaclass_is_weak($old_metaclass->name)
53 if !exists $options{weaken}
54 && blessed($old_metaclass)
55 && $old_metaclass->isa('Class::MOP::Class');
56 $old_metaclass->_remove_generated_metaobjects
57 if $old_metaclass && $old_metaclass->isa('Class::MOP::Class');
58 my $new_metaclass = $class->SUPER::reinitialize(%options);
59 $new_metaclass->_restore_metaobjects_from($old_metaclass)
60 if $old_metaclass && $old_metaclass->isa('Class::MOP::Class');
61 return $new_metaclass;
62}
63
64# NOTE: (meta-circularity)
65# this is a special form of _construct_instance
66# (see below), which is used to construct class
67# meta-object instances for any Class::MOP::*
68# class. All other classes will use the more
69# normal &construct_instance.
70
# spent 18.1ms (775µs+17.4) within Class::MOP::Class::_construct_class_instance which was called 69 times, avg 263µs/call: # 69 times (775µs+17.4ms) by Class::MOP::Class::initialize at line 41, avg 263µs/call
sub _construct_class_instance {
716915µs my $class = shift;
726971µs my $options = @_ == 1 ? $_[0] : {@_};
736921µs my $package_name = $options->{package};
746922µs (defined $package_name && $package_name)
75 || $class->_throw_exception("ConstructClassInstanceTakesPackageName");
76 # NOTE:
77 # return the metaclass if we have it cached,
78 # and it is still defined (it has not been
79 # reaped by DESTROY yet, which can happen
80 # annoyingly enough during global destruction)
81
826944µs6922µs if (defined(my $meta = Class::MOP::get_metaclass_by_name($package_name))) {
# spent 22µs making 69 calls to Class::MOP::get_metaclass_by_name, avg 323ns/call
83 return $meta;
84 }
85
86 $class
876927µs9160µs = ref $class
# spent 160µs making 9 calls to Class::MOP::Class::_real_ref_name, avg 18µs/call
88 ? $class->_real_ref_name
89 : $class;
90
91 # now create the metaclass
92697µs my $meta;
9369103µs67537µs if ($class eq 'Class::MOP::Class') {
# spent 537µs making 67 calls to Class::MOP::Class::_new, avg 8µs/call
94 $meta = $class->_new($options);
95 }
96 else {
97 # NOTE:
98 # it is safe to use meta here because
99 # class will always be a subclass of
100 # Class::MOP::Class, which defines meta
10125µs4763µs $meta = $class->meta->_construct_instance($options)
# spent 750µs making 2 calls to Class::MOP::Class::_construct_instance, avg 375µs/call # spent 12µs making 2 calls to Class::MOP::Object::meta, avg 6µs/call
102 }
103
104 # and check the metaclass compatibility
10569121µs6915.9ms $meta->_check_metaclass_compatibility();
# spent 16.0ms making 69 calls to Class::MOP::Class::_check_metaclass_compatibility, avg 232µs/call, recursion: max depth 1, sum of overlapping time 182µs
106
1076955µs6980µs Class::MOP::store_metaclass_by_name($package_name, $meta);
# spent 80µs making 69 calls to Class::MOP::store_metaclass_by_name, avg 1µs/call
108
109 # NOTE:
110 # we need to weaken any anon classes
111 # so that they can call DESTROY properly
1126921µs Class::MOP::weaken_metaclass($package_name) if $options->{weaken};
113
11469120µs $meta;
115}
116
117
# spent 473µs (156+317) within Class::MOP::Class::_real_ref_name which was called 61 times, avg 8µs/call: # 49 times (114µs+179µs) by Class::MOP::Class::_class_metaclass_can_be_made_compatible at line 336, avg 6µs/call # 9 times (34µs+126µs) by Class::MOP::Class::_construct_class_instance at line 87, avg 18µs/call # 2 times (7µs+12µs) by Class::MOP::Class::_immutable_metaclass at line 1364, avg 9µs/call # once (1µs+400ns) by Class::MOP::Class::_class_metaclass_is_compatible at line 250
sub _real_ref_name {
118618µs my $self = shift;
119
120 # NOTE: we need to deal with the possibility of class immutability here,
121 # and then get the name of the class appropriately
12261145µs84317µs return $self->is_immutable
# spent 265µs making 23 calls to Class::MOP::Class::Immutable::Class::MOP::Class::is_immutable, avg 12µs/call # spent 34µs making 23 calls to Class::MOP::Class::Immutable::Trait::_get_mutable_metaclass_name, avg 1µs/call # spent 18µs making 38 calls to Class::MOP::Class::is_immutable, avg 476ns/call
123 ? $self->_get_mutable_metaclass_name()
124 : ref $self;
125}
126
127
# spent 537µs within Class::MOP::Class::_new which was called 67 times, avg 8µs/call: # 67 times (537µs+0s) by Class::MOP::Class::_construct_class_instance at line 93, avg 8µs/call
sub _new {
1286712µs my $class = shift;
129
1306716µs return Class::MOP::Class->initialize($class)->new_object(@_)
131 if $class ne __PACKAGE__;
132
1336723µs my $options = @_ == 1 ? $_[0] : {@_};
134
135 return bless {
136 # inherited from Class::MOP::Package
137 'package' => $options->{package},
138
139 # NOTE:
140 # since the following attributes will
141 # actually be loaded from the symbol
142 # table, and actually bypass the instance
143 # entirely, we can just leave these things
144 # listed here for reference, because they
145 # should not actually have a value associated
146 # with the slot.
147 'namespace' => \undef,
148 'methods' => {},
149
150 # inherited from Class::MOP::Module
151 'version' => \undef,
152 'authority' => \undef,
153
154 # defined in Class::MOP::Class
155 'superclasses' => \undef,
156
157 'attributes' => {},
158 'attribute_metaclass' =>
159 ( $options->{'attribute_metaclass'} || 'Class::MOP::Attribute' ),
160 'method_metaclass' =>
161 ( $options->{'method_metaclass'} || 'Class::MOP::Method' ),
162 'wrapped_method_metaclass' => (
163 $options->{'wrapped_method_metaclass'}
164 || 'Class::MOP::Method::Wrapped'
165 ),
166 'instance_metaclass' =>
167 ( $options->{'instance_metaclass'} || 'Class::MOP::Instance' ),
168 'immutable_trait' => (
169 $options->{'immutable_trait'}
170 || 'Class::MOP::Class::Immutable::Trait'
171 ),
172 'constructor_name' => ( $options->{constructor_name} || 'new' ),
173 'constructor_class' => (
174 $options->{constructor_class} || 'Class::MOP::Method::Constructor'
175 ),
176 'destructor_class' => $options->{destructor_class},
17767526µs }, $class;
178}
179
180## Metaclass compatibility
181{
18216µs my %base_metaclass = (
183 attribute_metaclass => 'Class::MOP::Attribute',
184 method_metaclass => 'Class::MOP::Method',
185 wrapped_method_metaclass => 'Class::MOP::Method::Wrapped',
186 instance_metaclass => 'Class::MOP::Instance',
187 constructor_class => 'Class::MOP::Method::Constructor',
188 destructor_class => 'Class::MOP::Method::Destructor',
189 );
190
19187171µs
# spent 120µs within Class::MOP::Class::_base_metaclasses which was called 87 times, avg 1µs/call: # 48 times (78µs+0s) by Class::MOP::Class::_can_fix_metaclass_incompatibility at line 324, avg 2µs/call # 37 times (40µs+0s) by Class::MOP::Class::_check_metaclass_compatibility at line 202, avg 1µs/call # 2 times (3µs+0s) by Moose::Meta::Class::_base_metaclasses at line 628 of Moose/Meta/Class.pm, avg 1µs/call
sub _base_metaclasses { %base_metaclass }
192}
193
1941500ns
# spent 16.5ms (565µs+15.9) within Class::MOP::Class::_check_metaclass_compatibility which was called 72 times, avg 229µs/call: # 69 times (504µs+15.3ms) by Class::MOP::Class::_construct_class_instance at line 105, avg 230µs/call # 3 times (61µs+540µs) by Class::MOP::Class::superclasses at line 966, avg 200µs/call
sub _check_metaclass_compatibility {
1957216µs my $self = shift;
196
19772174µs721.56ms my @superclasses = $self->superclasses
# spent 1.49ms making 69 calls to Class::MOP::Class::superclasses, avg 22µs/call, recursion: max depth 1, sum of overlapping time 14µs # spent 100µs making 3 calls to Moose::Meta::Class::superclasses, avg 33µs/call, recursion: max depth 1, sum of overlapping time 25µs
198 or return;
199
2003846µs3813.8ms $self->_fix_metaclass_incompatibility(@superclasses);
# spent 13.9ms making 38 calls to Class::MOP::Class::_fix_metaclass_incompatibility, avg 366µs/call, recursion: max depth 1, sum of overlapping time 104µs
201
2023868µs3852µs my %base_metaclass = $self->_base_metaclasses;
# spent 40µs making 37 calls to Class::MOP::Class::_base_metaclasses, avg 1µs/call # spent 13µs making 1 call to Moose::Meta::Class::_base_metaclasses
203
204 # this is always okay ...
205 return
206 if ref($self) eq 'Class::MOP::Class'
207 && all {
208222312µs22248µs my $meta = $self->$_;
# spent 9µs making 37 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 235ns/call # spent 8µs making 37 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 222ns/call # spent 8µs making 37 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 216ns/call # spent 8µs making 37 calls to Class::MOP::Class::constructor_class, avg 214ns/call # spent 8µs making 37 calls to Class::MOP::Class::destructor_class, avg 211ns/call # spent 7µs making 37 calls to Class::MOP::Class::instance_metaclass, avg 200ns/call
209222174µs !defined($meta) || $meta eq $base_metaclass{$_};
210 }
21138133µs37426µs keys %base_metaclass;
# spent 426µs making 37 calls to List::Util::all, avg 12µs/call
212
21312µs for my $superclass (@superclasses) {
21413µs117µs $self->_check_class_metaclass_compatibility($superclass);
215 }
216
21713µs for my $metaclass_type ( keys %base_metaclass ) {
218611µs62µs next unless defined $self->$metaclass_type;
# spent 500ns making 1 call to Moose::Meta::Class::constructor_class # spent 500ns making 1 call to Moose::Meta::Class::destructor_class # spent 300ns making 1 call to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass # spent 200ns making 1 call to Class::MOP::Class::instance_metaclass # spent 200ns making 1 call to Class::MOP::Mixin::HasAttributes::attribute_metaclass # spent 200ns making 1 call to Class::MOP::Mixin::HasMethods::method_metaclass
21963µs for my $superclass (@superclasses) {
22067µs689µs $self->_check_single_metaclass_compatibility( $metaclass_type,
# spent 89µs making 6 calls to Class::MOP::Class::_check_single_metaclass_compatibility, avg 15µs/call
221 $superclass );
222 }
223 }
224}
225
226
# spent 17µs (5+12) within Class::MOP::Class::_check_class_metaclass_compatibility which was called: # once (5µs+12µs) by Class::MOP::Class::_check_metaclass_compatibility at line 214
sub _check_class_metaclass_compatibility {
2271300ns my $self = shift;
2281600ns my ( $superclass_name ) = @_;
229
23014µs112µs if (!$self->_class_metaclass_is_compatible($superclass_name)) {
231 my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name);
232
233 my $super_meta_type = $super_meta->_real_ref_name;
234
235 $self->_throw_exception( IncompatibleMetaclassOfSuperclass => class_name => $self->name,
236 class_meta_type => ref( $self ),
237 superclass_name => $superclass_name,
238 superclass_meta_type => $super_meta_type
239 );
240 }
241}
242
243
# spent 12µs (7+4) within Class::MOP::Class::_class_metaclass_is_compatible which was called: # once (7µs+4µs) by Class::MOP::Class::_check_class_metaclass_compatibility at line 230
sub _class_metaclass_is_compatible {
2441200ns my $self = shift;
2451300ns my ( $superclass_name ) = @_;
246
24711µs1700ns my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name)
# spent 700ns making 1 call to Class::MOP::get_metaclass_by_name
248 || return 1;
249
25011µs12µs my $super_meta_name = $super_meta->_real_ref_name;
# spent 2µs making 1 call to Class::MOP::Class::_real_ref_name
251
25213µs12µs return $self->_is_compatible_with($super_meta_name);
# spent 2µs making 1 call to Class::MOP::Object::_is_compatible_with
253}
254
255
# spent 89µs (12+77) within Class::MOP::Class::_check_single_metaclass_compatibility which was called 6 times, avg 15µs/call: # 6 times (12µs+77µs) by Class::MOP::Class::_check_metaclass_compatibility at line 220, avg 15µs/call
sub _check_single_metaclass_compatibility {
2566800ns my $self = shift;
25761µs my ( $metaclass_type, $superclass_name ) = @_;
258
25969µs677µs if (!$self->_single_metaclass_is_compatible($metaclass_type, $superclass_name)) {
# spent 77µs making 6 calls to Class::MOP::Class::_single_metaclass_is_compatible, avg 13µs/call
260 my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name);
261
262 $self->_throw_exception( MetaclassTypeIncompatible => class_name => $self->name,
263 superclass_name => $superclass_name,
264 metaclass_type => $metaclass_type
265 );
266 }
267}
268
269
# spent 77µs (58+19) within Class::MOP::Class::_single_metaclass_is_compatible which was called 6 times, avg 13µs/call: # 6 times (58µs+19µs) by Class::MOP::Class::_check_single_metaclass_compatibility at line 259, avg 13µs/call
sub _single_metaclass_is_compatible {
2706700ns my $self = shift;
2716800ns my ( $metaclass_type, $superclass_name ) = @_;
272
27363µs62µs my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name)
# spent 2µs making 6 calls to Class::MOP::get_metaclass_by_name, avg 317ns/call
274 || return 1;
275
276 # for instance, Moose::Meta::Class has a error_class attribute, but
277 # Class::MOP::Class doesn't - this shouldn't be an error
27868µs62µs return 1 unless $super_meta->can($metaclass_type);
# spent 2µs making 6 calls to UNIVERSAL::can, avg 300ns/call
279 # for instance, Moose::Meta::Class has a destructor_class, but
280 # Class::MOP::Class doesn't - this shouldn't be an error
28167µs61µs return 1 unless defined $super_meta->$metaclass_type;
# spent 400ns making 1 call to Moose::Meta::Class::destructor_class # spent 300ns making 1 call to Moose::Meta::Class::constructor_class # spent 200ns making 1 call to Class::MOP::Mixin::HasAttributes::attribute_metaclass # spent 200ns making 1 call to Class::MOP::Mixin::HasMethods::method_metaclass # spent 200ns making 1 call to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass # spent 100ns making 1 call to Class::MOP::Class::instance_metaclass
282 # if metaclass is defined in superclass but not here, it's not compatible
283 # this is a really odd case
28468µs61µs return 0 unless defined $self->$metaclass_type;
# spent 400ns making 1 call to Moose::Meta::Class::constructor_class # spent 400ns making 1 call to Moose::Meta::Class::destructor_class # spent 200ns making 1 call to Class::MOP::Mixin::HasAttributes::attribute_metaclass # spent 100ns making 1 call to Class::MOP::Class::instance_metaclass # spent 100ns making 1 call to Class::MOP::Mixin::HasMethods::method_metaclass # spent 100ns making 1 call to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass
285
286622µs1812µs return $self->$metaclass_type->_is_compatible_with($super_meta->$metaclass_type);
# spent 10µs making 6 calls to Class::MOP::Object::_is_compatible_with, avg 2µs/call # spent 800ns making 2 calls to Moose::Meta::Class::destructor_class, avg 400ns/call # spent 600ns making 2 calls to Moose::Meta::Class::constructor_class, avg 300ns/call # spent 300ns making 2 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 150ns/call # spent 200ns making 2 calls to Class::MOP::Class::instance_metaclass, avg 100ns/call # spent 200ns making 2 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 100ns/call # spent 200ns making 2 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 100ns/call
287}
288
289
# spent 13.8ms (274µs+13.5) within Class::MOP::Class::_fix_metaclass_incompatibility which was called 38 times, avg 363µs/call: # 38 times (274µs+13.5ms) by Class::MOP::Class::_check_metaclass_compatibility at line 200, avg 363µs/call
sub _fix_metaclass_incompatibility {
290387µs my $self = shift;
2918793µs498µs my @supers = map { Class::MOP::Class->initialize($_) } @_;
# spent 370µs making 49 calls to Class::MOP::Class::initialize, avg 8µs/call, recursion: max depth 2, sum of overlapping time 362µs
292
2933810µs my $necessary = 0;
2943821µs for my $super (@supers) {
2954951µs4913.2ms $necessary = 1
# spent 13.2ms making 49 calls to Class::MOP::Class::_can_fix_metaclass_incompatibility, avg 270µs/call
296 if $self->_can_fix_metaclass_incompatibility($super);
297 }
2983853µs return unless $necessary;
299
300 for my $super (@supers) {
301 if (!$self->_class_metaclass_is_compatible($super->name)) {
302 $self->_fix_class_metaclass_incompatibility($super);
303 }
304 }
305
306 my %base_metaclass = $self->_base_metaclasses;
307 for my $metaclass_type (keys %base_metaclass) {
308 for my $super (@supers) {
309 if (!$self->_single_metaclass_is_compatible($metaclass_type, $super->name)) {
310 $self->_fix_single_metaclass_incompatibility(
311 $metaclass_type, $super
312 );
313 }
314 }
315 }
316}
317
318
# spent 13.2ms (4.94+8.30) within Class::MOP::Class::_can_fix_metaclass_incompatibility which was called 49 times, avg 270µs/call: # 49 times (4.94ms+8.30ms) by Class::MOP::Class::_fix_metaclass_incompatibility at line 295, avg 270µs/call
sub _can_fix_metaclass_incompatibility {
3194911µs my $self = shift;
3204910µs my ($super_meta) = @_;
321
3224950µs49736µs return 1 if $self->_class_metaclass_can_be_made_compatible($super_meta);
# spent 736µs making 49 calls to Class::MOP::Class::_class_metaclass_can_be_made_compatible, avg 15µs/call
323
32449102µs49100µs my %base_metaclass = $self->_base_metaclasses;
# spent 78µs making 48 calls to Class::MOP::Class::_base_metaclasses, avg 2µs/call # spent 22µs making 1 call to Moose::Meta::Class::_base_metaclasses
3254951µs for my $metaclass_type (keys %base_metaclass) {
326294215µs2947.47ms return 1 if $self->_single_metaclass_can_be_made_compatible($super_meta, $metaclass_type);
# spent 7.47ms making 294 calls to Class::MOP::Class::_single_metaclass_can_be_made_compatible, avg 25µs/call
327 }
328
3294981µs return;
330}
331
332
# spent 736µs (174+562) within Class::MOP::Class::_class_metaclass_can_be_made_compatible which was called 49 times, avg 15µs/call: # 49 times (174µs+562µs) by Class::MOP::Class::_can_fix_metaclass_incompatibility at line 322, avg 15µs/call
sub _class_metaclass_can_be_made_compatible {
333497µs my $self = shift;
334495µs my ($super_meta) = @_;
335
33649149µs98562µs return $self->_can_be_made_compatible_with($super_meta->_real_ref_name);
# spent 293µs making 49 calls to Class::MOP::Class::_real_ref_name, avg 6µs/call # spent 269µs making 49 calls to Class::MOP::Object::_can_be_made_compatible_with, avg 5µs/call
337}
338
339
# spent 7.47ms (1.69+5.78) within Class::MOP::Class::_single_metaclass_can_be_made_compatible which was called 294 times, avg 25µs/call: # 294 times (1.69ms+5.78ms) by Class::MOP::Class::_can_fix_metaclass_incompatibility at line 326, avg 25µs/call
sub _single_metaclass_can_be_made_compatible {
34029434µs my $self = shift;
34129441µs my ($super_meta, $metaclass_type) = @_;
342
343294539µs29498µs my $specific_meta = $self->$metaclass_type;
# spent 18µs making 49 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 365ns/call # spent 17µs making 49 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 345ns/call # spent 16µs making 48 calls to Class::MOP::Class::constructor_class, avg 335ns/call # spent 15µs making 49 calls to Class::MOP::Class::instance_metaclass, avg 298ns/call # spent 14µs making 48 calls to Class::MOP::Class::destructor_class, avg 290ns/call # spent 14µs making 49 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 284ns/call # spent 3µs making 1 call to Moose::Meta::Class::destructor_class # spent 2µs making 1 call to Moose::Meta::Class::constructor_class
344
345294394µs29498µs return unless $super_meta->can($metaclass_type);
# spent 98µs making 294 calls to UNIVERSAL::can, avg 332ns/call
346294410µs29474µs my $super_specific_meta = $super_meta->$metaclass_type;
# spent 22µs making 49 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 439ns/call # spent 13µs making 49 calls to Class::MOP::Mixin::HasAttributes::attribute_metaclass, avg 269ns/call # spent 10µs making 48 calls to Class::MOP::Class::constructor_class, avg 215ns/call # spent 10µs making 48 calls to Class::MOP::Class::destructor_class, avg 200ns/call # spent 9µs making 49 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 188ns/call # spent 9µs making 49 calls to Class::MOP::Class::instance_metaclass, avg 182ns/call # spent 500ns making 1 call to Moose::Meta::Class::constructor_class # spent 500ns making 1 call to Moose::Meta::Class::destructor_class
347
348 # for instance, Moose::Meta::Class has a destructor_class, but
349 # Class::MOP::Class doesn't - this shouldn't be an error
35029481µs return unless defined $super_specific_meta;
351
352 # if metaclass is defined in superclass but not here, it's fixable
353 # this is a really odd case
35424618µs return 1 unless defined $specific_meta;
355
3562464.67ms2465.51ms return 1 if $specific_meta->_can_be_made_compatible_with($super_specific_meta);
# spent 5.51ms making 246 calls to Class::MOP::Object::_can_be_made_compatible_with, avg 22µs/call
357}
358
359sub _fix_class_metaclass_incompatibility {
360 my $self = shift;
361 my ( $super_meta ) = @_;
362
363 if ($self->_class_metaclass_can_be_made_compatible($super_meta)) {
364 ($self->is_pristine)
365 || $self->_throw_exception( CannotFixMetaclassCompatibility => class_name => $self->name,
366 superclass => $super_meta
367 );
368
369 my $super_meta_name = $super_meta->_real_ref_name;
370
371 $self->_make_compatible_with($super_meta_name);
372 }
373}
374
375sub _fix_single_metaclass_incompatibility {
376 my $self = shift;
377 my ( $metaclass_type, $super_meta ) = @_;
378
379 if ($self->_single_metaclass_can_be_made_compatible($super_meta, $metaclass_type)) {
380 ($self->is_pristine)
381 || $self->_throw_exception( CannotFixMetaclassCompatibility => class_name => $self->name,
382 superclass => $super_meta,
383 metaclass_type => $metaclass_type
384 );
385
386 my $new_metaclass = $self->$metaclass_type
387 ? $self->$metaclass_type->_get_compatible_metaclass($super_meta->$metaclass_type)
388 : $super_meta->$metaclass_type;
389 $self->{$metaclass_type} = $new_metaclass;
390 }
391}
392
393sub _restore_metaobjects_from {
394 my $self = shift;
395 my ($old_meta) = @_;
396
397 $self->_restore_metamethods_from($old_meta);
398 $self->_restore_metaattributes_from($old_meta);
399}
400
401sub _remove_generated_metaobjects {
402 my $self = shift;
403
404 for my $attr (map { $self->get_attribute($_) } $self->get_attribute_list) {
405 $attr->remove_accessors;
406 }
407}
408
409# creating classes with MOP ...
410
411
# spent 1.23ms (38µs+1.19) within Class::MOP::Class::create which was called 2 times, avg 615µs/call: # 2 times (38µs+1.19ms) by Class::MOP::Class::_immutable_metaclass at line 1366, avg 615µs/call
sub create {
4122700ns my $class = shift;
41321µs my @args = @_;
414
41522µs unshift @args, 'package' if @args % 2 == 1;
41622µs my %options = @args;
417
418 (ref $options{superclasses} eq 'ARRAY')
419 || __PACKAGE__->_throw_exception( CreateMOPClassTakesArrayRefOfSuperclasses => class => $class,
420 params => \%options
421 )
42222µs if exists $options{superclasses};
423
424 (ref $options{attributes} eq 'ARRAY')
425 || __PACKAGE__->_throw_exception( CreateMOPClassTakesArrayRefOfAttributes => class => $class,
426 params => \%options
427 )
4282600ns if exists $options{attributes};
429
430 (ref $options{methods} eq 'HASH')
431 || __PACKAGE__->_throw_exception( CreateMOPClassTakesHashRefOfMethods => class => $class,
432 params => \%options
433 )
4342600ns if exists $options{methods};
435
43621µs my $package = delete $options{package};
4372600ns my $superclasses = delete $options{superclasses};
43822µs my $attributes = delete $options{attributes};
4392500ns my $methods = delete $options{methods};
440 my $meta_name = exists $options{meta_name}
441 ? delete $options{meta_name}
44221µs : 'meta';
443
44424µs2202µs my $meta = $class->SUPER::create($package => %options);
# spent 202µs making 2 calls to Class::MOP::Module::create, avg 101µs/call
445
44624µs2629µs $meta->_add_meta_method($meta_name)
# spent 629µs making 2 calls to Class::MOP::Mixin::HasMethods::_add_meta_method, avg 315µs/call
447 if defined $meta_name;
448
44922µs2362µs $meta->superclasses(@{$superclasses})
# spent 362µs making 2 calls to Class::MOP::Class::superclasses, avg 181µs/call
450 if defined $superclasses;
451 # NOTE:
452 # process attributes first, so that they can
453 # install accessors, but locally defined methods
454 # can then overwrite them. It is maybe a little odd, but
455 # I think this should be the order of things.
4562900ns if (defined $attributes) {
457 foreach my $attr (@{$attributes}) {
458 $meta->add_attribute($attr);
459 }
460 }
4612500ns if (defined $methods) {
462 foreach my $method_name (keys %{$methods}) {
463 $meta->add_method($method_name, $methods->{$method_name});
464 }
465 }
46625µs return $meta;
467}
468
469# XXX: something more intelligent here?
470sub _anon_package_prefix { 'Class::MOP::Class::__ANON__::SERIAL::' }
471
472sub create_anon_class { shift->create_anon(@_) }
473sub is_anon_class { shift->is_anon(@_) }
474
475sub _anon_cache_key {
476 my $class = shift;
477 my %options = @_;
478 # Makes something like Super::Class|Super::Class::2
479 return join '=' => (
480 join( '|', sort @{ $options{superclasses} || [] } ),
481 );
482}
483
484# Instance Construction & Cloning
485
486
# spent 4.49ms (211µs+4.28) within Class::MOP::Class::new_object which was called 33 times, avg 136µs/call: # 24 times (136µs+2.64ms) by Class::MOP::Method::_new at line 59 of Class/MOP/Method.pm, avg 116µs/call # 6 times (38µs+921µs) by Class::MOP::Method::Accessor::_new at line 51 of Class/MOP/Method/Accessor.pm, avg 160µs/call # once (20µs+339µs) by Class::MOP::Attribute::_new at line 69 of Class/MOP/Attribute.pm # once (9µs+197µs) by Class::MOP::Object::_new at line 23 of Class/MOP/Object.pm # once (8µs+183µs) by Moose::Meta::Method::_new at line 7 of (eval 33)[Eval/Closure.pm:142]
sub new_object {
487338µs my $class = shift;
488
489 # NOTE:
490 # we need to protect the integrity of the
491 # Class::MOP::Class singletons here, so we
492 # delegate this to &construct_class_instance
493 # which will deal with the singletons
49433171µs6652µs return $class->_construct_class_instance(@_)
# spent 39µs making 33 calls to UNIVERSAL::isa, avg 1µs/call # spent 14µs making 33 calls to Class::MOP::Package::name, avg 412ns/call
495 if $class->name->isa('Class::MOP::Class');
4963376µs334.22ms return $class->_construct_instance(@_);
# spent 4.22ms making 33 calls to Class::MOP::Class::_construct_instance, avg 128µs/call
497}
498
499
# spent 4.97ms (812µs+4.16) within Class::MOP::Class::_construct_instance which was called 35 times, avg 142µs/call: # 33 times (746µs+3.48ms) by Class::MOP::Class::new_object at line 496, avg 128µs/call # 2 times (66µs+685µs) by Class::MOP::Class::_construct_class_instance at line 101, avg 375µs/call
sub _construct_instance {
500357µs my $class = shift;
5013514µs my $params = @_ == 1 ? $_[0] : {@_};
5023549µs351.05ms my $meta_instance = $class->get_meta_instance();
# spent 681µs making 10 calls to Class::MOP::Class::get_meta_instance, avg 68µs/call # spent 366µs making 25 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 15µs/call
503 # FIXME:
504 # the code below is almost certainly incorrect
505 # but this is foreign inheritance, so we might
506 # have to kludge it in the end.
507355µs my $instance;
50835125µs3525µs if (my $instance_class = blessed($params->{__INSTANCE__})) {
# spent 25µs making 35 calls to Scalar::Util::blessed, avg 726ns/call
509 ($instance_class eq $class->name)
510 || $class->_throw_exception( InstanceBlessedIntoWrongClass => class_name => $class->name,
511 params => $params,
512 instance => $params->{__INSTANCE__}
513 );
514 $instance = $params->{__INSTANCE__};
515 }
516 elsif (exists $params->{__INSTANCE__}) {
517 $class->_throw_exception( InstanceMustBeABlessedReference => class_name => $class->name,
518 params => $params,
519 instance => $params->{__INSTANCE__}
520 );
521 }
522 else {
5233551µs35172µs $instance = $meta_instance->create_instance();
# spent 172µs making 35 calls to Class::MOP::Instance::create_instance, avg 5µs/call
524 }
5253562µs35774µs foreach my $attr ($class->get_all_attributes()) {
# spent 435µs making 25 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 17µs/call # spent 338µs making 10 calls to Class::MOP::Class::get_all_attributes, avg 34µs/call
526245180µs2452.03ms $attr->initialize_instance_slot($meta_instance, $instance, $params);
# spent 2.03ms making 245 calls to Class::MOP::Attribute::initialize_instance_slot, avg 8µs/call
527 }
5283584µs70118µs if (Class::MOP::metaclass_is_weak($class->name)) {
# spent 109µs making 35 calls to Class::MOP::metaclass_is_weak, avg 3µs/call # spent 9µs making 35 calls to Class::MOP::Package::name, avg 251ns/call
529 $meta_instance->_set_mop_slot($instance, $class);
530 }
5313569µs return $instance;
532}
533
534
# spent 37.1ms (302µs+36.8) within Class::MOP::Class::_inline_new_object which was called 31 times, avg 1.20ms/call: # 31 times (302µs+36.8ms) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 98 of Class/MOP/Method/Constructor.pm, avg 1.20ms/call
sub _inline_new_object {
535315µs my $self = shift;
536
537 return (
53831197µs18636.8ms 'my $class = shift;',
# spent 35.2ms making 31 calls to Class::MOP::Class::_inline_slot_initializers, avg 1.14ms/call # spent 853µs making 31 calls to Class::MOP::Class::_inline_generate_instance, avg 28µs/call # spent 189µs making 1 call to Moose::Meta::Class::_inline_params # spent 183µs making 31 calls to Class::MOP::Class::_inline_preserve_weak_metaclasses, avg 6µs/call # spent 181µs making 31 calls to Class::MOP::Class::_inline_fallback_constructor, avg 6µs/call # spent 139µs making 1 call to Moose::Meta::Class::_inline_extra_init # spent 36µs making 30 calls to Class::MOP::Class::_inline_params, avg 1µs/call # spent 13µs making 30 calls to Class::MOP::Class::_inline_extra_init, avg 430ns/call
539 '$class = Scalar::Util::blessed($class) || $class;',
540 $self->_inline_fallback_constructor('$class'),
541 $self->_inline_params('$params', '$class'),
542 $self->_inline_generate_instance('$instance', '$class'),
543 $self->_inline_slot_initializers,
544 $self->_inline_preserve_weak_metaclasses,
545 $self->_inline_extra_init,
546 'return $instance',
547 );
548}
549
550
# spent 181µs (136+45) within Class::MOP::Class::_inline_fallback_constructor which was called 31 times, avg 6µs/call: # 31 times (136µs+45µs) by Class::MOP::Class::_inline_new_object at line 538, avg 6µs/call
sub _inline_fallback_constructor {
551314µs my $self = shift;
552316µs my ($class) = @_;
553 return (
55431126µs6245µs 'return ' . $self->_generate_fallback_constructor($class),
# spent 36µs making 30 calls to Class::MOP::Class::_generate_fallback_constructor, avg 1µs/call # spent 7µs making 31 calls to Class::MOP::Package::name, avg 223ns/call # spent 2µs making 1 call to Moose::Meta::Class::_generate_fallback_constructor
555 'if ' . $class . ' ne \'' . $self->name . '\';',
556 );
557}
558
559
# spent 36µs within Class::MOP::Class::_generate_fallback_constructor which was called 30 times, avg 1µs/call: # 30 times (36µs+0s) by Class::MOP::Class::_inline_fallback_constructor at line 554, avg 1µs/call
sub _generate_fallback_constructor {
560304µs my $self = shift;
561305µs my ($class) = @_;
5623046µs return 'Class::MOP::Class->initialize(' . $class . ')->new_object(@_)',
563}
564
565
# spent 36µs within Class::MOP::Class::_inline_params which was called 30 times, avg 1µs/call: # 30 times (36µs+0s) by Class::MOP::Class::_inline_new_object at line 538, avg 1µs/call
sub _inline_params {
566305µs my $self = shift;
567307µs my ($params, $class) = @_;
568 return (
5693041µs 'my ' . $params . ' = @_ == 1 ? $_[0] : {@_};',
570 );
571}
572
573
# spent 853µs (77+775) within Class::MOP::Class::_inline_generate_instance which was called 31 times, avg 28µs/call: # 31 times (77µs+775µs) by Class::MOP::Class::_inline_new_object at line 538, avg 28µs/call
sub _inline_generate_instance {
574315µs my $self = shift;
575316µs my ($inst, $class) = @_;
576 return (
5773185µs31775µs 'my ' . $inst . ' = ' . $self->_inline_create_instance($class) . ';',
# spent 775µs making 31 calls to Class::MOP::Class::_inline_create_instance, avg 25µs/call
578 );
579}
580
581
# spent 775µs (96+679) within Class::MOP::Class::_inline_create_instance which was called 31 times, avg 25µs/call: # 31 times (96µs+679µs) by Class::MOP::Class::_inline_generate_instance at line 577, avg 25µs/call
sub _inline_create_instance {
582313µs my $self = shift;
583
5843171µs62679µs return $self->get_meta_instance->inline_create_instance(@_);
# spent 647µs making 31 calls to Class::MOP::Class::get_meta_instance, avg 21µs/call # spent 32µs making 31 calls to Class::MOP::Instance::inline_create_instance, avg 1µs/call
585}
586
587
# spent 35.2ms (513µs+34.7) within Class::MOP::Class::_inline_slot_initializers which was called 31 times, avg 1.14ms/call: # 31 times (513µs+34.7ms) by Class::MOP::Class::_inline_new_object at line 538, avg 1.14ms/call
sub _inline_slot_initializers {
588314µs my $self = shift;
589
590315µs my $idx = 0;
591
592286193µs28629.6ms return map { $self->_inline_slot_initializer($_, $idx++) }
# spent 28.9ms making 282 calls to Class::MOP::Class::_inline_slot_initializer, avg 102µs/call # spent 711µs making 4 calls to Moose::Meta::Class::_inline_slot_initializer, avg 178µs/call
5937754.29ms15505.29ms sort { $a->name cmp $b->name } $self->get_all_attributes;
# spent 4.13ms making 31 calls to Class::MOP::Class::CORE:sort, avg 133µs/call # spent 995µs making 31 calls to Class::MOP::Class::get_all_attributes, avg 32µs/call # spent 172µs making 1488 calls to Class::MOP::Mixin::AttributeCore::name, avg 115ns/call
594}
595
596
# spent 29.5ms (1.46+28.1) within Class::MOP::Class::_inline_slot_initializer which was called 286 times, avg 103µs/call: # 282 times (1.42ms+27.5ms) by Class::MOP::Class::_inline_slot_initializers at line 592, avg 102µs/call # 4 times (40µs+610µs) by Moose::Meta::Class::_inline_slot_initializer at line 365 of Moose/Meta/Class.pm, avg 162µs/call
sub _inline_slot_initializer {
59728628µs my $self = shift;
59828636µs my ($attr, $idx) = @_;
599
600286429µs297449µs if (defined(my $init_arg = $attr->init_arg)) {
# spent 367µs making 11 calls to Class::MOP::Class::_inline_init_attr_from_default, avg 33µs/call # spent 82µs making 286 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 288ns/call
601275282µs27513.7ms my @source = (
# spent 13.4ms making 271 calls to Class::MOP::Class::_inline_init_attr_from_constructor, avg 49µs/call # spent 359µs making 4 calls to Moose::Meta::Class::_inline_init_attr_from_constructor, avg 90µs/call
602 'if (exists $params->{\'' . $init_arg . '\'}) {',
603 $self->_inline_init_attr_from_constructor($attr, $idx),
604 '}',
605 );
606275199µs27513.9ms if (my @default = $self->_inline_init_attr_from_default($attr, $idx)) {
# spent 13.6ms making 271 calls to Class::MOP::Class::_inline_init_attr_from_default, avg 50µs/call # spent 251µs making 4 calls to Moose::Meta::Class::_inline_init_attr_from_default, avg 63µs/call
607 push @source, (
608 'else {',
609 @default,
610 '}',
611 );
612 }
613275399µs return @source;
614 }
615 elsif (my @default = $self->_inline_init_attr_from_default($attr, $idx)) {
616 return (
617 '{',
618 @default,
619 '}',
620 );
621 }
622 else {
62311µs return ();
624 }
625}
626
627
# spent 13.4ms (1.16+12.2) within Class::MOP::Class::_inline_init_attr_from_constructor which was called 271 times, avg 49µs/call: # 271 times (1.16ms+12.2ms) by Class::MOP::Class::_inline_slot_initializer at line 601, avg 49µs/call
sub _inline_init_attr_from_constructor {
62827126µs my $self = shift;
62927129µs my ($attr, $idx) = @_;
630
631271553µs54212.1ms my @initial_value = $attr->_inline_set_value(
# spent 11.7ms making 269 calls to Class::MOP::Attribute::_inline_set_value, avg 43µs/call # spent 386µs making 2 calls to Moose::Meta::Attribute::_inline_set_value, avg 193µs/call # spent 29µs making 271 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 108ns/call
632 '$instance', '$params->{\'' . $attr->init_arg . '\'}',
633 );
634
635271144µs271132µs push @initial_value, (
# spent 132µs making 271 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 486ns/call
636 '$attrs->[' . $idx . ']->set_initial_value(',
637 '$instance,',
638 $attr->_inline_instance_get('$instance'),
639 ');',
640 ) if $attr->has_initializer;
641
642271288µs return @initial_value;
643}
644
645
# spent 14.0ms (4.71+9.30) within Class::MOP::Class::_inline_init_attr_from_default which was called 282 times, avg 50µs/call: # 271 times (4.67ms+8.98ms) by Class::MOP::Class::_inline_slot_initializer at line 606, avg 50µs/call # 11 times (41µs+326µs) by Class::MOP::Class::_inline_slot_initializer at line 600, avg 33µs/call
sub _inline_init_attr_from_default {
64628226µs my $self = shift;
64728233µs my ($attr, $idx) = @_;
648
649282153µs2821.02ms my $default = $self->_inline_default_value($attr, $idx);
# spent 1.02ms making 282 calls to Class::MOP::Class::_inline_default_value, avg 4µs/call
650282169µs return unless $default;
651
6529973µs998.24ms my @initial_value = $attr->_inline_set_value('$instance', $default);
# spent 8.24ms making 99 calls to Class::MOP::Attribute::_inline_set_value, avg 83µs/call
653
6549949µs9938µs push @initial_value, (
# spent 38µs making 99 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 382ns/call
655 '$attrs->[' . $idx . ']->set_initial_value(',
656 '$instance,',
657 $attr->_inline_instance_get('$instance'),
658 ');',
659 ) if $attr->has_initializer;
660
66199102µs return @initial_value;
662}
663
664
# spent 1.04ms (752µs+285µs) within Class::MOP::Class::_inline_default_value which was called 285 times, avg 4µs/call: # 282 times (740µs+281µs) by Class::MOP::Class::_inline_init_attr_from_default at line 649, avg 4µs/call # 3 times (12µs+3µs) by Moose::Meta::Class::_inline_init_attr_from_default at line 422 of Moose/Meta/Class.pm, avg 5µs/call
sub _inline_default_value {
66528525µs my $self = shift;
66628525µs my ($attr, $index) = @_;
667
668285346µs570284µs if ($attr->has_default) {
# spent 105µs making 285 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 369ns/call # spent 101µs making 101 calls to Class::MOP::Mixin::AttributeCore::is_default_a_coderef, avg 997ns/call # spent 79µs making 184 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 427ns/call
669 # NOTE:
670 # default values can either be CODE refs
671 # in which case we need to call them. Or
672 # they can be scalars (strings/numbers)
673 # in which case we can just deal with them
674 # in the code we eval.
675 if ($attr->is_default_a_coderef) {
676 return '$defaults->[' . $index . ']->($instance)';
677 }
678 else {
6793135µs return '$defaults->[' . $index . ']';
680 }
681 }
682 elsif ($attr->has_builder) {
683 return '$instance->' . $attr->builder;
684 }
685 else {
6861844.16ms return;
687 }
688}
689
690
# spent 183µs (98+85) within Class::MOP::Class::_inline_preserve_weak_metaclasses which was called 31 times, avg 6µs/call: # 31 times (98µs+85µs) by Class::MOP::Class::_inline_new_object at line 538, avg 6µs/call
sub _inline_preserve_weak_metaclasses {
691315µs my $self = shift;
6923168µs6285µs if (Class::MOP::metaclass_is_weak($self->name)) {
# spent 74µs making 31 calls to Class::MOP::metaclass_is_weak, avg 2µs/call # spent 11µs making 31 calls to Class::MOP::Package::name, avg 358ns/call
693 return (
694 $self->_inline_set_mop_slot(
695 '$instance', 'Class::MOP::class_of($class)'
696 ) . ';'
697 );
698 }
699 else {
7003138µs return ();
701 }
702}
703
7043032µs
# spent 13µs within Class::MOP::Class::_inline_extra_init which was called 30 times, avg 430ns/call: # 30 times (13µs+0s) by Class::MOP::Class::_inline_new_object at line 538, avg 430ns/call
sub _inline_extra_init { }
705
706
# spent 2.97ms (462µs+2.51) within Class::MOP::Class::_eval_environment which was called 31 times, avg 96µs/call: # 30 times (452µs+2.49ms) by Class::MOP::Method::Constructor::_eval_environment at line 86 of Class/MOP/Method/Constructor.pm, avg 98µs/call # once (10µs+26µs) by Moose::Meta::Class::_eval_environment at line 542 of Moose/Meta/Class.pm
sub _eval_environment {
707314µs my $self = shift;
708
7097841.53ms15682.54ms my @attrs = sort { $a->name cmp $b->name } $self->get_all_attributes;
# spent 1.46ms making 31 calls to Class::MOP::Class::CORE:sort, avg 47µs/call # spent 901µs making 31 calls to Class::MOP::Class::get_all_attributes, avg 29µs/call # spent 174µs making 1506 calls to Class::MOP::Mixin::AttributeCore::name, avg 116ns/call
710
711317190µs286150µs my $defaults = [map { $_->default } @attrs];
# spent 150µs making 286 calls to Class::MOP::Mixin::AttributeCore::default, avg 525ns/call
712
713 return {
7143167µs '$defaults' => \$defaults,
715 };
716}
717
718
719
# spent 4.47ms (276µs+4.20) within Class::MOP::Class::get_meta_instance which was called 324 times, avg 14µs/call: # 154 times (97µs+864µs) by Class::MOP::Attribute::_inline_instance_set at line 301 of Class/MOP/Attribute.pm, avg 6µs/call # 83 times (68µs+976µs) by Class::MOP::Attribute::_inline_instance_get at line 324 of Class/MOP/Attribute.pm, avg 13µs/call # 31 times (35µs+612µs) by Class::MOP::Class::_inline_create_instance at line 584, avg 21µs/call # 22 times (33µs+971µs) by Class::MOP::Class:::around at line 77 of Class/MOP/Class/Immutable/Trait.pm, avg 46µs/call # 17 times (13µs+57µs) by Class::MOP::Attribute::_inline_instance_has at line 345 of Class/MOP/Attribute.pm, avg 4µs/call # 10 times (25µs+656µs) by Class::MOP::Class::_construct_instance at line 502, avg 68µs/call # 3 times (2µs+0s) by Class::MOP::Attribute::has_value at line 332 of Class/MOP/Attribute.pm, avg 500ns/call # 2 times (1µs+0s) by Class::MOP::Attribute::get_raw_value at line 311 of Class/MOP/Attribute.pm, avg 550ns/call # once (2µs+58µs) by Moose::Exporter::BEGIN@8 at line 733 of Class/MOP.pm # once (500ns+0s) by Moose::Meta::Attribute::_inline_weaken_value at line 737 of Moose/Meta/Attribute.pm
sub get_meta_instance {
72032428µs my $self = shift;
721324407µs524.20ms $self->{'_meta_instance'} ||= $self->_create_meta_instance();
# spent 4.20ms making 52 calls to Class::MOP::Class::_create_meta_instance, avg 81µs/call
722}
723
724
# spent 4.20ms (367µs+3.83) within Class::MOP::Class::_create_meta_instance which was called 52 times, avg 81µs/call: # 52 times (367µs+3.83ms) by Class::MOP::Class::get_meta_instance at line 721, avg 81µs/call
sub _create_meta_instance {
725527µs my $self = shift;
726
72752201µs1563.80ms my $instance = $self->instance_metaclass->new(
# spent 2.07ms making 52 calls to Class::MOP::Instance::new, avg 40µs/call # spent 1.21ms making 40 calls to Class::MOP::Class::get_all_attributes, avg 30µs/call # spent 497µs making 12 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 41µs/call # spent 16µs making 52 calls to Class::MOP::Class::instance_metaclass, avg 304ns/call
728 associated_metaclass => $self,
729 attributes => [ $self->get_all_attributes() ],
730 );
731
7325243µs5228µs $self->add_meta_instance_dependencies()
# spent 28µs making 52 calls to Class::MOP::Instance::is_dependent_on_superclasses, avg 548ns/call
733 if $instance->is_dependent_on_superclasses();
734
7355268µs return $instance;
736}
737
738# TODO: this is actually not being used!
739sub _inline_rebless_instance {
740 my $self = shift;
741
742 return $self->get_meta_instance->inline_rebless_instance_structure(@_);
743}
744
745sub _inline_get_mop_slot {
746 my $self = shift;
747
748 return $self->get_meta_instance->_inline_get_mop_slot(@_);
749}
750
751sub _inline_set_mop_slot {
752 my $self = shift;
753
754 return $self->get_meta_instance->_inline_set_mop_slot(@_);
755}
756
757sub _inline_clear_mop_slot {
758 my $self = shift;
759
760 return $self->get_meta_instance->_inline_clear_mop_slot(@_);
761}
762
763sub clone_object {
764 my $class = shift;
765 my $instance = shift;
766 (blessed($instance) && $instance->isa($class->name))
767 || $class->_throw_exception( CloneObjectExpectsAnInstanceOfMetaclass => class_name => $class->name,
768 instance => $instance,
769 );
770 # NOTE:
771 # we need to protect the integrity of the
772 # Class::MOP::Class singletons here, they
773 # should not be cloned.
774 return $instance if $instance->isa('Class::MOP::Class');
775 $class->_clone_instance($instance, @_);
776}
777
778sub _clone_instance {
779 my ($class, $instance, %params) = @_;
780 (blessed($instance))
781 || $class->_throw_exception( OnlyInstancesCanBeCloned => class_name => $class->name,
782 instance => $instance,
783 params => \%params
784 );
785 my $meta_instance = $class->get_meta_instance();
786 my $clone = $meta_instance->clone_instance($instance);
787 foreach my $attr ($class->get_all_attributes()) {
788 if ( defined( my $init_arg = $attr->init_arg ) ) {
789 if (exists $params{$init_arg}) {
790 $attr->set_value($clone, $params{$init_arg});
791 }
792 }
793 }
794 return $clone;
795}
796
797sub _force_rebless_instance {
798 my ($self, $instance, %params) = @_;
799 my $old_metaclass = Class::MOP::class_of($instance);
800
801 $old_metaclass->rebless_instance_away($instance, $self, %params)
802 if $old_metaclass;
803
804 my $meta_instance = $self->get_meta_instance;
805
806 if (Class::MOP::metaclass_is_weak($old_metaclass->name)) {
807 $meta_instance->_clear_mop_slot($instance);
808 }
809
810 # rebless!
811 # we use $_[1] here because of t/cmop/rebless_overload.t regressions
812 # on 5.8.8
813 $meta_instance->rebless_instance_structure($_[1], $self);
814
815 $self->_fixup_attributes_after_rebless($instance, $old_metaclass, %params);
816
817 if (Class::MOP::metaclass_is_weak($self->name)) {
818 $meta_instance->_set_mop_slot($instance, $self);
819 }
820}
821
822sub rebless_instance {
823 my ($self, $instance, %params) = @_;
824 my $old_metaclass = Class::MOP::class_of($instance);
825
826 my $old_class = $old_metaclass ? $old_metaclass->name : blessed($instance);
827 $self->name->isa($old_class)
828 || $self->_throw_exception( CanReblessOnlyIntoASubclass => class_name => $self->name,
829 instance => $instance,
830 instance_class => blessed( $instance ),
831 params => \%params,
832 );
833
834 $self->_force_rebless_instance($_[1], %params);
835
836 return $instance;
837}
838
839sub rebless_instance_back {
840 my ( $self, $instance ) = @_;
841 my $old_metaclass = Class::MOP::class_of($instance);
842 my $old_class
843 = $old_metaclass ? $old_metaclass->name : blessed($instance);
844 $old_class->isa( $self->name )
845 || $self->_throw_exception( CanReblessOnlyIntoASuperclass => class_name => $self->name,
846 instance => $instance,
847 instance_class => blessed( $instance ),
848 );
849
850 $self->_force_rebless_instance($_[1]);
851
852 return $instance;
853}
854
855sub rebless_instance_away {
856 # this intentionally does nothing, it is just a hook
857}
858
859sub _fixup_attributes_after_rebless {
860 my $self = shift;
861 my ($instance, $rebless_from, %params) = @_;
862 my $meta_instance = $self->get_meta_instance;
863
864 for my $attr ( $rebless_from->get_all_attributes ) {
865 next if $self->find_attribute_by_name( $attr->name );
866 $meta_instance->deinitialize_slot( $instance, $_ ) for $attr->slots;
867 }
868
869 foreach my $attr ( $self->get_all_attributes ) {
870 if ( $attr->has_value($instance) ) {
871 if ( defined( my $init_arg = $attr->init_arg ) ) {
872 $params{$init_arg} = $attr->get_value($instance)
873 unless exists $params{$init_arg};
874 }
875 else {
876 $attr->set_value($instance, $attr->get_value($instance));
877 }
878 }
879 }
880
881 foreach my $attr ($self->get_all_attributes) {
882 $attr->initialize_instance_slot($meta_instance, $instance, \%params);
883 }
884}
885
886
# spent 928µs (249+680) within Class::MOP::Class::_attach_attribute which was called 135 times, avg 7µs/call: # 135 times (249µs+680µs) by Class::MOP::Mixin::HasAttributes::add_attribute at line 22 of Class/MOP/Mixin/HasAttributes.pm, avg 7µs/call
sub _attach_attribute {
88713526µs my ($self, $attribute) = @_;
888135220µs135680µs $attribute->attach_to_class($self);
# spent 680µs making 135 calls to Class::MOP::Attribute::attach_to_class, avg 5µs/call
889}
890
891
# spent 40.5ms (758µs+39.7) within Class::MOP::Class::_post_add_attribute which was called 135 times, avg 300µs/call: # 135 times (758µs+39.7ms) by Class::MOP::Mixin::HasAttributes::add_attribute at line 39 of Class/MOP/Mixin/HasAttributes.pm, avg 300µs/call
sub _post_add_attribute {
89213527µs my ( $self, $attribute ) = @_;
893
894135102µs135532µs $self->invalidate_meta_instances;
# spent 532µs making 135 calls to Class::MOP::Class::invalidate_meta_instances, avg 4µs/call
895
896 # invalidate package flag here
897
# spent 37.0ms (458µs+36.5) within Class::MOP::Class::try {...} which was called 135 times, avg 274µs/call: # 135 times (458µs+36.5ms) by Try::Tiny::try at line 92 of Try/Tiny.pm, avg 274µs/call
try {
898135132µs local $SIG{__DIE__};
899135314µs13536.5ms $attribute->install_accessors;
# spent 26.8ms making 130 calls to Class::MOP::Attribute::install_accessors, avg 206µs/call # spent 9.68ms making 5 calls to Moose::Meta::Attribute::install_accessors, avg 1.94ms/call
900 }
901 catch {
902 $self->remove_attribute( $attribute->name );
903 die $_;
904135529µs27039.2ms };
# spent 38.3ms making 135 calls to Try::Tiny::try, avg 284µs/call # spent 879µs making 135 calls to Try::Tiny::catch, avg 7µs/call
905}
906
907sub remove_attribute {
908 my $self = shift;
909
910 my $removed_attribute = $self->SUPER::remove_attribute(@_)
911 or return;
912
913 $self->invalidate_meta_instances;
914
915 $removed_attribute->remove_accessors;
916 $removed_attribute->detach_from_class;
917
918 return$removed_attribute;
919}
920
921
# spent 1.18ms (345µs+834µs) within Class::MOP::Class::find_attribute_by_name which was called 55 times, avg 21µs/call: # 55 times (345µs+834µs) by Class::MOP::Class::_immutable_metaclass at line 1343, avg 21µs/call
sub find_attribute_by_name {
9225511µs my ( $self, $attr_name ) = @_;
923
9245554µs55485µs foreach my $class ( $self->linearized_isa ) {
# spent 471µs making 51 calls to Class::MOP::Class::Immutable::Class::MOP::Class::linearized_isa, avg 9µs/call # spent 14µs making 4 calls to Class::MOP::Class::linearized_isa, avg 4µs/call
925 # fetch the meta-class ...
9265542µs55107µs my $meta = Class::MOP::Class->initialize($class);
# spent 107µs making 55 calls to Class::MOP::Class::initialize, avg 2µs/call
92755139µs110241µs return $meta->get_attribute($attr_name)
# spent 142µs making 55 calls to Class::MOP::Mixin::HasAttributes::has_attribute, avg 3µs/call # spent 99µs making 55 calls to Class::MOP::Mixin::HasAttributes::get_attribute, avg 2µs/call
928 if $meta->has_attribute($attr_name);
929 }
930
931 return;
932}
933
934
# spent 4.18ms (2.21+1.98) within Class::MOP::Class::get_all_attributes which was called 131 times, avg 32µs/call: # 40 times (673µs+539µs) by Class::MOP::Class::_create_meta_instance at line 727, avg 30µs/call # 31 times (529µs+465µs) by Class::MOP::Class::_inline_slot_initializers at line 593, avg 32µs/call # 31 times (488µs+413µs) by Class::MOP::Class::_eval_environment at line 709, avg 29µs/call # 16 times (279µs+376µs) by Class::MOP::Class:::around at line 71 of Class/MOP/Class/Immutable/Trait.pm, avg 41µs/call # 10 times (188µs+151µs) by Class::MOP::Class::_construct_instance at line 525, avg 34µs/call # once (34µs+15µs) by Moose::Meta::Attribute::new at line 58 of Moose/Meta/Attribute.pm # once (9µs+8µs) by Moose::Meta::Class::_inline_triggers at line 459 of Moose/Meta/Class.pm # once (8µs+7µs) by Moose::Meta::Class::_eval_environment at line 497 of Moose/Meta/Class.pm
sub get_all_attributes {
93513117µs my $self = shift;
93612451.78ms12451.93ms my %attrs = map { %{ Class::MOP::Class->initialize($_)->_attribute_map } }
# spent 1.19ms making 557 calls to Class::MOP::Class::initialize, avg 2µs/call, recursion: max depth 1, sum of overlapping time 50µs # spent 437µs making 115 calls to Class::MOP::Class::linearized_isa, avg 4µs/call # spent 215µs making 16 calls to Class::MOP::Class::Immutable::Class::MOP::Class::linearized_isa, avg 13µs/call # spent 138µs making 557 calls to Class::MOP::Mixin::HasAttributes::_attribute_map, avg 247ns/call
937 reverse $self->linearized_isa;
938131283µs return values %attrs;
939}
940
941# Inheritance
942
943sub superclasses {
9447911µs my $self = shift;
945
94679104µs791.35ms my $isa = $self->get_or_add_package_symbol('@ISA');
# spent 1.35ms making 79 calls to Class::MOP::Package::get_or_add_package_symbol, avg 17µs/call
947
9487922µs if (@_) {
94932µs my @supers = @_;
950326µs @{$isa} = @supers;
951
952 # NOTE:
953 # on 5.8 and below, we need to call
954 # a method to get Perl to detect
955 # a cycle in the class hierarchy
95637µs31µs my $class = $self->name;
# spent 1µs making 3 calls to Class::MOP::Package::name, avg 333ns/call
957312µs31µs $class->isa($class);
# spent 1µs making 3 calls to UNIVERSAL::isa, avg 433ns/call
958
959 # NOTE:
960 # we need to check the metaclass
961 # compatibility here so that we can
962 # be sure that the superclass is
963 # not potentially creating an issues
964 # we don't know about
965
96637µs3601µs $self->_check_metaclass_compatibility();
# spent 601µs making 3 calls to Class::MOP::Class::_check_metaclass_compatibility, avg 200µs/call
96736µs385µs $self->_superclasses_updated();
# spent 85µs making 3 calls to Class::MOP::Class::_superclasses_updated, avg 28µs/call
968 }
969
97079125µs return @{$isa};
971}
972
973
# spent 85µs (34+51) within Class::MOP::Class::_superclasses_updated which was called 3 times, avg 28µs/call: # 3 times (34µs+51µs) by Class::MOP::Class::superclasses at line 967, avg 28µs/call
sub _superclasses_updated {
9743900ns my $self = shift;
97535µs34µs $self->update_meta_instance_dependencies();
# spent 4µs making 3 calls to Class::MOP::Class::update_meta_instance_dependencies, avg 2µs/call
976 # keep strong references to all our parents, so they don't disappear if
977 # they are anon classes and don't have any direct instances
978 $self->_superclass_metas(
979619µs917µs map { Class::MOP::class_of($_) } $self->superclasses
# spent 10µs making 3 calls to Class::MOP::class_of, avg 3µs/call # spent 7µs making 3 calls to Class::MOP::Class::_superclass_metas, avg 2µs/call # spent 14µs making 2 calls to Class::MOP::Class::superclasses, avg 7µs/call, recursion: max depth 1, sum of overlapping time 14µs # spent 15µs making 1 call to Moose::Meta::Class::superclasses, recursion: max depth 1, sum of overlapping time 15µs
980 );
981}
982
983
# spent 7µs within Class::MOP::Class::_superclass_metas which was called 3 times, avg 2µs/call: # 3 times (7µs+0s) by Class::MOP::Class::_superclasses_updated at line 979, avg 2µs/call
sub _superclass_metas {
98431µs my $self = shift;
98538µs $self->{_superclass_metas} = [@_];
986}
987
988sub subclasses {
989 my $self = shift;
990 my $super_class = $self->name;
991
992 return @{ $super_class->mro::get_isarev() };
993}
994
995sub direct_subclasses {
996 my $self = shift;
997 my $super_class = $self->name;
998
999 return grep {
1000 grep {
1001 $_ eq $super_class
1002 } Class::MOP::Class->initialize($_)->superclasses
1003 } $self->subclasses;
1004}
1005
1006
# spent 1.19ms (878µs+313µs) within Class::MOP::Class::linearized_isa which was called 309 times, avg 4µs/call: # 174 times (488µs+180µs) by Class::MOP::Class::_method_lookup_order at line 1045, avg 4µs/call # 115 times (329µs+108µs) by Class::MOP::Class::get_all_attributes at line 936, avg 4µs/call # 16 times (51µs+20µs) by Class::MOP::Class:::around at line 53 of Class/MOP/Class/Immutable/Trait.pm, avg 4µs/call # 4 times (10µs+4µs) by Class::MOP::Class::find_attribute_by_name at line 924, avg 4µs/call
sub linearized_isa {
10073091.35ms618313µs return @{ mro::get_linear_isa( (shift)->name ) };
# spent 231µs making 309 calls to mro::get_linear_isa, avg 747ns/call # spent 82µs making 309 calls to Class::MOP::Package::name, avg 265ns/call
1008}
1009
1010sub class_precedence_list {
1011 my $self = shift;
1012 my $name = $self->name;
1013
1014 unless (Class::MOP::IS_RUNNING_ON_5_10()) {
1015 # NOTE:
1016 # We need to check for circular inheritance here
1017 # if we are not on 5.10, cause 5.8 detects it late.
1018 # This will do nothing if all is well, and blow up
1019 # otherwise. Yes, it's an ugly hack, better
1020 # suggestions are welcome.
1021 # - SL
1022 ($name || return)->isa('This is a test for circular inheritance')
1023 }
1024
1025 # if our mro is c3, we can
1026 # just grab the linear_isa
1027 if (mro::get_mro($name) eq 'c3') {
1028 return @{ mro::get_linear_isa($name) }
1029 }
1030 else {
1031 # NOTE:
1032 # we can't grab the linear_isa for dfs
1033 # since it has all the duplicates
1034 # already removed.
1035 return (
1036 $name,
1037 map {
1038 Class::MOP::Class->initialize($_)->class_precedence_list()
1039 } $self->superclasses()
1040 );
1041 }
1042}
1043
1044
# spent 955µs (286+669) within Class::MOP::Class::_method_lookup_order which was called 174 times, avg 5µs/call: # 90 times (155µs+382µs) by Class::MOP::Class::find_method_by_name at line 1132, avg 6µs/call # 75 times (113µs+242µs) by Class::MOP::Class::find_next_method_by_name at line 1178, avg 5µs/call # 7 times (15µs+38µs) by Class::MOP::Class::get_all_methods at line 1143, avg 8µs/call # 2 times (3µs+6µs) by Class::MOP::Class::find_all_methods_by_name at line 1162, avg 5µs/call
sub _method_lookup_order {
1045174298µs174669µs return (shift->linearized_isa, 'UNIVERSAL');
# spent 669µs making 174 calls to Class::MOP::Class::linearized_isa, avg 4µs/call
1046}
1047
1048## Methods
1049
1050{
1051
# spent 8.76ms (483µs+8.28) within Class::MOP::Class::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Class/MOP/Class.pm:1082] which was called 43 times, avg 204µs/call: # 43 times (483µs+8.28ms) by Class::MOP::Class::add_around_method_modifier at line 1108, avg 204µs/call
my $fetch_and_prepare_method = sub {
1052439µs my ($self, $method_name) = @_;
10534383µs4316µs my $wrapped_metaclass = $self->wrapped_method_metaclass;
# spent 16µs making 43 calls to Class::MOP::Mixin::HasMethods::wrapped_method_metaclass, avg 360ns/call
1054 # fetch it locally
10554324µs43413µs my $method = $self->get_method($method_name);
# spent 413µs making 43 calls to Class::MOP::Mixin::HasMethods::get_method, avg 10µs/call
1056 # if we don't have local ...
10574315µs unless ($method) {
1058 # try to find the next method
10594338µs434.89ms $method = $self->find_next_method_by_name($method_name);
# spent 4.89ms making 43 calls to Class::MOP::Class::find_next_method_by_name, avg 114µs/call
1060 # die if it does not exist
1061437µs (defined $method)
1062 || $self->_throw_exception( MethodNameNotFoundInInheritanceHierarchy => class_name => $self->name,
1063 method_name => $method_name
1064 );
1065 # and now make sure to wrap it
1066 # even if it is already wrapped
1067 # because we need a new sub ref
106843126µs861.23ms $method = $wrapped_metaclass->wrap($method,
# spent 1.22ms making 43 calls to Class::MOP::Method::Wrapped::wrap, avg 28µs/call # spent 10µs making 43 calls to Class::MOP::Package::name, avg 233ns/call
1069 package_name => $self->name,
1070 name => $method_name,
1071 );
1072 }
1073 else {
1074 # now make sure we wrap it properly
1075 $method = $wrapped_metaclass->wrap($method,
1076 package_name => $self->name,
1077 name => $method_name,
1078 ) unless $method->isa($wrapped_metaclass);
1079 }
10804335µs431.73ms $self->add_method($method_name => $method);
# spent 1.73ms making 43 calls to Class::MOP::Mixin::HasMethods::add_method, avg 40µs/call
10814364µs return $method;
108213µs };
1083
1084 sub add_before_method_modifier {
1085 my ($self, $method_name, $method_modifier) = @_;
1086 (defined $method_name && length $method_name)
1087 || $self->_throw_exception( MethodModifierNeedsMethodName => class_name => $self->name );
1088 my $method = $fetch_and_prepare_method->($self, $method_name);
1089 $method->add_before_modifier(
1090 subname(':before' => $method_modifier)
1091 );
1092 }
1093
1094 sub add_after_method_modifier {
1095 my ($self, $method_name, $method_modifier) = @_;
1096 (defined $method_name && length $method_name)
1097 || $self->_throw_exception( MethodModifierNeedsMethodName => class_name => $self->name );
1098 my $method = $fetch_and_prepare_method->($self, $method_name);
1099 $method->add_after_modifier(
1100 subname(':after' => $method_modifier)
1101 );
1102 }
1103
1104
# spent 16.5ms (210µs+16.2) within Class::MOP::Class::add_around_method_modifier which was called 43 times, avg 383µs/call: # 43 times (210µs+16.2ms) by Class::MOP::MiniTrait::apply at line 21 of Class/MOP/MiniTrait.pm, avg 383µs/call
sub add_around_method_modifier {
11054312µs my ($self, $method_name, $method_modifier) = @_;
1106437µs (defined $method_name && length $method_name)
1107 || $self->_throw_exception( MethodModifierNeedsMethodName => class_name => $self->name );
11084340µs438.76ms my $method = $fetch_and_prepare_method->($self, $method_name);
# spent 8.76ms making 43 calls to Class::MOP::Class::__ANON__[Class/MOP/Class.pm:1082], avg 204µs/call
110943213µs867.48ms $method->add_around_modifier(
# spent 7.39ms making 43 calls to Class::MOP::Method::Wrapped::add_around_modifier, avg 172µs/call # spent 90µs making 43 calls to Sub::Name::subname, avg 2µs/call
1110 subname(':around' => $method_modifier)
1111 );
1112 }
1113
1114 # NOTE:
1115 # the methods above used to be named like this:
1116 # ${pkg}::${method}:(before|after|around)
1117 # but this proved problematic when using one modifier
1118 # to wrap multiple methods (something which is likely
1119 # to happen pretty regularly IMO). So instead of naming
1120 # it like this, I have chosen to just name them purely
1121 # with their modifier names, like so:
1122 # :(before|after|around)
1123 # The fact is that in a stack trace, it will be fairly
1124 # evident from the context what method they are attached
1125 # to, and so don't need the fully qualified name.
1126}
1127
11281200ns
# spent 8.20ms (1.12+7.08) within Class::MOP::Class::find_method_by_name which was called 90 times, avg 91µs/call: # 56 times (789µs+5.35ms) by Class::MOP::MiniTrait::apply at line 21 of Class/MOP/MiniTrait.pm, avg 110µs/call # 25 times (263µs+1.34ms) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 19 of Class/MOP/Mixin/HasMethods.pm, avg 64µs/call # 7 times (47µs+198µs) by Moose::BEGIN@43 at line 16 of Moose/Meta/Attribute/Native.pm, avg 35µs/call # once (12µs+140µs) by Moose::Meta::Class::_inline_BUILDARGS at line 325 of Moose/Meta/Class.pm # once (8µs+58µs) by Moose::Meta::Method::Destructor::is_needed at line 66 of Moose/Meta/Method/Destructor.pm
sub find_method_by_name {
11299021µs my ($self, $method_name) = @_;
11309031µs (defined $method_name && length $method_name)
1131 || $self->_throw_exception( MethodNameNotGiven => class_name => $self->name );
113290101µs90537µs foreach my $class ($self->_method_lookup_order) {
# spent 537µs making 90 calls to Class::MOP::Class::_method_lookup_order, avg 6µs/call
1133345370µs6906.54ms my $method = Class::MOP::Class->initialize($class)->get_method($method_name);
# spent 5.55ms making 345 calls to Class::MOP::Mixin::HasMethods::get_method, avg 16µs/call # spent 990µs making 345 calls to Class::MOP::Class::initialize, avg 3µs/call
1134345153µs return $method if defined $method;
1135 }
11364351µs return;
1137}
1138
1139
# spent 5.14ms (232µs+4.91) within Class::MOP::Class::get_all_methods which was called 7 times, avg 734µs/call: # 7 times (232µs+4.91ms) by Class::MOP::MiniTrait::apply at line 17 of Class/MOP/MiniTrait.pm, avg 734µs/call
sub get_all_methods {
114072µs my $self = shift;
1141
114272µs my %methods;
1143716µs753µs for my $class ( reverse $self->_method_lookup_order ) {
# spent 53µs making 7 calls to Class::MOP::Class::_method_lookup_order, avg 8µs/call
11441512µs1533µs my $meta = Class::MOP::Class->initialize($class);
# spent 33µs making 15 calls to Class::MOP::Class::initialize, avg 2µs/call
1145
114615180µs1154.82ms $methods{ $_->name } = $_ for $meta->_get_local_methods;
# spent 4.79ms making 15 calls to Class::MOP::Mixin::HasMethods::_get_local_methods, avg 320µs/call # spent 24µs making 100 calls to Class::MOP::Method::name, avg 235ns/call
1147 }
1148
1149723µs return values %methods;
1150}
1151
1152sub get_all_method_names {
1153 my $self = shift;
1154 map { $_->name } $self->get_all_methods;
1155}
1156
1157
# spent 104µs (25+79) within Class::MOP::Class::find_all_methods_by_name which was called 2 times, avg 52µs/call: # once (15µs+42µs) by Moose::Meta::Class::_inline_BUILDALL at line 483 of Moose/Meta/Class.pm # once (10µs+38µs) by Moose::Meta::Method::Destructor::_generate_DEMOLISHALL at line 116 of Moose/Meta/Method/Destructor.pm
sub find_all_methods_by_name {
11582700ns my ($self, $method_name) = @_;
11592800ns (defined $method_name && length $method_name)
1160 || $self->_throw_exception( MethodNameNotGiven => class_name => $self->name );
11612300ns my @methods;
116222µs29µs foreach my $class ($self->_method_lookup_order) {
# spent 9µs making 2 calls to Class::MOP::Class::_method_lookup_order, avg 5µs/call
1163 # fetch the meta-class ...
116464µs613µs my $meta = Class::MOP::Class->initialize($class);
# spent 13µs making 6 calls to Class::MOP::Class::initialize, avg 2µs/call
116565µs657µs push @methods => {
# spent 57µs making 6 calls to Class::MOP::Mixin::HasMethods::has_method, avg 10µs/call
1166 name => $method_name,
1167 class => $class,
1168 code => $meta->get_method($method_name)
1169 } if $meta->has_method($method_name);
1170 }
117124µs return @methods;
1172}
1173
1174
# spent 6.51ms (686µs+5.82) within Class::MOP::Class::find_next_method_by_name which was called 75 times, avg 87µs/call: # 43 times (429µs+4.46ms) by Class::MOP::Class::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Class/MOP/Class.pm:1082] at line 1059, avg 114µs/call # 32 times (256µs+1.36ms) by Class::MOP::Method::Inlined::can_be_inlined at line 34 of Class/MOP/Method/Inlined.pm, avg 51µs/call
sub find_next_method_by_name {
11757518µs my ($self, $method_name) = @_;
11767521µs (defined $method_name && length $method_name)
1177 || $self->_throw_exception( MethodNameNotGiven => class_name => $self->name );
117875107µs75355µs my @cpl = ($self->_method_lookup_order);
# spent 355µs making 75 calls to Class::MOP::Class::_method_lookup_order, avg 5µs/call
11797518µs shift @cpl; # discard ourselves
11807528µs foreach my $class (@cpl) {
1181150178µs3005.47ms my $method = Class::MOP::Class->initialize($class)->get_method($method_name);
# spent 5.11ms making 150 calls to Class::MOP::Mixin::HasMethods::get_method, avg 34µs/call # spent 353µs making 150 calls to Class::MOP::Class::initialize, avg 2µs/call
1182150143µs return $method if defined $method;
1183 }
118422µs return;
1185}
1186
1187
# spent 4µs within Class::MOP::Class::update_meta_instance_dependencies which was called 3 times, avg 2µs/call: # 3 times (4µs+0s) by Class::MOP::Class::_superclasses_updated at line 975, avg 2µs/call
sub update_meta_instance_dependencies {
11883700ns my $self = shift;
1189
119036µs if ( $self->{meta_instance_dependencies} ) {
1191 return $self->add_meta_instance_dependencies;
1192 }
1193}
1194
1195sub add_meta_instance_dependencies {
1196 my $self = shift;
1197
1198 $self->remove_meta_instance_dependencies;
1199
1200 my @attrs = $self->get_all_attributes();
1201
1202 my %seen;
1203 my @classes = grep { not $seen{ $_->name }++ }
1204 map { $_->associated_class } @attrs;
1205
1206 foreach my $class (@classes) {
1207 $class->add_dependent_meta_instance($self);
1208 }
1209
1210 $self->{meta_instance_dependencies} = \@classes;
1211}
1212
1213sub remove_meta_instance_dependencies {
1214 my $self = shift;
1215
1216 if ( my $classes = delete $self->{meta_instance_dependencies} ) {
1217 foreach my $class (@$classes) {
1218 $class->remove_dependent_meta_instance($self);
1219 }
1220
1221 return $classes;
1222 }
1223
1224 return;
1225
1226}
1227
1228sub add_dependent_meta_instance {
1229 my ( $self, $metaclass ) = @_;
1230 push @{ $self->{dependent_meta_instances} }, $metaclass;
1231}
1232
1233sub remove_dependent_meta_instance {
1234 my ( $self, $metaclass ) = @_;
1235 my $name = $metaclass->name;
1236 @$_ = grep { $_->name ne $name } @$_
1237 for $self->{dependent_meta_instances};
1238}
1239
1240
# spent 532µs (425+107) within Class::MOP::Class::invalidate_meta_instances which was called 135 times, avg 4µs/call: # 135 times (425µs+107µs) by Class::MOP::Class::_post_add_attribute at line 894, avg 4µs/call
sub invalidate_meta_instances {
124113520µs my $self = shift;
1242 $_->invalidate_meta_instance()
1243135370µs135107µs for $self, @{ $self->{dependent_meta_instances} };
# spent 107µs making 135 calls to Class::MOP::Class::invalidate_meta_instance, avg 796ns/call
1244}
1245
1246
# spent 107µs within Class::MOP::Class::invalidate_meta_instance which was called 135 times, avg 796ns/call: # 135 times (107µs+0s) by Class::MOP::Class::invalidate_meta_instances at line 1243, avg 796ns/call
sub invalidate_meta_instance {
124713514µs my $self = shift;
1248135198µs undef $self->{_meta_instance};
1249}
1250
1251# check if we can reinitialize
1252sub is_pristine {
1253 my $self = shift;
1254
1255 # if any local attr is defined
1256 return if $self->get_attribute_list;
1257
1258 # or any non-declared methods
1259 for my $method ( map { $self->get_method($_) } $self->get_method_list ) {
1260 return if $method->isa("Class::MOP::Method::Generated");
1261 # FIXME do we need to enforce this too? return unless $method->isa( $self->method_metaclass );
1262 }
1263
1264 return 1;
1265}
1266
1267## Class closing
1268
12698889µs
# spent 36µs within Class::MOP::Class::is_mutable which was called 88 times, avg 407ns/call: # 55 times (29µs+0s) by Class::MOP::Class::make_immutable at line 1293, avg 524ns/call # 21 times (4µs+0s) by DBIx::MultiStatementDo::BEGIN@8 at line 243 of Moose.pm, avg 200ns/call # 9 times (2µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 717 of Moose/Util/TypeConstraints.pm, avg 244ns/call # 3 times (600ns+0s) by DBIx::MultiStatementDo::BEGIN@8 at line 279 of Moose.pm, avg 200ns/call
sub is_mutable { 1 }
12703838µs
# spent 18µs within Class::MOP::Class::is_immutable which was called 38 times, avg 476ns/call: # 38 times (18µs+0s) by Class::MOP::Class::_real_ref_name at line 122, avg 476ns/call
sub is_immutable { 0 }
1271
1272sub immutable_options { %{ $_[0]{__immutable}{options} || {} } }
1273
1274
# spent 438µs (356+83) within Class::MOP::Class::_immutable_options which was called 55 times, avg 8µs/call: # 54 times (343µs+76µs) by Class::MOP::Class::make_immutable at line 1297, avg 8µs/call # once (13µs+6µs) by Moose::Meta::Class::_immutable_options at line 757 of Moose/Meta/Class.pm
sub _immutable_options {
12755525µs my ( $self, @args ) = @_;
1276
1277 return (
127855431µs22083µs inline_accessors => 1,
# spent 28µs making 54 calls to Class::MOP::Class::immutable_trait, avg 515ns/call # spent 21µs making 55 calls to Class::MOP::Class::constructor_name, avg 380ns/call # spent 15µs making 54 calls to Class::MOP::Class::destructor_class, avg 278ns/call # spent 13µs making 54 calls to Class::MOP::Class::constructor_class, avg 243ns/call # spent 2µs making 1 call to Moose::Meta::Class::immutable_trait # spent 2µs making 1 call to Moose::Meta::Class::constructor_class # spent 2µs making 1 call to Moose::Meta::Class::destructor_class
1279 inline_constructor => 1,
1280 inline_destructor => 0,
1281 debug => 0,
1282 immutable_trait => $self->immutable_trait,
1283 constructor_name => $self->constructor_name,
1284 constructor_class => $self->constructor_class,
1285 destructor_class => $self->destructor_class,
1286 @args,
1287 );
1288}
1289
1290
# spent 125ms (513µs+125) within Class::MOP::Class::make_immutable which was called 55 times, avg 2.28ms/call: # 21 times (193µs+56.7ms) by DBIx::MultiStatementDo::BEGIN@8 at line 243 of Moose.pm, avg 2.71ms/call # 14 times (96µs+14.4ms) by Moose::Exporter::BEGIN@8 at line 748 of Class/MOP.pm, avg 1.04ms/call # 9 times (121µs+28.1ms) by Moose::Meta::Attribute::BEGIN@16 at line 717 of Moose/Util/TypeConstraints.pm, avg 3.13ms/call # 5 times (30µs+214µs) by Moose::Exporter::BEGIN@8 at line 775 of Class/MOP.pm, avg 49µs/call # 3 times (23µs+8.21ms) by DBIx::MultiStatementDo::BEGIN@8 at line 279 of Moose.pm, avg 2.74ms/call # 2 times (32µs+-32µs) by Class::MOP::Class::_immutable_metaclass at line 1373, avg 0s/call # once (18µs+17.3ms) by BenchmarkAnything::Storage::Frontend::Lib::BEGIN@280 at line 114 of DBIx/MultiStatementDo.pm
sub make_immutable {
12915531µs my ( $self, @args ) = @_;
1292
12935539µs5529µs return $self unless $self->is_mutable;
# spent 29µs making 55 calls to Class::MOP::Class::is_mutable, avg 524ns/call
1294
12955595µs my ($file, $line) = (caller)[1..2];
1296
129755124µs11094.6ms $self->_initialize_immutable(
# spent 94.2ms making 55 calls to Class::MOP::Class::_initialize_immutable, avg 1.71ms/call # spent 419µs making 54 calls to Class::MOP::Class::_immutable_options, avg 8µs/call # spent 25µs making 1 call to Moose::Meta::Class::_immutable_options
1298 file => $file,
1299 line => $line,
1300 $self->_immutable_options(@args),
1301 );
13025553µs5530.3ms $self->_rebless_as_immutable(@args);
# spent 30.5ms making 55 calls to Class::MOP::Class::_rebless_as_immutable, avg 554µs/call, recursion: max depth 1, sum of overlapping time 122µs
1303
130455100µs return $self;
1305}
1306
1307sub make_mutable {
1308 my $self = shift;
1309
1310 if ( $self->is_immutable ) {
1311 my @args = $self->immutable_options;
1312 $self->_rebless_as_mutable();
1313 $self->_remove_inlined_code(@args);
1314 delete $self->{__immutable};
1315 return $self;
1316 }
1317 else {
1318 return;
1319 }
1320}
1321
1322
# spent 30.3ms (171µs+30.2) within Class::MOP::Class::_rebless_as_immutable which was called 55 times, avg 552µs/call: # 55 times (171µs+30.2ms) by Class::MOP::Class::make_immutable at line 1302, avg 552µs/call
sub _rebless_as_immutable {
13235532µs my ( $self, @args ) = @_;
1324
13255527µs $self->{__immutable}{original_class} = ref $self;
1326
132755120µs5530.2ms bless $self => $self->_immutable_metaclass(@args);
# spent 30.3ms making 55 calls to Class::MOP::Class::_immutable_metaclass, avg 551µs/call, recursion: max depth 1, sum of overlapping time 111µs
1328}
1329
1330
# spent 30.2ms (568µs+29.6) within Class::MOP::Class::_immutable_metaclass which was called 55 times, avg 549µs/call: # 55 times (568µs+29.6ms) by Class::MOP::Class::_rebless_as_immutable at line 1327, avg 549µs/call
sub _immutable_metaclass {
13315540µs my ( $self, %args ) = @_;
1332
13335516µs if ( my $class = $args{immutable_metaclass} ) {
1334 return $class;
1335 }
1336
133755104µs5517µs my $trait = $args{immutable_trait} = $self->immutable_trait
# spent 16µs making 54 calls to Class::MOP::Class::immutable_trait, avg 298ns/call # spent 1µs making 1 call to Moose::Meta::Class::immutable_trait
1338 || $self->_throw_exception( NoImmutableTraitSpecifiedForClass => class_name => $self->name,
1339 params => \%args
1340 );
1341
13425551µs55313µs my $meta = $self->meta;
# spent 313µs making 55 calls to Class::MOP::Object::meta, avg 6µs/call
13435558µs551.18ms my $meta_attr = $meta->find_attribute_by_name("immutable_trait");
# spent 1.18ms making 55 calls to Class::MOP::Class::find_attribute_by_name, avg 21µs/call
1344
1345557µs my $class_name;
1346
13475579µs5550µs if ( $meta_attr and $trait eq $meta_attr->default ) {
# spent 50µs making 55 calls to Class::MOP::Mixin::AttributeCore::default, avg 902ns/call
1348 # if the trait is the same as the default we try and pick a
1349 # predictable name for the immutable metaclass
1350 $class_name = 'Class::MOP::Class::Immutable::' . ref($self);
1351 }
1352 else {
1353 $class_name = join '::', 'Class::MOP::Class::Immutable::CustomTrait',
1354 $trait, 'ForMetaClass', ref($self);
1355 }
1356
135755113µs5554µs return $class_name
# spent 54µs making 55 calls to Class::MOP::does_metaclass_exist, avg 985ns/call
1358 if Class::MOP::does_metaclass_exist($class_name);
1359
1360 # If the metaclass is a subclass of CMOP::Class which has had
1361 # metaclass roles applied (via Moose), then we want to make sure
1362 # that we preserve that anonymous class (see Fey::ORM for an
1363 # example of where this matters).
136422µs219µs my $meta_name = $meta->_real_ref_name;
# spent 19µs making 2 calls to Class::MOP::Class::_real_ref_name, avg 9µs/call
1365
136625µs21.23ms my $immutable_meta = $meta_name->create(
# spent 1.23ms making 2 calls to Class::MOP::Class::create, avg 615µs/call
1367 $class_name,
1368 superclasses => [ ref $self ],
1369 );
1370
137126µs226.6ms Class::MOP::MiniTrait::apply( $immutable_meta, $trait );
# spent 26.6ms making 2 calls to Class::MOP::MiniTrait::apply, avg 13.3ms/call
1372
137328µs20s $immutable_meta->make_immutable(
# spent 214µs making 2 calls to Class::MOP::Class::make_immutable, avg 107µs/call, recursion: max depth 1, sum of overlapping time 214µs
1374 inline_constructor => 0,
1375 inline_accessors => 0,
1376 );
1377
137826µs return $class_name;
1379}
1380
1381sub _remove_inlined_code {
1382 my $self = shift;
1383
1384 $self->remove_method( $_->name ) for $self->_inlined_methods;
1385
1386 delete $self->{__immutable}{inlined_methods};
1387}
1388
1389sub _inlined_methods { @{ $_[0]{__immutable}{inlined_methods} || [] } }
1390
1391
# spent 59µs within Class::MOP::Class::_add_inlined_method which was called 32 times, avg 2µs/call: # 31 times (58µs+0s) by Class::MOP::Class::_inline_constructor at line 1468, avg 2µs/call # once (1µs+0s) by Class::MOP::Class::_inline_destructor at line 1510
sub _add_inlined_method {
1392327µs my ( $self, $method ) = @_;
1393
13943265µs push @{ $self->{__immutable}{inlined_methods} ||= [] }, $method;
1395}
1396
1397
# spent 94.2ms (331µs+93.9) within Class::MOP::Class::_initialize_immutable which was called 55 times, avg 1.71ms/call: # 55 times (331µs+93.9ms) by Class::MOP::Class::make_immutable at line 1297, avg 1.71ms/call
sub _initialize_immutable {
139855136µs my ( $self, %args ) = @_;
1399
14005546µs $self->{__immutable}{options} = \%args;
140155149µs5593.9ms $self->_install_inlined_code(%args);
# spent 93.9ms making 55 calls to Class::MOP::Class::_install_inlined_code, avg 1.71ms/call
1402}
1403
1404
# spent 93.9ms (303µs+93.6) within Class::MOP::Class::_install_inlined_code which was called 55 times, avg 1.71ms/call: # 55 times (303µs+93.6ms) by Class::MOP::Class::_initialize_immutable at line 1401, avg 1.71ms/call
sub _install_inlined_code {
14055559µs my ( $self, %args ) = @_;
1406
1407 # FIXME
14085567µs3334.8ms $self->_inline_accessors(%args) if $args{inline_accessors};
# spent 34.8ms making 33 calls to Class::MOP::Class::_inline_accessors, avg 1.05ms/call
14095568µs3158.3ms $self->_inline_constructor(%args) if $args{inline_constructor};
# spent 58.3ms making 31 calls to Class::MOP::Class::_inline_constructor, avg 1.88ms/call
14105597µs1524µs $self->_inline_destructor(%args) if $args{inline_destructor};
# spent 524µs making 1 call to Class::MOP::Class::_inline_destructor
1411}
1412
1413sub _rebless_as_mutable {
1414 my $self = shift;
1415
1416 bless $self, $self->_get_mutable_metaclass_name;
1417
1418 return $self;
1419}
1420
1421
# spent 34.8ms (301µs+34.5) within Class::MOP::Class::_inline_accessors which was called 33 times, avg 1.05ms/call: # 33 times (301µs+34.5ms) by Class::MOP::Class::_install_inlined_code at line 1408, avg 1.05ms/call
sub _inline_accessors {
1422335µs my $self = shift;
1423
14243380µs3398µs foreach my $attr_name ( $self->get_attribute_list ) {
# spent 98µs making 33 calls to Class::MOP::Mixin::HasAttributes::get_attribute_list, avg 3µs/call
142576124µs15234.4ms $self->get_attribute($attr_name)->install_accessors(1);
# spent 33.5ms making 75 calls to Class::MOP::Attribute::install_accessors, avg 447µs/call # spent 720µs making 1 call to Moose::Meta::Attribute::install_accessors # spent 169µs making 76 calls to Class::MOP::Mixin::HasAttributes::get_attribute, avg 2µs/call
1426 }
1427}
1428
1429
# spent 58.3ms (578µs+57.7) within Class::MOP::Class::_inline_constructor which was called 31 times, avg 1.88ms/call: # 31 times (578µs+57.7ms) by Class::MOP::Class::_install_inlined_code at line 1409, avg 1.88ms/call
sub _inline_constructor {
14303160µs my ( $self, %args ) = @_;
1431
1432318µs my $name = $args{constructor_name};
1433 # A class may not even have a constructor, and that's okay.
1434317µs return unless defined $name;
1435
14363130µs31466µs if ( $self->has_method($name) && !$args{replace_constructor} ) {
# spent 466µs making 31 calls to Class::MOP::Mixin::HasMethods::has_method, avg 15µs/call
1437 my $class = $self->name;
1438 warn "Not inlining a constructor for $class since it defines"
1439 . " its own constructor.\n"
1440 . "If you are certain you don't need to inline your"
1441 . " constructor, specify inline_constructor => 0 in your"
1442 . " call to $class->meta->make_immutable\n";
1443 return;
1444 }
1445
1446319µs my $constructor_class = $args{constructor_class};
1447
1448 {
14496214µs local $@;
14503143µs31895µs use_package_optimistically($constructor_class);
# spent 895µs making 31 calls to Module::Runtime::use_package_optimistically, avg 29µs/call
1451 }
1452
1453 my $constructor = $constructor_class->new(
1454 options => \%args,
1455 metaclass => $self,
1456 is_inline => 1,
1457 package_name => $self->name,
1458 name => $name,
1459 definition_context => {
1460 description => "constructor " . $self->name . "::" . $name,
1461 file => $args{file},
1462 line => $args{line},
1463 },
146431196µs9350.1ms );
# spent 48.0ms making 30 calls to Class::MOP::Method::Constructor::new, avg 1.60ms/call # spent 2.04ms making 1 call to Moose::Meta::Method::Constructor::new # spent 16µs making 62 calls to Class::MOP::Package::name, avg 250ns/call
1465
146631101µs312.03ms if ( $args{replace_constructor} or $constructor->can_be_inlined ) {
# spent 2.03ms making 31 calls to Class::MOP::Method::Inlined::can_be_inlined, avg 65µs/call
14673125µs314.18ms $self->add_method( $name => $constructor );
# spent 4.18ms making 31 calls to Class::MOP::Mixin::HasMethods::add_method, avg 135µs/call
14683130µs3158µs $self->_add_inlined_method($constructor);
# spent 58µs making 31 calls to Class::MOP::Class::_add_inlined_method, avg 2µs/call
1469 }
1470}
1471
1472
# spent 524µs (34+490) within Class::MOP::Class::_inline_destructor which was called: # once (34µs+490µs) by Class::MOP::Class::_install_inlined_code at line 1410
sub _inline_destructor {
147313µs my ( $self, %args ) = @_;
1474
1475 ( exists $args{destructor_class} && defined $args{destructor_class} )
14761700ns || $self->_throw_exception( NoDestructorClassSpecified => class_name => $self->name,
1477 params => \%args,
1478 );
1479
148011µs111µs if ( $self->has_method('DESTROY') && ! $args{replace_destructor} ) {
# spent 11µs making 1 call to Class::MOP::Mixin::HasMethods::has_method
1481 my $class = $self->name;
1482 warn "Not inlining a destructor for $class since it defines"
1483 . " its own destructor.\n";
1484 return;
1485 }
1486
14871500ns my $destructor_class = $args{destructor_class};
1488
1489 {
14902600ns local $@;
14911900ns126µs use_package_optimistically($destructor_class);
# spent 26µs making 1 call to Module::Runtime::use_package_optimistically
1492 }
1493
149413µs275µs return unless $destructor_class->is_needed($self);
# spent 74µs making 1 call to Moose::Meta::Method::Destructor::is_needed # spent 600ns making 1 call to Class::MOP::Method::__ANON__[Class/MOP/Method.pm:16]
1495
1496 my $destructor = $destructor_class->new(
1497 options => \%args,
1498 metaclass => $self,
1499 package_name => $self->name,
1500 name => 'DESTROY',
1501 definition_context => {
1502 description => "destructor " . $self->name . "::DESTROY",
1503 file => $args{file},
1504 line => $args{line},
1505 },
150618µs3265µs );
# spent 265µs making 1 call to Moose::Meta::Method::Destructor::new # spent 400ns making 2 calls to Class::MOP::Package::name, avg 200ns/call
1507
150816µs171µs if ( $args{replace_destructor} or $destructor->can_be_inlined ) {
# spent 71µs making 1 call to Class::MOP::Method::Inlined::can_be_inlined
15091900ns141µs $self->add_method( 'DESTROY' => $destructor );
# spent 41µs making 1 call to Class::MOP::Mixin::HasMethods::add_method
15101900ns11µs $self->_add_inlined_method($destructor);
# spent 1µs making 1 call to Class::MOP::Class::_add_inlined_method
1511 }
1512}
1513
151415µs1;
1515
1516# ABSTRACT: Class Meta Object
1517
1518__END__
 
# spent 5.59ms (5.24+346µs) within Class::MOP::Class::CORE:sort which was called 62 times, avg 90µs/call: # 31 times (3.95ms+172µs) by Class::MOP::Class::_inline_slot_initializers at line 593, avg 133µs/call # 31 times (1.29ms+174µs) by Class::MOP::Class::_eval_environment at line 709, avg 47µs/call
sub Class::MOP::Class::CORE:sort; # opcode