| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Attribute.pm |
| Statements | Executed 14312 statements in 209ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 124 | 3 | 2 | 84.5ms | 354ms | Moose::Meta::Attribute::new |
| 193 | 5 | 1 | 26.7ms | 716ms | Moose::Meta::Attribute::_process_accessors |
| 1 | 1 | 1 | 20.0ms | 270ms | Moose::Meta::Attribute::BEGIN@20 |
| 122 | 2 | 2 | 18.2ms | 145ms | Moose::Meta::Attribute::_process_options |
| 197 | 3 | 3 | 17.4ms | 64.2ms | Moose::Meta::Attribute::inline_set |
| 121 | 2 | 2 | 7.83ms | 2.85s | Moose::Meta::Attribute::interpolate_class_and_new (recurses: max depth 1, inclusive time 8.16ms) |
| 125 | 3 | 2 | 7.58ms | 928ms | Moose::Meta::Attribute::install_accessors |
| 1 | 1 | 1 | 6.51ms | 7.19ms | Moose::Meta::Attribute::BEGIN@17 |
| 122 | 1 | 1 | 5.24ms | 102ms | Moose::Meta::Attribute::_process_isa_option |
| 9 | 1 | 1 | 5.03ms | 69.7ms | Moose::Meta::Attribute::install_delegation |
| 123 | 2 | 1 | 4.13ms | 2.51s | Moose::Meta::Attribute::interpolate_class (recurses: max depth 1, inclusive time 120µs) |
| 123 | 1 | 1 | 3.39ms | 4.74ms | Moose::Meta::Attribute::_check_associated_methods |
| 122 | 1 | 1 | 3.07ms | 3.07ms | Moose::Meta::Attribute::_process_is_option |
| 1 | 1 | 1 | 2.77ms | 3.89ms | Moose::Meta::Attribute::BEGIN@18 |
| 124 | 2 | 1 | 2.38ms | 2.45ms | Moose::Meta::Attribute::_process_lazy_build_option |
| 122 | 1 | 1 | 2.15ms | 10.7ms | Moose::Meta::Attribute::_process_does_option |
| 2 | 1 | 1 | 2.14ms | 17.8ms | Moose::Meta::Attribute::clone |
| 203 | 2 | 2 | 1.94ms | 1.94ms | Moose::Meta::Attribute::accessor_metaclass |
| 122 | 1 | 1 | 1.82ms | 1.82ms | Moose::Meta::Attribute::_process_required_option |
| 122 | 1 | 1 | 1.72ms | 1.75ms | Moose::Meta::Attribute::_process_coerce_option |
| 14 | 1 | 1 | 1.71ms | 7.88ms | Moose::Meta::Attribute::initialize_instance_slot |
| 122 | 1 | 1 | 1.61ms | 1.61ms | Moose::Meta::Attribute::_process_lazy_option |
| 122 | 1 | 1 | 1.61ms | 1.61ms | Moose::Meta::Attribute::_process_trigger_option |
| 122 | 1 | 1 | 1.60ms | 1.60ms | Moose::Meta::Attribute::_process_auto_deref_option |
| 23 | 1 | 1 | 1.60ms | 13.4ms | Moose::Meta::Attribute::_make_delegation_method |
| 11 | 1 | 1 | 641µs | 2.63ms | Moose::Meta::Attribute::_coerce_and_verify |
| 11 | 1 | 1 | 612µs | 973µs | Moose::Meta::Attribute::_set_initial_slot_value |
| 124 | 1 | 1 | 547µs | 547µs | Moose::Meta::Attribute::CORE:sort (opcode) |
| 9 | 1 | 1 | 472µs | 1.78ms | Moose::Meta::Attribute::verify_against_type_constraint |
| 2 | 1 | 1 | 430µs | 18.4ms | Moose::Meta::Attribute::clone_and_inherit_options |
| 44 | 2 | 1 | 383µs | 383µs | Moose::Meta::Attribute::CORE:match (opcode) |
| 7 | 1 | 1 | 336µs | 422µs | Moose::Meta::Attribute::_canonicalize_handles |
| 5 | 1 | 1 | 327µs | 4.75ms | Moose::Meta::Attribute::does |
| 33 | 2 | 2 | 281µs | 281µs | Moose::Meta::Attribute::delegation_metaclass |
| 2 | 1 | 1 | 180µs | 464µs | Moose::Meta::Attribute::_weaken_value |
| 5 | 1 | 1 | 99µs | 3.52ms | Moose::Meta::Attribute::__ANON__[:40] |
| 1 | 1 | 1 | 77µs | 96µs | Moose::Meta::Attribute::BEGIN@4 |
| 1 | 1 | 1 | 39µs | 107µs | Moose::Meta::Attribute::BEGIN@5 |
| 1 | 1 | 1 | 39µs | 218µs | Moose::Meta::Attribute::BEGIN@10 |
| 1 | 1 | 1 | 39µs | 73µs | Moose::Meta::Attribute::BEGIN@16 |
| 1 | 1 | 1 | 37µs | 164µs | Moose::Meta::Attribute::BEGIN@9 |
| 1 | 1 | 1 | 37µs | 41.0ms | Moose::Meta::Attribute::BEGIN@23 |
| 1 | 1 | 1 | 36µs | 222µs | Moose::Meta::Attribute::BEGIN@8 |
| 1 | 1 | 1 | 31µs | 31µs | Moose::Meta::Attribute::BEGIN@21 |
| 2 | 1 | 1 | 26µs | 26µs | Moose::Meta::Attribute::illegal_options_for_inheritance |
| 1 | 1 | 1 | 25µs | 25µs | Moose::Meta::Attribute::BEGIN@19 |
| 1 | 1 | 1 | 19µs | 19µs | Moose::Meta::Attribute::BEGIN@11 |
| 1 | 1 | 1 | 19µs | 19µs | Moose::Meta::Attribute::BEGIN@7 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::Custom::Moose::register_implementation |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::__ANON__[:306] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::__ANON__[:529] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::__ANON__[:752] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::_call_builder |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::_find_delegate_metaclass |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::_get_delegate_method_list |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::get_value |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::remove_accessors |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::remove_delegation |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::set_value |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::throw_error |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Moose::Meta::Attribute; | ||||
| 3 | |||||
| 4 | 3 | 103µs | 2 | 114µs | # spent 96µs (77+19) within Moose::Meta::Attribute::BEGIN@4 which was called:
# once (77µs+19µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 4 # spent 96µs making 1 call to Moose::Meta::Attribute::BEGIN@4
# spent 19µs making 1 call to strict::import |
| 5 | 3 | 98µs | 2 | 176µs | # spent 107µs (39+68) within Moose::Meta::Attribute::BEGIN@5 which was called:
# once (39µs+68µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 5 # spent 107µs making 1 call to Moose::Meta::Attribute::BEGIN@5
# spent 68µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 3 | 91µs | 1 | 19µs | # spent 19µs within Moose::Meta::Attribute::BEGIN@7 which was called:
# once (19µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 7 # spent 19µs making 1 call to Moose::Meta::Attribute::BEGIN@7 |
| 8 | 3 | 106µs | 2 | 408µs | # spent 222µs (36+186) within Moose::Meta::Attribute::BEGIN@8 which was called:
# once (36µs+186µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 8 # spent 222µs making 1 call to Moose::Meta::Attribute::BEGIN@8
# spent 186µs making 1 call to Exporter::import |
| 9 | 3 | 97µs | 2 | 291µs | # spent 164µs (37+127) within Moose::Meta::Attribute::BEGIN@9 which was called:
# once (37µs+127µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 9 # spent 164µs making 1 call to Moose::Meta::Attribute::BEGIN@9
# spent 127µs making 1 call to Exporter::import |
| 10 | 3 | 93µs | 2 | 398µs | # spent 218µs (39+179) within Moose::Meta::Attribute::BEGIN@10 which was called:
# once (39µs+179µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 10 # spent 218µs making 1 call to Moose::Meta::Attribute::BEGIN@10
# spent 180µs making 1 call to Exporter::import |
| 11 | 3 | 159µs | 1 | 19µs | # spent 19µs within Moose::Meta::Attribute::BEGIN@11 which was called:
# once (19µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 11 # spent 19µs making 1 call to Moose::Meta::Attribute::BEGIN@11 |
| 12 | |||||
| 13 | 1 | 5µs | our $VERSION = '1.19'; | ||
| 14 | 1 | 4µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 15 | |||||
| 16 | 3 | 117µs | 2 | 107µs | # spent 73µs (39+34) within Moose::Meta::Attribute::BEGIN@16 which was called:
# once (39µs+34µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 16 # spent 73µs making 1 call to Moose::Meta::Attribute::BEGIN@16
# spent 34µs making 1 call to Package::DeprecationManager::__ANON__[Package/DeprecationManager.pm:61] |
| 17 | 3 | 506µs | 1 | 7.19ms | # spent 7.19ms (6.51+682µs) within Moose::Meta::Attribute::BEGIN@17 which was called:
# once (6.51ms+682µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 17 # spent 7.19ms making 1 call to Moose::Meta::Attribute::BEGIN@17 |
| 18 | 3 | 459µs | 1 | 3.89ms | # spent 3.89ms (2.77+1.12) within Moose::Meta::Attribute::BEGIN@18 which was called:
# once (2.77ms+1.12ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 18 # spent 3.89ms making 1 call to Moose::Meta::Attribute::BEGIN@18 |
| 19 | 3 | 80µs | 1 | 25µs | # spent 25µs within Moose::Meta::Attribute::BEGIN@19 which was called:
# once (25µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 19 # spent 25µs making 1 call to Moose::Meta::Attribute::BEGIN@19 |
| 20 | 3 | 455µs | 1 | 270ms | # spent 270ms (20.0+250) within Moose::Meta::Attribute::BEGIN@20 which was called:
# once (20.0ms+250ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 20 # spent 270ms making 1 call to Moose::Meta::Attribute::BEGIN@20 |
| 21 | 3 | 111µs | 1 | 31µs | # spent 31µs within Moose::Meta::Attribute::BEGIN@21 which was called:
# once (31µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 21 # spent 31µs making 1 call to Moose::Meta::Attribute::BEGIN@21 |
| 22 | |||||
| 23 | 3 | 14.2ms | 2 | 81.9ms | # spent 41.0ms (37µs+40.9) within Moose::Meta::Attribute::BEGIN@23 which was called:
# once (37µs+40.9ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 23 # spent 41.0ms making 1 call to Moose::Meta::Attribute::BEGIN@23
# spent 40.9ms making 1 call to base::import |
| 24 | |||||
| 25 | 1 | 16µs | 1 | 11.3ms | Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); # spent 11.3ms making 1 call to Class::MOP::MiniTrait::apply |
| 26 | |||||
| 27 | 1 | 45µs | 2 | 3.30ms | __PACKAGE__->meta->add_attribute('traits' => ( # spent 3.22ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 84µs making 1 call to Class::MOP::Object::meta |
| 28 | reader => 'applied_traits', | ||||
| 29 | predicate => 'has_applied_traits', | ||||
| 30 | )); | ||||
| 31 | |||||
| 32 | # we need to have a ->does method in here to | ||||
| 33 | # more easily support traits, and the introspection | ||||
| 34 | # of those traits. We extend the does check to look | ||||
| 35 | # for metatrait aliases. | ||||
| 36 | # spent 4.75ms (327µs+4.43) within Moose::Meta::Attribute::does which was called 5 times, avg 951µs/call:
# 5 times (327µs+4.43ms) by Moose::Meta::Attribute::interpolate_class at line 114, avg 951µs/call | ||||
| 37 | 5 | 27µs | my ($self, $role_name) = @_; | ||
| 38 | # spent 3.52ms (99µs+3.42) within Moose::Meta::Attribute::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Attribute.pm:40] which was called 5 times, avg 705µs/call:
# 5 times (99µs+3.42ms) by Try::Tiny::try at line 71 of Try/Tiny.pm, avg 705µs/call | ||||
| 39 | 5 | 97µs | 5 | 3.42ms | Moose::Util::resolve_metatrait_alias(Attribute => $role_name) # spent 3.42ms making 5 calls to Moose::Util::resolve_metatrait_alias, avg 685µs/call |
| 40 | 5 | 120µs | 5 | 3.89ms | }; # spent 3.89ms making 5 calls to Try::Tiny::try, avg 779µs/call |
| 41 | 5 | 15µs | return 0 if !defined($name); # failed to load class | ||
| 42 | 5 | 149µs | 5 | 532µs | return $self->Moose::Object::does($name); # spent 532µs making 5 calls to Moose::Object::does, avg 106µs/call |
| 43 | } | ||||
| 44 | |||||
| 45 | sub throw_error { | ||||
| 46 | my $self = shift; | ||||
| 47 | my $class = ( ref $self && $self->associated_class ) || "Moose::Meta::Class"; | ||||
| 48 | unshift @_, "message" if @_ % 2 == 1; | ||||
| 49 | unshift @_, attr => $self if ref $self; | ||||
| 50 | unshift @_, $class; | ||||
| 51 | my $handler = $class->can("throw_error"); # to avoid incrementing depth by 1 | ||||
| 52 | goto $handler; | ||||
| 53 | } | ||||
| 54 | |||||
| 55 | # spent 354ms (84.5+269) within Moose::Meta::Attribute::new which was called 124 times, avg 2.85ms/call:
# 121 times (82.5ms+262ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 83, avg 2.85ms/call
# 2 times (1.30ms+1.24ms) by Moose::Meta::Attribute::clone at line 239, avg 1.27ms/call
# once (702µs+5.77ms) by Moose::BEGIN@21 at line 20 of Moose/Meta/TypeCoercion.pm | ||||
| 56 | 124 | 1.47ms | my ($class, $name, %options) = @_; | ||
| 57 | 124 | 1.84ms | 122 | 147ms | $class->_process_options($name, \%options) unless $options{__hack_no_process_options}; # used from clone()... YECHKKK FIXME ICKY YUCK GROSS # spent 143ms making 120 calls to Moose::Meta::Attribute::_process_options, avg 1.19ms/call
# spent 1.70ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::_process_options
# spent 1.61ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::_process_options |
| 58 | |||||
| 59 | 124 | 483µs | delete $options{__hack_no_process_options}; | ||
| 60 | |||||
| 61 | my %attrs = | ||||
| 62 | ( map { $_ => 1 } | ||||
| 63 | 3476 | 34.8ms | 3476 | 34.6ms | grep { defined } # spent 34.6ms making 3476 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call |
| 64 | 124 | 23.6ms | 248 | 25.7ms | map { $_->init_arg() } # spent 11.4ms making 119 calls to Class::MOP::Object::meta, avg 96µs/call
# spent 9.46ms making 118 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 80µs/call
# spent 4.37ms making 6 calls to Class::MOP::Class::get_all_attributes, avg 728µs/call
# spent 287µs making 3 calls to Class::MOP::Class::__ANON__::SERIAL::1::meta, avg 96µs/call
# spent 136µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::meta
# spent 97µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::meta |
| 65 | $class->meta()->get_all_attributes() | ||||
| 66 | ); | ||||
| 67 | |||||
| 68 | 124 | 3.95ms | 124 | 547µs | my @bad = sort grep { ! $attrs{$_} } keys %options; # spent 547µs making 124 calls to Moose::Meta::Attribute::CORE:sort, avg 4µs/call |
| 69 | |||||
| 70 | 124 | 360µs | if (@bad) | ||
| 71 | { | ||||
| 72 | Carp::cluck "Found unknown argument(s) passed to '$name' attribute constructor in '$class': @bad"; | ||||
| 73 | } | ||||
| 74 | |||||
| 75 | 124 | 7.23ms | 124 | 61.6ms | return $class->SUPER::new($name, %options); # spent 61.6ms making 124 calls to Class::MOP::Attribute::new, avg 497µs/call |
| 76 | } | ||||
| 77 | |||||
| 78 | # spent 2.85s (7.83ms+2.84) within Moose::Meta::Attribute::interpolate_class_and_new which was called 121 times, avg 23.6ms/call:
# 114 times (7.37ms+2.84s) by Moose::Meta::Class::_process_new_attribute at line 438 of Moose/Meta/Class.pm, avg 25.0ms/call
# 7 times (465µs+5.15ms) by Moose::Meta::Role::Attribute::attribute_for_class at line 67 of Moose/Meta/Role/Attribute.pm, avg 803µs/call | ||||
| 79 | 121 | 1.39ms | my ($class, $name, %args) = @_; | ||
| 80 | |||||
| 81 | 121 | 1.97ms | 121 | 2.51s | my ( $new_class, @traits ) = $class->interpolate_class(\%args); # spent 2.51s making 121 calls to Moose::Meta::Attribute::interpolate_class, avg 20.7ms/call, recursion: max depth 1, sum of overlapping time 120µs |
| 82 | |||||
| 83 | 121 | 3.95ms | 121 | 345ms | $new_class->new($name, %args, ( scalar(@traits) ? ( traits => \@traits ) : () ) ); # spent 345ms making 121 calls to Moose::Meta::Attribute::new, avg 2.85ms/call |
| 84 | } | ||||
| 85 | |||||
| 86 | # spent 2.51s (4.13ms+2.50) within Moose::Meta::Attribute::interpolate_class which was called 123 times, avg 20.4ms/call:
# 121 times (4.08ms+2.50s) by Moose::Meta::Attribute::interpolate_class_and_new at line 81, avg 20.7ms/call
# 2 times (59µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 209, avg 30µs/call | ||||
| 87 | 123 | 420µs | my ($class, $options) = @_; | ||
| 88 | |||||
| 89 | 123 | 336µs | $class = ref($class) || $class; | ||
| 90 | |||||
| 91 | 123 | 598µs | if ( my $metaclass_name = delete $options->{metaclass} ) { | ||
| 92 | my $new_class = Moose::Util::resolve_metaclass_alias( Attribute => $metaclass_name ); | ||||
| 93 | |||||
| 94 | if ( $class ne $new_class ) { | ||||
| 95 | if ( $new_class->can("interpolate_class") ) { | ||||
| 96 | return $new_class->interpolate_class($options); | ||||
| 97 | } else { | ||||
| 98 | $class = $new_class; | ||||
| 99 | } | ||||
| 100 | } | ||||
| 101 | } | ||||
| 102 | |||||
| 103 | 123 | 257µs | my @traits; | ||
| 104 | |||||
| 105 | 123 | 419µs | if (my $traits = $options->{traits}) { | ||
| 106 | 5 | 11µs | my $i = 0; | ||
| 107 | 5 | 26µs | while ($i < @$traits) { | ||
| 108 | 5 | 19µs | my $trait = $traits->[$i++]; | ||
| 109 | 5 | 10µs | next if ref($trait); # options to a trait we discarded | ||
| 110 | |||||
| 111 | 5 | 67µs | 5 | 2.37s | $trait = Moose::Util::resolve_metatrait_alias(Attribute => $trait) # spent 2.37s making 5 calls to Moose::Util::resolve_metatrait_alias, avg 474ms/call |
| 112 | || $trait; | ||||
| 113 | |||||
| 114 | 5 | 72µs | 5 | 4.75ms | next if $class->does($trait); # spent 4.75ms making 5 calls to Moose::Meta::Attribute::does, avg 951µs/call |
| 115 | |||||
| 116 | 5 | 23µs | push @traits, $trait; | ||
| 117 | |||||
| 118 | # are there options? | ||||
| 119 | 5 | 37µs | push @traits, $traits->[$i++] | ||
| 120 | if $traits->[$i] && ref($traits->[$i]); | ||||
| 121 | } | ||||
| 122 | |||||
| 123 | 5 | 25µs | if (@traits) { | ||
| 124 | 5 | 115µs | 5 | 129ms | my $anon_class = Moose::Meta::Class->create_anon_class( # spent 129ms making 5 calls to Moose::Meta::Class::create_anon_class, avg 25.8ms/call |
| 125 | superclasses => [ $class ], | ||||
| 126 | roles => [ @traits ], | ||||
| 127 | cache => 1, | ||||
| 128 | ); | ||||
| 129 | |||||
| 130 | 5 | 119µs | 5 | 37µs | $class = $anon_class->name; # spent 37µs making 5 calls to Class::MOP::Package::name, avg 7µs/call |
| 131 | } | ||||
| 132 | } | ||||
| 133 | |||||
| 134 | 123 | 2.17ms | return ( wantarray ? ( $class, @traits ) : $class ); | ||
| 135 | } | ||||
| 136 | |||||
| 137 | # ... | ||||
| 138 | |||||
| 139 | # method-generating options shouldn't be overridden | ||||
| 140 | # spent 26µs within Moose::Meta::Attribute::illegal_options_for_inheritance which was called 2 times, avg 13µs/call:
# 2 times (26µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 168, avg 13µs/call | ||||
| 141 | 2 | 38µs | qw(reader writer accessor clearer predicate) | ||
| 142 | } | ||||
| 143 | |||||
| 144 | # NOTE/TODO | ||||
| 145 | # This method *must* be able to handle | ||||
| 146 | # Class::MOP::Attribute instances as | ||||
| 147 | # well. Yes, I know that is wrong, but | ||||
| 148 | # apparently we didn't realize it was | ||||
| 149 | # doing that and now we have some code | ||||
| 150 | # which is dependent on it. The real | ||||
| 151 | # solution of course is to push this | ||||
| 152 | # feature back up into Class::MOP::Attribute | ||||
| 153 | # but I not right now, I am too lazy. | ||||
| 154 | # However if you are reading this and | ||||
| 155 | # looking for something to do,.. please | ||||
| 156 | # be my guest. | ||||
| 157 | # - stevan | ||||
| 158 | # spent 18.4ms (430µs+18.0) within Moose::Meta::Attribute::clone_and_inherit_options which was called 2 times, avg 9.22ms/call:
# 2 times (430µs+18.0ms) by Moose::Meta::Class::_process_inherited_attribute at line 446 of Moose/Meta/Class.pm, avg 9.22ms/call | ||||
| 159 | 2 | 15µs | my ($self, %options) = @_; | ||
| 160 | |||||
| 161 | # NOTE: | ||||
| 162 | # we may want to extends a Class::MOP::Attribute | ||||
| 163 | # in which case we need to be able to use the | ||||
| 164 | # core set of legal options that have always | ||||
| 165 | # been here. But we allows Moose::Meta::Attribute | ||||
| 166 | # instances to changes them. | ||||
| 167 | # - SL | ||||
| 168 | 2 | 77µs | 4 | 40µs | my @illegal_options = $self->can('illegal_options_for_inheritance') # spent 26µs making 2 calls to Moose::Meta::Attribute::illegal_options_for_inheritance, avg 13µs/call
# spent 14µs making 2 calls to UNIVERSAL::can, avg 7µs/call |
| 169 | ? $self->illegal_options_for_inheritance | ||||
| 170 | : (); | ||||
| 171 | |||||
| 172 | 2 | 18µs | my @found_illegal_options = grep { exists $options{$_} && exists $self->{$_} ? $_ : undef } @illegal_options; | ||
| 173 | 2 | 7µs | (scalar @found_illegal_options == 0) | ||
| 174 | || $self->throw_error("Illegal inherited options => (" . (join ', ' => @found_illegal_options) . ")", data => \%options); | ||||
| 175 | |||||
| 176 | 2 | 5µs | if ($options{isa}) { | ||
| 177 | my $type_constraint; | ||||
| 178 | if (blessed($options{isa}) && $options{isa}->isa('Moose::Meta::TypeConstraint')) { | ||||
| 179 | $type_constraint = $options{isa}; | ||||
| 180 | } | ||||
| 181 | else { | ||||
| 182 | $type_constraint = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($options{isa}); | ||||
| 183 | (defined $type_constraint) | ||||
| 184 | || $self->throw_error("Could not find the type constraint '" . $options{isa} . "'", data => $options{isa}); | ||||
| 185 | } | ||||
| 186 | |||||
| 187 | $options{type_constraint} = $type_constraint; | ||||
| 188 | } | ||||
| 189 | |||||
| 190 | 2 | 6µs | if ($options{does}) { | ||
| 191 | my $type_constraint; | ||||
| 192 | if (blessed($options{does}) && $options{does}->isa('Moose::Meta::TypeConstraint')) { | ||||
| 193 | $type_constraint = $options{does}; | ||||
| 194 | } | ||||
| 195 | else { | ||||
| 196 | $type_constraint = Moose::Util::TypeConstraints::find_or_create_does_type_constraint($options{does}); | ||||
| 197 | (defined $type_constraint) | ||||
| 198 | || $self->throw_error("Could not find the type constraint '" . $options{does} . "'", data => $options{does}); | ||||
| 199 | } | ||||
| 200 | |||||
| 201 | $options{type_constraint} = $type_constraint; | ||||
| 202 | } | ||||
| 203 | |||||
| 204 | # NOTE: | ||||
| 205 | # this doesn't apply to Class::MOP::Attributes, | ||||
| 206 | # so we can ignore it for them. | ||||
| 207 | # - SL | ||||
| 208 | 2 | 46µs | 2 | 13µs | if ($self->can('interpolate_class')) { # spent 13µs making 2 calls to UNIVERSAL::can, avg 7µs/call |
| 209 | 2 | 35µs | 2 | 59µs | ( $options{metaclass}, my @traits ) = $self->interpolate_class(\%options); # spent 59µs making 2 calls to Moose::Meta::Attribute::interpolate_class, avg 30µs/call |
| 210 | |||||
| 211 | 2 | 4µs | my %seen; | ||
| 212 | 2 | 31µs | 2 | 26µs | my @all_traits = grep { $seen{$_}++ } @{ $self->applied_traits || [] }, @traits; # spent 26µs making 2 calls to Moose::Meta::Attribute::applied_traits, avg 13µs/call |
| 213 | 2 | 8µs | $options{traits} = \@all_traits if @all_traits; | ||
| 214 | } | ||||
| 215 | |||||
| 216 | # This method can be called on a CMOP::Attribute object, so we need to | ||||
| 217 | # make sure we can call this method. | ||||
| 218 | 2 | 113µs | 6 | 58µs | $self->_process_lazy_build_option( $self->name, \%options ) # spent 31µs making 2 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 16µs/call
# spent 14µs making 2 calls to UNIVERSAL::can, avg 7µs/call
# spent 13µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 7µs/call |
| 219 | if $self->can('_process_lazy_build_option'); | ||||
| 220 | |||||
| 221 | 2 | 70µs | 2 | 17.8ms | $self->clone(%options); # spent 17.8ms making 2 calls to Moose::Meta::Attribute::clone, avg 8.90ms/call |
| 222 | } | ||||
| 223 | |||||
| 224 | # spent 17.8ms (2.14+15.7) within Moose::Meta::Attribute::clone which was called 2 times, avg 8.90ms/call:
# 2 times (2.14ms+15.7ms) by Moose::Meta::Attribute::clone_and_inherit_options at line 221, avg 8.90ms/call | ||||
| 225 | 2 | 16µs | my ( $self, %params ) = @_; | ||
| 226 | |||||
| 227 | 2 | 11µs | my $class = delete $params{metaclass} || ref $self; | ||
| 228 | |||||
| 229 | 2 | 5µs | my ( @init, @non_init ); | ||
| 230 | |||||
| 231 | 58 | 816µs | 60 | 9.15ms | foreach my $attr ( grep { $_->has_value($self) } Class::MOP::class_of($self)->get_all_attributes ) { # spent 8.94ms making 56 calls to Class::MOP::Attribute::has_value, avg 160µs/call
# spent 144µs making 2 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 72µs/call
# spent 68µs making 2 calls to Class::MOP::class_of, avg 34µs/call |
| 232 | 21 | 336µs | 21 | 202µs | push @{ $attr->has_init_arg ? \@init : \@non_init }, $attr; # spent 202µs making 21 calls to Class::MOP::Mixin::AttributeCore::has_init_arg, avg 10µs/call |
| 233 | } | ||||
| 234 | |||||
| 235 | 23 | 504µs | 42 | 3.77ms | my %new_params = ( ( map { $_->init_arg => $_->get_value($self) } @init ), %params ); # spent 3.56ms making 21 calls to Class::MOP::Attribute::get_value, avg 170µs/call
# spent 206µs making 21 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call |
| 236 | |||||
| 237 | 2 | 12µs | my $name = delete $new_params{name}; | ||
| 238 | |||||
| 239 | 2 | 62µs | 2 | 2.55ms | my $clone = $class->new($name, %new_params, __hack_no_process_options => 1 ); # spent 2.55ms making 2 calls to Moose::Meta::Attribute::new, avg 1.27ms/call |
| 240 | |||||
| 241 | 2 | 15µs | foreach my $attr ( @non_init ) { | ||
| 242 | $attr->set_value($clone, $attr->get_value($self)); | ||||
| 243 | } | ||||
| 244 | |||||
| 245 | 2 | 46µs | return $clone; | ||
| 246 | } | ||||
| 247 | |||||
| 248 | # spent 145ms (18.2+126) within Moose::Meta::Attribute::_process_options which was called 122 times, avg 1.18ms/call:
# 120 times (17.7ms+126ms) by Moose::Meta::Attribute::new at line 57, avg 1.19ms/call
# 2 times (463µs+825µs) by Class::MOP::Method::Wrapped::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm:49] at line 48 of Class/MOP/Method/Wrapped.pm, avg 644µs/call | ||||
| 249 | 122 | 509µs | my ( $class, $name, $options ) = @_; | ||
| 250 | |||||
| 251 | 122 | 1.32ms | 122 | 3.07ms | $class->_process_is_option( $name, $options ); # spent 3.07ms making 122 calls to Moose::Meta::Attribute::_process_is_option, avg 25µs/call |
| 252 | 122 | 1.56ms | 122 | 102ms | $class->_process_isa_option( $name, $options ); # spent 102ms making 122 calls to Moose::Meta::Attribute::_process_isa_option, avg 834µs/call |
| 253 | 122 | 1.60ms | 122 | 10.7ms | $class->_process_does_option( $name, $options ); # spent 10.7ms making 122 calls to Moose::Meta::Attribute::_process_does_option, avg 87µs/call |
| 254 | 122 | 1.45ms | 122 | 1.75ms | $class->_process_coerce_option( $name, $options ); # spent 1.75ms making 122 calls to Moose::Meta::Attribute::_process_coerce_option, avg 14µs/call |
| 255 | 122 | 1.39ms | 122 | 1.61ms | $class->_process_trigger_option( $name, $options ); # spent 1.61ms making 122 calls to Moose::Meta::Attribute::_process_trigger_option, avg 13µs/call |
| 256 | 122 | 1.46ms | 122 | 1.60ms | $class->_process_auto_deref_option( $name, $options ); # spent 1.60ms making 122 calls to Moose::Meta::Attribute::_process_auto_deref_option, avg 13µs/call |
| 257 | 122 | 1.44ms | 122 | 2.42ms | $class->_process_lazy_build_option( $name, $options ); # spent 2.42ms making 122 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 20µs/call |
| 258 | 122 | 1.39ms | 122 | 1.61ms | $class->_process_lazy_option( $name, $options ); # spent 1.61ms making 122 calls to Moose::Meta::Attribute::_process_lazy_option, avg 13µs/call |
| 259 | 122 | 2.61ms | 122 | 1.82ms | $class->_process_required_option( $name, $options ); # spent 1.82ms making 122 calls to Moose::Meta::Attribute::_process_required_option, avg 15µs/call |
| 260 | } | ||||
| 261 | |||||
| 262 | # spent 3.07ms within Moose::Meta::Attribute::_process_is_option which was called 122 times, avg 25µs/call:
# 122 times (3.07ms+0s) by Moose::Meta::Attribute::_process_options at line 251, avg 25µs/call | ||||
| 263 | 122 | 434µs | my ( $class, $name, $options ) = @_; | ||
| 264 | |||||
| 265 | 122 | 457µs | return unless $options->{is}; | ||
| 266 | |||||
| 267 | ### ------------------------- | ||||
| 268 | ## is => ro, writer => _foo # turns into (reader => foo, writer => _foo) as before | ||||
| 269 | ## is => rw, writer => _foo # turns into (reader => foo, writer => _foo) | ||||
| 270 | ## is => rw, accessor => _foo # turns into (accessor => _foo) | ||||
| 271 | ## is => ro, accessor => _foo # error, accesor is rw | ||||
| 272 | ### ------------------------- | ||||
| 273 | |||||
| 274 | 115 | 1.95ms | if ( $options->{is} eq 'ro' ) { | ||
| 275 | 91 | 242µs | $class->throw_error( | ||
| 276 | "Cannot define an accessor name on a read-only attribute, accessors are read/write", | ||||
| 277 | data => $options ) | ||||
| 278 | if exists $options->{accessor}; | ||||
| 279 | 91 | 510µs | $options->{reader} ||= $name; | ||
| 280 | } | ||||
| 281 | elsif ( $options->{is} eq 'rw' ) { | ||||
| 282 | if ( $options->{writer} ) { | ||||
| 283 | $options->{reader} ||= $name; | ||||
| 284 | } | ||||
| 285 | else { | ||||
| 286 | 24 | 130µs | $options->{accessor} ||= $name; | ||
| 287 | } | ||||
| 288 | } | ||||
| 289 | elsif ( $options->{is} eq 'bare' ) { | ||||
| 290 | return; | ||||
| 291 | # do nothing, but don't complain (later) about missing methods | ||||
| 292 | } | ||||
| 293 | else { | ||||
| 294 | $class->throw_error( "I do not understand this option (is => " | ||||
| 295 | . $options->{is} | ||||
| 296 | . ") on attribute ($name)", data => $options->{is} ); | ||||
| 297 | } | ||||
| 298 | } | ||||
| 299 | |||||
| 300 | # spent 102ms (5.24+96.6) within Moose::Meta::Attribute::_process_isa_option which was called 122 times, avg 834µs/call:
# 122 times (5.24ms+96.6ms) by Moose::Meta::Attribute::_process_options at line 252, avg 834µs/call | ||||
| 301 | 122 | 541µs | my ( $class, $name, $options ) = @_; | ||
| 302 | |||||
| 303 | 122 | 595µs | return unless exists $options->{isa}; | ||
| 304 | |||||
| 305 | 100 | 234µs | if ( exists $options->{does} ) { | ||
| 306 | if ( try { $options->{isa}->can('does') } ) { | ||||
| 307 | ( $options->{isa}->does( $options->{does} ) ) | ||||
| 308 | || $class->throw_error( | ||||
| 309 | "Cannot have an isa option and a does option if the isa does not do the does on attribute ($name)", | ||||
| 310 | data => $options ); | ||||
| 311 | } | ||||
| 312 | else { | ||||
| 313 | $class->throw_error( | ||||
| 314 | "Cannot have an isa option which cannot ->does() on attribute ($name)", | ||||
| 315 | data => $options ); | ||||
| 316 | } | ||||
| 317 | } | ||||
| 318 | |||||
| 319 | # allow for anon-subtypes here ... | ||||
| 320 | 100 | 3.12ms | 100 | 550µs | if ( blessed( $options->{isa} ) # spent 550µs making 100 calls to Scalar::Util::blessed, avg 5µs/call |
| 321 | && $options->{isa}->isa('Moose::Meta::TypeConstraint') ) { | ||||
| 322 | $options->{type_constraint} = $options->{isa}; | ||||
| 323 | } | ||||
| 324 | else { | ||||
| 325 | 100 | 1.70ms | 100 | 96.0ms | $options->{type_constraint} # spent 96.0ms making 100 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 960µs/call |
| 326 | = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint( | ||||
| 327 | $options->{isa} ); | ||||
| 328 | } | ||||
| 329 | } | ||||
| 330 | |||||
| 331 | # spent 10.7ms (2.15+8.50) within Moose::Meta::Attribute::_process_does_option which was called 122 times, avg 87µs/call:
# 122 times (2.15ms+8.50ms) by Moose::Meta::Attribute::_process_options at line 253, avg 87µs/call | ||||
| 332 | 122 | 548µs | my ( $class, $name, $options ) = @_; | ||
| 333 | |||||
| 334 | 122 | 1.45ms | return unless exists $options->{does} && ! exists $options->{isa}; | ||
| 335 | |||||
| 336 | # allow for anon-subtypes here ... | ||||
| 337 | 11 | 325µs | 11 | 57µs | if ( blessed( $options->{does} ) # spent 57µs making 11 calls to Scalar::Util::blessed, avg 5µs/call |
| 338 | && $options->{does}->isa('Moose::Meta::TypeConstraint') ) { | ||||
| 339 | $options->{type_constraint} = $options->{does}; | ||||
| 340 | } | ||||
| 341 | else { | ||||
| 342 | 11 | 169µs | 11 | 8.45ms | $options->{type_constraint} # spent 8.45ms making 11 calls to Moose::Util::TypeConstraints::find_or_create_does_type_constraint, avg 768µs/call |
| 343 | = Moose::Util::TypeConstraints::find_or_create_does_type_constraint( | ||||
| 344 | $options->{does} ); | ||||
| 345 | } | ||||
| 346 | } | ||||
| 347 | |||||
| 348 | # spent 1.75ms (1.72+25µs) within Moose::Meta::Attribute::_process_coerce_option which was called 122 times, avg 14µs/call:
# 122 times (1.72ms+25µs) by Moose::Meta::Attribute::_process_options at line 254, avg 14µs/call | ||||
| 349 | 122 | 535µs | my ( $class, $name, $options ) = @_; | ||
| 350 | |||||
| 351 | 122 | 1.47ms | return unless $options->{coerce}; | ||
| 352 | |||||
| 353 | 2 | 6µs | ( exists $options->{type_constraint} ) | ||
| 354 | || $class->throw_error( | ||||
| 355 | "You cannot have coercion without specifying a type constraint on attribute ($name)", | ||||
| 356 | data => $options ); | ||||
| 357 | |||||
| 358 | 2 | 6µs | $class->throw_error( | ||
| 359 | "You cannot have a weak reference to a coerced value on attribute ($name)", | ||||
| 360 | data => $options ) | ||||
| 361 | if $options->{weak_ref}; | ||||
| 362 | |||||
| 363 | 2 | 40µs | 2 | 25µs | unless ( $options->{type_constraint}->has_coercion ) { # spent 25µs making 2 calls to Moose::Meta::TypeConstraint::has_coercion, avg 12µs/call |
| 364 | my $type = $options->{type_constraint}->name; | ||||
| 365 | |||||
| 366 | Moose::Deprecated::deprecated( | ||||
| 367 | feature => 'coerce without coercion', | ||||
| 368 | message => | ||||
| 369 | "You cannot coerce an attribute ($name) unless its type ($type) has a coercion" | ||||
| 370 | ); | ||||
| 371 | } | ||||
| 372 | } | ||||
| 373 | |||||
| 374 | # spent 1.61ms within Moose::Meta::Attribute::_process_trigger_option which was called 122 times, avg 13µs/call:
# 122 times (1.61ms+0s) by Moose::Meta::Attribute::_process_options at line 255, avg 13µs/call | ||||
| 375 | 122 | 491µs | my ( $class, $name, $options ) = @_; | ||
| 376 | |||||
| 377 | 122 | 1.43ms | return unless exists $options->{trigger}; | ||
| 378 | |||||
| 379 | ( 'CODE' eq ref $options->{trigger} ) | ||||
| 380 | || $class->throw_error("Trigger must be a CODE ref on attribute ($name)", data => $options->{trigger}); | ||||
| 381 | } | ||||
| 382 | |||||
| 383 | # spent 1.60ms within Moose::Meta::Attribute::_process_auto_deref_option which was called 122 times, avg 13µs/call:
# 122 times (1.60ms+0s) by Moose::Meta::Attribute::_process_options at line 256, avg 13µs/call | ||||
| 384 | 122 | 476µs | my ( $class, $name, $options ) = @_; | ||
| 385 | |||||
| 386 | 122 | 1.54ms | return unless $options->{auto_deref}; | ||
| 387 | |||||
| 388 | ( exists $options->{type_constraint} ) | ||||
| 389 | || $class->throw_error( | ||||
| 390 | "You cannot auto-dereference without specifying a type constraint on attribute ($name)", | ||||
| 391 | data => $options ); | ||||
| 392 | |||||
| 393 | ( $options->{type_constraint}->is_a_type_of('ArrayRef') | ||||
| 394 | || $options->{type_constraint}->is_a_type_of('HashRef') ) | ||||
| 395 | || $class->throw_error( | ||||
| 396 | "You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute ($name)", | ||||
| 397 | data => $options ); | ||||
| 398 | } | ||||
| 399 | |||||
| 400 | # spent 2.45ms (2.38+75µs) within Moose::Meta::Attribute::_process_lazy_build_option which was called 124 times, avg 20µs/call:
# 122 times (2.34ms+75µs) by Moose::Meta::Attribute::_process_options at line 257, avg 20µs/call
# 2 times (31µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 218, avg 16µs/call | ||||
| 401 | 124 | 520µs | my ( $class, $name, $options ) = @_; | ||
| 402 | |||||
| 403 | 124 | 1.46ms | return unless $options->{lazy_build}; | ||
| 404 | |||||
| 405 | 16 | 43µs | $class->throw_error( | ||
| 406 | "You can not use lazy_build and default for the same attribute ($name)", | ||||
| 407 | data => $options ) | ||||
| 408 | if exists $options->{default}; | ||||
| 409 | |||||
| 410 | 16 | 64µs | $options->{lazy} = 1; | ||
| 411 | 16 | 110µs | $options->{builder} ||= "_build_${name}"; | ||
| 412 | |||||
| 413 | 16 | 454µs | 16 | 76µs | if ( $name =~ /^_/ ) { # spent 76µs making 16 calls to Moose::Meta::Attribute::CORE:match, avg 5µs/call |
| 414 | 2 | 14µs | $options->{clearer} ||= "_clear${name}"; | ||
| 415 | 2 | 13µs | $options->{predicate} ||= "_has${name}"; | ||
| 416 | } | ||||
| 417 | else { | ||||
| 418 | 14 | 96µs | $options->{clearer} ||= "clear_${name}"; | ||
| 419 | 14 | 85µs | $options->{predicate} ||= "has_${name}"; | ||
| 420 | } | ||||
| 421 | } | ||||
| 422 | |||||
| 423 | # spent 1.61ms within Moose::Meta::Attribute::_process_lazy_option which was called 122 times, avg 13µs/call:
# 122 times (1.61ms+0s) by Moose::Meta::Attribute::_process_options at line 258, avg 13µs/call | ||||
| 424 | 122 | 461µs | my ( $class, $name, $options ) = @_; | ||
| 425 | |||||
| 426 | 122 | 1.33ms | return unless $options->{lazy}; | ||
| 427 | |||||
| 428 | 19 | 233µs | ( exists $options->{default} || defined $options->{builder} ) | ||
| 429 | || $class->throw_error( | ||||
| 430 | "You cannot have a lazy attribute ($name) without specifying a default value for it", | ||||
| 431 | data => $options ); | ||||
| 432 | } | ||||
| 433 | |||||
| 434 | # spent 1.82ms within Moose::Meta::Attribute::_process_required_option which was called 122 times, avg 15µs/call:
# 122 times (1.82ms+0s) by Moose::Meta::Attribute::_process_options at line 259, avg 15µs/call | ||||
| 435 | 122 | 524µs | my ( $class, $name, $options ) = @_; | ||
| 436 | |||||
| 437 | 122 | 1.69ms | if ( | ||
| 438 | $options->{required} | ||||
| 439 | && !( | ||||
| 440 | ( !exists $options->{init_arg} || defined $options->{init_arg} ) | ||||
| 441 | || exists $options->{default} | ||||
| 442 | || defined $options->{builder} | ||||
| 443 | ) | ||||
| 444 | ) { | ||||
| 445 | $class->throw_error( | ||||
| 446 | "You cannot have a required attribute ($name) without a default, builder, or an init_arg", | ||||
| 447 | data => $options ); | ||||
| 448 | } | ||||
| 449 | } | ||||
| 450 | |||||
| 451 | # spent 7.88ms (1.71+6.17) within Moose::Meta::Attribute::initialize_instance_slot which was called 14 times, avg 563µs/call:
# 14 times (1.71ms+6.17ms) by Class::MOP::Class::_construct_instance at line 603 of Class/MOP/Class.pm, avg 563µs/call | ||||
| 452 | 14 | 52µs | my ($self, $meta_instance, $instance, $params) = @_; | ||
| 453 | 14 | 167µs | 14 | 135µs | my $init_arg = $self->init_arg(); # spent 135µs making 14 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call |
| 454 | # try to fetch the init arg from the %params ... | ||||
| 455 | |||||
| 456 | 14 | 23µs | my $val; | ||
| 457 | 14 | 23µs | my $value_is_set; | ||
| 458 | 14 | 73µs | if ( defined($init_arg) and exists $params->{$init_arg}) { | ||
| 459 | 2 | 7µs | $val = $params->{$init_arg}; | ||
| 460 | 2 | 5µs | $value_is_set = 1; | ||
| 461 | } | ||||
| 462 | else { | ||||
| 463 | # skip it if it's lazy | ||||
| 464 | 12 | 221µs | 12 | 151µs | return if $self->is_lazy; # spent 151µs making 12 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 13µs/call |
| 465 | # and die if it's required and doesn't have a default value | ||||
| 466 | 10 | 118µs | 11 | 124µs | $self->throw_error("Attribute (" . $self->name . ") is required", object => $instance, data => $params) # spent 114µs making 10 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 11µs/call
# spent 11µs making 1 call to Class::MOP::Mixin::AttributeCore::has_default |
| 467 | if $self->is_required && !$self->has_default && !$self->has_builder; | ||||
| 468 | |||||
| 469 | # if nothing was in the %params, we can use the | ||||
| 470 | # attribute's default value (if it has one) | ||||
| 471 | 10 | 132µs | 11 | 105µs | if ($self->has_default) { # spent 95µs making 10 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 9µs/call
# spent 10µs making 1 call to Class::MOP::Mixin::AttributeCore::has_builder |
| 472 | 9 | 97µs | 9 | 352µs | $val = $self->default($instance); # spent 352µs making 9 calls to Class::MOP::Mixin::AttributeCore::default, avg 39µs/call |
| 473 | 9 | 22µs | $value_is_set = 1; | ||
| 474 | } | ||||
| 475 | elsif ($self->has_builder) { | ||||
| 476 | $val = $self->_call_builder($instance); | ||||
| 477 | $value_is_set = 1; | ||||
| 478 | } | ||||
| 479 | } | ||||
| 480 | |||||
| 481 | 12 | 30µs | return unless $value_is_set; | ||
| 482 | |||||
| 483 | 11 | 126µs | 11 | 2.63ms | $val = $self->_coerce_and_verify( $val, $instance ); # spent 2.63ms making 11 calls to Moose::Meta::Attribute::_coerce_and_verify, avg 240µs/call |
| 484 | |||||
| 485 | 11 | 141µs | 11 | 2.18ms | $self->set_initial_value($instance, $val); # spent 2.18ms making 11 calls to Class::MOP::Attribute::set_initial_value, avg 198µs/call |
| 486 | |||||
| 487 | 11 | 182µs | 4 | 493µs | if ( ref $val && $self->is_weak_ref ) { # spent 464µs making 2 calls to Moose::Meta::Attribute::_weaken_value, avg 232µs/call
# spent 29µs making 2 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 14µs/call |
| 488 | $self->_weaken_value($instance); | ||||
| 489 | } | ||||
| 490 | } | ||||
| 491 | |||||
| 492 | sub _call_builder { | ||||
| 493 | my ( $self, $instance ) = @_; | ||||
| 494 | |||||
| 495 | my $builder = $self->builder(); | ||||
| 496 | |||||
| 497 | return $instance->$builder() | ||||
| 498 | if $instance->can( $self->builder ); | ||||
| 499 | |||||
| 500 | $self->throw_error( blessed($instance) | ||||
| 501 | . " does not support builder method '" | ||||
| 502 | . $self->builder | ||||
| 503 | . "' for attribute '" | ||||
| 504 | . $self->name | ||||
| 505 | . "'", | ||||
| 506 | object => $instance, | ||||
| 507 | ); | ||||
| 508 | } | ||||
| 509 | |||||
| 510 | ## Slot management | ||||
| 511 | |||||
| 512 | # FIXME: | ||||
| 513 | # this duplicates too much code from | ||||
| 514 | # Class::MOP::Attribute, we need to | ||||
| 515 | # refactor these bits eventually. | ||||
| 516 | # - SL | ||||
| 517 | # spent 973µs (612+361) within Moose::Meta::Attribute::_set_initial_slot_value which was called 11 times, avg 88µs/call:
# 11 times (612µs+361µs) by Class::MOP::Attribute::set_initial_value at line 253 of Class/MOP/Attribute.pm, avg 88µs/call | ||||
| 518 | 11 | 46µs | my ($self, $meta_instance, $instance, $value) = @_; | ||
| 519 | |||||
| 520 | 11 | 227µs | 11 | 66µs | my $slot_name = $self->name; # spent 66µs making 11 calls to Class::MOP::Mixin::AttributeCore::name, avg 6µs/call |
| 521 | |||||
| 522 | 11 | 336µs | 22 | 295µs | return $meta_instance->set_slot_value($instance, $slot_name, $value) # spent 179µs making 11 calls to Class::MOP::Instance::set_slot_value, avg 16µs/call
# spent 116µs making 11 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 11µs/call |
| 523 | unless $self->has_initializer; | ||||
| 524 | |||||
| 525 | my $callback = sub { | ||||
| 526 | my $val = $self->_coerce_and_verify( shift, $instance );; | ||||
| 527 | |||||
| 528 | $meta_instance->set_slot_value($instance, $slot_name, $val); | ||||
| 529 | }; | ||||
| 530 | |||||
| 531 | my $initializer = $self->initializer; | ||||
| 532 | |||||
| 533 | # most things will just want to set a value, so make it first arg | ||||
| 534 | $instance->$initializer($value, $callback, $self); | ||||
| 535 | } | ||||
| 536 | |||||
| 537 | sub set_value { | ||||
| 538 | my ($self, $instance, @args) = @_; | ||||
| 539 | my $value = $args[0]; | ||||
| 540 | |||||
| 541 | my $attr_name = $self->name; | ||||
| 542 | |||||
| 543 | if ($self->is_required and not @args) { | ||||
| 544 | $self->throw_error("Attribute ($attr_name) is required", object => $instance); | ||||
| 545 | } | ||||
| 546 | |||||
| 547 | $value = $self->_coerce_and_verify( $value, $instance ); | ||||
| 548 | |||||
| 549 | my @old; | ||||
| 550 | if ( $self->has_trigger && $self->has_value($instance) ) { | ||||
| 551 | @old = $self->get_value($instance, 'for trigger'); | ||||
| 552 | } | ||||
| 553 | |||||
| 554 | $self->SUPER::set_value($instance, $value); | ||||
| 555 | |||||
| 556 | if ( ref $value && $self->is_weak_ref ) { | ||||
| 557 | $self->_weaken_value($instance); | ||||
| 558 | } | ||||
| 559 | |||||
| 560 | if ($self->has_trigger) { | ||||
| 561 | $self->trigger->($instance, $value, @old); | ||||
| 562 | } | ||||
| 563 | } | ||||
| 564 | |||||
| 565 | # spent 464µs (180+284) within Moose::Meta::Attribute::_weaken_value which was called 2 times, avg 232µs/call:
# 2 times (180µs+284µs) by Moose::Meta::Attribute::initialize_instance_slot at line 487, avg 232µs/call | ||||
| 566 | 2 | 7µs | my ( $self, $instance ) = @_; | ||
| 567 | |||||
| 568 | 2 | 75µs | 6 | 186µs | my $meta_instance = Class::MOP::Class->initialize( blessed($instance) ) # spent 100µs making 2 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 50µs/call
# spent 73µs making 2 calls to Class::MOP::Class::initialize, avg 37µs/call
# spent 14µs making 2 calls to Scalar::Util::blessed, avg 7µs/call |
| 569 | ->get_meta_instance; | ||||
| 570 | |||||
| 571 | 2 | 76µs | 4 | 98µs | $meta_instance->weaken_slot_value( $instance, $self->name ); # spent 87µs making 2 calls to Class::MOP::Instance::weaken_slot_value, avg 43µs/call
# spent 11µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 6µs/call |
| 572 | } | ||||
| 573 | |||||
| 574 | sub get_value { | ||||
| 575 | my ($self, $instance, $for_trigger) = @_; | ||||
| 576 | |||||
| 577 | if ($self->is_lazy) { | ||||
| 578 | unless ($self->has_value($instance)) { | ||||
| 579 | my $value; | ||||
| 580 | if ($self->has_default) { | ||||
| 581 | $value = $self->default($instance); | ||||
| 582 | } elsif ( $self->has_builder ) { | ||||
| 583 | $value = $self->_call_builder($instance); | ||||
| 584 | } | ||||
| 585 | |||||
| 586 | $value = $self->_coerce_and_verify( $value, $instance ); | ||||
| 587 | |||||
| 588 | $self->set_initial_value($instance, $value); | ||||
| 589 | } | ||||
| 590 | } | ||||
| 591 | |||||
| 592 | if ( $self->should_auto_deref && ! $for_trigger ) { | ||||
| 593 | |||||
| 594 | my $type_constraint = $self->type_constraint; | ||||
| 595 | |||||
| 596 | if ($type_constraint->is_a_type_of('ArrayRef')) { | ||||
| 597 | my $rv = $self->SUPER::get_value($instance); | ||||
| 598 | return unless defined $rv; | ||||
| 599 | return wantarray ? @{ $rv } : $rv; | ||||
| 600 | } | ||||
| 601 | elsif ($type_constraint->is_a_type_of('HashRef')) { | ||||
| 602 | my $rv = $self->SUPER::get_value($instance); | ||||
| 603 | return unless defined $rv; | ||||
| 604 | return wantarray ? %{ $rv } : $rv; | ||||
| 605 | } | ||||
| 606 | else { | ||||
| 607 | $self->throw_error("Can not auto de-reference the type constraint '" . $type_constraint->name . "'", object => $instance, type_constraint => $type_constraint); | ||||
| 608 | } | ||||
| 609 | |||||
| 610 | } | ||||
| 611 | else { | ||||
| 612 | |||||
| 613 | return $self->SUPER::get_value($instance); | ||||
| 614 | } | ||||
| 615 | } | ||||
| 616 | |||||
| 617 | ## installing accessors | ||||
| 618 | |||||
| 619 | 203 | 3.04ms | # spent 1.94ms within Moose::Meta::Attribute::accessor_metaclass which was called 203 times, avg 10µs/call:
# 193 times (1.84ms+0s) by Class::MOP::Attribute::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Attribute.pm:342] at line 334 of Class/MOP/Attribute.pm, avg 10µs/call
# 10 times (101µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 172 of Moose/Meta/Attribute/Native/Trait.pm, avg 10µs/call | ||
| 620 | |||||
| 621 | # spent 928ms (7.58+920) within Moose::Meta::Attribute::install_accessors which was called 125 times, avg 7.42ms/call:
# 122 times (7.29ms+872ms) by Class::MOP::Class::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Class.pm:790] at line 789 of Class/MOP/Class.pm, avg 7.21ms/call
# 2 times (222µs+41.3ms) by Class::MOP::Method::Wrapped::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm:43] at line 33 of Class/MOP/Method/Wrapped.pm, avg 20.8ms/call
# once (64µs+6.58ms) by Class::MOP::Class::_inline_accessors at line 1305 of Class/MOP/Class.pm | ||||
| 622 | 125 | 411µs | my $self = shift; | ||
| 623 | 125 | 3.28ms | 125 | 848ms | $self->SUPER::install_accessors(@_); # spent 848ms making 125 calls to Class::MOP::Attribute::install_accessors, avg 6.79ms/call |
| 624 | 125 | 2.09ms | 134 | 71.7ms | $self->install_delegation if $self->has_handles; # spent 69.7ms making 9 calls to Moose::Meta::Attribute::install_delegation, avg 7.75ms/call
# spent 2.00ms making 125 calls to Moose::Meta::Mixin::AttributeCore::has_handles, avg 16µs/call |
| 625 | 125 | 1.56ms | return; | ||
| 626 | } | ||||
| 627 | |||||
| 628 | # spent 4.74ms (3.39+1.35) within Moose::Meta::Attribute::_check_associated_methods which was called 123 times, avg 39µs/call:
# 123 times (3.39ms+1.35ms) by Moose::Meta::Class::add_attribute at line 307 of Moose/Meta/Class.pm, avg 39µs/call | ||||
| 629 | 123 | 424µs | my $self = shift; | ||
| 630 | 123 | 2.71ms | 123 | 1.35ms | unless ( # spent 1.35ms making 123 calls to Class::MOP::Attribute::associated_methods, avg 11µs/call |
| 631 | @{ $self->associated_methods } | ||||
| 632 | || ($self->_is_metadata || '') eq 'bare' | ||||
| 633 | ) { | ||||
| 634 | Carp::cluck( | ||||
| 635 | 'Attribute (' . $self->name . ') of class ' | ||||
| 636 | . $self->associated_class->name | ||||
| 637 | . ' has no associated methods' | ||||
| 638 | . ' (did you mean to provide an "is" argument?)' | ||||
| 639 | . "\n" | ||||
| 640 | ) | ||||
| 641 | } | ||||
| 642 | } | ||||
| 643 | |||||
| 644 | # spent 716ms (26.7+690) within Moose::Meta::Attribute::_process_accessors which was called 193 times, avg 3.71ms/call:
# 97 times (13.4ms+397ms) by Class::MOP::Attribute::install_accessors at line 360 of Class/MOP/Attribute.pm, avg 4.23ms/call
# 30 times (4.15ms+60.7ms) by Class::MOP::Attribute::install_accessors at line 368 of Class/MOP/Attribute.pm, avg 2.16ms/call
# 29 times (4.15ms+60.4ms) by Class::MOP::Attribute::install_accessors at line 372 of Class/MOP/Attribute.pm, avg 2.23ms/call
# 26 times (3.48ms+132ms) by Class::MOP::Attribute::install_accessors at line 356 of Class/MOP/Attribute.pm, avg 5.22ms/call
# 11 times (1.48ms+39.1ms) by Class::MOP::Attribute::install_accessors at line 364 of Class/MOP/Attribute.pm, avg 3.69ms/call | ||||
| 645 | 193 | 570µs | my $self = shift; | ||
| 646 | 193 | 866µs | my ($type, $accessor, $generate_as_inline_methods) = @_; | ||
| 647 | |||||
| 648 | 193 | 628µs | $accessor = ( keys %$accessor )[0] if ( ref($accessor) || '' ) eq 'HASH'; | ||
| 649 | 193 | 4.11ms | 386 | 62.3ms | my $method = $self->associated_class->get_method($accessor); # spent 60.5ms making 193 calls to Class::MOP::Mixin::HasMethods::get_method, avg 314µs/call
# spent 1.75ms making 193 calls to Class::MOP::Attribute::associated_class, avg 9µs/call |
| 650 | |||||
| 651 | 193 | 508µs | 4 | 29µs | if ( $method # spent 11µs making 1 call to Class::MOP::Method::Accessor::associated_attribute
# spent 11µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call
# spent 7µs making 1 call to UNIVERSAL::isa |
| 652 | && $method->isa('Class::MOP::Method::Accessor') | ||||
| 653 | && $method->associated_attribute->name ne $self->name ) { | ||||
| 654 | |||||
| 655 | my $other_attr_name = $method->associated_attribute->name; | ||||
| 656 | my $name = $self->name; | ||||
| 657 | |||||
| 658 | Carp::cluck( | ||||
| 659 | "You are overwriting an accessor ($accessor) for the $other_attr_name attribute" | ||||
| 660 | . " with a new accessor method for the $name attribute" ); | ||||
| 661 | } | ||||
| 662 | |||||
| 663 | 193 | 472µs | 1 | 5µs | if ( # spent 5µs making 1 call to UNIVERSAL::isa |
| 664 | $method | ||||
| 665 | && !$method->isa('Class::MOP::Method::Accessor') | ||||
| 666 | && ( !$self->definition_context | ||||
| 667 | || $method->package_name eq $self->definition_context->{package} ) | ||||
| 668 | ) { | ||||
| 669 | |||||
| 670 | Carp::cluck( | ||||
| 671 | "You are overwriting a locally defined method ($accessor) with " | ||||
| 672 | . "an accessor" ); | ||||
| 673 | } | ||||
| 674 | |||||
| 675 | 193 | 8.32ms | 770 | 70.4ms | if ( !$self->associated_class->has_method($accessor) # spent 37.5ms making 193 calls to Class::MOP::Mixin::HasMethods::has_method, avg 195µs/call
# spent 29.2ms making 192 calls to Class::MOP::Package::has_package_symbol, avg 152µs/call
# spent 3.66ms making 385 calls to Class::MOP::Attribute::associated_class, avg 10µs/call |
| 676 | && $self->associated_class->has_package_symbol( '&' . $accessor ) ) { | ||||
| 677 | |||||
| 678 | Carp::cluck( | ||||
| 679 | "You are overwriting a locally defined function ($accessor) with " | ||||
| 680 | . "an accessor" ); | ||||
| 681 | } | ||||
| 682 | |||||
| 683 | 193 | 7.69ms | 193 | 557ms | $self->SUPER::_process_accessors(@_); # spent 557ms making 193 calls to Class::MOP::Attribute::_process_accessors, avg 2.89ms/call |
| 684 | } | ||||
| 685 | |||||
| 686 | sub remove_accessors { | ||||
| 687 | my $self = shift; | ||||
| 688 | $self->SUPER::remove_accessors(@_); | ||||
| 689 | $self->remove_delegation if $self->has_handles; | ||||
| 690 | return; | ||||
| 691 | } | ||||
| 692 | |||||
| 693 | # spent 64.2ms (17.4+46.8) within Moose::Meta::Attribute::inline_set which was called 197 times, avg 326µs/call:
# 139 times (11.9ms+14.5ms) by Moose::Meta::Method::Constructor::_generate_slot_assignment at line 302 of Moose/Meta/Method/Constructor.pm, avg 190µs/call
# 56 times (5.18ms+31.4ms) by Moose::Meta::Method::Accessor::_inline_store at line 248 of Moose/Meta/Method/Accessor.pm, avg 653µs/call
# 2 times (286µs+854µs) by Class::MOP::Method::Constructor::_generate_slot_initializer at line 145 of Class/MOP/Method/Constructor.pm, avg 570µs/call | ||||
| 694 | 197 | 640µs | my $self = shift; | ||
| 695 | 197 | 688µs | my ( $instance, $value ) = @_; | ||
| 696 | |||||
| 697 | 197 | 3.87ms | 394 | 29.0ms | my $mi = $self->associated_class->get_meta_instance; # spent 27.2ms making 196 calls to Class::MOP::Class::get_meta_instance, avg 139µs/call
# spent 1.75ms making 197 calls to Class::MOP::Attribute::associated_class, avg 9µs/call
# spent 79µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance |
| 698 | |||||
| 699 | 197 | 4.45ms | 394 | 14.1ms | my $code # spent 9.32ms making 197 calls to Class::MOP::Instance::inline_set_slot_value, avg 47µs/call
# spent 4.77ms making 197 calls to Class::MOP::Attribute::slots, avg 24µs/call |
| 700 | = $mi->inline_set_slot_value( $instance, $self->slots, $value ) . ";"; | ||||
| 701 | 197 | 2.74ms | 217 | 3.68ms | $code # spent 3.03ms making 197 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 15µs/call
# spent 426µs making 10 calls to Class::MOP::Instance::inline_weaken_slot_value, avg 43µs/call
# spent 218µs making 10 calls to Class::MOP::Attribute::slots, avg 22µs/call |
| 702 | .= $mi->inline_weaken_slot_value( $instance, $self->slots, $value ) | ||||
| 703 | . " if ref $value;" | ||||
| 704 | if $self->is_weak_ref; | ||||
| 705 | |||||
| 706 | 197 | 2.69ms | return $code; | ||
| 707 | } | ||||
| 708 | |||||
| 709 | # spent 69.7ms (5.03+64.7) within Moose::Meta::Attribute::install_delegation which was called 9 times, avg 7.75ms/call:
# 9 times (5.03ms+64.7ms) by Moose::Meta::Attribute::install_accessors at line 624, avg 7.75ms/call | ||||
| 710 | 9 | 30µs | my $self = shift; | ||
| 711 | |||||
| 712 | # NOTE: | ||||
| 713 | # Here we canonicalize the 'handles' option | ||||
| 714 | # this will sort out any details and always | ||||
| 715 | # return an hash of methods which we want | ||||
| 716 | # to delagate to, see that method for details | ||||
| 717 | 9 | 181µs | 9 | 686µs | my %handles = $self->_canonicalize_handles; # spent 422µs making 7 calls to Moose::Meta::Attribute::_canonicalize_handles, avg 60µs/call
# spent 139µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::_canonicalize_handles
# spent 126µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::_canonicalize_handles |
| 718 | |||||
| 719 | |||||
| 720 | # install the delegation ... | ||||
| 721 | 9 | 124µs | 9 | 104µs | my $associated_class = $self->associated_class; # spent 104µs making 9 calls to Class::MOP::Attribute::associated_class, avg 12µs/call |
| 722 | 9 | 225µs | foreach my $handle (keys %handles) { | ||
| 723 | 28 | 119µs | my $method_to_call = $handles{$handle}; | ||
| 724 | 28 | 557µs | 28 | 169µs | my $class_name = $associated_class->name; # spent 169µs making 28 calls to Class::MOP::Package::name, avg 6µs/call |
| 725 | 28 | 113µs | my $name = "${class_name}::${handle}"; | ||
| 726 | |||||
| 727 | 28 | 333µs | 28 | 8.35ms | (!$associated_class->has_method($handle)) # spent 8.35ms making 28 calls to Class::MOP::Mixin::HasMethods::has_method, avg 298µs/call |
| 728 | || $self->throw_error("You cannot overwrite a locally defined method ($handle) with a delegation", method_name => $handle); | ||||
| 729 | |||||
| 730 | # NOTE: | ||||
| 731 | # handles is not allowed to delegate | ||||
| 732 | # any of these methods, as they will | ||||
| 733 | # override the ones in your class, which | ||||
| 734 | # is almost certainly not what you want. | ||||
| 735 | |||||
| 736 | # FIXME warn when $handle was explicitly specified, but not if the source is a regex or something | ||||
| 737 | #cluck("Not delegating method '$handle' because it is a core method") and | ||||
| 738 | 28 | 2.04ms | 84 | 1.03ms | next if $class_name->isa("Moose::Object") and $handle =~ /^BUILD|DEMOLISH$/ || Moose::Object->can($handle); # spent 459µs making 28 calls to UNIVERSAL::can, avg 16µs/call
# spent 308µs making 28 calls to Moose::Meta::Attribute::CORE:match, avg 11µs/call
# spent 259µs making 28 calls to UNIVERSAL::isa, avg 9µs/call |
| 739 | |||||
| 740 | 28 | 381µs | 28 | 40.0ms | my $method = $self->_make_delegation_method($handle, $method_to_call); # spent 17.9ms making 3 calls to Class::MOP::Class::__ANON__::SERIAL::5::_make_delegation_method, avg 5.96ms/call
# spent 13.4ms making 23 calls to Moose::Meta::Attribute::_make_delegation_method, avg 581µs/call
# spent 8.75ms making 2 calls to Class::MOP::Class::__ANON__::SERIAL::2::_make_delegation_method, avg 4.37ms/call |
| 741 | |||||
| 742 | 28 | 1.26ms | 84 | 13.9ms | $self->associated_class->add_method($method->name, $method); # spent 13.4ms making 28 calls to Class::MOP::Mixin::HasMethods::add_method, avg 480µs/call
# spent 297µs making 28 calls to Class::MOP::Attribute::associated_class, avg 11µs/call
# spent 155µs making 28 calls to Class::MOP::Method::name, avg 6µs/call |
| 743 | 28 | 535µs | 28 | 451µs | $self->associate_method($method); # spent 451µs making 28 calls to Class::MOP::Attribute::associate_method, avg 16µs/call |
| 744 | } | ||||
| 745 | } | ||||
| 746 | |||||
| 747 | sub remove_delegation { | ||||
| 748 | my $self = shift; | ||||
| 749 | my %handles = $self->_canonicalize_handles; | ||||
| 750 | my $associated_class = $self->associated_class; | ||||
| 751 | foreach my $handle (keys %handles) { | ||||
| 752 | next unless any { $handle eq $_ } | ||||
| 753 | map { $_->name } | ||||
| 754 | @{ $self->associated_methods }; | ||||
| 755 | $self->associated_class->remove_method($handle); | ||||
| 756 | } | ||||
| 757 | } | ||||
| 758 | |||||
| 759 | # private methods to help delegation ... | ||||
| 760 | |||||
| 761 | # spent 422µs (336+86) within Moose::Meta::Attribute::_canonicalize_handles which was called 7 times, avg 60µs/call:
# 7 times (336µs+86µs) by Moose::Meta::Attribute::install_delegation at line 717, avg 60µs/call | ||||
| 762 | 7 | 21µs | my $self = shift; | ||
| 763 | 7 | 108µs | 7 | 86µs | my $handles = $self->handles; # spent 86µs making 7 calls to Moose::Meta::Mixin::AttributeCore::handles, avg 12µs/call |
| 764 | 7 | 28µs | if (my $handle_type = ref($handles)) { | ||
| 765 | 7 | 181µs | if ($handle_type eq 'HASH') { | ||
| 766 | return %{$handles}; | ||||
| 767 | } | ||||
| 768 | elsif ($handle_type eq 'ARRAY') { | ||||
| 769 | return map { $_ => $_ } @{$handles}; | ||||
| 770 | } | ||||
| 771 | elsif ($handle_type eq 'Regexp') { | ||||
| 772 | ($self->has_type_constraint) | ||||
| 773 | || $self->throw_error("Cannot delegate methods based on a Regexp without a type constraint (isa)", data => $handles); | ||||
| 774 | return map { ($_ => $_) } | ||||
| 775 | grep { /$handles/ } $self->_get_delegate_method_list; | ||||
| 776 | } | ||||
| 777 | elsif ($handle_type eq 'CODE') { | ||||
| 778 | return $handles->($self, $self->_find_delegate_metaclass); | ||||
| 779 | } | ||||
| 780 | elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::DuckType')) { | ||||
| 781 | return map { $_ => $_ } @{ $handles->methods }; | ||||
| 782 | } | ||||
| 783 | elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::Role')) { | ||||
| 784 | $handles = $handles->role; | ||||
| 785 | } | ||||
| 786 | else { | ||||
| 787 | $self->throw_error("Unable to canonicalize the 'handles' option with $handles", data => $handles); | ||||
| 788 | } | ||||
| 789 | } | ||||
| 790 | |||||
| 791 | Class::MOP::load_class($handles); | ||||
| 792 | my $role_meta = Class::MOP::class_of($handles); | ||||
| 793 | |||||
| 794 | (blessed $role_meta && $role_meta->isa('Moose::Meta::Role')) | ||||
| 795 | || $self->throw_error("Unable to canonicalize the 'handles' option with $handles because its metaclass is not a Moose::Meta::Role", data => $handles); | ||||
| 796 | |||||
| 797 | return map { $_ => $_ } | ||||
| 798 | map { $_->name } | ||||
| 799 | grep { !$_->isa('Class::MOP::Method::Meta') } ( | ||||
| 800 | $role_meta->_get_local_methods, | ||||
| 801 | $role_meta->get_required_method_list, | ||||
| 802 | ); | ||||
| 803 | } | ||||
| 804 | |||||
| 805 | sub _get_delegate_method_list { | ||||
| 806 | my $self = shift; | ||||
| 807 | my $meta = $self->_find_delegate_metaclass; | ||||
| 808 | if ($meta->isa('Class::MOP::Class')) { | ||||
| 809 | return map { $_->name } # NOTE: !never! delegate &meta | ||||
| 810 | grep { $_->package_name ne 'Moose::Object' && !$_->isa('Class::MOP::Method::Meta') } | ||||
| 811 | $meta->get_all_methods; | ||||
| 812 | } | ||||
| 813 | elsif ($meta->isa('Moose::Meta::Role')) { | ||||
| 814 | return $meta->get_method_list; | ||||
| 815 | } | ||||
| 816 | else { | ||||
| 817 | $self->throw_error("Unable to recognize the delegate metaclass '$meta'", data => $meta); | ||||
| 818 | } | ||||
| 819 | } | ||||
| 820 | |||||
| 821 | sub _find_delegate_metaclass { | ||||
| 822 | my $self = shift; | ||||
| 823 | if (my $class = $self->_isa_metadata) { | ||||
| 824 | unless ( Class::MOP::is_class_loaded($class) ) { | ||||
| 825 | $self->throw_error( | ||||
| 826 | sprintf( | ||||
| 827 | 'The %s attribute is trying to delegate to a class which has not been loaded - %s', | ||||
| 828 | $self->name, $class | ||||
| 829 | ) | ||||
| 830 | ); | ||||
| 831 | } | ||||
| 832 | # we might be dealing with a non-Moose class, | ||||
| 833 | # and need to make our own metaclass. if there's | ||||
| 834 | # already a metaclass, it will be returned | ||||
| 835 | return Class::MOP::Class->initialize($class); | ||||
| 836 | } | ||||
| 837 | elsif (my $role = $self->_does_metadata) { | ||||
| 838 | unless ( Class::MOP::is_class_loaded($class) ) { | ||||
| 839 | $self->throw_error( | ||||
| 840 | sprintf( | ||||
| 841 | 'The %s attribute is trying to delegate to a role which has not been loaded - %s', | ||||
| 842 | $self->name, $role | ||||
| 843 | ) | ||||
| 844 | ); | ||||
| 845 | } | ||||
| 846 | |||||
| 847 | return Class::MOP::class_of($role); | ||||
| 848 | } | ||||
| 849 | else { | ||||
| 850 | $self->throw_error("Cannot find delegate metaclass for attribute " . $self->name); | ||||
| 851 | } | ||||
| 852 | } | ||||
| 853 | |||||
| 854 | 33 | 437µs | # spent 281µs within Moose::Meta::Attribute::delegation_metaclass which was called 33 times, avg 9µs/call:
# 23 times (188µs+0s) by Moose::Meta::Attribute::_make_delegation_method at line 864, avg 8µs/call
# 10 times (93µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 172 of Moose/Meta/Attribute/Native/Trait.pm, avg 9µs/call | ||
| 855 | |||||
| 856 | # spent 13.4ms (1.60+11.8) within Moose::Meta::Attribute::_make_delegation_method which was called 23 times, avg 581µs/call:
# 23 times (1.60ms+11.8ms) by Moose::Meta::Attribute::install_delegation at line 740, avg 581µs/call | ||||
| 857 | 23 | 127µs | my ( $self, $handle_name, $method_to_call ) = @_; | ||
| 858 | |||||
| 859 | 23 | 49µs | my @curried_arguments; | ||
| 860 | |||||
| 861 | 23 | 60µs | ($method_to_call, @curried_arguments) = @$method_to_call | ||
| 862 | if 'ARRAY' eq ref($method_to_call); | ||||
| 863 | |||||
| 864 | 23 | 1.33ms | 92 | 11.8ms | return $self->delegation_metaclass->new( # spent 11.2ms making 23 calls to Moose::Meta::Method::Delegation::new, avg 487µs/call
# spent 228µs making 23 calls to Class::MOP::Attribute::associated_class, avg 10µs/call
# spent 188µs making 23 calls to Moose::Meta::Attribute::delegation_metaclass, avg 8µs/call
# spent 136µs making 23 calls to Class::MOP::Package::name, avg 6µs/call |
| 865 | name => $handle_name, | ||||
| 866 | package_name => $self->associated_class->name, | ||||
| 867 | attribute => $self, | ||||
| 868 | delegate_to_method => $method_to_call, | ||||
| 869 | curried_arguments => \@curried_arguments, | ||||
| 870 | ); | ||||
| 871 | } | ||||
| 872 | |||||
| 873 | # spent 2.63ms (641µs+1.99) within Moose::Meta::Attribute::_coerce_and_verify which was called 11 times, avg 240µs/call:
# 11 times (641µs+1.99ms) by Moose::Meta::Attribute::initialize_instance_slot at line 483, avg 240µs/call | ||||
| 874 | 11 | 32µs | my $self = shift; | ||
| 875 | 11 | 26µs | my $val = shift; | ||
| 876 | 11 | 24µs | my $instance = shift; | ||
| 877 | |||||
| 878 | 11 | 194µs | 11 | 111µs | return $val unless $self->has_type_constraint; # spent 111µs making 11 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 10µs/call |
| 879 | |||||
| 880 | 9 | 94µs | 9 | 98µs | $val = $self->type_constraint->coerce($val) # spent 98µs making 9 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 11µs/call |
| 881 | if $self->should_coerce && $self->type_constraint->has_coercion; | ||||
| 882 | |||||
| 883 | 9 | 96µs | 9 | 1.78ms | $self->verify_against_type_constraint($val, instance => $instance); # spent 1.78ms making 9 calls to Moose::Meta::Attribute::verify_against_type_constraint, avg 198µs/call |
| 884 | |||||
| 885 | 9 | 101µs | return $val; | ||
| 886 | } | ||||
| 887 | |||||
| 888 | # spent 1.78ms (472µs+1.31) within Moose::Meta::Attribute::verify_against_type_constraint which was called 9 times, avg 198µs/call:
# 9 times (472µs+1.31ms) by Moose::Meta::Attribute::_coerce_and_verify at line 883, avg 198µs/call | ||||
| 889 | 9 | 26µs | my $self = shift; | ||
| 890 | 9 | 21µs | my $val = shift; | ||
| 891 | |||||
| 892 | 9 | 83µs | 9 | 76µs | return 1 if !$self->has_type_constraint; # spent 76µs making 9 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 8µs/call |
| 893 | |||||
| 894 | 9 | 97µs | 9 | 102µs | my $type_constraint = $self->type_constraint; # spent 102µs making 9 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 11µs/call |
| 895 | |||||
| 896 | 9 | 170µs | 9 | 1.13ms | $type_constraint->check($val) # spent 1.13ms making 9 calls to Moose::Meta::TypeConstraint::check, avg 126µs/call |
| 897 | || $self->throw_error("Attribute (" | ||||
| 898 | . $self->name | ||||
| 899 | . ") does not pass the type constraint because: " | ||||
| 900 | . $type_constraint->get_message($val), data => $val, @_); | ||||
| 901 | } | ||||
| 902 | |||||
| 903 | package Moose::Meta::Attribute::Custom::Moose; | ||||
| 904 | sub register_implementation { 'Moose::Meta::Attribute' } | ||||
| 905 | |||||
| 906 | 1 | 32µs | 1; | ||
| 907 | |||||
| 908 | __END__ | ||||
sub Moose::Meta::Attribute::CORE:match; # opcode | |||||
# spent 547µs within Moose::Meta::Attribute::CORE:sort which was called 124 times, avg 4µs/call:
# 124 times (547µs+0s) by Moose::Meta::Attribute::new at line 68, avg 4µs/call |