| 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 10308 statements in 148ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 72 | 2 | 2 | 49.2ms | 280ms | Moose::Meta::Attribute::new |
| 1 | 1 | 1 | 20.4ms | 272ms | Moose::Meta::Attribute::BEGIN@20 |
| 89 | 4 | 1 | 12.6ms | 400ms | Moose::Meta::Attribute::_process_accessors |
| 72 | 3 | 3 | 11.6ms | 38.0ms | Moose::Meta::Attribute::_process_options |
| 110 | 1 | 1 | 10.2ms | 67.0ms | Moose::Meta::Attribute::initialize_instance_slot |
| 94 | 3 | 3 | 8.75ms | 37.6ms | Moose::Meta::Attribute::inline_set |
| 1 | 1 | 1 | 6.70ms | 7.39ms | Moose::Meta::Attribute::BEGIN@17 |
| 98 | 1 | 1 | 6.07ms | 30.4ms | Moose::Meta::Attribute::_coerce_and_verify |
| 98 | 1 | 1 | 5.72ms | 21.9ms | Moose::Meta::Attribute::verify_against_type_constraint |
| 98 | 1 | 1 | 5.13ms | 8.30ms | Moose::Meta::Attribute::_set_initial_slot_value |
| 71 | 2 | 2 | 4.99ms | 3.91s | Moose::Meta::Attribute::interpolate_class_and_new (recurses: max depth 1, inclusive time 20.5ms) |
| 73 | 3 | 2 | 4.68ms | 587ms | Moose::Meta::Attribute::install_accessors |
| 7 | 1 | 1 | 3.50ms | 116ms | Moose::Meta::Attribute::install_delegation |
| 72 | 1 | 1 | 3.09ms | 14.8ms | Moose::Meta::Attribute::_process_isa_option |
| 71 | 1 | 1 | 2.89ms | 3.65s | Moose::Meta::Attribute::interpolate_class (recurses: max depth 1, inclusive time 285µs) |
| 1 | 1 | 1 | 2.68ms | 3.80ms | Moose::Meta::Attribute::BEGIN@18 |
| 71 | 1 | 1 | 1.96ms | 2.73ms | Moose::Meta::Attribute::_check_associated_methods |
| 72 | 1 | 1 | 1.59ms | 1.59ms | Moose::Meta::Attribute::_process_is_option |
| 72 | 1 | 1 | 1.35ms | 4.04ms | Moose::Meta::Attribute::_process_does_option |
| 117 | 2 | 2 | 1.23ms | 1.23ms | Moose::Meta::Attribute::accessor_metaclass |
| 72 | 1 | 1 | 1.08ms | 1.08ms | Moose::Meta::Attribute::_process_coerce_option |
| 72 | 1 | 1 | 1.04ms | 1.04ms | Moose::Meta::Attribute::_process_required_option |
| 72 | 1 | 1 | 1.04ms | 1.04ms | Moose::Meta::Attribute::_process_lazy_option |
| 72 | 1 | 1 | 997µs | 997µs | Moose::Meta::Attribute::_process_lazy_build_option |
| 72 | 1 | 1 | 974µs | 974µs | Moose::Meta::Attribute::_process_auto_deref_option |
| 72 | 1 | 1 | 957µs | 957µs | Moose::Meta::Attribute::_process_trigger_option |
| 6 | 1 | 1 | 416µs | 14.4ms | Moose::Meta::Attribute::does |
| 72 | 1 | 1 | 314µs | 314µs | Moose::Meta::Attribute::CORE:sort (opcode) |
| 29 | 2 | 2 | 281µs | 281µs | Moose::Meta::Attribute::delegation_metaclass |
| 14 | 1 | 1 | 232µs | 232µs | Moose::Meta::Attribute::CORE:match (opcode) |
| 6 | 1 | 1 | 126µs | 5.47ms | Moose::Meta::Attribute::__ANON__[:40] |
| 1 | 1 | 1 | 105µs | 1.60ms | Moose::Meta::Attribute::clone_and_inherit_options |
| 1 | 1 | 1 | 87µs | 1.26ms | Moose::Meta::Attribute::_make_delegation_method |
| 1 | 1 | 1 | 78µs | 91µs | Moose::Meta::Attribute::_canonicalize_handles |
| 1 | 1 | 1 | 72µs | 89µs | Moose::Meta::Attribute::BEGIN@4 |
| 1 | 1 | 1 | 49µs | 88µs | Moose::Meta::Attribute::BEGIN@16 |
| 1 | 1 | 1 | 38µs | 106µs | Moose::Meta::Attribute::BEGIN@5 |
| 1 | 1 | 1 | 38µs | 219µs | Moose::Meta::Attribute::BEGIN@10 |
| 1 | 1 | 1 | 38µs | 167µs | Moose::Meta::Attribute::BEGIN@9 |
| 1 | 1 | 1 | 37µs | 38.4ms | 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 |
| 1 | 1 | 1 | 24µs | 24µs | Moose::Meta::Attribute::BEGIN@19 |
| 1 | 1 | 1 | 20µs | 20µs | Moose::Meta::Attribute::BEGIN@7 |
| 1 | 1 | 1 | 20µs | 20µs | Moose::Meta::Attribute::BEGIN@11 |
| 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::_weaken_value |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::clone |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::get_value |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::illegal_options_for_inheritance |
| 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 | 102µs | 2 | 106µs | # spent 89µs (72+17) within Moose::Meta::Attribute::BEGIN@4 which was called:
# once (72µs+17µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 4 # spent 89µs making 1 call to Moose::Meta::Attribute::BEGIN@4
# spent 17µs making 1 call to strict::import |
| 5 | 3 | 95µs | 2 | 173µs | # spent 106µs (38+67) within Moose::Meta::Attribute::BEGIN@5 which was called:
# once (38µs+67µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 5 # spent 106µs making 1 call to Moose::Meta::Attribute::BEGIN@5
# spent 67µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 3 | 89µs | 1 | 20µs | # spent 20µs within Moose::Meta::Attribute::BEGIN@7 which was called:
# once (20µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 7 # spent 20µs making 1 call to Moose::Meta::Attribute::BEGIN@7 |
| 8 | 3 | 104µ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 | 96µs | 2 | 297µs | # spent 167µs (38+130) within Moose::Meta::Attribute::BEGIN@9 which was called:
# once (38µs+130µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 9 # spent 167µs making 1 call to Moose::Meta::Attribute::BEGIN@9
# spent 130µs making 1 call to Exporter::import |
| 10 | 3 | 91µs | 2 | 399µs | # spent 219µs (38+180) within Moose::Meta::Attribute::BEGIN@10 which was called:
# once (38µs+180µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 10 # spent 219µs making 1 call to Moose::Meta::Attribute::BEGIN@10
# spent 180µs making 1 call to Exporter::import |
| 11 | 3 | 189µs | 1 | 20µs | # spent 20µs within Moose::Meta::Attribute::BEGIN@11 which was called:
# once (20µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 11 # spent 20µ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 | 115µs | 2 | 127µs | # spent 88µs (49+39) within Moose::Meta::Attribute::BEGIN@16 which was called:
# once (49µs+39µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 16 # spent 88µs making 1 call to Moose::Meta::Attribute::BEGIN@16
# spent 39µs making 1 call to Package::DeprecationManager::__ANON__[Package/DeprecationManager.pm:61] |
| 17 | 3 | 513µs | 1 | 7.39ms | # spent 7.39ms (6.70+685µs) within Moose::Meta::Attribute::BEGIN@17 which was called:
# once (6.70ms+685µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 17 # spent 7.39ms making 1 call to Moose::Meta::Attribute::BEGIN@17 |
| 18 | 3 | 473µs | 1 | 3.80ms | # spent 3.80ms (2.68+1.12) within Moose::Meta::Attribute::BEGIN@18 which was called:
# once (2.68ms+1.12ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 18 # spent 3.80ms making 1 call to Moose::Meta::Attribute::BEGIN@18 |
| 19 | 3 | 80µs | 1 | 24µs | # spent 24µs within Moose::Meta::Attribute::BEGIN@19 which was called:
# once (24µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 19 # spent 24µs making 1 call to Moose::Meta::Attribute::BEGIN@19 |
| 20 | 3 | 431µs | 1 | 272ms | # spent 272ms (20.4+252) within Moose::Meta::Attribute::BEGIN@20 which was called:
# once (20.4ms+252ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 20 # spent 272ms making 1 call to Moose::Meta::Attribute::BEGIN@20 |
| 21 | 3 | 107µ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.1ms | 2 | 76.8ms | # spent 38.4ms (37µs+38.4) within Moose::Meta::Attribute::BEGIN@23 which was called:
# once (37µs+38.4ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 23 # spent 38.4ms making 1 call to Moose::Meta::Attribute::BEGIN@23
# spent 38.4ms 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 | 43µs | 2 | 3.34ms | __PACKAGE__->meta->add_attribute('traits' => ( # spent 3.26ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 81µ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 14.4ms (416µs+14.0) within Moose::Meta::Attribute::does which was called 6 times, avg 2.40ms/call:
# 6 times (416µs+14.0ms) by Moose::Meta::Attribute::interpolate_class at line 114, avg 2.40ms/call | ||||
| 37 | 6 | 36µs | my ($self, $role_name) = @_; | ||
| 38 | # spent 5.47ms (126µs+5.34) 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 6 times, avg 911µs/call:
# 6 times (126µs+5.34ms) by Try::Tiny::try at line 71 of Try/Tiny.pm, avg 911µs/call | ||||
| 39 | 6 | 127µs | 6 | 5.34ms | Moose::Util::resolve_metatrait_alias(Attribute => $role_name) # spent 5.34ms making 6 calls to Moose::Util::resolve_metatrait_alias, avg 890µs/call |
| 40 | 6 | 155µs | 6 | 5.93ms | }; # spent 5.93ms making 6 calls to Try::Tiny::try, avg 989µs/call |
| 41 | 6 | 19µs | return 0 if !defined($name); # failed to load class | ||
| 42 | 6 | 179µs | 6 | 8.05ms | return $self->Moose::Object::does($name); # spent 8.05ms making 6 calls to Moose::Object::does, avg 1.34ms/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 280ms (49.2+231) within Moose::Meta::Attribute::new which was called 72 times, avg 3.89ms/call:
# 71 times (48.5ms+225ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 83, avg 3.85ms/call
# once (694µs+5.82ms) by Moose::BEGIN@21 at line 20 of Moose/Meta/TypeCoercion.pm | ||||
| 56 | 72 | 824µs | my ($class, $name, %options) = @_; | ||
| 57 | 72 | 1.10ms | 72 | 49.6ms | $class->_process_options($name, \%options) unless $options{__hack_no_process_options}; # used from clone()... YECHKKK FIXME ICKY YUCK GROSS # spent 23.4ms making 47 calls to Moose::Meta::Attribute::_process_options, avg 498µs/call
# spent 13.2ms making 18 calls to Class::MOP::Class::__ANON__::SERIAL::1::_process_options, avg 733µs/call
# spent 4.24ms making 2 calls to Class::MOP::Class::__ANON__::SERIAL::5::_process_options, avg 2.12ms/call
# spent 2.37ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::8::_process_options
# spent 2.12ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::15::_process_options
# spent 1.79ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::11::_process_options
# spent 1.77ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::19::_process_options
# spent 677µs making 1 call to MooseX::Role::Parameterized::Meta::Parameter::_process_options |
| 58 | |||||
| 59 | 72 | 277µs | delete $options{__hack_no_process_options}; | ||
| 60 | |||||
| 61 | my %attrs = | ||||
| 62 | ( map { $_ => 1 } | ||||
| 63 | 2028 | 20.7ms | 2028 | 20.2ms | grep { defined } # spent 20.2ms making 2028 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call |
| 64 | 72 | 13.3ms | 144 | 30.7ms | map { $_->init_arg() } # spent 18.7ms making 25 calls to Class::MOP::Class::get_all_attributes, avg 747µs/call
# spent 4.50ms making 47 calls to Class::MOP::Object::meta, avg 96µs/call
# spent 4.19ms making 46 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 91µs/call
# spent 1.71ms making 18 calls to Class::MOP::Class::__ANON__::SERIAL::1::meta, avg 95µs/call
# spent 916µs making 1 call to Class::MOP::Class::Immutable::Moose::Meta::Class::get_all_attributes
# spent 184µs making 2 calls to Class::MOP::Class::__ANON__::SERIAL::5::meta, avg 92µs/call
# spent 101µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::15::meta
# spent 100µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::11::meta
# spent 99µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::19::meta
# spent 98µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::8::meta
# spent 94µs making 1 call to MooseX::Role::Parameterized::Meta::Parameter::meta |
| 65 | $class->meta()->get_all_attributes() | ||||
| 66 | ); | ||||
| 67 | |||||
| 68 | 72 | 2.26ms | 72 | 314µs | my @bad = sort grep { ! $attrs{$_} } keys %options; # spent 314µs making 72 calls to Moose::Meta::Attribute::CORE:sort, avg 4µs/call |
| 69 | |||||
| 70 | 72 | 198µs | if (@bad) | ||
| 71 | { | ||||
| 72 | Carp::cluck "Found unknown argument(s) passed to '$name' attribute constructor in '$class': @bad"; | ||||
| 73 | } | ||||
| 74 | |||||
| 75 | 72 | 4.33ms | 72 | 130ms | return $class->SUPER::new($name, %options); # spent 130ms making 72 calls to Class::MOP::Attribute::new, avg 1.80ms/call |
| 76 | } | ||||
| 77 | |||||
| 78 | # spent 3.91s (4.99ms+3.90) within Moose::Meta::Attribute::interpolate_class_and_new which was called 71 times, avg 55.0ms/call:
# 50 times (3.48ms+3.83s) by Moose::Meta::Class::_process_new_attribute at line 438 of Moose/Meta/Class.pm, avg 76.7ms/call
# 21 times (1.50ms+72.0ms) by Moose::Meta::Role::Attribute::attribute_for_class at line 67 of Moose/Meta/Role/Attribute.pm, avg 3.50ms/call | ||||
| 79 | 71 | 862µs | my ($class, $name, %args) = @_; | ||
| 80 | |||||
| 81 | 71 | 1.24ms | 71 | 3.65s | my ( $new_class, @traits ) = $class->interpolate_class(\%args); # spent 3.65s making 71 calls to Moose::Meta::Attribute::interpolate_class, avg 51.4ms/call, recursion: max depth 1, sum of overlapping time 285µs |
| 82 | |||||
| 83 | 71 | 2.57ms | 71 | 273ms | $new_class->new($name, %args, ( scalar(@traits) ? ( traits => \@traits ) : () ) ); # spent 273ms making 71 calls to Moose::Meta::Attribute::new, avg 3.85ms/call |
| 84 | } | ||||
| 85 | |||||
| 86 | # spent 3.65s (2.89ms+3.65) within Moose::Meta::Attribute::interpolate_class which was called 71 times, avg 51.4ms/call:
# 71 times (2.89ms+3.65s) by Moose::Meta::Attribute::interpolate_class_and_new at line 81, avg 51.4ms/call | ||||
| 87 | 71 | 272µs | my ($class, $options) = @_; | ||
| 88 | |||||
| 89 | 71 | 160µs | $class = ref($class) || $class; | ||
| 90 | |||||
| 91 | 71 | 331µ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 | 71 | 140µs | my @traits; | ||
| 104 | |||||
| 105 | 71 | 227µs | if (my $traits = $options->{traits}) { | ||
| 106 | 6 | 14µs | my $i = 0; | ||
| 107 | 6 | 33µs | while ($i < @$traits) { | ||
| 108 | 6 | 24µs | my $trait = $traits->[$i++]; | ||
| 109 | 6 | 11µs | next if ref($trait); # options to a trait we discarded | ||
| 110 | |||||
| 111 | 6 | 83µs | 6 | 3.35s | $trait = Moose::Util::resolve_metatrait_alias(Attribute => $trait) # spent 3.35s making 6 calls to Moose::Util::resolve_metatrait_alias, avg 558ms/call |
| 112 | || $trait; | ||||
| 113 | |||||
| 114 | 6 | 153µs | 6 | 14.4ms | next if $class->does($trait); # spent 14.4ms making 6 calls to Moose::Meta::Attribute::does, avg 2.40ms/call |
| 115 | |||||
| 116 | 6 | 94µs | push @traits, $trait; | ||
| 117 | |||||
| 118 | # are there options? | ||||
| 119 | 6 | 42µs | push @traits, $traits->[$i++] | ||
| 120 | if $traits->[$i] && ref($traits->[$i]); | ||||
| 121 | } | ||||
| 122 | |||||
| 123 | 6 | 30µs | if (@traits) { | ||
| 124 | 6 | 195µs | 6 | 286ms | my $anon_class = Moose::Meta::Class->create_anon_class( # spent 286ms making 6 calls to Moose::Meta::Class::create_anon_class, avg 47.6ms/call |
| 125 | superclasses => [ $class ], | ||||
| 126 | roles => [ @traits ], | ||||
| 127 | cache => 1, | ||||
| 128 | ); | ||||
| 129 | |||||
| 130 | 6 | 138µs | 6 | 40µs | $class = $anon_class->name; # spent 40µs making 6 calls to Class::MOP::Package::name, avg 7µs/call |
| 131 | } | ||||
| 132 | } | ||||
| 133 | |||||
| 134 | 71 | 1.27ms | return ( wantarray ? ( $class, @traits ) : $class ); | ||
| 135 | } | ||||
| 136 | |||||
| 137 | # ... | ||||
| 138 | |||||
| 139 | # method-generating options shouldn't be overridden | ||||
| 140 | sub illegal_options_for_inheritance { | ||||
| 141 | 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 1.60ms (105µs+1.49) within Moose::Meta::Attribute::clone_and_inherit_options which was called:
# once (105µs+1.49ms) by Moose::Meta::Class::_process_inherited_attribute at line 452 of Moose/Meta/Class.pm | ||||
| 159 | 1 | 8µ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 | 1 | 44µs | 1 | 24µs | my @illegal_options = $self->can('illegal_options_for_inheritance') # spent 24µs making 1 call to UNIVERSAL::can |
| 169 | ? $self->illegal_options_for_inheritance | ||||
| 170 | : (); | ||||
| 171 | |||||
| 172 | 1 | 3µs | my @found_illegal_options = grep { exists $options{$_} && exists $self->{$_} ? $_ : undef } @illegal_options; | ||
| 173 | 1 | 3µs | (scalar @found_illegal_options == 0) | ||
| 174 | || $self->throw_error("Illegal inherited options => (" . (join ', ' => @found_illegal_options) . ")", data => \%options); | ||||
| 175 | |||||
| 176 | 1 | 3µ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 | 1 | 3µ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 | 1 | 33µs | 1 | 18µs | if ($self->can('interpolate_class')) { # spent 18µs making 1 call to UNIVERSAL::can |
| 209 | ( $options{metaclass}, my @traits ) = $self->interpolate_class(\%options); | ||||
| 210 | |||||
| 211 | my %seen; | ||||
| 212 | my @all_traits = grep { $seen{$_}++ } @{ $self->applied_traits || [] }, @traits; | ||||
| 213 | $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 | 1 | 34µs | 1 | 17µs | $self->_process_lazy_build_option( $self->name, \%options ) # spent 17µs making 1 call to UNIVERSAL::can |
| 219 | if $self->can('_process_lazy_build_option'); | ||||
| 220 | |||||
| 221 | 1 | 34µs | 1 | 1.43ms | $self->clone(%options); # spent 1.43ms making 1 call to Class::MOP::Attribute::clone |
| 222 | } | ||||
| 223 | |||||
| 224 | sub clone { | ||||
| 225 | my ( $self, %params ) = @_; | ||||
| 226 | |||||
| 227 | my $class = delete $params{metaclass} || ref $self; | ||||
| 228 | |||||
| 229 | my ( @init, @non_init ); | ||||
| 230 | |||||
| 231 | foreach my $attr ( grep { $_->has_value($self) } Class::MOP::class_of($self)->get_all_attributes ) { | ||||
| 232 | push @{ $attr->has_init_arg ? \@init : \@non_init }, $attr; | ||||
| 233 | } | ||||
| 234 | |||||
| 235 | my %new_params = ( ( map { $_->init_arg => $_->get_value($self) } @init ), %params ); | ||||
| 236 | |||||
| 237 | my $name = delete $new_params{name}; | ||||
| 238 | |||||
| 239 | my $clone = $class->new($name, %new_params, __hack_no_process_options => 1 ); | ||||
| 240 | |||||
| 241 | foreach my $attr ( @non_init ) { | ||||
| 242 | $attr->set_value($clone, $attr->get_value($self)); | ||||
| 243 | } | ||||
| 244 | |||||
| 245 | return $clone; | ||||
| 246 | } | ||||
| 247 | |||||
| 248 | # spent 38.0ms (11.6+26.5) within Moose::Meta::Attribute::_process_options which was called 72 times, avg 528µs/call:
# 47 times (6.86ms+16.6ms) by Moose::Meta::Attribute::new at line 57, avg 498µs/call
# 24 times (4.44ms+9.61ms) 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 586µs/call
# once (280µs+291µs) by Class::MOP::Class:::around at line 19 of MooseX/Role/Parameterized/Meta/Parameter.pm | ||||
| 249 | 72 | 309µs | my ( $class, $name, $options ) = @_; | ||
| 250 | |||||
| 251 | 72 | 935µs | 72 | 1.59ms | $class->_process_is_option( $name, $options ); # spent 1.59ms making 72 calls to Moose::Meta::Attribute::_process_is_option, avg 22µs/call |
| 252 | 72 | 1.06ms | 72 | 14.8ms | $class->_process_isa_option( $name, $options ); # spent 14.8ms making 72 calls to Moose::Meta::Attribute::_process_isa_option, avg 205µs/call |
| 253 | 72 | 998µs | 72 | 4.04ms | $class->_process_does_option( $name, $options ); # spent 4.04ms making 72 calls to Moose::Meta::Attribute::_process_does_option, avg 56µs/call |
| 254 | 72 | 989µs | 72 | 1.08ms | $class->_process_coerce_option( $name, $options ); # spent 1.08ms making 72 calls to Moose::Meta::Attribute::_process_coerce_option, avg 15µs/call |
| 255 | 72 | 951µs | 72 | 957µs | $class->_process_trigger_option( $name, $options ); # spent 957µs making 72 calls to Moose::Meta::Attribute::_process_trigger_option, avg 13µs/call |
| 256 | 72 | 949µs | 72 | 974µs | $class->_process_auto_deref_option( $name, $options ); # spent 974µs making 72 calls to Moose::Meta::Attribute::_process_auto_deref_option, avg 14µs/call |
| 257 | 72 | 897µs | 72 | 997µs | $class->_process_lazy_build_option( $name, $options ); # spent 997µs making 72 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 14µs/call |
| 258 | 72 | 928µs | 72 | 1.04ms | $class->_process_lazy_option( $name, $options ); # spent 1.04ms making 72 calls to Moose::Meta::Attribute::_process_lazy_option, avg 14µs/call |
| 259 | 72 | 1.62ms | 72 | 1.04ms | $class->_process_required_option( $name, $options ); # spent 1.04ms making 72 calls to Moose::Meta::Attribute::_process_required_option, avg 14µs/call |
| 260 | } | ||||
| 261 | |||||
| 262 | # spent 1.59ms within Moose::Meta::Attribute::_process_is_option which was called 72 times, avg 22µs/call:
# 72 times (1.59ms+0s) by Moose::Meta::Attribute::_process_options at line 251, avg 22µs/call | ||||
| 263 | 72 | 271µs | my ( $class, $name, $options ) = @_; | ||
| 264 | |||||
| 265 | 72 | 542µ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 | 47 | 866µs | if ( $options->{is} eq 'ro' ) { | ||
| 275 | 39 | 101µ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 | 39 | 207µs | $options->{reader} ||= $name; | ||
| 280 | } | ||||
| 281 | elsif ( $options->{is} eq 'rw' ) { | ||||
| 282 | if ( $options->{writer} ) { | ||||
| 283 | $options->{reader} ||= $name; | ||||
| 284 | } | ||||
| 285 | else { | ||||
| 286 | 8 | 43µ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 14.8ms (3.09+11.7) within Moose::Meta::Attribute::_process_isa_option which was called 72 times, avg 205µs/call:
# 72 times (3.09ms+11.7ms) by Moose::Meta::Attribute::_process_options at line 252, avg 205µs/call | ||||
| 301 | 72 | 314µs | my ( $class, $name, $options ) = @_; | ||
| 302 | |||||
| 303 | 72 | 346µs | return unless exists $options->{isa}; | ||
| 304 | |||||
| 305 | 62 | 155µ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 | 62 | 2.49ms | 106 | 4.74ms | if ( blessed( $options->{isa} ) # spent 4.27ms making 44 calls to MooseX::Types::TypeDecorator::isa, avg 97µs/call
# spent 468µs making 62 calls to Scalar::Util::blessed, avg 8µs/call |
| 321 | && $options->{isa}->isa('Moose::Meta::TypeConstraint') ) { | ||||
| 322 | $options->{type_constraint} = $options->{isa}; | ||||
| 323 | } | ||||
| 324 | else { | ||||
| 325 | 18 | 294µs | 18 | 6.93ms | $options->{type_constraint} # spent 6.93ms making 18 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 385µs/call |
| 326 | = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint( | ||||
| 327 | $options->{isa} ); | ||||
| 328 | } | ||||
| 329 | } | ||||
| 330 | |||||
| 331 | # spent 4.04ms (1.35+2.69) within Moose::Meta::Attribute::_process_does_option which was called 72 times, avg 56µs/call:
# 72 times (1.35ms+2.69ms) by Moose::Meta::Attribute::_process_options at line 253, avg 56µs/call | ||||
| 332 | 72 | 320µs | my ( $class, $name, $options ) = @_; | ||
| 333 | |||||
| 334 | 72 | 834µs | return unless exists $options->{does} && ! exists $options->{isa}; | ||
| 335 | |||||
| 336 | # allow for anon-subtypes here ... | ||||
| 337 | 9 | 317µs | 12 | 355µs | if ( blessed( $options->{does} ) # spent 296µs making 3 calls to MooseX::Types::TypeDecorator::isa, avg 99µs/call
# spent 59µs making 9 calls to Scalar::Util::blessed, avg 7µs/call |
| 338 | && $options->{does}->isa('Moose::Meta::TypeConstraint') ) { | ||||
| 339 | $options->{type_constraint} = $options->{does}; | ||||
| 340 | } | ||||
| 341 | else { | ||||
| 342 | 6 | 92µs | 6 | 2.34ms | $options->{type_constraint} # spent 2.34ms making 6 calls to Moose::Util::TypeConstraints::find_or_create_does_type_constraint, avg 389µs/call |
| 343 | = Moose::Util::TypeConstraints::find_or_create_does_type_constraint( | ||||
| 344 | $options->{does} ); | ||||
| 345 | } | ||||
| 346 | } | ||||
| 347 | |||||
| 348 | # spent 1.08ms within Moose::Meta::Attribute::_process_coerce_option which was called 72 times, avg 15µs/call:
# 72 times (1.08ms+0s) by Moose::Meta::Attribute::_process_options at line 254, avg 15µs/call | ||||
| 349 | 72 | 362µs | my ( $class, $name, $options ) = @_; | ||
| 350 | |||||
| 351 | 72 | 939µs | return unless $options->{coerce}; | ||
| 352 | |||||
| 353 | ( 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 | $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 | unless ( $options->{type_constraint}->has_coercion ) { | ||||
| 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 957µs within Moose::Meta::Attribute::_process_trigger_option which was called 72 times, avg 13µs/call:
# 72 times (957µs+0s) by Moose::Meta::Attribute::_process_options at line 255, avg 13µs/call | ||||
| 375 | 72 | 292µs | my ( $class, $name, $options ) = @_; | ||
| 376 | |||||
| 377 | 72 | 869µs | 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 974µs within Moose::Meta::Attribute::_process_auto_deref_option which was called 72 times, avg 14µs/call:
# 72 times (974µs+0s) by Moose::Meta::Attribute::_process_options at line 256, avg 14µs/call | ||||
| 384 | 72 | 295µs | my ( $class, $name, $options ) = @_; | ||
| 385 | |||||
| 386 | 72 | 898µs | 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 997µs within Moose::Meta::Attribute::_process_lazy_build_option which was called 72 times, avg 14µs/call:
# 72 times (997µs+0s) by Moose::Meta::Attribute::_process_options at line 257, avg 14µs/call | ||||
| 401 | 72 | 314µs | my ( $class, $name, $options ) = @_; | ||
| 402 | |||||
| 403 | 72 | 912µs | return unless $options->{lazy_build}; | ||
| 404 | |||||
| 405 | $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 | $options->{lazy} = 1; | ||||
| 411 | $options->{builder} ||= "_build_${name}"; | ||||
| 412 | |||||
| 413 | if ( $name =~ /^_/ ) { | ||||
| 414 | $options->{clearer} ||= "_clear${name}"; | ||||
| 415 | $options->{predicate} ||= "_has${name}"; | ||||
| 416 | } | ||||
| 417 | else { | ||||
| 418 | $options->{clearer} ||= "clear_${name}"; | ||||
| 419 | $options->{predicate} ||= "has_${name}"; | ||||
| 420 | } | ||||
| 421 | } | ||||
| 422 | |||||
| 423 | # spent 1.04ms within Moose::Meta::Attribute::_process_lazy_option which was called 72 times, avg 14µs/call:
# 72 times (1.04ms+0s) by Moose::Meta::Attribute::_process_options at line 258, avg 14µs/call | ||||
| 424 | 72 | 300µs | my ( $class, $name, $options ) = @_; | ||
| 425 | |||||
| 426 | 72 | 817µs | return unless $options->{lazy}; | ||
| 427 | |||||
| 428 | 11 | 136µ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.04ms within Moose::Meta::Attribute::_process_required_option which was called 72 times, avg 14µs/call:
# 72 times (1.04ms+0s) by Moose::Meta::Attribute::_process_options at line 259, avg 14µs/call | ||||
| 435 | 72 | 304µs | my ( $class, $name, $options ) = @_; | ||
| 436 | |||||
| 437 | 72 | 940µs | 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 67.0ms (10.2+56.8) within Moose::Meta::Attribute::initialize_instance_slot which was called 110 times, avg 609µs/call:
# 110 times (10.2ms+56.8ms) by Class::MOP::Class::_construct_instance at line 603 of Class/MOP/Class.pm, avg 609µs/call | ||||
| 452 | 110 | 474µs | my ($self, $meta_instance, $instance, $params) = @_; | ||
| 453 | 110 | 1.42ms | 110 | 1.22ms | my $init_arg = $self->init_arg(); # spent 1.22ms making 110 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 11µs/call |
| 454 | # try to fetch the init arg from the %params ... | ||||
| 455 | |||||
| 456 | 110 | 200µs | my $val; | ||
| 457 | 110 | 204µs | my $value_is_set; | ||
| 458 | 110 | 592µs | if ( defined($init_arg) and exists $params->{$init_arg}) { | ||
| 459 | 90 | 238µs | $val = $params->{$init_arg}; | ||
| 460 | 90 | 216µs | $value_is_set = 1; | ||
| 461 | } | ||||
| 462 | else { | ||||
| 463 | # skip it if it's lazy | ||||
| 464 | 20 | 358µs | 20 | 313µs | return if $self->is_lazy; # spent 313µs making 20 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 16µs/call |
| 465 | # and die if it's required and doesn't have a default value | ||||
| 466 | 12 | 207µs | 12 | 147µs | $self->throw_error("Attribute (" . $self->name . ") is required", object => $instance, data => $params) # spent 147µs making 12 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 12µs/call |
| 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 | 12 | 231µs | 16 | 174µs | if ($self->has_default) { # spent 130µs making 12 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 11µs/call
# spent 44µs making 4 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 11µs/call |
| 472 | 8 | 87µs | 8 | 324µs | $val = $self->default($instance); # spent 324µs making 8 calls to Class::MOP::Mixin::AttributeCore::default, avg 41µs/call |
| 473 | 8 | 19µ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 | 102 | 220µs | return unless $value_is_set; | ||
| 482 | |||||
| 483 | 98 | 1.27ms | 98 | 30.4ms | $val = $self->_coerce_and_verify( $val, $instance ); # spent 30.4ms making 98 calls to Moose::Meta::Attribute::_coerce_and_verify, avg 310µs/call |
| 484 | |||||
| 485 | 98 | 1.27ms | 98 | 23.0ms | $self->set_initial_value($instance, $val); # spent 23.0ms making 98 calls to Class::MOP::Attribute::set_initial_value, avg 234µs/call |
| 486 | |||||
| 487 | 98 | 2.25ms | 90 | 1.24ms | if ( ref $val && $self->is_weak_ref ) { # spent 1.24ms making 90 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 8.30ms (5.13+3.17) within Moose::Meta::Attribute::_set_initial_slot_value which was called 98 times, avg 85µs/call:
# 98 times (5.13ms+3.17ms) by Class::MOP::Attribute::set_initial_value at line 253 of Class/MOP/Attribute.pm, avg 85µs/call | ||||
| 518 | 98 | 401µs | my ($self, $meta_instance, $instance, $value) = @_; | ||
| 519 | |||||
| 520 | 98 | 1.93ms | 98 | 597µs | my $slot_name = $self->name; # spent 597µs making 98 calls to Class::MOP::Mixin::AttributeCore::name, avg 6µs/call |
| 521 | |||||
| 522 | 98 | 2.83ms | 196 | 2.58ms | return $meta_instance->set_slot_value($instance, $slot_name, $value) # spent 1.54ms making 98 calls to Class::MOP::Instance::set_slot_value, avg 16µs/call
# spent 1.04ms making 98 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 | sub _weaken_value { | ||||
| 566 | my ( $self, $instance ) = @_; | ||||
| 567 | |||||
| 568 | my $meta_instance = Class::MOP::Class->initialize( blessed($instance) ) | ||||
| 569 | ->get_meta_instance; | ||||
| 570 | |||||
| 571 | $meta_instance->weaken_slot_value( $instance, $self->name ); | ||||
| 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 | 117 | 1.72ms | # spent 1.23ms within Moose::Meta::Attribute::accessor_metaclass which was called 117 times, avg 11µs/call:
# 89 times (951µs+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 11µs/call
# 28 times (283µ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 587ms (4.68+583) within Moose::Meta::Attribute::install_accessors which was called 73 times, avg 8.04ms/call:
# 66 times (3.92ms+420ms) 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 6.43ms/call
# 6 times (681µs+155ms) 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 26.0ms/call
# once (75µs+6.59ms) by Class::MOP::Class::_inline_accessors at line 1305 of Class/MOP/Class.pm | ||||
| 622 | 73 | 220µs | my $self = shift; | ||
| 623 | 73 | 1.97ms | 73 | 465ms | $self->SUPER::install_accessors(@_); # spent 465ms making 73 calls to Class::MOP::Attribute::install_accessors, avg 6.37ms/call |
| 624 | 73 | 1.35ms | 80 | 117ms | $self->install_delegation if $self->has_handles; # spent 116ms making 7 calls to Moose::Meta::Attribute::install_delegation, avg 16.6ms/call
# spent 1.44ms making 73 calls to Moose::Meta::Mixin::AttributeCore::has_handles, avg 20µs/call |
| 625 | 73 | 936µs | return; | ||
| 626 | } | ||||
| 627 | |||||
| 628 | # spent 2.73ms (1.96+775µs) within Moose::Meta::Attribute::_check_associated_methods which was called 71 times, avg 38µs/call:
# 71 times (1.96ms+775µs) by Moose::Meta::Class::add_attribute at line 307 of Moose/Meta/Class.pm, avg 38µs/call | ||||
| 629 | 71 | 242µs | my $self = shift; | ||
| 630 | 71 | 1.75ms | 71 | 775µs | unless ( # spent 775µs making 71 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 400ms (12.6+388) within Moose::Meta::Attribute::_process_accessors which was called 89 times, avg 4.50ms/call:
# 65 times (9.22ms+287ms) by Class::MOP::Attribute::install_accessors at line 360 of Class/MOP/Attribute.pm, avg 4.56ms/call
# 9 times (1.32ms+34.6ms) by Class::MOP::Attribute::install_accessors at line 364 of Class/MOP/Attribute.pm, avg 3.99ms/call
# 8 times (1.07ms+51.9ms) by Class::MOP::Attribute::install_accessors at line 356 of Class/MOP/Attribute.pm, avg 6.62ms/call
# 7 times (993µs+14.2ms) by Class::MOP::Attribute::install_accessors at line 368 of Class/MOP/Attribute.pm, avg 2.17ms/call | ||||
| 645 | 89 | 263µs | my $self = shift; | ||
| 646 | 89 | 412µs | my ($type, $accessor, $generate_as_inline_methods) = @_; | ||
| 647 | |||||
| 648 | 89 | 266µs | $accessor = ( keys %$accessor )[0] if ( ref($accessor) || '' ) eq 'HASH'; | ||
| 649 | 89 | 1.87ms | 178 | 29.7ms | my $method = $self->associated_class->get_method($accessor); # spent 29.0ms making 89 calls to Class::MOP::Mixin::HasMethods::get_method, avg 325µs/call
# spent 757µs making 89 calls to Class::MOP::Attribute::associated_class, avg 9µs/call |
| 650 | |||||
| 651 | 89 | 265µs | 4 | 30µs | if ( $method # spent 12µs making 1 call to Class::MOP::Method::Accessor::associated_attribute
# spent 10µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call
# spent 8µ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 | 89 | 226µ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 | 89 | 4.11ms | 354 | 33.0ms | if ( !$self->associated_class->has_method($accessor) # spent 17.4ms making 89 calls to Class::MOP::Mixin::HasMethods::has_method, avg 196µs/call
# spent 13.9ms making 88 calls to Class::MOP::Package::has_package_symbol, avg 158µs/call
# spent 1.68ms making 177 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 | 89 | 3.52ms | 89 | 325ms | $self->SUPER::_process_accessors(@_); # spent 325ms making 89 calls to Class::MOP::Attribute::_process_accessors, avg 3.65ms/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 37.6ms (8.75+28.9) within Moose::Meta::Attribute::inline_set which was called 94 times, avg 400µs/call:
# 64 times (5.72ms+6.88ms) by Moose::Meta::Method::Constructor::_generate_slot_assignment at line 302 of Moose/Meta/Method/Constructor.pm, avg 197µs/call
# 28 times (2.67ms+21.2ms) by Moose::Meta::Method::Accessor::_inline_store at line 248 of Moose/Meta/Method/Accessor.pm, avg 852µs/call
# 2 times (367µs+823µs) by Class::MOP::Method::Constructor::_generate_slot_initializer at line 145 of Class/MOP/Method/Constructor.pm, avg 595µs/call | ||||
| 694 | 94 | 316µs | my $self = shift; | ||
| 695 | 94 | 373µs | my ( $instance, $value ) = @_; | ||
| 696 | |||||
| 697 | 94 | 1.95ms | 188 | 20.3ms | my $mi = $self->associated_class->get_meta_instance; # spent 19.3ms making 93 calls to Class::MOP::Class::get_meta_instance, avg 208µs/call
# spent 865µs making 94 calls to Class::MOP::Attribute::associated_class, avg 9µs/call
# spent 83µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance |
| 698 | |||||
| 699 | 94 | 2.21ms | 188 | 6.87ms | my $code # spent 4.57ms making 94 calls to Class::MOP::Instance::inline_set_slot_value, avg 49µs/call
# spent 2.30ms making 94 calls to Class::MOP::Attribute::slots, avg 24µs/call |
| 700 | = $mi->inline_set_slot_value( $instance, $self->slots, $value ) . ";"; | ||||
| 701 | 94 | 1.39ms | 98 | 1.75ms | $code # spent 1.61ms making 94 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 17µs/call
# spent 89µs making 2 calls to Class::MOP::Instance::inline_weaken_slot_value, avg 44µs/call
# spent 43µs making 2 calls to Class::MOP::Attribute::slots, avg 21µs/call |
| 702 | .= $mi->inline_weaken_slot_value( $instance, $self->slots, $value ) | ||||
| 703 | . " if ref $value;" | ||||
| 704 | if $self->is_weak_ref; | ||||
| 705 | |||||
| 706 | 94 | 1.33ms | return $code; | ||
| 707 | } | ||||
| 708 | |||||
| 709 | # spent 116ms (3.50+112) within Moose::Meta::Attribute::install_delegation which was called 7 times, avg 16.6ms/call:
# 7 times (3.50ms+112ms) by Moose::Meta::Attribute::install_accessors at line 624, avg 16.6ms/call | ||||
| 710 | 7 | 25µ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 | 7 | 128µs | 7 | 939µs | my %handles = $self->_canonicalize_handles; # spent 257µs making 2 calls to Class::MOP::Class::__ANON__::SERIAL::5::_canonicalize_handles, avg 129µs/call
# spent 171µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::11::_canonicalize_handles
# spent 147µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::19::_canonicalize_handles
# spent 145µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::15::_canonicalize_handles
# spent 128µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::8::_canonicalize_handles
# spent 91µs making 1 call to Moose::Meta::Attribute::_canonicalize_handles |
| 718 | |||||
| 719 | |||||
| 720 | # install the delegation ... | ||||
| 721 | 7 | 95µs | 7 | 80µs | my $associated_class = $self->associated_class; # spent 80µs making 7 calls to Class::MOP::Attribute::associated_class, avg 11µs/call |
| 722 | 7 | 183µs | foreach my $handle (keys %handles) { | ||
| 723 | 15 | 55µs | my $method_to_call = $handles{$handle}; | ||
| 724 | 15 | 327µs | 15 | 103µs | my $class_name = $associated_class->name; # spent 103µs making 15 calls to Class::MOP::Package::name, avg 7µs/call |
| 725 | 15 | 64µs | my $name = "${class_name}::${handle}"; | ||
| 726 | |||||
| 727 | 15 | 194µs | 15 | 4.83ms | (!$associated_class->has_method($handle)) # spent 4.83ms making 15 calls to Class::MOP::Mixin::HasMethods::has_method, avg 322µ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 | 15 | 1.29ms | 43 | 683µs | next if $class_name->isa("Moose::Object") and $handle =~ /^BUILD|DEMOLISH$/ || Moose::Object->can($handle); # spent 279µs making 14 calls to UNIVERSAL::can, avg 20µs/call
# spent 232µs making 14 calls to Moose::Meta::Attribute::CORE:match, avg 17µs/call
# spent 172µs making 15 calls to UNIVERSAL::isa, avg 11µs/call |
| 739 | |||||
| 740 | 15 | 262µs | 15 | 97.3ms | my $method = $self->_make_delegation_method($handle, $method_to_call); # spent 27.9ms making 4 calls to Class::MOP::Class::__ANON__::SERIAL::5::_make_delegation_method, avg 6.98ms/call
# spent 22.2ms making 3 calls to Class::MOP::Class::__ANON__::SERIAL::15::_make_delegation_method, avg 7.41ms/call
# spent 17.3ms making 3 calls to Class::MOP::Class::__ANON__::SERIAL::19::_make_delegation_method, avg 5.78ms/call
# spent 15.7ms making 2 calls to Class::MOP::Class::__ANON__::SERIAL::11::_make_delegation_method, avg 7.83ms/call
# spent 12.9ms making 2 calls to Class::MOP::Class::__ANON__::SERIAL::8::_make_delegation_method, avg 6.43ms/call
# spent 1.26ms making 1 call to Moose::Meta::Attribute::_make_delegation_method |
| 741 | |||||
| 742 | 15 | 1.05ms | 45 | 8.28ms | $self->associated_class->add_method($method->name, $method); # spent 7.96ms making 15 calls to Class::MOP::Mixin::HasMethods::add_method, avg 531µs/call
# spent 212µs making 15 calls to Class::MOP::Attribute::associated_class, avg 14µs/call
# spent 108µs making 15 calls to Class::MOP::Method::name, avg 7µs/call |
| 743 | 15 | 362µs | 15 | 265µs | $self->associate_method($method); # spent 265µs making 15 calls to Class::MOP::Attribute::associate_method, avg 18µ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 91µs (78+13) within Moose::Meta::Attribute::_canonicalize_handles which was called:
# once (78µs+13µs) by Moose::Meta::Attribute::install_delegation at line 717 | ||||
| 762 | 1 | 3µs | my $self = shift; | ||
| 763 | 1 | 42µs | 1 | 13µs | my $handles = $self->handles; # spent 13µs making 1 call to Moose::Meta::Mixin::AttributeCore::handles |
| 764 | 1 | 4µs | if (my $handle_type = ref($handles)) { | ||
| 765 | 1 | 26µ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 | 29 | 392µs | # spent 281µs within Moose::Meta::Attribute::delegation_metaclass which was called 29 times, avg 10µs/call:
# 28 times (274µ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
# once (8µs+0s) by Moose::Meta::Attribute::_make_delegation_method at line 864 | ||
| 855 | |||||
| 856 | # spent 1.26ms (87µs+1.17) within Moose::Meta::Attribute::_make_delegation_method which was called:
# once (87µs+1.17ms) by Moose::Meta::Attribute::install_delegation at line 740 | ||||
| 857 | 1 | 5µs | my ( $self, $handle_name, $method_to_call ) = @_; | ||
| 858 | |||||
| 859 | 1 | 2µs | my @curried_arguments; | ||
| 860 | |||||
| 861 | 1 | 2µs | ($method_to_call, @curried_arguments) = @$method_to_call | ||
| 862 | if 'ARRAY' eq ref($method_to_call); | ||||
| 863 | |||||
| 864 | 1 | 81µs | 4 | 1.17ms | return $self->delegation_metaclass->new( # spent 1.15ms making 1 call to Moose::Meta::Method::Delegation::new
# spent 10µs making 1 call to Class::MOP::Attribute::associated_class
# spent 8µs making 1 call to Moose::Meta::Attribute::delegation_metaclass
# spent 6µs making 1 call to Class::MOP::Package::name |
| 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 30.4ms (6.07+24.3) within Moose::Meta::Attribute::_coerce_and_verify which was called 98 times, avg 310µs/call:
# 98 times (6.07ms+24.3ms) by Moose::Meta::Attribute::initialize_instance_slot at line 483, avg 310µs/call | ||||
| 874 | 98 | 295µs | my $self = shift; | ||
| 875 | 98 | 210µs | my $val = shift; | ||
| 876 | 98 | 207µs | my $instance = shift; | ||
| 877 | |||||
| 878 | 98 | 1.18ms | 98 | 1.09ms | return $val unless $self->has_type_constraint; # spent 1.09ms making 98 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 11µs/call |
| 879 | |||||
| 880 | 98 | 1.21ms | 98 | 1.32ms | $val = $self->type_constraint->coerce($val) # spent 1.32ms making 98 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 13µs/call |
| 881 | if $self->should_coerce && $self->type_constraint->has_coercion; | ||||
| 882 | |||||
| 883 | 98 | 1.12ms | 98 | 21.9ms | $self->verify_against_type_constraint($val, instance => $instance); # spent 21.9ms making 98 calls to Moose::Meta::Attribute::verify_against_type_constraint, avg 223µs/call |
| 884 | |||||
| 885 | 98 | 1.11ms | return $val; | ||
| 886 | } | ||||
| 887 | |||||
| 888 | # spent 21.9ms (5.72+16.2) within Moose::Meta::Attribute::verify_against_type_constraint which was called 98 times, avg 223µs/call:
# 98 times (5.72ms+16.2ms) by Moose::Meta::Attribute::_coerce_and_verify at line 883, avg 223µs/call | ||||
| 889 | 98 | 362µs | my $self = shift; | ||
| 890 | 98 | 229µs | my $val = shift; | ||
| 891 | |||||
| 892 | 98 | 928µs | 98 | 852µs | return 1 if !$self->has_type_constraint; # spent 852µs making 98 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 9µs/call |
| 893 | |||||
| 894 | 98 | 1.14ms | 98 | 1.27ms | my $type_constraint = $self->type_constraint; # spent 1.27ms making 98 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 13µs/call |
| 895 | |||||
| 896 | 98 | 2.25ms | 98 | 14.1ms | $type_constraint->check($val) # spent 12.0ms making 92 calls to Moose::Meta::TypeConstraint::check, avg 131µs/call
# spent 2.05ms making 6 calls to MooseX::Types::TypeDecorator::AUTOLOAD, avg 342µ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 | 31µs | 1; | ||
| 907 | |||||
| 908 | __END__ | ||||
# spent 232µs within Moose::Meta::Attribute::CORE:match which was called 14 times, avg 17µs/call:
# 14 times (232µs+0s) by Moose::Meta::Attribute::install_delegation at line 738, avg 17µs/call | |||||
# spent 314µs within Moose::Meta::Attribute::CORE:sort which was called 72 times, avg 4µs/call:
# 72 times (314µs+0s) by Moose::Meta::Attribute::new at line 68, avg 4µs/call |