| Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/Attribute.pm |
| Statements | Executed 1179 statements in 9.10ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 7.48ms | 65.3ms | Moose::Meta::Attribute::BEGIN@16 |
| 6 | 2 | 1 | 4.28ms | 9.55ms | Moose::Meta::Attribute::_process_accessors |
| 1 | 1 | 1 | 1.44ms | 2.07ms | Moose::Meta::Attribute::BEGIN@6 |
| 1 | 1 | 1 | 419µs | 660µs | Moose::Meta::Attribute::BEGIN@13 |
| 1 | 1 | 1 | 396µs | 557µs | Moose::Meta::Attribute::BEGIN@14 |
| 5 | 2 | 2 | 304µs | 4.62ms | Moose::Meta::Attribute::new |
| 12 | 4 | 3 | 158µs | 1.69ms | Moose::Meta::Attribute::_inline_set_value |
| 6 | 1 | 1 | 144µs | 328µs | Moose::Meta::Attribute::_eval_environment |
| 13 | 2 | 1 | 131µs | 652µs | Moose::Meta::Attribute::_inline_check_constraint |
| 5 | 1 | 1 | 106µs | 3.54ms | Moose::Meta::Attribute::_process_options |
| 4 | 1 | 1 | 49µs | 4.15ms | Moose::Meta::Attribute::interpolate_class_and_new |
| 1 | 1 | 1 | 48µs | 332µs | Moose::Meta::Attribute::install_delegation |
| 6 | 2 | 1 | 46µs | 10.4ms | Moose::Meta::Attribute::install_accessors |
| 6 | 2 | 1 | 46µs | 414µs | Moose::Meta::Attribute::_inline_get_value |
| 13 | 2 | 1 | 45µs | 104µs | Moose::Meta::Attribute::_inline_weaken_value |
| 5 | 1 | 1 | 44µs | 3.38ms | Moose::Meta::Attribute::_process_isa_option |
| 12 | 1 | 1 | 42µs | 706µs | Moose::Meta::Attribute::_inline_tc_code |
| 12 | 1 | 1 | 29µs | 79µs | Moose::Meta::Attribute::_writer_value_needs_copy |
| 13 | 2 | 1 | 26µs | 60µs | Moose::Meta::Attribute::_inline_check_coercion |
| 6 | 1 | 1 | 26µs | 143µs | Moose::Meta::Attribute::_inline_get_old_value_for_trigger |
| 6 | 1 | 1 | 26µs | 190µs | Moose::Meta::Attribute::_inline_check_lazy |
| 6 | 1 | 1 | 25µs | 64µs | Moose::Meta::Attribute::_inline_check_required |
| 6 | 1 | 1 | 21µs | 55µs | Moose::Meta::Attribute::_auto_deref |
| 6 | 1 | 1 | 17µs | 72µs | Moose::Meta::Attribute::_inline_return_auto_deref |
| 6 | 1 | 1 | 17µs | 60µs | Moose::Meta::Attribute::_inline_trigger |
| 2 | 1 | 1 | 17µs | 156µs | Moose::Meta::Attribute::_make_delegation_method |
| 1 | 1 | 1 | 16µs | 94µs | Moose::Meta::Attribute::_inline_init_from_default |
| 12 | 2 | 1 | 16µs | 16µs | Moose::Meta::Attribute::_inline_throw_exception |
| 4 | 1 | 1 | 16µs | 16µs | Moose::Meta::Attribute::interpolate_class |
| 5 | 1 | 1 | 15µs | 15µs | Moose::Meta::Attribute::_process_is_option |
| 4 | 1 | 1 | 12µs | 13µs | Moose::Meta::Attribute::_check_associated_methods |
| 1 | 1 | 1 | 10µs | 43µs | Moose::Meta::Attribute::BEGIN@8 |
| 1 | 1 | 1 | 10µs | 11µs | Moose::Meta::Attribute::_canonicalize_handles |
| 1 | 1 | 1 | 9µs | 10µs | Moose::Meta::TypeCoercion::BEGIN@1 |
| 5 | 1 | 1 | 8µs | 8µs | Moose::Meta::Attribute::_process_required_option |
| 5 | 1 | 1 | 8µs | 8µs | Moose::Meta::Attribute::_process_does_option |
| 1 | 1 | 1 | 8µs | 10µs | Moose::Meta::Attribute::_inline_generate_default |
| 1 | 1 | 1 | 7µs | 35µs | Moose::Meta::Attribute::BEGIN@21 |
| 5 | 1 | 1 | 7µs | 7µs | Moose::Meta::Attribute::_process_trigger_option |
| 1 | 1 | 1 | 7µs | 43µs | Moose::Meta::Attribute::BEGIN@7 |
| 5 | 1 | 1 | 7µs | 7µs | Moose::Meta::Attribute::_process_lazy_option |
| 1 | 1 | 1 | 7µs | 26µs | Moose::Meta::Attribute::BEGIN@9 |
| 1 | 1 | 1 | 6µs | 16µs | Moose::Meta::Attribute::_inline_init_slot |
| 1 | 1 | 1 | 6µs | 6.26ms | Moose::Meta::Attribute::BEGIN@19 |
| 1 | 1 | 1 | 6µs | 12µs | Moose::Meta::Attribute::BEGIN@12 |
| 1 | 1 | 1 | 6µs | 85µs | Moose::Meta::Attribute::BEGIN@15 |
| 5 | 1 | 1 | 5µs | 5µs | Moose::Meta::Attribute::_process_auto_deref_option |
| 5 | 1 | 1 | 5µs | 5µs | Moose::Meta::Attribute::_process_coerce_option |
| 1 | 1 | 1 | 5µs | 9µs | Moose::Meta::TypeCoercion::BEGIN@2 |
| 1 | 1 | 1 | 5µs | 5µs | Moose::Meta::Attribute::BEGIN@17 |
| 5 | 1 | 1 | 4µs | 4µs | Moose::Meta::Attribute::_process_lazy_build_option |
| 6 | 1 | 1 | 4µs | 4µs | Moose::Meta::Attribute::accessor_metaclass |
| 2 | 1 | 1 | 2µs | 2µs | Moose::Meta::Attribute::CORE:match (opcode) |
| 6 | 2 | 1 | 2µs | 2µs | Moose::Meta::Attribute::CORE:sort (opcode) |
| 1 | 1 | 1 | 2µs | 2µs | Moose::Meta::Attribute::BEGIN@10 |
| 2 | 1 | 1 | 1µs | 1µs | Moose::Meta::Attribute::delegation_metaclass |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::Custom::Moose::register_implementation |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::__ANON__[:1115] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::__ANON__[:139] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::__ANON__[:312] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::__ANON__[:39] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::__ANON__[:542] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::_call_builder |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::_coerce_and_verify |
| 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::_inline_copy_value |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::_make_initializer_writer_callback |
| 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::clone_and_inherit_options |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::does |
| 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::initialize_instance_slot |
| 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::verify_against_type_constraint |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | 2 | 14µs | 2 | 12µs | # spent 10µs (9+2) within Moose::Meta::TypeCoercion::BEGIN@1 which was called:
# once (9µs+2µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 1 # spent 10µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@1
# spent 2µs making 1 call to strict::import |
| 2 | 2 | 32µs | 2 | 13µs | # spent 9µs (5+4) within Moose::Meta::TypeCoercion::BEGIN@2 which was called:
# once (5µs+4µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 2 # spent 9µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@2
# spent 4µs making 1 call to warnings::import |
| 3 | package Moose::Meta::Attribute; | ||||
| 4 | 1 | 400ns | our $VERSION = '2.1605'; | ||
| 5 | |||||
| 6 | 2 | 102µs | 1 | 2.07ms | # spent 2.07ms (1.44+630µs) within Moose::Meta::Attribute::BEGIN@6 which was called:
# once (1.44ms+630µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 6 # spent 2.07ms making 1 call to Moose::Meta::Attribute::BEGIN@6 |
| 7 | 2 | 21µs | 2 | 80µs | # spent 43µs (7+36) within Moose::Meta::Attribute::BEGIN@7 which was called:
# once (7µs+36µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 7 # spent 43µs making 1 call to Moose::Meta::Attribute::BEGIN@7
# spent 36µs making 1 call to Exporter::import |
| 8 | 3 | 32µs | 3 | 62µs | # spent 43µs (10+33) within Moose::Meta::Attribute::BEGIN@8 which was called:
# once (10µs+33µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 8 # spent 43µs making 1 call to Moose::Meta::Attribute::BEGIN@8
# spent 11µs making 1 call to UNIVERSAL::VERSION
# spent 8µs making 1 call to List::Util::import |
| 9 | 2 | 15µs | 2 | 46µs | # spent 26µs (7+20) within Moose::Meta::Attribute::BEGIN@9 which was called:
# once (7µs+20µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 9 # spent 26µs making 1 call to Moose::Meta::Attribute::BEGIN@9
# spent 20µs making 1 call to Exporter::import |
| 10 | 2 | 13µs | 1 | 2µs | # spent 2µs within Moose::Meta::Attribute::BEGIN@10 which was called:
# once (2µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 10 # spent 2µs making 1 call to Moose::Meta::Attribute::BEGIN@10 |
| 11 | |||||
| 12 | 2 | 15µs | 2 | 18µs | # spent 12µs (6+6) within Moose::Meta::Attribute::BEGIN@12 which was called:
# once (6µs+6µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 12 # spent 12µs making 1 call to Moose::Meta::Attribute::BEGIN@12
# spent 6µs making 1 call to Package::DeprecationManager::__ANON__[Package/DeprecationManager.pm:87] |
| 13 | 2 | 79µs | 1 | 660µs | # spent 660µs (419+240) within Moose::Meta::Attribute::BEGIN@13 which was called:
# once (419µs+240µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 13 # spent 660µs making 1 call to Moose::Meta::Attribute::BEGIN@13 |
| 14 | 2 | 78µs | 1 | 557µs | # spent 557µs (396+161) within Moose::Meta::Attribute::BEGIN@14 which was called:
# once (396µs+161µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 14 # spent 557µs making 1 call to Moose::Meta::Attribute::BEGIN@14 |
| 15 | 2 | 18µs | 2 | 165µs | # spent 85µs (6+80) within Moose::Meta::Attribute::BEGIN@15 which was called:
# once (6µs+80µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 15 # spent 85µs making 1 call to Moose::Meta::Attribute::BEGIN@15
# spent 80µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
| 16 | 2 | 79µs | 1 | 65.3ms | # spent 65.3ms (7.48+57.8) within Moose::Meta::Attribute::BEGIN@16 which was called:
# once (7.48ms+57.8ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 16 # spent 65.3ms making 1 call to Moose::Meta::Attribute::BEGIN@16 |
| 17 | 2 | 18µs | 1 | 5µs | # spent 5µs within Moose::Meta::Attribute::BEGIN@17 which was called:
# once (5µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 17 # spent 5µs making 1 call to Moose::Meta::Attribute::BEGIN@17 |
| 18 | |||||
| 19 | 2 | 30µs | 2 | 12.5ms | # spent 6.26ms (6µs+6.26) within Moose::Meta::Attribute::BEGIN@19 which was called:
# once (6µs+6.26ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 19 # spent 6.26ms making 1 call to Moose::Meta::Attribute::BEGIN@19
# spent 6.26ms making 1 call to parent::import |
| 20 | |||||
| 21 | 2 | 2.84ms | 2 | 63µs | # spent 35µs (7+28) within Moose::Meta::Attribute::BEGIN@21 which was called:
# once (7µs+28µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 21 # spent 35µs making 1 call to Moose::Meta::Attribute::BEGIN@21
# spent 28µs making 1 call to Exporter::import |
| 22 | |||||
| 23 | 1 | 2µs | 1 | 969µs | Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); # spent 969µs making 1 call to Class::MOP::MiniTrait::apply |
| 24 | |||||
| 25 | 1 | 4µs | 3 | 323µs | __PACKAGE__->meta->add_attribute('traits' => ( # spent 311µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 7µs making 1 call to Class::MOP::_definition_context
# spent 6µs making 1 call to Class::MOP::Object::meta |
| 26 | reader => 'applied_traits', | ||||
| 27 | predicate => 'has_applied_traits', | ||||
| 28 | Class::MOP::_definition_context(), | ||||
| 29 | )); | ||||
| 30 | |||||
| 31 | # we need to have a ->does method in here to | ||||
| 32 | # more easily support traits, and the introspection | ||||
| 33 | # of those traits. We extend the does check to look | ||||
| 34 | # for metatrait aliases. | ||||
| 35 | sub does { | ||||
| 36 | my ($self, $role_name) = @_; | ||||
| 37 | my $name = try { | ||||
| 38 | Moose::Util::resolve_metatrait_alias(Attribute => $role_name) | ||||
| 39 | }; | ||||
| 40 | return 0 if !defined($name); # failed to load class | ||||
| 41 | return $self->Moose::Object::does($name); | ||||
| 42 | } | ||||
| 43 | |||||
| 44 | sub _inline_throw_exception { | ||||
| 45 | 12 | 3µs | my ( $self, $exception_type, $throw_args ) = @_; | ||
| 46 | 12 | 19µs | return 'die Module::Runtime::use_module("Moose::Exception::' . $exception_type . '")->new(' . ($throw_args || '') . ')'; | ||
| 47 | } | ||||
| 48 | |||||
| 49 | # spent 4.62ms (304µs+4.31) within Moose::Meta::Attribute::new which was called 5 times, avg 923µs/call:
# 4 times (243µs+3.84ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 99, avg 1.02ms/call
# once (61µs+468µs) by Moose::BEGIN@26 at line 19 of Moose/Meta/TypeCoercion.pm | ||||
| 50 | 5 | 8µs | my ($class, $name, %options) = @_; | ||
| 51 | 5 | 8µs | 5 | 3.54ms | $class->_process_options($name, \%options) unless $options{__hack_no_process_options}; # used from clone()... YECHKKK FIXME ICKY YUCK GROSS # spent 3.54ms making 5 calls to Moose::Meta::Attribute::_process_options, avg 709µs/call |
| 52 | |||||
| 53 | 5 | 2µs | delete $options{__hack_no_process_options}; | ||
| 54 | |||||
| 55 | my %attrs = | ||||
| 56 | ( map { $_ => 1 } | ||||
| 57 | grep { defined } | ||||
| 58 | 145 | 263µs | 150 | 275µs | map { $_->init_arg() } # spent 143µs making 4 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 36µs/call
# spent 50µs making 1 call to Class::MOP::Class::get_all_attributes
# spent 42µs making 5 calls to Class::MOP::Object::meta, avg 8µs/call
# spent 40µs making 140 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 288ns/call |
| 59 | $class->meta()->get_all_attributes() | ||||
| 60 | ); | ||||
| 61 | |||||
| 62 | 5 | 20µs | 5 | 2µs | my @bad = sort grep { ! $attrs{$_} } keys %options; # spent 2µs making 5 calls to Moose::Meta::Attribute::CORE:sort, avg 360ns/call |
| 63 | |||||
| 64 | 5 | 2µs | if (@bad) | ||
| 65 | { | ||||
| 66 | my $s = @bad > 1 ? 's' : ''; | ||||
| 67 | my $list = join "', '", @bad; | ||||
| 68 | |||||
| 69 | my $package = $options{definition_context}{package}; | ||||
| 70 | my $context = $options{definition_context}{context} | ||||
| 71 | || 'attribute constructor'; | ||||
| 72 | my $type = $options{definition_context}{type} || 'class'; | ||||
| 73 | |||||
| 74 | my $location = ''; | ||||
| 75 | if (defined($package)) { | ||||
| 76 | $location = " in "; | ||||
| 77 | $location .= "$type " if $type; | ||||
| 78 | $location .= $package; | ||||
| 79 | } | ||||
| 80 | |||||
| 81 | Carp::cluck "Found unknown argument$s '$list' in the $context for '$name'$location"; | ||||
| 82 | } | ||||
| 83 | |||||
| 84 | 5 | 28µs | 5 | 490µs | return $class->SUPER::new($name, %options); # spent 490µs making 5 calls to Class::MOP::Attribute::new, avg 98µs/call |
| 85 | } | ||||
| 86 | |||||
| 87 | # spent 4.15ms (49µs+4.10) within Moose::Meta::Attribute::interpolate_class_and_new which was called 4 times, avg 1.04ms/call:
# 4 times (49µs+4.10ms) by Moose::Meta::Class::_process_new_attribute at line 712 of Moose/Meta/Class.pm, avg 1.04ms/call | ||||
| 88 | 4 | 1µs | my $class = shift; | ||
| 89 | 4 | 1µs | my $name = shift; | ||
| 90 | |||||
| 91 | 4 | 3µs | throw_exception( MustPassEvenNumberOfAttributeOptions => attribute_name => $name, | ||
| 92 | options => \@_ | ||||
| 93 | ) | ||||
| 94 | if @_ % 2 == 1; | ||||
| 95 | |||||
| 96 | 4 | 6µs | my %args = @_; | ||
| 97 | |||||
| 98 | 4 | 10µs | 4 | 16µs | my ( $new_class, @traits ) = $class->interpolate_class(\%args); # spent 16µs making 4 calls to Moose::Meta::Attribute::interpolate_class, avg 4µs/call |
| 99 | 4 | 29µs | 4 | 4.09ms | $new_class->new($name, %args, ( scalar(@traits) ? ( traits => \@traits ) : () ) ); # spent 4.09ms making 4 calls to Moose::Meta::Attribute::new, avg 1.02ms/call |
| 100 | } | ||||
| 101 | |||||
| 102 | # spent 16µs within Moose::Meta::Attribute::interpolate_class which was called 4 times, avg 4µs/call:
# 4 times (16µs+0s) by Moose::Meta::Attribute::interpolate_class_and_new at line 98, avg 4µs/call | ||||
| 103 | 4 | 2µs | my ($class, $options) = @_; | ||
| 104 | |||||
| 105 | 4 | 2µs | $class = ref($class) || $class; | ||
| 106 | |||||
| 107 | 4 | 2µs | if ( my $metaclass_name = delete $options->{metaclass} ) { | ||
| 108 | my $new_class = Moose::Util::resolve_metaclass_alias( Attribute => $metaclass_name ); | ||||
| 109 | |||||
| 110 | if ( $class ne $new_class ) { | ||||
| 111 | if ( $new_class->can("interpolate_class") ) { | ||||
| 112 | return $new_class->interpolate_class($options); | ||||
| 113 | } else { | ||||
| 114 | $class = $new_class; | ||||
| 115 | } | ||||
| 116 | } | ||||
| 117 | } | ||||
| 118 | |||||
| 119 | 4 | 1µs | my @traits; | ||
| 120 | |||||
| 121 | 4 | 2µs | if (my $traits = $options->{traits}) { | ||
| 122 | my $i = 0; | ||||
| 123 | my $has_foreign_options = 0; | ||||
| 124 | |||||
| 125 | while ($i < @$traits) { | ||||
| 126 | my $trait = $traits->[$i++]; | ||||
| 127 | next if ref($trait); # options to a trait we discarded | ||||
| 128 | |||||
| 129 | $trait = Moose::Util::resolve_metatrait_alias(Attribute => $trait) | ||||
| 130 | || $trait; | ||||
| 131 | |||||
| 132 | next if $class->does($trait); | ||||
| 133 | |||||
| 134 | push @traits, $trait; | ||||
| 135 | |||||
| 136 | # are there options? | ||||
| 137 | if ($traits->[$i] && ref($traits->[$i])) { | ||||
| 138 | $has_foreign_options = 1 | ||||
| 139 | if any { $_ ne '-alias' && $_ ne '-excludes' } keys %{ $traits->[$i] }; | ||||
| 140 | |||||
| 141 | push @traits, $traits->[$i++]; | ||||
| 142 | } | ||||
| 143 | } | ||||
| 144 | |||||
| 145 | if (@traits) { | ||||
| 146 | my %options = ( | ||||
| 147 | superclasses => [ $class ], | ||||
| 148 | roles => [ @traits ], | ||||
| 149 | ); | ||||
| 150 | |||||
| 151 | if ($has_foreign_options) { | ||||
| 152 | $options{weaken} = 0; | ||||
| 153 | } | ||||
| 154 | else { | ||||
| 155 | $options{cache} = 1; | ||||
| 156 | } | ||||
| 157 | |||||
| 158 | my $anon_class = Moose::Meta::Class->create_anon_class(%options); | ||||
| 159 | $class = $anon_class->name; | ||||
| 160 | } | ||||
| 161 | } | ||||
| 162 | |||||
| 163 | 4 | 10µs | return ( wantarray ? ( $class, @traits ) : $class ); | ||
| 164 | } | ||||
| 165 | |||||
| 166 | # ... | ||||
| 167 | |||||
| 168 | # method-generating options shouldn't be overridden | ||||
| 169 | sub illegal_options_for_inheritance { | ||||
| 170 | qw(reader writer accessor clearer predicate) | ||||
| 171 | } | ||||
| 172 | |||||
| 173 | # NOTE/TODO | ||||
| 174 | # This method *must* be able to handle | ||||
| 175 | # Class::MOP::Attribute instances as | ||||
| 176 | # well. Yes, I know that is wrong, but | ||||
| 177 | # apparently we didn't realize it was | ||||
| 178 | # doing that and now we have some code | ||||
| 179 | # which is dependent on it. The real | ||||
| 180 | # solution of course is to push this | ||||
| 181 | # feature back up into Class::MOP::Attribute | ||||
| 182 | # but I not right now, I am too lazy. | ||||
| 183 | # However if you are reading this and | ||||
| 184 | # looking for something to do,.. please | ||||
| 185 | # be my guest. | ||||
| 186 | # - stevan | ||||
| 187 | sub clone_and_inherit_options { | ||||
| 188 | my ($self, %options) = @_; | ||||
| 189 | |||||
| 190 | # NOTE: | ||||
| 191 | # we may want to extends a Class::MOP::Attribute | ||||
| 192 | # in which case we need to be able to use the | ||||
| 193 | # core set of legal options that have always | ||||
| 194 | # been here. But we allows Moose::Meta::Attribute | ||||
| 195 | # instances to changes them. | ||||
| 196 | # - SL | ||||
| 197 | my @illegal_options = $self->can('illegal_options_for_inheritance') | ||||
| 198 | ? $self->illegal_options_for_inheritance | ||||
| 199 | : (); | ||||
| 200 | |||||
| 201 | my @found_illegal_options = grep { exists $options{$_} && exists $self->{$_} ? $_ : undef } @illegal_options; | ||||
| 202 | (scalar @found_illegal_options == 0) | ||||
| 203 | || throw_exception( IllegalInheritedOptions => illegal_options => \@found_illegal_options, | ||||
| 204 | params => \%options | ||||
| 205 | ); | ||||
| 206 | |||||
| 207 | $self->_process_isa_option( $self->name, \%options ); | ||||
| 208 | $self->_process_does_option( $self->name, \%options ); | ||||
| 209 | |||||
| 210 | # NOTE: | ||||
| 211 | # this doesn't apply to Class::MOP::Attributes, | ||||
| 212 | # so we can ignore it for them. | ||||
| 213 | # - SL | ||||
| 214 | if ($self->can('interpolate_class')) { | ||||
| 215 | ( $options{metaclass}, my @traits ) = $self->interpolate_class(\%options); | ||||
| 216 | |||||
| 217 | my %seen; | ||||
| 218 | my @all_traits = grep { $seen{$_}++ } @{ $self->applied_traits || [] }, @traits; | ||||
| 219 | $options{traits} = \@all_traits if @all_traits; | ||||
| 220 | } | ||||
| 221 | |||||
| 222 | # This method can be called on a CMOP::Attribute object, so we need to | ||||
| 223 | # make sure we can call this method. | ||||
| 224 | $self->_process_lazy_build_option( $self->name, \%options ) | ||||
| 225 | if $self->can('_process_lazy_build_option'); | ||||
| 226 | |||||
| 227 | $self->clone(%options); | ||||
| 228 | } | ||||
| 229 | |||||
| 230 | sub clone { | ||||
| 231 | my ( $self, %params ) = @_; | ||||
| 232 | |||||
| 233 | my $class = delete $params{metaclass} || ref $self; | ||||
| 234 | |||||
| 235 | my ( @init, @non_init ); | ||||
| 236 | |||||
| 237 | foreach my $attr ( grep { $_->has_value($self) } Class::MOP::class_of($self)->get_all_attributes ) { | ||||
| 238 | push @{ $attr->has_init_arg ? \@init : \@non_init }, $attr; | ||||
| 239 | } | ||||
| 240 | |||||
| 241 | my %new_params = ( ( map { $_->init_arg => $_->get_value($self) } @init ), %params ); | ||||
| 242 | |||||
| 243 | my $name = delete $new_params{name}; | ||||
| 244 | |||||
| 245 | my $clone = $class->new($name, %new_params, __hack_no_process_options => 1 ); | ||||
| 246 | |||||
| 247 | foreach my $attr ( @non_init ) { | ||||
| 248 | $attr->set_value($clone, $attr->get_value($self)); | ||||
| 249 | } | ||||
| 250 | |||||
| 251 | return $clone; | ||||
| 252 | } | ||||
| 253 | |||||
| 254 | # spent 3.54ms (106µs+3.44) within Moose::Meta::Attribute::_process_options which was called 5 times, avg 709µs/call:
# 5 times (106µs+3.44ms) by Moose::Meta::Attribute::new at line 51, avg 709µs/call | ||||
| 255 | 5 | 2µs | my ( $class, $name, $options ) = @_; | ||
| 256 | |||||
| 257 | 5 | 7µs | 5 | 15µs | $class->_process_is_option( $name, $options ); # spent 15µs making 5 calls to Moose::Meta::Attribute::_process_is_option, avg 3µs/call |
| 258 | 5 | 24µs | 5 | 3.38ms | $class->_process_isa_option( $name, $options ); # spent 3.38ms making 5 calls to Moose::Meta::Attribute::_process_isa_option, avg 676µs/call |
| 259 | 5 | 6µs | 5 | 8µs | $class->_process_does_option( $name, $options ); # spent 8µs making 5 calls to Moose::Meta::Attribute::_process_does_option, avg 2µs/call |
| 260 | 5 | 4µs | 5 | 5µs | $class->_process_coerce_option( $name, $options ); # spent 5µs making 5 calls to Moose::Meta::Attribute::_process_coerce_option, avg 1µs/call |
| 261 | 5 | 5µs | 5 | 7µs | $class->_process_trigger_option( $name, $options ); # spent 7µs making 5 calls to Moose::Meta::Attribute::_process_trigger_option, avg 1µs/call |
| 262 | 5 | 5µs | 5 | 5µs | $class->_process_auto_deref_option( $name, $options ); # spent 5µs making 5 calls to Moose::Meta::Attribute::_process_auto_deref_option, avg 1µs/call |
| 263 | 5 | 4µs | 5 | 4µs | $class->_process_lazy_build_option( $name, $options ); # spent 4µs making 5 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 900ns/call |
| 264 | 5 | 6µs | 5 | 7µs | $class->_process_lazy_option( $name, $options ); # spent 7µs making 5 calls to Moose::Meta::Attribute::_process_lazy_option, avg 1µs/call |
| 265 | 5 | 12µs | 5 | 8µs | $class->_process_required_option( $name, $options ); # spent 8µs making 5 calls to Moose::Meta::Attribute::_process_required_option, avg 2µs/call |
| 266 | } | ||||
| 267 | |||||
| 268 | # spent 15µs within Moose::Meta::Attribute::_process_is_option which was called 5 times, avg 3µs/call:
# 5 times (15µs+0s) by Moose::Meta::Attribute::_process_options at line 257, avg 3µs/call | ||||
| 269 | 5 | 1µs | my ( $class, $name, $options ) = @_; | ||
| 270 | |||||
| 271 | 5 | 3µs | return unless $options->{is}; | ||
| 272 | |||||
| 273 | ### ------------------------- | ||||
| 274 | ## is => ro, writer => _foo # turns into (reader => foo, writer => _foo) as before | ||||
| 275 | ## is => rw, writer => _foo # turns into (reader => foo, writer => _foo) | ||||
| 276 | ## is => rw, accessor => _foo # turns into (accessor => _foo) | ||||
| 277 | ## is => ro, accessor => _foo # error, accesor is rw | ||||
| 278 | ### ------------------------- | ||||
| 279 | |||||
| 280 | 4 | 12µs | if ( $options->{is} eq 'ro' ) { | ||
| 281 | throw_exception("AccessorMustReadWrite" => attribute_name => $name, | ||||
| 282 | params => $options, | ||||
| 283 | ) | ||||
| 284 | if exists $options->{accessor}; | ||||
| 285 | $options->{reader} ||= $name; | ||||
| 286 | } | ||||
| 287 | elsif ( $options->{is} eq 'rw' ) { | ||||
| 288 | if ( $options->{writer} ) { | ||||
| 289 | $options->{reader} ||= $name; | ||||
| 290 | } | ||||
| 291 | else { | ||||
| 292 | 4 | 2µs | $options->{accessor} ||= $name; | ||
| 293 | } | ||||
| 294 | } | ||||
| 295 | elsif ( $options->{is} eq 'bare' ) { | ||||
| 296 | return; | ||||
| 297 | # do nothing, but don't complain (later) about missing methods | ||||
| 298 | } | ||||
| 299 | else { | ||||
| 300 | throw_exception( InvalidValueForIs => attribute_name => $name, | ||||
| 301 | params => $options, | ||||
| 302 | ); | ||||
| 303 | } | ||||
| 304 | } | ||||
| 305 | |||||
| 306 | # spent 3.38ms (44µs+3.33) within Moose::Meta::Attribute::_process_isa_option which was called 5 times, avg 676µs/call:
# 5 times (44µs+3.33ms) by Moose::Meta::Attribute::_process_options at line 258, avg 676µs/call | ||||
| 307 | 5 | 2µs | my ( $class, $name, $options ) = @_; | ||
| 308 | |||||
| 309 | 5 | 6µs | return unless exists $options->{isa}; | ||
| 310 | |||||
| 311 | 4 | 1µs | if ( exists $options->{does} ) { | ||
| 312 | if ( try { $options->{isa}->can('does') } ) { | ||||
| 313 | ( $options->{isa}->does( $options->{does} ) ) | ||||
| 314 | || throw_exception( IsaDoesNotDoTheRole => attribute_name => $name, | ||||
| 315 | params => $options, | ||||
| 316 | ); | ||||
| 317 | } | ||||
| 318 | else { | ||||
| 319 | throw_exception( IsaLacksDoesMethod => attribute_name => $name, | ||||
| 320 | params => $options, | ||||
| 321 | ); | ||||
| 322 | } | ||||
| 323 | } | ||||
| 324 | |||||
| 325 | # allow for anon-subtypes here ... | ||||
| 326 | # | ||||
| 327 | # Checking for Specio explicitly is completely revolting. At some point | ||||
| 328 | # this needs to be refactored so that Moose core defines a standard type | ||||
| 329 | # API that all types must implement. Unfortunately, the current core API | ||||
| 330 | # is _not_ the right API, so we probably need to A) come up with the new | ||||
| 331 | # API (Specio is a good start); B) refactor the core types to implement | ||||
| 332 | # that API; C) do duck type checking on type objects. | ||||
| 333 | 4 | 26µs | 8 | 2µs | if ( blessed( $options->{isa} ) # spent 2µs making 8 calls to Scalar::Util::blessed, avg 188ns/call |
| 334 | && $options->{isa}->isa('Moose::Meta::TypeConstraint') ) { | ||||
| 335 | $options->{type_constraint} = $options->{isa}; | ||||
| 336 | } | ||||
| 337 | elsif ( | ||||
| 338 | blessed( $options->{isa} ) | ||||
| 339 | && $options->{isa}->can('does') | ||||
| 340 | && $options->{isa}->does('Specio::Constraint::Role::Interface') | ||||
| 341 | ) { | ||||
| 342 | $options->{type_constraint} = $options->{isa}; | ||||
| 343 | } | ||||
| 344 | else { | ||||
| 345 | $options->{type_constraint} | ||||
| 346 | = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint( | ||||
| 347 | $options->{isa}, | ||||
| 348 | { package_defined_in => $options->{definition_context}->{package} } | ||||
| 349 | 4 | 12µs | 4 | 3.33ms | ); # spent 3.33ms making 4 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 833µs/call |
| 350 | } | ||||
| 351 | } | ||||
| 352 | |||||
| 353 | # spent 8µs within Moose::Meta::Attribute::_process_does_option which was called 5 times, avg 2µs/call:
# 5 times (8µs+0s) by Moose::Meta::Attribute::_process_options at line 259, avg 2µs/call | ||||
| 354 | 5 | 2µs | my ( $class, $name, $options ) = @_; | ||
| 355 | |||||
| 356 | 5 | 8µs | return unless exists $options->{does} && ! exists $options->{isa}; | ||
| 357 | |||||
| 358 | # allow for anon-subtypes here ... | ||||
| 359 | if ( blessed( $options->{does} ) | ||||
| 360 | && $options->{does}->isa('Moose::Meta::TypeConstraint') ) { | ||||
| 361 | $options->{type_constraint} = $options->{does}; | ||||
| 362 | } | ||||
| 363 | else { | ||||
| 364 | $options->{type_constraint} | ||||
| 365 | = Moose::Util::TypeConstraints::find_or_create_does_type_constraint( | ||||
| 366 | $options->{does}, | ||||
| 367 | { package_defined_in => $options->{definition_context}->{package} } | ||||
| 368 | ); | ||||
| 369 | } | ||||
| 370 | } | ||||
| 371 | |||||
| 372 | # spent 5µs within Moose::Meta::Attribute::_process_coerce_option which was called 5 times, avg 1µs/call:
# 5 times (5µs+0s) by Moose::Meta::Attribute::_process_options at line 260, avg 1µs/call | ||||
| 373 | 5 | 1µs | my ( $class, $name, $options ) = @_; | ||
| 374 | |||||
| 375 | 5 | 7µs | return unless $options->{coerce}; | ||
| 376 | |||||
| 377 | ( exists $options->{type_constraint} ) | ||||
| 378 | || throw_exception( CoercionNeedsTypeConstraint => attribute_name => $name, | ||||
| 379 | params => $options, | ||||
| 380 | ); | ||||
| 381 | |||||
| 382 | throw_exception( CannotCoerceAWeakRef => attribute_name => $name, | ||||
| 383 | params => $options, | ||||
| 384 | ) | ||||
| 385 | if $options->{weak_ref}; | ||||
| 386 | |||||
| 387 | unless ( $options->{type_constraint}->has_coercion ) { | ||||
| 388 | my $type = $options->{type_constraint}->name; | ||||
| 389 | |||||
| 390 | throw_exception( CannotCoerceAttributeWhichHasNoCoercion => attribute_name => $name, | ||||
| 391 | type_name => $type, | ||||
| 392 | params => $options | ||||
| 393 | ); | ||||
| 394 | } | ||||
| 395 | } | ||||
| 396 | |||||
| 397 | # spent 7µs within Moose::Meta::Attribute::_process_trigger_option which was called 5 times, avg 1µs/call:
# 5 times (7µs+0s) by Moose::Meta::Attribute::_process_options at line 261, avg 1µs/call | ||||
| 398 | 5 | 3µs | my ( $class, $name, $options ) = @_; | ||
| 399 | |||||
| 400 | 5 | 7µs | return unless exists $options->{trigger}; | ||
| 401 | |||||
| 402 | ( 'CODE' eq ref $options->{trigger} ) | ||||
| 403 | 1 | 2µs | || throw_exception( TriggerMustBeACodeRef => attribute_name => $name, | ||
| 404 | params => $options, | ||||
| 405 | ); | ||||
| 406 | } | ||||
| 407 | |||||
| 408 | # spent 5µs within Moose::Meta::Attribute::_process_auto_deref_option which was called 5 times, avg 1µs/call:
# 5 times (5µs+0s) by Moose::Meta::Attribute::_process_options at line 262, avg 1µs/call | ||||
| 409 | 5 | 1µs | my ( $class, $name, $options ) = @_; | ||
| 410 | |||||
| 411 | 5 | 7µs | return unless $options->{auto_deref}; | ||
| 412 | |||||
| 413 | ( exists $options->{type_constraint} ) | ||||
| 414 | || throw_exception( CannotAutoDerefWithoutIsa => attribute_name => $name, | ||||
| 415 | params => $options, | ||||
| 416 | ); | ||||
| 417 | |||||
| 418 | ( $options->{type_constraint}->is_a_type_of('ArrayRef') | ||||
| 419 | || $options->{type_constraint}->is_a_type_of('HashRef') ) | ||||
| 420 | || throw_exception( AutoDeRefNeedsArrayRefOrHashRef => attribute_name => $name, | ||||
| 421 | params => $options, | ||||
| 422 | ); | ||||
| 423 | } | ||||
| 424 | |||||
| 425 | # spent 4µs within Moose::Meta::Attribute::_process_lazy_build_option which was called 5 times, avg 900ns/call:
# 5 times (4µs+0s) by Moose::Meta::Attribute::_process_options at line 263, avg 900ns/call | ||||
| 426 | 5 | 1µs | my ( $class, $name, $options ) = @_; | ||
| 427 | |||||
| 428 | 5 | 8µs | return unless $options->{lazy_build}; | ||
| 429 | |||||
| 430 | throw_exception( CannotUseLazyBuildAndDefaultSimultaneously => attribute_name => $name, | ||||
| 431 | params => $options, | ||||
| 432 | ) | ||||
| 433 | if exists $options->{default}; | ||||
| 434 | |||||
| 435 | $options->{lazy} = 1; | ||||
| 436 | $options->{builder} ||= "_build_${name}"; | ||||
| 437 | |||||
| 438 | if ( $name =~ /^_/ ) { | ||||
| 439 | $options->{clearer} ||= "_clear${name}"; | ||||
| 440 | $options->{predicate} ||= "_has${name}"; | ||||
| 441 | } | ||||
| 442 | else { | ||||
| 443 | $options->{clearer} ||= "clear_${name}"; | ||||
| 444 | $options->{predicate} ||= "has_${name}"; | ||||
| 445 | } | ||||
| 446 | } | ||||
| 447 | |||||
| 448 | # spent 7µs within Moose::Meta::Attribute::_process_lazy_option which was called 5 times, avg 1µs/call:
# 5 times (7µs+0s) by Moose::Meta::Attribute::_process_options at line 264, avg 1µs/call | ||||
| 449 | 5 | 2µs | my ( $class, $name, $options ) = @_; | ||
| 450 | |||||
| 451 | 5 | 9µs | return unless $options->{lazy}; | ||
| 452 | |||||
| 453 | ( exists $options->{default} || defined $options->{builder} ) | ||||
| 454 | 1 | 1µs | || throw_exception( LazyAttributeNeedsADefault => params => $options, | ||
| 455 | attribute_name => $name, | ||||
| 456 | ); | ||||
| 457 | } | ||||
| 458 | |||||
| 459 | # spent 8µs within Moose::Meta::Attribute::_process_required_option which was called 5 times, avg 2µs/call:
# 5 times (8µs+0s) by Moose::Meta::Attribute::_process_options at line 265, avg 2µs/call | ||||
| 460 | 5 | 1µs | my ( $class, $name, $options ) = @_; | ||
| 461 | |||||
| 462 | 5 | 9µs | if ( | ||
| 463 | $options->{required} | ||||
| 464 | && !( | ||||
| 465 | ( !exists $options->{init_arg} || defined $options->{init_arg} ) | ||||
| 466 | || exists $options->{default} | ||||
| 467 | || defined $options->{builder} | ||||
| 468 | ) | ||||
| 469 | ) { | ||||
| 470 | throw_exception( RequiredAttributeNeedsADefault => params => $options, | ||||
| 471 | attribute_name => $name, | ||||
| 472 | ); | ||||
| 473 | } | ||||
| 474 | } | ||||
| 475 | |||||
| 476 | sub initialize_instance_slot { | ||||
| 477 | my ($self, $meta_instance, $instance, $params) = @_; | ||||
| 478 | my $init_arg = $self->init_arg(); | ||||
| 479 | # try to fetch the init arg from the %params ... | ||||
| 480 | |||||
| 481 | my $val; | ||||
| 482 | my $value_is_set; | ||||
| 483 | if ( defined($init_arg) and exists $params->{$init_arg}) { | ||||
| 484 | $val = $params->{$init_arg}; | ||||
| 485 | $value_is_set = 1; | ||||
| 486 | } | ||||
| 487 | else { | ||||
| 488 | # skip it if it's lazy | ||||
| 489 | return if $self->is_lazy; | ||||
| 490 | # and die if it's required and doesn't have a default value | ||||
| 491 | my $class_name = blessed( $instance ); | ||||
| 492 | throw_exception(AttributeIsRequired => attribute_name => $self->name, | ||||
| 493 | class_name => $class_name, | ||||
| 494 | params => $params, | ||||
| 495 | ) | ||||
| 496 | if $self->is_required && !$self->has_default && !$self->has_builder; | ||||
| 497 | |||||
| 498 | # if nothing was in the %params, we can use the | ||||
| 499 | # attribute's default value (if it has one) | ||||
| 500 | if ($self->has_default) { | ||||
| 501 | $val = $self->default($instance); | ||||
| 502 | $value_is_set = 1; | ||||
| 503 | } | ||||
| 504 | elsif ($self->has_builder) { | ||||
| 505 | $val = $self->_call_builder($instance); | ||||
| 506 | $value_is_set = 1; | ||||
| 507 | } | ||||
| 508 | } | ||||
| 509 | |||||
| 510 | return unless $value_is_set; | ||||
| 511 | |||||
| 512 | $val = $self->_coerce_and_verify( $val, $instance ); | ||||
| 513 | |||||
| 514 | $self->set_initial_value($instance, $val); | ||||
| 515 | |||||
| 516 | if ( ref $val && $self->is_weak_ref ) { | ||||
| 517 | $self->_weaken_value($instance); | ||||
| 518 | } | ||||
| 519 | } | ||||
| 520 | |||||
| 521 | sub _call_builder { | ||||
| 522 | my ( $self, $instance ) = @_; | ||||
| 523 | |||||
| 524 | my $builder = $self->builder(); | ||||
| 525 | |||||
| 526 | return $instance->$builder() | ||||
| 527 | if $instance->can( $self->builder ); | ||||
| 528 | |||||
| 529 | throw_exception( BuilderDoesNotExist => instance => $instance, | ||||
| 530 | attribute => $self, | ||||
| 531 | ); | ||||
| 532 | } | ||||
| 533 | |||||
| 534 | ## Slot management | ||||
| 535 | |||||
| 536 | sub _make_initializer_writer_callback { | ||||
| 537 | my $self = shift; | ||||
| 538 | my ($meta_instance, $instance, $slot_name) = @_; | ||||
| 539 | my $old_callback = $self->SUPER::_make_initializer_writer_callback(@_); | ||||
| 540 | return sub { | ||||
| 541 | $old_callback->($self->_coerce_and_verify($_[0], $instance)); | ||||
| 542 | }; | ||||
| 543 | } | ||||
| 544 | |||||
| 545 | sub set_value { | ||||
| 546 | my ($self, $instance, @args) = @_; | ||||
| 547 | my $value = $args[0]; | ||||
| 548 | |||||
| 549 | my $attr_name = quotemeta($self->name); | ||||
| 550 | |||||
| 551 | my $class_name = blessed( $instance ); | ||||
| 552 | if ($self->is_required and not @args) { | ||||
| 553 | throw_exception( AttributeIsRequired => attribute_name => $self->name, | ||||
| 554 | class_name => $class_name, | ||||
| 555 | ); | ||||
| 556 | } | ||||
| 557 | |||||
| 558 | $value = $self->_coerce_and_verify( $value, $instance ); | ||||
| 559 | |||||
| 560 | my @old; | ||||
| 561 | if ( $self->has_trigger && $self->has_value($instance) ) { | ||||
| 562 | @old = $self->get_value($instance, 'for trigger'); | ||||
| 563 | } | ||||
| 564 | |||||
| 565 | $self->SUPER::set_value($instance, $value); | ||||
| 566 | |||||
| 567 | if ( ref $value && $self->is_weak_ref ) { | ||||
| 568 | $self->_weaken_value($instance); | ||||
| 569 | } | ||||
| 570 | |||||
| 571 | if ($self->has_trigger) { | ||||
| 572 | $self->trigger->($instance, $value, @old); | ||||
| 573 | } | ||||
| 574 | } | ||||
| 575 | |||||
| 576 | # spent 1.69ms (158µs+1.54) within Moose::Meta::Attribute::_inline_set_value which was called 12 times, avg 141µs/call:
# 4 times (75µs+730µs) by Class::MOP::Method::Accessor::try {...} at line 113 of Class/MOP/Method/Accessor.pm, avg 201µs/call
# 4 times (30µs+300µs) by Moose::Meta::Class::_inline_init_attr_from_constructor at line 398 of Moose/Meta/Class.pm, avg 82µs/call
# 2 times (39µs+348µs) by Class::MOP::Class::_inline_init_attr_from_constructor at line 631 of Class/MOP/Class.pm, avg 193µs/call
# 2 times (14µs+158µs) by Moose::Meta::Class::_inline_init_attr_from_default at line 425 of Moose/Meta/Class.pm, avg 86µs/call | ||||
| 577 | 12 | 2µs | my $self = shift; | ||
| 578 | 12 | 5µs | my ($instance, $value, $tc, $coercion, $message, $for_constructor) = @_; | ||
| 579 | |||||
| 580 | 12 | 3µs | my $old = '@old'; | ||
| 581 | 12 | 1µs | my $copy = '$val'; | ||
| 582 | 12 | 2µs | $tc ||= '$type_constraint'; | ||
| 583 | 12 | 1µs | $coercion ||= '$type_coercion'; | ||
| 584 | 12 | 1µs | $message ||= '$type_message'; | ||
| 585 | |||||
| 586 | 12 | 1µs | my @code; | ||
| 587 | 12 | 10µs | 12 | 79µs | if ($self->_writer_value_needs_copy) { # spent 79µs making 12 calls to Moose::Meta::Attribute::_writer_value_needs_copy, avg 7µs/call |
| 588 | push @code, $self->_inline_copy_value($value, $copy); | ||||
| 589 | $value = $copy; | ||||
| 590 | } | ||||
| 591 | |||||
| 592 | # constructors already handle required checks | ||||
| 593 | 12 | 18µs | 6 | 64µs | push @code, $self->_inline_check_required # spent 64µs making 6 calls to Moose::Meta::Attribute::_inline_check_required, avg 11µs/call |
| 594 | unless $for_constructor; | ||||
| 595 | |||||
| 596 | 12 | 19µs | 12 | 706µs | push @code, $self->_inline_tc_code($value, $tc, $coercion, $message); # spent 706µs making 12 calls to Moose::Meta::Attribute::_inline_tc_code, avg 59µs/call |
| 597 | |||||
| 598 | # constructors do triggers all at once at the end | ||||
| 599 | 12 | 8µs | 6 | 143µs | push @code, $self->_inline_get_old_value_for_trigger($instance, $old) # spent 143µs making 6 calls to Moose::Meta::Attribute::_inline_get_old_value_for_trigger, avg 24µs/call |
| 600 | unless $for_constructor; | ||||
| 601 | |||||
| 602 | 12 | 29µs | 24 | 483µs | push @code, ( # spent 381µs making 12 calls to Class::MOP::Attribute::_inline_set_value, avg 32µs/call
# spent 102µs making 12 calls to Moose::Meta::Attribute::_inline_weaken_value, avg 8µs/call |
| 603 | $self->SUPER::_inline_set_value($instance, $value), | ||||
| 604 | $self->_inline_weaken_value($instance, $value), | ||||
| 605 | ); | ||||
| 606 | |||||
| 607 | # constructors do triggers all at once at the end | ||||
| 608 | 12 | 9µs | 6 | 60µs | push @code, $self->_inline_trigger($instance, $value, $old) # spent 60µs making 6 calls to Moose::Meta::Attribute::_inline_trigger, avg 10µs/call |
| 609 | unless $for_constructor; | ||||
| 610 | |||||
| 611 | 12 | 23µs | return @code; | ||
| 612 | } | ||||
| 613 | |||||
| 614 | # spent 79µs (29+51) within Moose::Meta::Attribute::_writer_value_needs_copy which was called 12 times, avg 7µs/call:
# 12 times (29µs+51µs) by Moose::Meta::Attribute::_inline_set_value at line 587, avg 7µs/call | ||||
| 615 | 12 | 2µs | my $self = shift; | ||
| 616 | 12 | 27µs | 12 | 51µs | return $self->should_coerce; # spent 51µs making 12 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 4µs/call |
| 617 | } | ||||
| 618 | |||||
| 619 | sub _inline_copy_value { | ||||
| 620 | my $self = shift; | ||||
| 621 | my ($value, $copy) = @_; | ||||
| 622 | |||||
| 623 | return 'my ' . $copy . ' = ' . $value . ';' | ||||
| 624 | } | ||||
| 625 | |||||
| 626 | # spent 64µs (25+39) within Moose::Meta::Attribute::_inline_check_required which was called 6 times, avg 11µs/call:
# 6 times (25µs+39µs) by Moose::Meta::Attribute::_inline_set_value at line 593, avg 11µs/call | ||||
| 627 | 6 | 1µs | my $self = shift; | ||
| 628 | |||||
| 629 | 6 | 14µs | 6 | 36µs | return unless $self->is_required; # spent 36µs making 6 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 6µs/call |
| 630 | |||||
| 631 | 1 | 6µs | 1 | 300ns | my $attr_name = quotemeta($self->name); # spent 300ns making 1 call to Class::MOP::Mixin::AttributeCore::name |
| 632 | |||||
| 633 | return ( | ||||
| 634 | 1 | 4µs | 1 | 3µs | 'if (@_ < 2) {', # spent 3µs making 1 call to Moose::Meta::Attribute::_inline_throw_exception |
| 635 | $self->_inline_throw_exception( AttributeIsRequired => | ||||
| 636 | 'attribute_name => "'.$attr_name.'",'. | ||||
| 637 | 'class_name => $class_name' | ||||
| 638 | ) . ';', | ||||
| 639 | '}', | ||||
| 640 | ); | ||||
| 641 | } | ||||
| 642 | |||||
| 643 | # spent 706µs (42+664) within Moose::Meta::Attribute::_inline_tc_code which was called 12 times, avg 59µs/call:
# 12 times (42µs+664µs) by Moose::Meta::Attribute::_inline_set_value at line 596, avg 59µs/call | ||||
| 644 | 12 | 2µs | my $self = shift; | ||
| 645 | 12 | 4µs | my ($value, $tc, $coercion, $message, $is_lazy) = @_; | ||
| 646 | return ( | ||||
| 647 | 12 | 30µs | 24 | 664µs | $self->_inline_check_coercion( # spent 607µs making 12 calls to Moose::Meta::Attribute::_inline_check_constraint, avg 51µs/call
# spent 57µs making 12 calls to Moose::Meta::Attribute::_inline_check_coercion, avg 5µs/call |
| 648 | $value, $tc, $coercion, $is_lazy, | ||||
| 649 | ), | ||||
| 650 | $self->_inline_check_constraint( | ||||
| 651 | $value, $tc, $message, $is_lazy, | ||||
| 652 | ), | ||||
| 653 | ); | ||||
| 654 | } | ||||
| 655 | |||||
| 656 | sub _inline_check_coercion { | ||||
| 657 | 13 | 2µs | my $self = shift; | ||
| 658 | 13 | 3µs | my ($value, $tc, $coercion) = @_; | ||
| 659 | |||||
| 660 | 13 | 20µs | 13 | 34µs | return unless $self->should_coerce && $self->type_constraint->has_coercion; # spent 34µs making 13 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 3µs/call |
| 661 | |||||
| 662 | if ( $self->type_constraint->can_be_inlined ) { | ||||
| 663 | return ( | ||||
| 664 | 'if (! (' . $self->type_constraint->_inline_check($value) . ')) {', | ||||
| 665 | $value . ' = ' . $coercion . '->(' . $value . ');', | ||||
| 666 | '}', | ||||
| 667 | ); | ||||
| 668 | } | ||||
| 669 | else { | ||||
| 670 | return ( | ||||
| 671 | 'if (!' . $tc . '->(' . $value . ')) {', | ||||
| 672 | $value . ' = ' . $coercion . '->(' . $value . ');', | ||||
| 673 | '}', | ||||
| 674 | ); | ||||
| 675 | } | ||||
| 676 | } | ||||
| 677 | |||||
| 678 | # spent 652µs (131+521) within Moose::Meta::Attribute::_inline_check_constraint which was called 13 times, avg 50µs/call:
# 12 times (121µs+486µs) by Moose::Meta::Attribute::_inline_tc_code at line 647, avg 51µs/call
# once (10µs+36µs) by Moose::Meta::Attribute::_inline_init_from_default at line 891 | ||||
| 679 | 13 | 2µs | my $self = shift; | ||
| 680 | 13 | 2µs | my ($value, $tc, $message) = @_; | ||
| 681 | |||||
| 682 | 13 | 14µs | 13 | 36µs | return unless $self->has_type_constraint; # spent 36µs making 13 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 3µs/call |
| 683 | |||||
| 684 | 11 | 16µs | 11 | 2µs | my $attr_name = quotemeta($self->name); # spent 2µs making 11 calls to Class::MOP::Mixin::AttributeCore::name, avg 218ns/call |
| 685 | |||||
| 686 | 11 | 69µs | 55 | 483µs | if ( $self->type_constraint->can_be_inlined ) { # spent 206µs making 3 calls to Moose::Meta::TypeConstraint::Parameterized::_inline_check, avg 69µs/call
# spent 139µs making 8 calls to Moose::Meta::TypeConstraint::_inline_check, avg 17µs/call
# spent 66µs making 3 calls to Moose::Meta::TypeConstraint::Parameterized::can_be_inlined, avg 22µs/call
# spent 48µs making 8 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 6µs/call
# spent 13µs making 11 calls to Moose::Meta::Attribute::_inline_throw_exception, avg 1µs/call
# spent 11µs making 22 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 509ns/call |
| 687 | return ( | ||||
| 688 | 'if (! (' . $self->type_constraint->_inline_check($value) . ')) {', | ||||
| 689 | 'my $msg = do { local $_ = ' . $value . '; ' | ||||
| 690 | . $message . '->(' . $value . ');' | ||||
| 691 | . '};'. | ||||
| 692 | $self->_inline_throw_exception( ValidationFailedForInlineTypeConstraint => | ||||
| 693 | 'type_constraint_message => $msg , '. | ||||
| 694 | 'class_name => $class_name, '. | ||||
| 695 | 'attribute_name => "'.$attr_name.'",'. | ||||
| 696 | 'value => '.$value | ||||
| 697 | ).';', | ||||
| 698 | '}', | ||||
| 699 | ); | ||||
| 700 | } | ||||
| 701 | else { | ||||
| 702 | return ( | ||||
| 703 | 'if (!' . $tc . '->(' . $value . ')) {', | ||||
| 704 | 'my $msg = do { local $_ = ' . $value . '; ' | ||||
| 705 | . $message . '->(' . $value . ');' | ||||
| 706 | . '};'. | ||||
| 707 | $self->_inline_throw_exception( ValidationFailedForInlineTypeConstraint => | ||||
| 708 | 'type_constraint_message => $msg , '. | ||||
| 709 | 'class_name => $class_name, '. | ||||
| 710 | 'attribute_name => "'.$attr_name.'",'. | ||||
| 711 | 'value => '.$value | ||||
| 712 | ).';', | ||||
| 713 | '}', | ||||
| 714 | ); | ||||
| 715 | } | ||||
| 716 | } | ||||
| 717 | |||||
| 718 | # spent 143µs (26+117) within Moose::Meta::Attribute::_inline_get_old_value_for_trigger which was called 6 times, avg 24µs/call:
# 6 times (26µs+117µs) by Moose::Meta::Attribute::_inline_set_value at line 599, avg 24µs/call | ||||
| 719 | 6 | 1µs | my $self = shift; | ||
| 720 | 6 | 2µs | my ($instance, $old) = @_; | ||
| 721 | |||||
| 722 | 6 | 13µs | 6 | 30µs | return unless $self->has_trigger; # spent 30µs making 6 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 5µs/call |
| 723 | |||||
| 724 | return ( | ||||
| 725 | 1 | 6µs | 2 | 87µs | 'my ' . $old . ' = ' . $self->_inline_instance_has($instance), # spent 76µs making 1 call to Class::MOP::Attribute::_inline_instance_has
# spent 11µs making 1 call to Class::MOP::Attribute::_inline_instance_get |
| 726 | '? ' . $self->_inline_instance_get($instance), | ||||
| 727 | ': ();', | ||||
| 728 | ); | ||||
| 729 | } | ||||
| 730 | |||||
| 731 | sub _inline_weaken_value { | ||||
| 732 | 13 | 2µs | my $self = shift; | ||
| 733 | 13 | 2µs | my ($instance, $value) = @_; | ||
| 734 | |||||
| 735 | 13 | 25µs | 13 | 43µs | return unless $self->is_weak_ref; # spent 43µs making 13 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 3µs/call |
| 736 | |||||
| 737 | 2 | 5µs | 4 | 6µs | my $mi = $self->associated_class->get_meta_instance; # spent 5µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance
# spent 500ns making 1 call to Class::MOP::Class::get_meta_instance
# spent 400ns making 2 calls to Class::MOP::Attribute::associated_class, avg 200ns/call |
| 738 | return ( | ||||
| 739 | 2 | 10µs | 4 | 9µs | $mi->inline_weaken_slot_value($instance, $self->name), # spent 9µs making 2 calls to Class::MOP::Instance::inline_weaken_slot_value, avg 5µs/call
# spent 400ns making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 200ns/call |
| 740 | 'if ref ' . $value . ';', | ||||
| 741 | ); | ||||
| 742 | } | ||||
| 743 | |||||
| 744 | # spent 60µs (17+43) within Moose::Meta::Attribute::_inline_trigger which was called 6 times, avg 10µs/call:
# 6 times (17µs+43µs) by Moose::Meta::Attribute::_inline_set_value at line 608, avg 10µs/call | ||||
| 745 | 6 | 1µs | my $self = shift; | ||
| 746 | 6 | 2µs | my ($instance, $value, $old) = @_; | ||
| 747 | |||||
| 748 | 6 | 11µs | 6 | 43µs | return unless $self->has_trigger; # spent 43µs making 6 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 7µs/call |
| 749 | |||||
| 750 | 1 | 2µs | return '$trigger->(' . $instance . ', ' . $value . ', ' . $old . ');'; | ||
| 751 | } | ||||
| 752 | |||||
| 753 | # spent 328µs (144+185) within Moose::Meta::Attribute::_eval_environment which was called 6 times, avg 55µs/call:
# 6 times (144µs+185µs) by Moose::Meta::Method::Accessor::_eval_environment at line 46 of Moose/Meta/Method/Accessor.pm, avg 55µs/call | ||||
| 754 | 6 | 2µs | my $self = shift; | ||
| 755 | |||||
| 756 | 6 | 2µs | my $env = { }; | ||
| 757 | |||||
| 758 | 6 | 12µs | 7 | 47µs | $env->{'$trigger'} = \($self->trigger) # spent 44µs making 6 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 7µs/call
# spent 2µs making 1 call to Moose::Meta::Mixin::AttributeCore::trigger |
| 759 | if $self->has_trigger; | ||||
| 760 | 6 | 12µs | 9 | 8µs | $env->{'$attr_default'} = \($self->default) # spent 4µs making 3 calls to Class::MOP::Mixin::AttributeCore::default, avg 1µs/call
# spent 4µs making 6 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 650ns/call |
| 761 | if $self->has_default; | ||||
| 762 | |||||
| 763 | 6 | 9µs | 6 | 28µs | if ($self->has_type_constraint) { # spent 28µs making 6 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 5µs/call |
| 764 | 4 | 3µs | 4 | 2µs | my $tc_obj = $self->type_constraint; # spent 2µs making 4 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 600ns/call |
| 765 | |||||
| 766 | 4 | 3µs | 4 | 37µs | $env->{'$type_constraint'} = \( # spent 20µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::can_be_inlined
# spent 16µs making 3 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 6µs/call |
| 767 | $tc_obj->_compiled_type_constraint | ||||
| 768 | ) unless $tc_obj->can_be_inlined; | ||||
| 769 | # these two could probably get inlined versions too | ||||
| 770 | 4 | 8µs | 4 | 4µs | $env->{'$type_coercion'} = \( # spent 4µs making 4 calls to Moose::Meta::TypeConstraint::has_coercion, avg 925ns/call |
| 771 | $tc_obj->coercion->_compiled_type_coercion | ||||
| 772 | ) if $tc_obj->has_coercion; | ||||
| 773 | 4 | 8µs | 8 | 5µs | $env->{'$type_message'} = \( # spent 3µs making 4 calls to Moose::Meta::TypeConstraint::_default_message, avg 650ns/call
# spent 2µs making 4 calls to Moose::Meta::TypeConstraint::has_message, avg 575ns/call |
| 774 | $tc_obj->has_message ? $tc_obj->message : $tc_obj->_default_message | ||||
| 775 | ); | ||||
| 776 | |||||
| 777 | 4 | 8µs | 4 | 46µs | $env = { %$env, %{ $tc_obj->inline_environment } }; # spent 30µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::inline_environment
# spent 16µs making 3 calls to Moose::Meta::TypeConstraint::inline_environment, avg 5µs/call |
| 778 | } | ||||
| 779 | |||||
| 780 | 6 | 21µs | 12 | 4µs | $env->{'$class_name'} = \($self->associated_class->name); # spent 2µs making 6 calls to Class::MOP::Attribute::associated_class, avg 367ns/call
# spent 2µs making 6 calls to Class::MOP::Package::name, avg 317ns/call |
| 781 | |||||
| 782 | # XXX ugh, fix these | ||||
| 783 | 6 | 6µs | 6 | 3µs | $env->{'$attr'} = \$self # spent 3µs making 6 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 517ns/call |
| 784 | if $self->has_initializer && $self->is_lazy; | ||||
| 785 | # pretty sure this is only going to be closed over if you use a custom | ||||
| 786 | # error class at this point, but we should still get rid of this | ||||
| 787 | # at some point | ||||
| 788 | 6 | 10µs | 6 | 1µs | $env->{'$meta'} = \($self->associated_class); # spent 1µs making 6 calls to Class::MOP::Attribute::associated_class, avg 200ns/call |
| 789 | |||||
| 790 | 6 | 8µs | return $env; | ||
| 791 | } | ||||
| 792 | |||||
| 793 | sub _weaken_value { | ||||
| 794 | my ( $self, $instance ) = @_; | ||||
| 795 | |||||
| 796 | my $meta_instance = Class::MOP::Class->initialize( blessed($instance) ) | ||||
| 797 | ->get_meta_instance; | ||||
| 798 | |||||
| 799 | $meta_instance->weaken_slot_value( $instance, $self->name ); | ||||
| 800 | } | ||||
| 801 | |||||
| 802 | sub get_value { | ||||
| 803 | my ($self, $instance, $for_trigger) = @_; | ||||
| 804 | |||||
| 805 | if ($self->is_lazy) { | ||||
| 806 | unless ($self->has_value($instance)) { | ||||
| 807 | my $value; | ||||
| 808 | if ($self->has_default) { | ||||
| 809 | $value = $self->default($instance); | ||||
| 810 | } elsif ( $self->has_builder ) { | ||||
| 811 | $value = $self->_call_builder($instance); | ||||
| 812 | } | ||||
| 813 | |||||
| 814 | $value = $self->_coerce_and_verify( $value, $instance ); | ||||
| 815 | |||||
| 816 | $self->set_initial_value($instance, $value); | ||||
| 817 | |||||
| 818 | if ( ref $value && $self->is_weak_ref ) { | ||||
| 819 | $self->_weaken_value($instance); | ||||
| 820 | } | ||||
| 821 | } | ||||
| 822 | } | ||||
| 823 | |||||
| 824 | if ( $self->should_auto_deref && ! $for_trigger ) { | ||||
| 825 | |||||
| 826 | my $type_constraint = $self->type_constraint; | ||||
| 827 | |||||
| 828 | if ($type_constraint->is_a_type_of('ArrayRef')) { | ||||
| 829 | my $rv = $self->SUPER::get_value($instance); | ||||
| 830 | return unless defined $rv; | ||||
| 831 | return wantarray ? @{ $rv } : $rv; | ||||
| 832 | } | ||||
| 833 | elsif ($type_constraint->is_a_type_of('HashRef')) { | ||||
| 834 | my $rv = $self->SUPER::get_value($instance); | ||||
| 835 | return unless defined $rv; | ||||
| 836 | return wantarray ? %{ $rv } : $rv; | ||||
| 837 | } | ||||
| 838 | else { | ||||
| 839 | throw_exception( CannotAutoDereferenceTypeConstraint => type_name => $type_constraint->name, | ||||
| 840 | instance => $instance, | ||||
| 841 | attribute => $self | ||||
| 842 | ); | ||||
| 843 | } | ||||
| 844 | |||||
| 845 | } | ||||
| 846 | else { | ||||
| 847 | |||||
| 848 | return $self->SUPER::get_value($instance); | ||||
| 849 | } | ||||
| 850 | } | ||||
| 851 | |||||
| 852 | # spent 414µs (46+369) within Moose::Meta::Attribute::_inline_get_value which was called 6 times, avg 69µs/call:
# 4 times (26µs+188µs) by Class::MOP::Method::Accessor::try {...} at line 113 of Class/MOP/Method/Accessor.pm, avg 54µs/call
# 2 times (19µs+181µs) by Class::MOP::Method::Accessor::try {...} at line 151 of Class/MOP/Method/Accessor.pm, avg 100µs/call | ||||
| 853 | 6 | 2µs | my $self = shift; | ||
| 854 | 6 | 2µs | my ($instance, $tc, $coercion, $message) = @_; | ||
| 855 | |||||
| 856 | 6 | 8µs | 6 | 107µs | my $slot_access = $self->_inline_instance_get($instance); # spent 107µs making 6 calls to Class::MOP::Attribute::_inline_instance_get, avg 18µs/call |
| 857 | 6 | 2µs | $tc ||= '$type_constraint'; | ||
| 858 | 6 | 2µs | $coercion ||= '$type_coercion'; | ||
| 859 | 6 | 800ns | $message ||= '$type_message'; | ||
| 860 | |||||
| 861 | return ( | ||||
| 862 | 6 | 19µs | 12 | 262µs | $self->_inline_check_lazy($instance, $tc, $coercion, $message), # spent 190µs making 6 calls to Moose::Meta::Attribute::_inline_check_lazy, avg 32µs/call
# spent 72µs making 6 calls to Moose::Meta::Attribute::_inline_return_auto_deref, avg 12µs/call |
| 863 | $self->_inline_return_auto_deref($slot_access), | ||||
| 864 | ); | ||||
| 865 | } | ||||
| 866 | |||||
| 867 | # spent 190µs (26+164) within Moose::Meta::Attribute::_inline_check_lazy which was called 6 times, avg 32µs/call:
# 6 times (26µs+164µs) by Moose::Meta::Attribute::_inline_get_value at line 862, avg 32µs/call | ||||
| 868 | 6 | 900ns | my $self = shift; | ||
| 869 | 6 | 3µs | my ($instance, $tc, $coercion, $message) = @_; | ||
| 870 | |||||
| 871 | 6 | 14µs | 6 | 62µs | return unless $self->is_lazy; # spent 62µs making 6 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 10µs/call |
| 872 | |||||
| 873 | 1 | 1µs | 1 | 8µs | my $slot_exists = $self->_inline_instance_has($instance); # spent 8µs making 1 call to Class::MOP::Attribute::_inline_instance_has |
| 874 | |||||
| 875 | return ( | ||||
| 876 | 1 | 4µs | 1 | 94µs | 'if (!' . $slot_exists . ') {', # spent 94µs making 1 call to Moose::Meta::Attribute::_inline_init_from_default |
| 877 | $self->_inline_init_from_default($instance, '$default', $tc, $coercion, $message, 'lazy'), | ||||
| 878 | '}', | ||||
| 879 | ); | ||||
| 880 | } | ||||
| 881 | |||||
| 882 | # spent 94µs (16+77) within Moose::Meta::Attribute::_inline_init_from_default which was called:
# once (16µs+77µs) by Moose::Meta::Attribute::_inline_check_lazy at line 876 | ||||
| 883 | 1 | 200ns | my $self = shift; | ||
| 884 | 1 | 500ns | my ($instance, $default, $tc, $coercion, $message, $for_lazy) = @_; | ||
| 885 | |||||
| 886 | 1 | 900ns | 1 | 600ns | if (!($self->has_default || $self->has_builder)) { # spent 600ns making 1 call to Class::MOP::Mixin::AttributeCore::has_default |
| 887 | throw_exception( LazyAttributeNeedsADefault => attribute => $self ); | ||||
| 888 | } | ||||
| 889 | |||||
| 890 | return ( | ||||
| 891 | 1 | 8µs | 6 | 77µs | $self->_inline_generate_default($instance, $default), # spent 46µs making 1 call to Moose::Meta::Attribute::_inline_check_constraint
# spent 16µs making 1 call to Moose::Meta::Attribute::_inline_init_slot
# spent 10µs making 1 call to Moose::Meta::Attribute::_inline_generate_default
# spent 2µs making 1 call to Moose::Meta::Attribute::_inline_check_coercion
# spent 2µs making 1 call to Moose::Meta::Attribute::_inline_weaken_value
# spent 400ns making 1 call to Moose::Meta::Mixin::AttributeCore::has_type_constraint |
| 892 | # intentionally not using _inline_tc_code, since that can be overridden | ||||
| 893 | # to do things like possibly only do member tc checks, which isn't | ||||
| 894 | # appropriate for checking the result of a default | ||||
| 895 | $self->has_type_constraint | ||||
| 896 | ? ($self->_inline_check_coercion($default, $tc, $coercion, $for_lazy), | ||||
| 897 | $self->_inline_check_constraint($default, $tc, $message, $for_lazy)) | ||||
| 898 | : (), | ||||
| 899 | $self->_inline_init_slot($instance, $default), | ||||
| 900 | $self->_inline_weaken_value($instance, $default), | ||||
| 901 | ); | ||||
| 902 | } | ||||
| 903 | |||||
| 904 | # spent 10µs (8+2) within Moose::Meta::Attribute::_inline_generate_default which was called:
# once (8µs+2µs) by Moose::Meta::Attribute::_inline_init_from_default at line 891 | ||||
| 905 | 1 | 300ns | my $self = shift; | ||
| 906 | 1 | 300ns | my ($instance, $default) = @_; | ||
| 907 | |||||
| 908 | 1 | 900ns | 1 | 300ns | if ($self->has_default) { # spent 300ns making 1 call to Class::MOP::Mixin::AttributeCore::has_default |
| 909 | 1 | 800ns | my $source = 'my ' . $default . ' = $attr_default'; | ||
| 910 | 1 | 1µs | 1 | 2µs | $source .= '->(' . $instance . ')' # spent 2µs making 1 call to Class::MOP::Mixin::AttributeCore::is_default_a_coderef |
| 911 | if $self->is_default_a_coderef; | ||||
| 912 | 1 | 3µs | return $source . ';'; | ||
| 913 | } | ||||
| 914 | elsif ($self->has_builder) { | ||||
| 915 | my $builder = B::perlstring($self->builder); | ||||
| 916 | my $builder_str = quotemeta($self->builder); | ||||
| 917 | my $attr_name_str = quotemeta($self->name); | ||||
| 918 | return ( | ||||
| 919 | 'my ' . $default . ';', | ||||
| 920 | 'if (my $builder = ' . $instance . '->can(' . $builder . ')) {', | ||||
| 921 | $default . ' = ' . $instance . '->$builder;', | ||||
| 922 | '}', | ||||
| 923 | 'else {', | ||||
| 924 | 'my $class = ref(' . $instance . ') || ' . $instance . ';', | ||||
| 925 | $self->_inline_throw_exception( | ||||
| 926 | BuilderMethodNotSupportedForInlineAttribute => | ||||
| 927 | 'class_name => $class,'. | ||||
| 928 | 'attribute_name => "'.$attr_name_str.'",'. | ||||
| 929 | 'instance => '.$instance.','. | ||||
| 930 | 'builder => "'.$builder_str.'"' | ||||
| 931 | ) . ';', | ||||
| 932 | '}', | ||||
| 933 | ); | ||||
| 934 | } | ||||
| 935 | else { | ||||
| 936 | confess( | ||||
| 937 | "Can't generate a default for " . $self->name | ||||
| 938 | . " since no default or builder was specified" | ||||
| 939 | ); | ||||
| 940 | } | ||||
| 941 | } | ||||
| 942 | |||||
| 943 | # spent 16µs (6+10) within Moose::Meta::Attribute::_inline_init_slot which was called:
# once (6µs+10µs) by Moose::Meta::Attribute::_inline_init_from_default at line 891 | ||||
| 944 | 1 | 900ns | my $self = shift; | ||
| 945 | 1 | 300ns | my ($inv, $value) = @_; | ||
| 946 | |||||
| 947 | 1 | 1µs | 1 | 800ns | if ($self->has_initializer) { # spent 800ns making 1 call to Class::MOP::Mixin::AttributeCore::has_initializer |
| 948 | return '$attr->set_initial_value(' . $inv . ', ' . $value . ');'; | ||||
| 949 | } | ||||
| 950 | else { | ||||
| 951 | 1 | 3µs | 1 | 9µs | return $self->_inline_instance_set($inv, $value) . ';'; # spent 9µs making 1 call to Class::MOP::Attribute::_inline_instance_set |
| 952 | } | ||||
| 953 | } | ||||
| 954 | |||||
| 955 | # spent 72µs (17+55) within Moose::Meta::Attribute::_inline_return_auto_deref which was called 6 times, avg 12µs/call:
# 6 times (17µs+55µs) by Moose::Meta::Attribute::_inline_get_value at line 862, avg 12µs/call | ||||
| 956 | 6 | 1µs | my $self = shift; | ||
| 957 | |||||
| 958 | 6 | 16µs | 6 | 55µs | return 'return ' . $self->_auto_deref(@_) . ';'; # spent 55µs making 6 calls to Moose::Meta::Attribute::_auto_deref, avg 9µs/call |
| 959 | } | ||||
| 960 | |||||
| 961 | # spent 55µs (21+34) within Moose::Meta::Attribute::_auto_deref which was called 6 times, avg 9µs/call:
# 6 times (21µs+34µs) by Moose::Meta::Attribute::_inline_return_auto_deref at line 958, avg 9µs/call | ||||
| 962 | 6 | 2µs | my $self = shift; | ||
| 963 | 6 | 1µs | my ($ref_value) = @_; | ||
| 964 | |||||
| 965 | 6 | 18µs | 6 | 34µs | return $ref_value unless $self->should_auto_deref; # spent 34µs making 6 calls to Moose::Meta::Mixin::AttributeCore::should_auto_deref, avg 6µs/call |
| 966 | |||||
| 967 | my $type_constraint = $self->type_constraint; | ||||
| 968 | |||||
| 969 | my $sigil; | ||||
| 970 | if ($type_constraint->is_a_type_of('ArrayRef')) { | ||||
| 971 | $sigil = '@'; | ||||
| 972 | } | ||||
| 973 | elsif ($type_constraint->is_a_type_of('HashRef')) { | ||||
| 974 | $sigil = '%'; | ||||
| 975 | } | ||||
| 976 | else { | ||||
| 977 | confess( | ||||
| 978 | 'Can not auto de-reference the type constraint \'' | ||||
| 979 | . $type_constraint->name | ||||
| 980 | . '\'' | ||||
| 981 | ); | ||||
| 982 | } | ||||
| 983 | |||||
| 984 | return 'wantarray ' | ||||
| 985 | . '? ' . $sigil . '{ (' . $ref_value . ') || return } ' | ||||
| 986 | . ': (' . $ref_value . ')'; | ||||
| 987 | } | ||||
| 988 | |||||
| 989 | ## installing accessors | ||||
| 990 | |||||
| 991 | 6 | 8µs | # spent 4µs within Moose::Meta::Attribute::accessor_metaclass which was called 6 times, avg 633ns/call:
# 6 times (4µs+0s) by Class::MOP::Attribute::try {...} at line 407 of Class/MOP/Attribute.pm, avg 633ns/call | ||
| 992 | |||||
| 993 | # spent 10.4ms (46µs+10.4) within Moose::Meta::Attribute::install_accessors which was called 6 times, avg 1.73ms/call:
# 5 times (40µs+9.64ms) by Class::MOP::Class::try {...} at line 899 of Class/MOP/Class.pm, avg 1.94ms/call
# once (6µs+714µs) by Class::MOP::Class::_inline_accessors at line 1425 of Class/MOP/Class.pm | ||||
| 994 | 6 | 1µs | my $self = shift; | ||
| 995 | 6 | 9µs | 6 | 9.99ms | $self->SUPER::install_accessors(@_); # spent 9.99ms making 6 calls to Class::MOP::Attribute::install_accessors, avg 1.66ms/call |
| 996 | 6 | 11µs | 7 | 369µs | $self->install_delegation if $self->has_handles; # spent 332µs making 1 call to Moose::Meta::Attribute::install_delegation
# spent 37µs making 6 calls to Moose::Meta::Mixin::AttributeCore::has_handles, avg 6µs/call |
| 997 | 6 | 10µs | return; | ||
| 998 | } | ||||
| 999 | |||||
| 1000 | # spent 13µs (12+2) within Moose::Meta::Attribute::_check_associated_methods which was called 4 times, avg 3µs/call:
# 4 times (12µs+2µs) by Moose::Meta::Class::add_attribute at line 576 of Moose/Meta/Class.pm, avg 3µs/call | ||||
| 1001 | 4 | 800ns | my $self = shift; | ||
| 1002 | 4 | 15µs | 4 | 2µs | unless ( # spent 2µs making 4 calls to Class::MOP::Attribute::associated_methods, avg 450ns/call |
| 1003 | @{ $self->associated_methods } | ||||
| 1004 | || ($self->_is_metadata || '') eq 'bare' | ||||
| 1005 | ) { | ||||
| 1006 | Carp::cluck( | ||||
| 1007 | 'Attribute (' . $self->name . ') of class ' | ||||
| 1008 | . $self->associated_class->name | ||||
| 1009 | . ' has no associated methods' | ||||
| 1010 | . ' (did you mean to provide an "is" argument?)' | ||||
| 1011 | . "\n" | ||||
| 1012 | ) | ||||
| 1013 | } | ||||
| 1014 | } | ||||
| 1015 | |||||
| 1016 | # spent 9.55ms (4.28+5.27) within Moose::Meta::Attribute::_process_accessors which was called 6 times, avg 1.59ms/call:
# 4 times (4.23ms+3.58ms) by Class::MOP::Attribute::install_accessors at line 446 of Class/MOP/Attribute.pm, avg 1.95ms/call
# 2 times (47µs+1.70ms) by Class::MOP::Attribute::install_accessors at line 450 of Class/MOP/Attribute.pm, avg 872µs/call | ||||
| 1017 | 6 | 900ns | my $self = shift; | ||
| 1018 | 6 | 2µs | my ($type, $accessor, $generate_as_inline_methods) = @_; | ||
| 1019 | |||||
| 1020 | 6 | 2µs | $accessor = ( keys %$accessor )[0] if ( ref($accessor) || '' ) eq 'HASH'; | ||
| 1021 | 6 | 16µs | 12 | 112µs | my $method = $self->associated_class->get_method($accessor); # spent 111µs making 6 calls to Class::MOP::Mixin::HasMethods::get_method, avg 18µs/call
# spent 1µs making 6 calls to Class::MOP::Attribute::associated_class, avg 200ns/call |
| 1022 | |||||
| 1023 | 6 | 8µs | 5 | 2µs | if ( $method # spent 1µs making 1 call to Class::MOP::Method::Accessor::associated_attribute
# spent 500ns making 1 call to UNIVERSAL::isa
# spent 300ns making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 150ns/call
# spent 100ns making 1 call to Class::MOP::Method::__ANON__[Class/MOP/Method.pm:16] |
| 1024 | && $method->isa('Class::MOP::Method::Accessor') | ||||
| 1025 | && $method->associated_attribute->name ne $self->name ) { | ||||
| 1026 | |||||
| 1027 | my $other_attr_name = $method->associated_attribute->name; | ||||
| 1028 | my $name = $self->name; | ||||
| 1029 | |||||
| 1030 | Carp::cluck( | ||||
| 1031 | "You are overwriting an accessor ($accessor) for the $other_attr_name attribute" | ||||
| 1032 | . " with a new accessor method for the $name attribute" ); | ||||
| 1033 | } | ||||
| 1034 | |||||
| 1035 | 6 | 11µs | 3 | 1µs | if ( # spent 600ns making 1 call to Class::MOP::Method::is_stub
# spent 300ns making 1 call to UNIVERSAL::isa
# spent 100ns making 1 call to Class::MOP::Method::__ANON__[Class/MOP/Method.pm:16] |
| 1036 | $method | ||||
| 1037 | && !$method->is_stub | ||||
| 1038 | && !$method->isa('Class::MOP::Method::Accessor') | ||||
| 1039 | && ( !$self->definition_context | ||||
| 1040 | || $method->package_name eq $self->definition_context->{package} ) | ||||
| 1041 | ) { | ||||
| 1042 | |||||
| 1043 | Carp::cluck( | ||||
| 1044 | "You are overwriting a locally defined method ($accessor) with " | ||||
| 1045 | . "an accessor" ); | ||||
| 1046 | } | ||||
| 1047 | |||||
| 1048 | 6 | 4.21ms | 22 | 96µs | if ( !$self->associated_class->has_method($accessor) # spent 61µs making 6 calls to Class::MOP::Mixin::HasMethods::has_method, avg 10µs/call
# spent 32µs making 5 calls to Class::MOP::Package::has_package_symbol, avg 6µs/call
# spent 3µs making 11 calls to Class::MOP::Attribute::associated_class, avg 236ns/call |
| 1049 | && $self->associated_class->has_package_symbol( '&' . $accessor ) ) { | ||||
| 1050 | |||||
| 1051 | Carp::cluck( | ||||
| 1052 | "You are overwriting a locally defined function ($accessor) with " | ||||
| 1053 | . "an accessor" ); | ||||
| 1054 | } | ||||
| 1055 | |||||
| 1056 | 6 | 17µs | 6 | 5.06ms | $self->SUPER::_process_accessors(@_); # spent 5.06ms making 6 calls to Class::MOP::Attribute::_process_accessors, avg 844µs/call |
| 1057 | } | ||||
| 1058 | |||||
| 1059 | sub remove_accessors { | ||||
| 1060 | my $self = shift; | ||||
| 1061 | $self->SUPER::remove_accessors(@_); | ||||
| 1062 | $self->remove_delegation if $self->has_handles; | ||||
| 1063 | return; | ||||
| 1064 | } | ||||
| 1065 | |||||
| 1066 | # spent 332µs (48+284) within Moose::Meta::Attribute::install_delegation which was called:
# once (48µs+284µs) by Moose::Meta::Attribute::install_accessors at line 996 | ||||
| 1067 | 1 | 300ns | my $self = shift; | ||
| 1068 | |||||
| 1069 | # NOTE: | ||||
| 1070 | # Here we canonicalize the 'handles' option | ||||
| 1071 | # this will sort out any details and always | ||||
| 1072 | # return an hash of methods which we want | ||||
| 1073 | # to delegate to, see that method for details | ||||
| 1074 | 1 | 3µs | 1 | 11µs | my %handles = $self->_canonicalize_handles; # spent 11µs making 1 call to Moose::Meta::Attribute::_canonicalize_handles |
| 1075 | |||||
| 1076 | # install the delegation ... | ||||
| 1077 | 1 | 2µs | 1 | 300ns | my $associated_class = $self->associated_class; # spent 300ns making 1 call to Class::MOP::Attribute::associated_class |
| 1078 | 1 | 3µs | 1 | 200ns | my $class_name = $associated_class->name; # spent 200ns making 1 call to Class::MOP::Package::name |
| 1079 | |||||
| 1080 | 1 | 6µs | 1 | 600ns | foreach my $handle ( sort keys %handles ) { # spent 600ns making 1 call to Moose::Meta::Attribute::CORE:sort |
| 1081 | 2 | 900ns | my $method_to_call = $handles{$handle}; | ||
| 1082 | 2 | 1µs | my $name = "${class_name}::${handle}"; | ||
| 1083 | |||||
| 1084 | 2 | 2µs | 2 | 23µs | if ( my $method = $associated_class->get_method($handle) ) { # spent 23µs making 2 calls to Class::MOP::Mixin::HasMethods::get_method, avg 12µs/call |
| 1085 | throw_exception( | ||||
| 1086 | CannotDelegateLocalMethodIsPresent => attribute => $self, | ||||
| 1087 | method => $method, | ||||
| 1088 | ) unless $method->is_stub; | ||||
| 1089 | } | ||||
| 1090 | |||||
| 1091 | # NOTE: | ||||
| 1092 | # handles is not allowed to delegate | ||||
| 1093 | # any of these methods, as they will | ||||
| 1094 | # override the ones in your class, which | ||||
| 1095 | # is almost certainly not what you want. | ||||
| 1096 | |||||
| 1097 | # FIXME warn when $handle was explicitly specified, but not if the source is a regex or something | ||||
| 1098 | #cluck("Not delegating method '$handle' because it is a core method") and | ||||
| 1099 | next | ||||
| 1100 | 2 | 19µs | 6 | 7µs | if $class_name->isa("Moose::Object") # spent 4µs making 2 calls to UNIVERSAL::can, avg 2µs/call
# spent 2µs making 2 calls to Moose::Meta::Attribute::CORE:match, avg 1µs/call
# spent 1µs making 2 calls to UNIVERSAL::isa, avg 550ns/call |
| 1101 | and $handle =~ /^BUILD|DEMOLISH$/ || Moose::Object->can($handle); | ||||
| 1102 | |||||
| 1103 | 2 | 3µs | 2 | 156µs | my $method = $self->_make_delegation_method($handle, $method_to_call); # spent 156µs making 2 calls to Moose::Meta::Attribute::_make_delegation_method, avg 78µs/call |
| 1104 | |||||
| 1105 | 2 | 8µs | 6 | 83µs | $self->associated_class->add_method($method->name, $method); # spent 82µs making 2 calls to Class::MOP::Mixin::HasMethods::add_method, avg 41µs/call
# spent 700ns making 2 calls to Class::MOP::Attribute::associated_class, avg 350ns/call
# spent 400ns making 2 calls to Class::MOP::Method::name, avg 200ns/call |
| 1106 | 2 | 3µs | 2 | 2µs | $self->associate_method($method); # spent 2µs making 2 calls to Class::MOP::Attribute::associate_method, avg 1µs/call |
| 1107 | } | ||||
| 1108 | } | ||||
| 1109 | |||||
| 1110 | sub remove_delegation { | ||||
| 1111 | my $self = shift; | ||||
| 1112 | my %handles = $self->_canonicalize_handles; | ||||
| 1113 | my $associated_class = $self->associated_class; | ||||
| 1114 | foreach my $handle (keys %handles) { | ||||
| 1115 | next unless any { $handle eq $_ } | ||||
| 1116 | map { $_->name } | ||||
| 1117 | @{ $self->associated_methods }; | ||||
| 1118 | $self->associated_class->remove_method($handle); | ||||
| 1119 | } | ||||
| 1120 | } | ||||
| 1121 | |||||
| 1122 | # private methods to help delegation ... | ||||
| 1123 | |||||
| 1124 | # spent 11µs (10+2) within Moose::Meta::Attribute::_canonicalize_handles which was called:
# once (10µs+2µs) by Moose::Meta::Attribute::install_delegation at line 1074 | ||||
| 1125 | 1 | 300ns | my $self = shift; | ||
| 1126 | 1 | 3µs | 1 | 2µs | my $handles = $self->handles; # spent 2µs making 1 call to Moose::Meta::Mixin::AttributeCore::handles |
| 1127 | 1 | 900ns | if (my $handle_type = ref($handles)) { | ||
| 1128 | 1 | 4µs | if ($handle_type eq 'HASH') { | ||
| 1129 | return %{$handles}; | ||||
| 1130 | } | ||||
| 1131 | elsif ($handle_type eq 'ARRAY') { | ||||
| 1132 | return map { $_ => $_ } @{$handles}; | ||||
| 1133 | } | ||||
| 1134 | elsif ($handle_type eq 'Regexp') { | ||||
| 1135 | ($self->has_type_constraint) | ||||
| 1136 | || throw_exception( CannotDelegateWithoutIsa => attribute => $self ); | ||||
| 1137 | return map { ($_ => $_) } | ||||
| 1138 | grep { /$handles/ } $self->_get_delegate_method_list; | ||||
| 1139 | } | ||||
| 1140 | elsif ($handle_type eq 'CODE') { | ||||
| 1141 | return $handles->($self, $self->_find_delegate_metaclass); | ||||
| 1142 | } | ||||
| 1143 | elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::DuckType')) { | ||||
| 1144 | return map { $_ => $_ } @{ $handles->methods }; | ||||
| 1145 | } | ||||
| 1146 | elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::Role')) { | ||||
| 1147 | $handles = $handles->role; | ||||
| 1148 | } | ||||
| 1149 | else { | ||||
| 1150 | throw_exception( UnableToCanonicalizeHandles => attribute => $self, | ||||
| 1151 | handles => $handles | ||||
| 1152 | ); | ||||
| 1153 | } | ||||
| 1154 | } | ||||
| 1155 | |||||
| 1156 | Moose::Util::_load_user_class($handles); | ||||
| 1157 | my $role_meta = Class::MOP::class_of($handles); | ||||
| 1158 | |||||
| 1159 | (blessed $role_meta && $role_meta->isa('Moose::Meta::Role')) | ||||
| 1160 | || throw_exception( UnableToCanonicalizeNonRolePackage => attribute => $self, | ||||
| 1161 | handles => $handles | ||||
| 1162 | ); | ||||
| 1163 | |||||
| 1164 | return map { $_ => $_ } | ||||
| 1165 | map { $_->name } | ||||
| 1166 | grep { !$_->isa('Class::MOP::Method::Meta') } ( | ||||
| 1167 | $role_meta->_get_local_methods, | ||||
| 1168 | $role_meta->get_required_method_list, | ||||
| 1169 | ); | ||||
| 1170 | } | ||||
| 1171 | |||||
| 1172 | sub _get_delegate_method_list { | ||||
| 1173 | my $self = shift; | ||||
| 1174 | my $meta = $self->_find_delegate_metaclass; | ||||
| 1175 | if ($meta->isa('Class::MOP::Class')) { | ||||
| 1176 | return map { $_->name } # NOTE: !never! delegate &meta | ||||
| 1177 | grep { $_->package_name ne 'Moose::Object' && !$_->isa('Class::MOP::Method::Meta') } | ||||
| 1178 | $meta->get_all_methods; | ||||
| 1179 | } | ||||
| 1180 | elsif ($meta->isa('Moose::Meta::Role')) { | ||||
| 1181 | return $meta->get_method_list; | ||||
| 1182 | } | ||||
| 1183 | else { | ||||
| 1184 | throw_exception( UnableToRecognizeDelegateMetaclass => attribute => $self, | ||||
| 1185 | delegate_metaclass => $meta | ||||
| 1186 | ); | ||||
| 1187 | } | ||||
| 1188 | } | ||||
| 1189 | |||||
| 1190 | sub _find_delegate_metaclass { | ||||
| 1191 | my $self = shift; | ||||
| 1192 | my $class = $self->_isa_metadata; | ||||
| 1193 | my $role = $self->_does_metadata; | ||||
| 1194 | |||||
| 1195 | if ( $class ) { | ||||
| 1196 | # make sure isa is actually a class | ||||
| 1197 | unless ( $self->type_constraint->isa("Moose::Meta::TypeConstraint::Class") ) { | ||||
| 1198 | throw_exception( DelegationToATypeWhichIsNotAClass => attribute => $self ); | ||||
| 1199 | } | ||||
| 1200 | |||||
| 1201 | # make sure the class is loaded | ||||
| 1202 | unless ( Moose::Util::_is_package_loaded($class) ) { | ||||
| 1203 | throw_exception( DelegationToAClassWhichIsNotLoaded => attribute => $self, | ||||
| 1204 | class_name => $class | ||||
| 1205 | ); | ||||
| 1206 | } | ||||
| 1207 | # we might be dealing with a non-Moose class, | ||||
| 1208 | # and need to make our own metaclass. if there's | ||||
| 1209 | # already a metaclass, it will be returned | ||||
| 1210 | return Class::MOP::Class->initialize($class); | ||||
| 1211 | } | ||||
| 1212 | elsif ( $role ) { | ||||
| 1213 | unless ( Moose::Util::_is_package_loaded($role) ) { | ||||
| 1214 | throw_exception( DelegationToARoleWhichIsNotLoaded => attribute => $self, | ||||
| 1215 | role_name => $role | ||||
| 1216 | ); | ||||
| 1217 | } | ||||
| 1218 | |||||
| 1219 | return Class::MOP::class_of($role); | ||||
| 1220 | } | ||||
| 1221 | else { | ||||
| 1222 | throw_exception( CannotFindDelegateMetaclass => attribute => $self ); | ||||
| 1223 | } | ||||
| 1224 | } | ||||
| 1225 | |||||
| 1226 | 2 | 3µs | # spent 1µs within Moose::Meta::Attribute::delegation_metaclass which was called 2 times, avg 600ns/call:
# 2 times (1µs+0s) by Moose::Meta::Attribute::_make_delegation_method at line 1236, avg 600ns/call | ||
| 1227 | |||||
| 1228 | # spent 156µs (17+139) within Moose::Meta::Attribute::_make_delegation_method which was called 2 times, avg 78µs/call:
# 2 times (17µs+139µs) by Moose::Meta::Attribute::install_delegation at line 1103, avg 78µs/call | ||||
| 1229 | 2 | 800ns | my ( $self, $handle_name, $method_to_call ) = @_; | ||
| 1230 | |||||
| 1231 | 2 | 500ns | my @curried_arguments; | ||
| 1232 | |||||
| 1233 | 2 | 500ns | ($method_to_call, @curried_arguments) = @$method_to_call | ||
| 1234 | if 'ARRAY' eq ref($method_to_call); | ||||
| 1235 | |||||
| 1236 | 2 | 15µs | 8 | 139µs | return $self->delegation_metaclass->new( # spent 137µs making 2 calls to Moose::Meta::Method::Delegation::new, avg 68µs/call
# spent 1µs making 2 calls to Moose::Meta::Attribute::delegation_metaclass, avg 600ns/call
# spent 600ns making 2 calls to Class::MOP::Attribute::associated_class, avg 300ns/call
# spent 400ns making 2 calls to Class::MOP::Package::name, avg 200ns/call |
| 1237 | name => $handle_name, | ||||
| 1238 | package_name => $self->associated_class->name, | ||||
| 1239 | attribute => $self, | ||||
| 1240 | delegate_to_method => $method_to_call, | ||||
| 1241 | curried_arguments => \@curried_arguments, | ||||
| 1242 | ); | ||||
| 1243 | } | ||||
| 1244 | |||||
| 1245 | sub _coerce_and_verify { | ||||
| 1246 | my $self = shift; | ||||
| 1247 | my $val = shift; | ||||
| 1248 | my $instance = shift; | ||||
| 1249 | |||||
| 1250 | return $val unless $self->has_type_constraint; | ||||
| 1251 | |||||
| 1252 | $val = $self->type_constraint->coerce($val) | ||||
| 1253 | if $self->should_coerce && $self->type_constraint->has_coercion; | ||||
| 1254 | |||||
| 1255 | $self->verify_against_type_constraint($val, instance => $instance); | ||||
| 1256 | |||||
| 1257 | return $val; | ||||
| 1258 | } | ||||
| 1259 | |||||
| 1260 | sub verify_against_type_constraint { | ||||
| 1261 | my $self = shift; | ||||
| 1262 | my $val = shift; | ||||
| 1263 | |||||
| 1264 | return 1 if !$self->has_type_constraint; | ||||
| 1265 | |||||
| 1266 | my $type_constraint = $self->type_constraint; | ||||
| 1267 | |||||
| 1268 | $type_constraint->check($val) | ||||
| 1269 | || throw_exception( ValidationFailedForTypeConstraint => type => $type_constraint, | ||||
| 1270 | value => $val, | ||||
| 1271 | attribute => $self, | ||||
| 1272 | ); | ||||
| 1273 | } | ||||
| 1274 | |||||
| 1275 | package Moose::Meta::Attribute::Custom::Moose; | ||||
| 1276 | 1 | 200ns | our $VERSION = '2.1403'; | ||
| 1277 | |||||
| 1278 | sub register_implementation { 'Moose::Meta::Attribute' } | ||||
| 1279 | 1 | 4µs | 1; | ||
| 1280 | |||||
| 1281 | # ABSTRACT: The Moose attribute metaclass | ||||
| 1282 | |||||
| 1283 | __END__ | ||||
# spent 2µs within Moose::Meta::Attribute::CORE:match which was called 2 times, avg 1µs/call:
# 2 times (2µs+0s) by Moose::Meta::Attribute::install_delegation at line 1100, avg 1µs/call | |||||
sub Moose::Meta::Attribute::CORE:sort; # opcode |