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

Filename/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Attribute.pm
StatementsExecuted 21607 statements in 314ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1243279.0ms334msMoose::Meta::Attribute::::new Moose::Meta::Attribute::new
1935124.5ms848msMoose::Meta::Attribute::::_process_accessors Moose::Meta::Attribute::_process_accessors
1955322.7ms134msMoose::Meta::Attribute::::_inline_set_value Moose::Meta::Attribute::_inline_set_value
11120.6ms314msMoose::Meta::Attribute::::BEGIN@20 Moose::Meta::Attribute::BEGIN@20
1222218.7ms146msMoose::Meta::Attribute::::_process_options Moose::Meta::Attribute::_process_options
2102113.3ms20.9msMoose::Meta::Attribute::::_inline_check_constraint Moose::Meta::Attribute::_inline_check_constraint
121227.72ms551msMoose::Meta::Attribute::::interpolate_class_and_new Moose::Meta::Attribute::interpolate_class_and_new (recurses: max depth 1, inclusive time 7.74ms)
123217.72ms131msMoose::Meta::Attribute::::_inline_get_value Moose::Meta::Attribute::_inline_get_value
125327.58ms1.04sMoose::Meta::Attribute::::install_accessors Moose::Meta::Attribute::install_accessors
195116.73ms33.8msMoose::Meta::Attribute::::_inline_tc_code Moose::Meta::Attribute::_inline_tc_code
195116.07ms9.70msMoose::Meta::Attribute::::_inline_weaken_value Moose::Meta::Attribute::_inline_weaken_value
210215.91ms8.50msMoose::Meta::Attribute::::_inline_check_coercion Moose::Meta::Attribute::_inline_check_coercion
122115.33ms102msMoose::Meta::Attribute::::_process_isa_option Moose::Meta::Attribute::_process_isa_option
128224.93ms20.9msMoose::Meta::Attribute::::_inline_check_lazy Moose::Meta::Attribute::_inline_check_lazy
199224.80ms7.62msMoose::Meta::Attribute::::_writer_value_needs_copy Moose::Meta::Attribute::_writer_value_needs_copy
9114.77ms65.1msMoose::Meta::Attribute::::install_delegation Moose::Meta::Attribute::install_delegation
211314.26ms4.26msMoose::Meta::Attribute::::_inline_throw_error Moose::Meta::Attribute::_inline_throw_error
123214.17ms225msMoose::Meta::Attribute::::interpolate_class Moose::Meta::Attribute::interpolate_class (recurses: max depth 1, inclusive time 120µs)
123113.62ms5.54msMoose::Meta::Attribute::::_auto_deref Moose::Meta::Attribute::_auto_deref
123113.51ms9.06msMoose::Meta::Attribute::::_inline_return_auto_deref Moose::Meta::Attribute::_inline_return_auto_deref
122113.08ms3.08msMoose::Meta::Attribute::::_process_is_option Moose::Meta::Attribute::_process_is_option
1113.05ms3.97msMoose::Meta::Attribute::::BEGIN@17 Moose::Meta::Attribute::BEGIN@17
123112.86ms3.66msMoose::Meta::Attribute::::_check_associated_methods Moose::Meta::Attribute::_check_associated_methods
1112.71ms3.80msMoose::Meta::Attribute::::BEGIN@18 Moose::Meta::Attribute::BEGIN@18
124212.67ms2.75msMoose::Meta::Attribute::::_process_lazy_build_option Moose::Meta::Attribute::_process_lazy_build_option
19112.19ms11.0msMoose::Meta::Attribute::::_inline_init_from_default Moose::Meta::Attribute::_inline_init_from_default
122112.15ms10.3msMoose::Meta::Attribute::::_process_does_option Moose::Meta::Attribute::_process_does_option
2112.14ms17.5msMoose::Meta::Attribute::::clone Moose::Meta::Attribute::clone
203221.87ms1.87msMoose::Meta::Attribute::::accessor_metaclass Moose::Meta::Attribute::accessor_metaclass
122111.79ms1.79msMoose::Meta::Attribute::::_process_required_option Moose::Meta::Attribute::_process_required_option
122111.78ms1.80msMoose::Meta::Attribute::::_process_coerce_option Moose::Meta::Attribute::_process_coerce_option
122111.72ms1.72msMoose::Meta::Attribute::::_process_trigger_option Moose::Meta::Attribute::_process_trigger_option
122111.71ms1.71msMoose::Meta::Attribute::::_process_auto_deref_option Moose::Meta::Attribute::_process_auto_deref_option
122111.70ms1.70msMoose::Meta::Attribute::::_process_lazy_option Moose::Meta::Attribute::_process_lazy_option
14111.63ms7.71msMoose::Meta::Attribute::::initialize_instance_slot Moose::Meta::Attribute::initialize_instance_slot
23111.54ms12.5msMoose::Meta::Attribute::::_make_delegation_method Moose::Meta::Attribute::_make_delegation_method
19111.34ms2.07msMoose::Meta::Attribute::::_inline_generate_default Moose::Meta::Attribute::_inline_generate_default
39111.19ms2.08msMoose::Meta::Attribute::::_inline_get_old_value_for_trigger Moose::Meta::Attribute::_inline_get_old_value_for_trigger
41221.19ms1.97msMoose::Meta::Attribute::::_inline_trigger Moose::Meta::Attribute::_inline_trigger
39111.13ms2.06msMoose::Meta::Attribute::::_inline_check_required Moose::Meta::Attribute::_inline_check_required
1911937µs3.72msMoose::Meta::Attribute::::_inline_init_slot Moose::Meta::Attribute::_inline_init_slot
1111641µs2.61msMoose::Meta::Attribute::::_coerce_and_verify Moose::Meta::Attribute::_coerce_and_verify
911559µs1.75msMoose::Meta::Attribute::::verify_against_type_constraint Moose::Meta::Attribute::verify_against_type_constraint
12411558µs558µsMoose::Meta::Attribute::::CORE:sort Moose::Meta::Attribute::CORE:sort (opcode)
211446µs18.1msMoose::Meta::Attribute::::clone_and_inherit_options Moose::Meta::Attribute::clone_and_inherit_options
711390µs481µsMoose::Meta::Attribute::::_canonicalize_handles Moose::Meta::Attribute::_canonicalize_handles
4421375µs375µsMoose::Meta::Attribute::::CORE:match Moose::Meta::Attribute::CORE:match (opcode)
511374µs4.97msMoose::Meta::Attribute::::does Moose::Meta::Attribute::does
3322279µs279µsMoose::Meta::Attribute::::delegation_metaclass Moose::Meta::Attribute::delegation_metaclass
211150µs421µsMoose::Meta::Attribute::::_weaken_value Moose::Meta::Attribute::_weaken_value
511101µs3.76msMoose::Meta::Attribute::::__ANON__[:40] Moose::Meta::Attribute::__ANON__[:40]
11170µs89µsMoose::Meta::Attribute::::BEGIN@4 Moose::Meta::Attribute::BEGIN@4
31161µs61µsMoose::Meta::Attribute::::_inline_copy_value Moose::Meta::Attribute::_inline_copy_value
11139µs228µsMoose::Meta::Attribute::::BEGIN@8 Moose::Meta::Attribute::BEGIN@8
11139µs108µsMoose::Meta::Attribute::::BEGIN@5 Moose::Meta::Attribute::BEGIN@5
11138µs70µsMoose::Meta::Attribute::::BEGIN@16 Moose::Meta::Attribute::BEGIN@16
11138µs213µsMoose::Meta::Attribute::::BEGIN@10 Moose::Meta::Attribute::BEGIN@10
11137µs164µsMoose::Meta::Attribute::::BEGIN@9 Moose::Meta::Attribute::BEGIN@9
11136µs37.9msMoose::Meta::Attribute::::BEGIN@23 Moose::Meta::Attribute::BEGIN@23
21130µs30µsMoose::Meta::Attribute::::illegal_options_for_inheritance Moose::Meta::Attribute::illegal_options_for_inheritance
11130µs30µsMoose::Meta::Attribute::::BEGIN@21 Moose::Meta::Attribute::BEGIN@21
11123µs23µsMoose::Meta::Attribute::::BEGIN@19 Moose::Meta::Attribute::BEGIN@19
11120µs20µsMoose::Meta::Attribute::::BEGIN@11 Moose::Meta::Attribute::BEGIN@11
11119µs19µsMoose::Meta::Attribute::::BEGIN@7 Moose::Meta::Attribute::BEGIN@7
0000s0sMoose::Meta::Attribute::Custom::Moose::::register_implementationMoose::Meta::Attribute::Custom::Moose::register_implementation
0000s0sMoose::Meta::Attribute::::__ANON__[:311] Moose::Meta::Attribute::__ANON__[:311]
0000s0sMoose::Meta::Attribute::::__ANON__[:523] Moose::Meta::Attribute::__ANON__[:523]
0000s0sMoose::Meta::Attribute::::__ANON__[:997] Moose::Meta::Attribute::__ANON__[:997]
0000s0sMoose::Meta::Attribute::::_call_builder Moose::Meta::Attribute::_call_builder
0000s0sMoose::Meta::Attribute::::_find_delegate_metaclass Moose::Meta::Attribute::_find_delegate_metaclass
0000s0sMoose::Meta::Attribute::::_get_delegate_method_list Moose::Meta::Attribute::_get_delegate_method_list
0000s0sMoose::Meta::Attribute::::_make_initializer_writer_callback Moose::Meta::Attribute::_make_initializer_writer_callback
0000s0sMoose::Meta::Attribute::::get_value Moose::Meta::Attribute::get_value
0000s0sMoose::Meta::Attribute::::remove_accessors Moose::Meta::Attribute::remove_accessors
0000s0sMoose::Meta::Attribute::::remove_delegation Moose::Meta::Attribute::remove_delegation
0000s0sMoose::Meta::Attribute::::set_value Moose::Meta::Attribute::set_value
0000s0sMoose::Meta::Attribute::::throw_error Moose::Meta::Attribute::throw_error
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Moose::Meta::Attribute;
3
4398µs2107µs
# spent 89µs (70+18) within Moose::Meta::Attribute::BEGIN@4 which was called: # once (70µs+18µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 4
use strict;
# spent 89µs making 1 call to Moose::Meta::Attribute::BEGIN@4 # spent 18µs making 1 call to strict::import
5395µs2177µs
# spent 108µs (39+69) within Moose::Meta::Attribute::BEGIN@5 which was called: # once (39µs+69µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 5
use warnings;
# spent 108µs making 1 call to Moose::Meta::Attribute::BEGIN@5 # spent 69µs making 1 call to warnings::import
6
73145µs119µs
# spent 19µs within Moose::Meta::Attribute::BEGIN@7 which was called: # once (19µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 7
use Class::MOP ();
# spent 19µs making 1 call to Moose::Meta::Attribute::BEGIN@7
83107µs2416µs
# spent 228µs (39+189) within Moose::Meta::Attribute::BEGIN@8 which was called: # once (39µs+189µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 8
use Scalar::Util 'blessed', 'weaken';
# spent 228µs making 1 call to Moose::Meta::Attribute::BEGIN@8 # spent 189µs making 1 call to Exporter::import
9394µs2292µs
# spent 164µs (37+128) within Moose::Meta::Attribute::BEGIN@9 which was called: # once (37µs+128µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 9
use List::MoreUtils 'any';
# spent 164µs making 1 call to Moose::Meta::Attribute::BEGIN@9 # spent 128µs making 1 call to Exporter::import
10390µs2387µs
# spent 213µs (38+175) within Moose::Meta::Attribute::BEGIN@10 which was called: # once (38µs+175µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 10
use Try::Tiny;
# spent 213µs making 1 call to Moose::Meta::Attribute::BEGIN@10 # spent 175µs making 1 call to Exporter::import
113156µs120µ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
use overload ();
# spent 20µs making 1 call to Moose::Meta::Attribute::BEGIN@11
12
1317µsour $VERSION = '1.19';
1415µsour $AUTHORITY = 'cpan:STEVAN';
15
16394µs2102µs
# spent 70µs (38+32) within Moose::Meta::Attribute::BEGIN@16 which was called: # once (38µs+32µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 16
use Moose::Deprecated;
173514µs13.97ms
# spent 3.97ms (3.05+917µs) within Moose::Meta::Attribute::BEGIN@17 which was called: # once (3.05ms+917µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 17
use Moose::Meta::Method::Accessor;
# spent 3.97ms making 1 call to Moose::Meta::Attribute::BEGIN@17
183514µs13.80ms
# spent 3.80ms (2.71+1.08) within Moose::Meta::Attribute::BEGIN@18 which was called: # once (2.71ms+1.08ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 18
use Moose::Meta::Method::Delegation;
# spent 3.80ms making 1 call to Moose::Meta::Attribute::BEGIN@18
193166µs123µs
# spent 23µs within Moose::Meta::Attribute::BEGIN@19 which was called: # once (23µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 19
use Moose::Util ();
# spent 23µs making 1 call to Moose::Meta::Attribute::BEGIN@19
203749µs1314ms
# spent 314ms (20.6+293) within Moose::Meta::Attribute::BEGIN@20 which was called: # once (20.6ms+293ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 20
use Moose::Util::TypeConstraints ();
# spent 314ms making 1 call to Moose::Meta::Attribute::BEGIN@20
213109µs130µs
# spent 30µs within Moose::Meta::Attribute::BEGIN@21 which was called: # once (30µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 21
use Class::MOP::MiniTrait;
# spent 30µs making 1 call to Moose::Meta::Attribute::BEGIN@21
22
23317.7ms275.7ms
# spent 37.9ms (36µs+37.8) within Moose::Meta::Attribute::BEGIN@23 which was called: # once (36µs+37.8ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 23
use base 'Class::MOP::Attribute', 'Moose::Meta::Mixin::AttributeCore';
# spent 37.9ms making 1 call to Moose::Meta::Attribute::BEGIN@23 # spent 37.8ms making 1 call to base::import
24
25122µs19.11msClass::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
# spent 9.11ms making 1 call to Class::MOP::MiniTrait::apply
26
27167µs23.04ms__PACKAGE__->meta->add_attribute('traits' => (
# spent 2.96ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 83µs making 1 call to Class::MOP::Object::meta
28 reader => 'applied_traits',
29 predicate => 'has_applied_traits',
30));
31
32# we need to have a ->does method in here to
33# more easily support traits, and the introspection
34# of those traits. We extend the does check to look
35# for metatrait aliases.
36
# spent 4.97ms (374µs+4.60) within Moose::Meta::Attribute::does which was called 5 times, avg 995µs/call: # 5 times (374µs+4.60ms) by Moose::Meta::Attribute::interpolate_class at line 119, avg 995µs/call
sub does {
37530µs my ($self, $role_name) = @_;
38
# spent 3.76ms (101µs+3.66) within Moose::Meta::Attribute::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Attribute.pm:40] which was called 5 times, avg 753µs/call: # 5 times (101µs+3.66ms) by Try::Tiny::try at line 71 of Try/Tiny.pm, avg 753µs/call
my $name = try {
39599µs53.66ms Moose::Util::resolve_metatrait_alias(Attribute => $role_name)
# spent 3.66ms making 5 calls to Moose::Util::resolve_metatrait_alias, avg 732µs/call
405131µs54.14ms };
# spent 4.14ms making 5 calls to Try::Tiny::try, avg 827µs/call
41518µs return 0 if !defined($name); # failed to load class
425152µs5462µs return $self->Moose::Object::does($name);
# spent 462µs making 5 calls to Moose::Object::does, avg 92µs/call
43}
44
45sub 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 4.26ms within Moose::Meta::Attribute::_inline_throw_error which was called 211 times, avg 20µs/call: # 190 times (3.83ms+0s) by Moose::Meta::Attribute::_inline_check_constraint at line 646, avg 20µs/call # 19 times (389µs+0s) by Moose::Meta::Attribute::_inline_generate_default at line 803, avg 20µs/call # 2 times (40µs+0s) by Moose::Meta::Attribute::_inline_check_required at line 611, avg 20µs/call
sub _inline_throw_error {
562111.05ms my ( $self, $msg, $args ) = @_;
572113.83ms "\$meta->throw_error($msg" . ($args ? ", $args" : "") . ")"; # FIXME makes deparsing *REALLY* hard
58}
59
60
# spent 334ms (79.0+255) within Moose::Meta::Attribute::new which was called 124 times, avg 2.70ms/call: # 121 times (77.2ms+249ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 88, avg 2.69ms/call # 2 times (1.23ms+1.05ms) by Moose::Meta::Attribute::clone at line 244, avg 1.14ms/call # once (664µs+5.47ms) by Moose::BEGIN@21 at line 20 of Moose/Meta/TypeCoercion.pm
sub new {
611241.48ms my ($class, $name, %options) = @_;
621241.81ms122148ms $class->_process_options($name, \%options) unless $options{__hack_no_process_options}; # used from clone()... YECHKKK FIXME ICKY YUCK GROSS
# spent 145ms making 120 calls to Moose::Meta::Attribute::_process_options, avg 1.20ms/call # spent 1.70ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::_process_options # spent 1.62ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::_process_options
63
64124446µs delete $options{__hack_no_process_options};
65
66 my %attrs =
67 ( map { $_ => 1 }
68347658.4ms347618.0ms grep { defined }
# spent 18.0ms making 3476 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 5µs/call
6912423.5ms24825.3ms map { $_->init_arg() }
# spent 11.3ms making 119 calls to Class::MOP::Object::meta, avg 95µs/call # spent 9.53ms making 118 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 81µs/call # spent 4.03ms making 6 calls to Class::MOP::Class::get_all_attributes, avg 672µs/call # spent 282µs making 3 calls to Class::MOP::Class::__ANON__::SERIAL::1::meta, avg 94µs/call # spent 101µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::meta # spent 98µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::meta
70 $class->meta()->get_all_attributes()
71 );
72
731243.87ms124558µs my @bad = sort grep { ! $attrs{$_} } keys %options;
# spent 558µs making 124 calls to Moose::Meta::Attribute::CORE:sort, avg 4µs/call
74
75124337µs if (@bad)
76 {
77 Carp::cluck "Found unknown argument(s) passed to '$name' attribute constructor in '$class': @bad";
78 }
79
801247.33ms12463.6ms return $class->SUPER::new($name, %options);
# spent 63.6ms making 124 calls to Class::MOP::Attribute::new, avg 513µs/call
81}
82
83
# spent 551ms (7.72+543) within Moose::Meta::Attribute::interpolate_class_and_new which was called 121 times, avg 4.55ms/call: # 114 times (7.23ms+538ms) by Moose::Meta::Class::_process_new_attribute at line 622 of Moose/Meta/Class.pm, avg 4.78ms/call # 7 times (490µs+4.59ms) by Moose::Meta::Role::Attribute::attribute_for_class at line 67 of Moose/Meta/Role/Attribute.pm, avg 725µs/call
sub interpolate_class_and_new {
841211.39ms my ($class, $name, %args) = @_;
85
861211.94ms121224ms my ( $new_class, @traits ) = $class->interpolate_class(\%args);
# spent 225ms making 121 calls to Moose::Meta::Attribute::interpolate_class, avg 1.86ms/call, recursion: max depth 1, sum of overlapping time 120µs
87
881213.87ms121326ms $new_class->new($name, %args, ( scalar(@traits) ? ( traits => \@traits ) : () ) );
# spent 326ms making 121 calls to Moose::Meta::Attribute::new, avg 2.69ms/call
89}
90
91
# spent 225ms (4.17+220) within Moose::Meta::Attribute::interpolate_class which was called 123 times, avg 1.83ms/call: # 121 times (4.11ms+220ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 86, avg 1.85ms/call # 2 times (63µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 214, avg 31µs/call
sub interpolate_class {
92123482µs my ($class, $options) = @_;
93
94123325µs $class = ref($class) || $class;
95
96123600µs if ( my $metaclass_name = delete $options->{metaclass} ) {
97 my $new_class = Moose::Util::resolve_metaclass_alias( Attribute => $metaclass_name );
98
99 if ( $class ne $new_class ) {
100 if ( $new_class->can("interpolate_class") ) {
101 return $new_class->interpolate_class($options);
102 } else {
103 $class = $new_class;
104 }
105 }
106 }
107
108123258µs my @traits;
109
110123407µs if (my $traits = $options->{traits}) {
111513µs my $i = 0;
112524µs while ($i < @$traits) {
113518µs my $trait = $traits->[$i++];
11459µs next if ref($trait); # options to a trait we discarded
115
116566µs589.8ms $trait = Moose::Util::resolve_metatrait_alias(Attribute => $trait)
# spent 89.8ms making 5 calls to Moose::Util::resolve_metatrait_alias, avg 18.0ms/call
117 || $trait;
118
119572µs54.97ms next if $class->does($trait);
# spent 4.97ms making 5 calls to Moose::Meta::Attribute::does, avg 995µs/call
120
121524µs push @traits, $trait;
122
123 # are there options?
124538µs push @traits, $traits->[$i++]
125 if $traits->[$i] && ref($traits->[$i]);
126 }
127
128524µs if (@traits) {
1295115µs5126ms my $anon_class = Moose::Meta::Class->create_anon_class(
# spent 126ms making 5 calls to Moose::Meta::Class::create_anon_class, avg 25.1ms/call
130 superclasses => [ $class ],
131 roles => [ @traits ],
132 cache => 1,
133 );
134
1355113µs533µs $class = $anon_class->name;
# spent 33µs making 5 calls to Class::MOP::Package::name, avg 7µs/call
136 }
137 }
138
1391232.14ms return ( wantarray ? ( $class, @traits ) : $class );
140}
141
142# ...
143
144# method-generating options shouldn't be overridden
145
# spent 30µs within Moose::Meta::Attribute::illegal_options_for_inheritance which was called 2 times, avg 15µs/call: # 2 times (30µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 173, avg 15µs/call
sub illegal_options_for_inheritance {
146245µs qw(reader writer accessor clearer predicate)
147}
148
149# NOTE/TODO
150# This method *must* be able to handle
151# Class::MOP::Attribute instances as
152# well. Yes, I know that is wrong, but
153# apparently we didn't realize it was
154# doing that and now we have some code
155# which is dependent on it. The real
156# solution of course is to push this
157# feature back up into Class::MOP::Attribute
158# but I not right now, I am too lazy.
159# However if you are reading this and
160# looking for something to do,.. please
161# be my guest.
162# - stevan
163
# spent 18.1ms (446µs+17.7) within Moose::Meta::Attribute::clone_and_inherit_options which was called 2 times, avg 9.07ms/call: # 2 times (446µs+17.7ms) by Moose::Meta::Class::_process_inherited_attribute at line 630 of Moose/Meta/Class.pm, avg 9.07ms/call
sub clone_and_inherit_options {
164215µs my ($self, %options) = @_;
165
166 # NOTE:
167 # we may want to extends a Class::MOP::Attribute
168 # in which case we need to be able to use the
169 # core set of legal options that have always
170 # been here. But we allows Moose::Meta::Attribute
171 # instances to changes them.
172 # - SL
173290µs447µs my @illegal_options = $self->can('illegal_options_for_inheritance')
# spent 30µs making 2 calls to Moose::Meta::Attribute::illegal_options_for_inheritance, avg 15µs/call # spent 17µs making 2 calls to UNIVERSAL::can, avg 8µs/call
174 ? $self->illegal_options_for_inheritance
175 : ();
176
177219µs my @found_illegal_options = grep { exists $options{$_} && exists $self->{$_} ? $_ : undef } @illegal_options;
17827µs (scalar @found_illegal_options == 0)
179 || $self->throw_error("Illegal inherited options => (" . (join ', ' => @found_illegal_options) . ")", data => \%options);
180
18126µs if ($options{isa}) {
182 my $type_constraint;
183 if (blessed($options{isa}) && $options{isa}->isa('Moose::Meta::TypeConstraint')) {
184 $type_constraint = $options{isa};
185 }
186 else {
187 $type_constraint = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($options{isa});
188 (defined $type_constraint)
189 || $self->throw_error("Could not find the type constraint '" . $options{isa} . "'", data => $options{isa});
190 }
191
192 $options{type_constraint} = $type_constraint;
193 }
194
19526µs if ($options{does}) {
196 my $type_constraint;
197 if (blessed($options{does}) && $options{does}->isa('Moose::Meta::TypeConstraint')) {
198 $type_constraint = $options{does};
199 }
200 else {
201 $type_constraint = Moose::Util::TypeConstraints::find_or_create_does_type_constraint($options{does});
202 (defined $type_constraint)
203 || $self->throw_error("Could not find the type constraint '" . $options{does} . "'", data => $options{does});
204 }
205
206 $options{type_constraint} = $type_constraint;
207 }
208
209 # NOTE:
210 # this doesn't apply to Class::MOP::Attributes,
211 # so we can ignore it for them.
212 # - SL
213263µs214µs if ($self->can('interpolate_class')) {
# spent 14µs making 2 calls to UNIVERSAL::can, avg 7µs/call
214236µs263µs ( $options{metaclass}, my @traits ) = $self->interpolate_class(\%options);
# spent 63µs making 2 calls to Moose::Meta::Attribute::interpolate_class, avg 31µs/call
215
21624µs my %seen;
217232µs229µs my @all_traits = grep { $seen{$_}++ } @{ $self->applied_traits || [] }, @traits;
# spent 29µs making 2 calls to Moose::Meta::Attribute::applied_traits, avg 14µs/call
21828µs $options{traits} = \@all_traits if @all_traits;
219 }
220
221 # This method can be called on a CMOP::Attribute object, so we need to
222 # make sure we can call this method.
223298µs659µs $self->_process_lazy_build_option( $self->name, \%options )
# spent 32µs making 2 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 16µs/call # spent 14µs making 2 calls to UNIVERSAL::can, avg 7µs/call # spent 13µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 7µs/call
224 if $self->can('_process_lazy_build_option');
225
226271µs217.5ms $self->clone(%options);
# spent 17.5ms making 2 calls to Moose::Meta::Attribute::clone, avg 8.75ms/call
227}
228
229
# spent 17.5ms (2.14+15.3) within Moose::Meta::Attribute::clone which was called 2 times, avg 8.75ms/call: # 2 times (2.14ms+15.3ms) by Moose::Meta::Attribute::clone_and_inherit_options at line 226, avg 8.75ms/call
sub clone {
230216µs my ( $self, %params ) = @_;
231
232211µs my $class = delete $params{metaclass} || ref $self;
233
23425µs my ( @init, @non_init );
235
23658751µs609.11ms foreach my $attr ( grep { $_->has_value($self) } Class::MOP::class_of($self)->get_all_attributes ) {
# spent 8.89ms making 56 calls to Class::MOP::Attribute::has_value, avg 159µs/call # spent 146µs making 2 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 73µs/call # spent 71µs making 2 calls to Class::MOP::class_of, avg 36µs/call
23721348µs21202µs push @{ $attr->has_init_arg ? \@init : \@non_init }, $attr;
# spent 202µs making 21 calls to Class::MOP::Mixin::AttributeCore::has_init_arg, avg 10µs/call
238 }
239
24023666µs423.77ms my %new_params = ( ( map { $_->init_arg => $_->get_value($self) } @init ), %params );
# spent 3.66ms making 21 calls to Class::MOP::Attribute::get_value, avg 174µs/call # spent 107µs making 21 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 5µs/call
241
242211µs my $name = delete $new_params{name};
243
2442109µs22.27ms my $clone = $class->new($name, %new_params, __hack_no_process_options => 1 );
# spent 2.27ms making 2 calls to Moose::Meta::Attribute::new, avg 1.14ms/call
245
246214µs foreach my $attr ( @non_init ) {
247 $attr->set_value($clone, $attr->get_value($self));
248 }
249
250246µs return $clone;
251}
252
253
# spent 146ms (18.7+127) within Moose::Meta::Attribute::_process_options which was called 122 times, avg 1.20ms/call: # 120 times (18.2ms+126ms) by Moose::Meta::Attribute::new at line 62, avg 1.20ms/call # 2 times (498µs+856µs) by Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:49] at line 48 of Class/MOP/Method/Wrapped.pm, avg 677µs/call
sub _process_options {
254122561µs my ( $class, $name, $options ) = @_;
255
2561221.43ms1223.08ms $class->_process_is_option( $name, $options );
# spent 3.08ms making 122 calls to Moose::Meta::Attribute::_process_is_option, avg 25µs/call
2571221.58ms122102ms $class->_process_isa_option( $name, $options );
# spent 102ms making 122 calls to Moose::Meta::Attribute::_process_isa_option, avg 839µs/call
2581221.57ms12210.3ms $class->_process_does_option( $name, $options );
# spent 10.3ms making 122 calls to Moose::Meta::Attribute::_process_does_option, avg 85µs/call
2591221.49ms1221.80ms $class->_process_coerce_option( $name, $options );
# spent 1.80ms making 122 calls to Moose::Meta::Attribute::_process_coerce_option, avg 15µs/call
2601221.42ms1221.72ms $class->_process_trigger_option( $name, $options );
# spent 1.72ms making 122 calls to Moose::Meta::Attribute::_process_trigger_option, avg 14µs/call
2611221.42ms1221.71ms $class->_process_auto_deref_option( $name, $options );
# spent 1.71ms making 122 calls to Moose::Meta::Attribute::_process_auto_deref_option, avg 14µs/call
2621221.44ms1222.72ms $class->_process_lazy_build_option( $name, $options );
# spent 2.72ms making 122 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 22µs/call
2631221.51ms1221.70ms $class->_process_lazy_option( $name, $options );
# spent 1.70ms making 122 calls to Moose::Meta::Attribute::_process_lazy_option, avg 14µs/call
2641222.68ms1221.79ms $class->_process_required_option( $name, $options );
# spent 1.79ms making 122 calls to Moose::Meta::Attribute::_process_required_option, avg 15µs/call
265}
266
267
# spent 3.08ms within Moose::Meta::Attribute::_process_is_option which was called 122 times, avg 25µs/call: # 122 times (3.08ms+0s) by Moose::Meta::Attribute::_process_options at line 256, avg 25µs/call
sub _process_is_option {
268122444µs my ( $class, $name, $options ) = @_;
269
270122422µs return unless $options->{is};
271
272 ### -------------------------
273 ## is => ro, writer => _foo # turns into (reader => foo, writer => _foo) as before
274 ## is => rw, writer => _foo # turns into (reader => foo, writer => _foo)
275 ## is => rw, accessor => _foo # turns into (accessor => _foo)
276 ## is => ro, accessor => _foo # error, accesor is rw
277 ### -------------------------
278
2791151.99ms if ( $options->{is} eq 'ro' ) {
28091218µs $class->throw_error(
281 "Cannot define an accessor name on a read-only attribute, accessors are read/write",
282 data => $options )
283 if exists $options->{accessor};
28491494µs $options->{reader} ||= $name;
285 }
286 elsif ( $options->{is} eq 'rw' ) {
287 if ( $options->{writer} ) {
288 $options->{reader} ||= $name;
289 }
290 else {
29124141µs $options->{accessor} ||= $name;
292 }
293 }
294 elsif ( $options->{is} eq 'bare' ) {
295 return;
296 # do nothing, but don't complain (later) about missing methods
297 }
298 else {
299 $class->throw_error( "I do not understand this option (is => "
300 . $options->{is}
301 . ") on attribute ($name)", data => $options->{is} );
302 }
303}
304
305
# spent 102ms (5.33+97.0) within Moose::Meta::Attribute::_process_isa_option which was called 122 times, avg 839µs/call: # 122 times (5.33ms+97.0ms) by Moose::Meta::Attribute::_process_options at line 257, avg 839µs/call
sub _process_isa_option {
306122581µs my ( $class, $name, $options ) = @_;
307
308122627µs return unless exists $options->{isa};
309
310100255µs if ( exists $options->{does} ) {
311 if ( try { $options->{isa}->can('does') } ) {
312 ( $options->{isa}->does( $options->{does} ) )
313 || $class->throw_error(
314 "Cannot have an isa option and a does option if the isa does not do the does on attribute ($name)",
315 data => $options );
316 }
317 else {
318 $class->throw_error(
319 "Cannot have an isa option which cannot ->does() on attribute ($name)",
320 data => $options );
321 }
322 }
323
324 # allow for anon-subtypes here ...
3251002.95ms100552µs if ( blessed( $options->{isa} )
# spent 552µs making 100 calls to Scalar::Util::blessed, avg 6µs/call
326 && $options->{isa}->isa('Moose::Meta::TypeConstraint') ) {
327 $options->{type_constraint} = $options->{isa};
328 }
329 else {
3301001.64ms10096.5ms $options->{type_constraint}
# spent 96.5ms making 100 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 965µs/call
331 = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint(
332 $options->{isa} );
333 }
334}
335
336
# spent 10.3ms (2.15+8.18) within Moose::Meta::Attribute::_process_does_option which was called 122 times, avg 85µs/call: # 122 times (2.15ms+8.18ms) by Moose::Meta::Attribute::_process_options at line 258, avg 85µs/call
sub _process_does_option {
337122569µs my ( $class, $name, $options ) = @_;
338
3391221.46ms return unless exists $options->{does} && ! exists $options->{isa};
340
341 # allow for anon-subtypes here ...
34211323µs1157µs if ( blessed( $options->{does} )
# spent 57µs making 11 calls to Scalar::Util::blessed, avg 5µs/call
343 && $options->{does}->isa('Moose::Meta::TypeConstraint') ) {
344 $options->{type_constraint} = $options->{does};
345 }
346 else {
34711174µs118.13ms $options->{type_constraint}
# spent 8.13ms making 11 calls to Moose::Util::TypeConstraints::find_or_create_does_type_constraint, avg 739µs/call
348 = Moose::Util::TypeConstraints::find_or_create_does_type_constraint(
349 $options->{does} );
350 }
351}
352
353
# spent 1.80ms (1.78+24µs) within Moose::Meta::Attribute::_process_coerce_option which was called 122 times, avg 15µs/call: # 122 times (1.78ms+24µs) by Moose::Meta::Attribute::_process_options at line 259, avg 15µs/call
sub _process_coerce_option {
354122541µs my ( $class, $name, $options ) = @_;
355
3561222.03ms return unless $options->{coerce};
357
35826µs ( exists $options->{type_constraint} )
359 || $class->throw_error(
360 "You cannot have coercion without specifying a type constraint on attribute ($name)",
361 data => $options );
362
36326µs $class->throw_error(
364 "You cannot have a weak reference to a coerced value on attribute ($name)",
365 data => $options )
366 if $options->{weak_ref};
367
368243µs224µs unless ( $options->{type_constraint}->has_coercion ) {
# spent 24µs making 2 calls to Moose::Meta::TypeConstraint::has_coercion, avg 12µs/call
369 my $type = $options->{type_constraint}->name;
370
371 Moose::Deprecated::deprecated(
372 feature => 'coerce without coercion',
373 message =>
374 "You cannot coerce an attribute ($name) unless its type ($type) has a coercion"
375 );
376 }
377}
378
379
# spent 1.72ms within Moose::Meta::Attribute::_process_trigger_option which was called 122 times, avg 14µs/call: # 122 times (1.72ms+0s) by Moose::Meta::Attribute::_process_options at line 260, avg 14µs/call
sub _process_trigger_option {
380122550µs my ( $class, $name, $options ) = @_;
381
3821221.48ms return unless exists $options->{trigger};
383
384 ( 'CODE' eq ref $options->{trigger} )
385 || $class->throw_error("Trigger must be a CODE ref on attribute ($name)", data => $options->{trigger});
386}
387
388
# spent 1.71ms within Moose::Meta::Attribute::_process_auto_deref_option which was called 122 times, avg 14µs/call: # 122 times (1.71ms+0s) by Moose::Meta::Attribute::_process_options at line 261, avg 14µs/call
sub _process_auto_deref_option {
389122583µs my ( $class, $name, $options ) = @_;
390
3911221.52ms return unless $options->{auto_deref};
392
393 ( exists $options->{type_constraint} )
394 || $class->throw_error(
395 "You cannot auto-dereference without specifying a type constraint on attribute ($name)",
396 data => $options );
397
398 ( $options->{type_constraint}->is_a_type_of('ArrayRef')
399 || $options->{type_constraint}->is_a_type_of('HashRef') )
400 || $class->throw_error(
401 "You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute ($name)",
402 data => $options );
403}
404
405
# spent 2.75ms (2.67+85µs) within Moose::Meta::Attribute::_process_lazy_build_option which was called 124 times, avg 22µs/call: # 122 times (2.63ms+85µs) by Moose::Meta::Attribute::_process_options at line 262, avg 22µs/call # 2 times (32µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 223, avg 16µs/call
sub _process_lazy_build_option {
406124573µs my ( $class, $name, $options ) = @_;
407
4081241.49ms return unless $options->{lazy_build};
409
4101648µs $class->throw_error(
411 "You can not use lazy_build and default for the same attribute ($name)",
412 data => $options )
413 if exists $options->{default};
414
4151665µs $options->{lazy} = 1;
41616227µs $options->{builder} ||= "_build_${name}";
417
41816498µs1685µs if ( $name =~ /^_/ ) {
# spent 85µs making 16 calls to Moose::Meta::Attribute::CORE:match, avg 5µs/call
419215µs $options->{clearer} ||= "_clear${name}";
420213µs $options->{predicate} ||= "_has${name}";
421 }
422 else {
42314104µs $options->{clearer} ||= "clear_${name}";
42414125µs $options->{predicate} ||= "has_${name}";
425 }
426}
427
428
# spent 1.70ms within Moose::Meta::Attribute::_process_lazy_option which was called 122 times, avg 14µs/call: # 122 times (1.70ms+0s) by Moose::Meta::Attribute::_process_options at line 263, avg 14µs/call
sub _process_lazy_option {
429122471µs my ( $class, $name, $options ) = @_;
430
4311221.29ms return unless $options->{lazy};
432
43319258µs ( exists $options->{default} || defined $options->{builder} )
434 || $class->throw_error(
435 "You cannot have a lazy attribute ($name) without specifying a default value for it",
436 data => $options );
437}
438
439
# spent 1.79ms within Moose::Meta::Attribute::_process_required_option which was called 122 times, avg 15µs/call: # 122 times (1.79ms+0s) by Moose::Meta::Attribute::_process_options at line 264, avg 15µs/call
sub _process_required_option {
440122497µs my ( $class, $name, $options ) = @_;
441
4421221.63ms if (
443 $options->{required}
444 && !(
445 ( !exists $options->{init_arg} || defined $options->{init_arg} )
446 || exists $options->{default}
447 || defined $options->{builder}
448 )
449 ) {
450 $class->throw_error(
451 "You cannot have a required attribute ($name) without a default, builder, or an init_arg",
452 data => $options );
453 }
454}
455
456
# spent 7.71ms (1.63+6.08) within Moose::Meta::Attribute::initialize_instance_slot which was called 14 times, avg 551µs/call: # 14 times (1.63ms+6.08ms) by Class::MOP::Class::_construct_instance at line 579 of Class/MOP/Class.pm, avg 551µs/call
sub initialize_instance_slot {
4571453µs my ($self, $meta_instance, $instance, $params) = @_;
45814294µs1484µs my $init_arg = $self->init_arg();
# spent 84µs making 14 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 6µs/call
459 # try to fetch the init arg from the %params ...
460
4611426µs my $val;
4621424µs my $value_is_set;
4631480µs if ( defined($init_arg) and exists $params->{$init_arg}) {
46427µs $val = $params->{$init_arg};
46525µs $value_is_set = 1;
466 }
467 else {
468 # skip it if it's lazy
46912150µs12156µs return if $self->is_lazy;
# spent 156µs making 12 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 13µs/call
470 # and die if it's required and doesn't have a default value
47110126µs11131µs $self->throw_error("Attribute (" . $self->name . ") is required", object => $instance, data => $params)
# spent 119µs making 10 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 12µs/call # spent 11µs making 1 call to Class::MOP::Mixin::AttributeCore::has_default
472 if $self->is_required && !$self->has_default && !$self->has_builder;
473
474 # if nothing was in the %params, we can use the
475 # attribute's default value (if it has one)
47610138µs11110µs if ($self->has_default) {
# spent 99µs making 10 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 10µs/call # spent 11µs making 1 call to Class::MOP::Mixin::AttributeCore::has_builder
4779100µs9374µs $val = $self->default($instance);
# spent 374µs making 9 calls to Class::MOP::Mixin::AttributeCore::default, avg 42µs/call
478922µs $value_is_set = 1;
479 }
480 elsif ($self->has_builder) {
481 $val = $self->_call_builder($instance);
482 $value_is_set = 1;
483 }
484 }
485
4861231µs return unless $value_is_set;
487
48811132µs112.61ms $val = $self->_coerce_and_verify( $val, $instance );
# spent 2.61ms making 11 calls to Moose::Meta::Attribute::_coerce_and_verify, avg 237µs/call
489
49011147µs112.16ms $self->set_initial_value($instance, $val);
# spent 2.16ms making 11 calls to Class::MOP::Attribute::set_initial_value, avg 197µs/call
491
49211190µs4451µs if ( ref $val && $self->is_weak_ref ) {
# spent 421µs making 2 calls to Moose::Meta::Attribute::_weaken_value, avg 211µs/call # spent 30µs making 2 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 15µs/call
493 $self->_weaken_value($instance);
494 }
495}
496
497sub _call_builder {
498 my ( $self, $instance ) = @_;
499
500 my $builder = $self->builder();
501
502 return $instance->$builder()
503 if $instance->can( $self->builder );
504
505 $self->throw_error( blessed($instance)
506 . " does not support builder method '"
507 . $self->builder
508 . "' for attribute '"
509 . $self->name
510 . "'",
511 object => $instance,
512 );
513}
514
515## Slot management
516
517sub _make_initializer_writer_callback {
518 my $self = shift;
519 my ($meta_instance, $instance, $slot_name) = @_;
520 my $old_callback = $self->SUPER::_make_initializer_writer_callback(@_);
521 return sub {
522 $old_callback->($self->_coerce_and_verify($_[0], $instance));
523 };
524}
525
526sub set_value {
527 my ($self, $instance, @args) = @_;
528 my $value = $args[0];
529
530 my $attr_name = $self->name;
531
532 if ($self->is_required and not @args) {
533 $self->throw_error("Attribute ($attr_name) is required", object => $instance);
534 }
535
536 $value = $self->_coerce_and_verify( $value, $instance );
537
538 my @old;
539 if ( $self->has_trigger && $self->has_value($instance) ) {
540 @old = $self->get_value($instance, 'for trigger');
541 }
542
543 $self->SUPER::set_value($instance, $value);
544
545 if ( ref $value && $self->is_weak_ref ) {
546 $self->_weaken_value($instance);
547 }
548
549 if ($self->has_trigger) {
550 $self->trigger->($instance, $value, @old);
551 }
552}
553
554
# spent 134ms (22.7+111) within Moose::Meta::Attribute::_inline_set_value which was called 195 times, avg 685µs/call: # 105 times (11.1ms+42.9ms) by Moose::Meta::Class::_inline_init_attr_from_constructor at line 374 of Moose/Meta/Class.pm, avg 514µs/call # 51 times (5.28ms+19.6ms) by Moose::Meta::Class::_inline_init_attr_from_default at line 399 of Moose/Meta/Class.pm, avg 488µs/call # 26 times (4.24ms+37.3ms) by Class::MOP::Method::Accessor::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Accessor.pm:118] at line 110 of Class/MOP/Method/Accessor.pm, avg 1.60ms/call # 11 times (1.70ms+7.22ms) by Class::MOP::Method::Accessor::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Accessor.pm:182] at line 177 of Class/MOP/Method/Accessor.pm, avg 811µs/call # 2 times (337µs+3.96ms) by Class::MOP::Class::_inline_init_attr_from_constructor at line 684 of Class/MOP/Class.pm, avg 2.15ms/call
sub _inline_set_value {
555195560µs my $self = shift;
556195926µs my ($instance, $value, $tc, $tc_obj, $for_constructor) = @_;
557
558195448µs my $old = '@old';
559195414µs my $copy = '$val';
560195406µs $tc ||= '$type_constraint';
561195370µs $tc_obj ||= '$type_constraint_obj';
562
563195373µs my @code;
5641951.98ms1957.49ms if ($self->_writer_value_needs_copy) {
# spent 7.49ms making 195 calls to Moose::Meta::Attribute::_writer_value_needs_copy, avg 38µs/call
565337µs361µs push @code, $self->_inline_copy_value($value, $copy);
# spent 61µs making 3 calls to Moose::Meta::Attribute::_inline_copy_value, avg 20µs/call
56639µs $value = $copy;
567 }
568
569 # constructors already handle required checks
570195804µs392.06ms push @code, $self->_inline_check_required
# spent 2.06ms making 39 calls to Moose::Meta::Attribute::_inline_check_required, avg 53µs/call
571 unless $for_constructor;
572
5731952.93ms19533.8ms push @code, $self->_inline_tc_code($value, $tc, $tc_obj);
# spent 33.8ms making 195 calls to Moose::Meta::Attribute::_inline_tc_code, avg 173µs/call
574
575 # constructors do triggers all at once at the end
576195796µs392.08ms push @code, $self->_inline_get_old_value_for_trigger($instance, $old)
# spent 2.08ms making 39 calls to Moose::Meta::Attribute::_inline_get_old_value_for_trigger, avg 53µs/call
577 unless $for_constructor;
578
5791957.17ms39063.6ms push @code, (
# spent 53.9ms making 195 calls to Class::MOP::Attribute::_inline_set_value, avg 276µs/call # spent 9.70ms making 195 calls to Moose::Meta::Attribute::_inline_weaken_value, avg 50µs/call
580 $self->SUPER::_inline_set_value($instance, $value),
581 $self->_inline_weaken_value($instance, $value),
582 );
583
584 # constructors do triggers all at once at the end
585195793µs391.89ms push @code, $self->_inline_trigger($instance, $value, $old)
# spent 1.89ms making 39 calls to Moose::Meta::Attribute::_inline_trigger, avg 49µs/call
586 unless $for_constructor;
587
5881953.56ms return @code;
589}
590
591
# spent 7.62ms (4.80+2.82) within Moose::Meta::Attribute::_writer_value_needs_copy which was called 199 times, avg 38µs/call: # 195 times (4.71ms+2.78ms) by Moose::Meta::Attribute::_inline_set_value at line 564, avg 38µs/call # 4 times (94µs+42µs) by Moose::Meta::Method::Accessor::_writer_value_needs_copy at line 93 of Moose/Meta/Method/Accessor.pm, avg 34µs/call
sub _writer_value_needs_copy {
592199526µs my $self = shift;
5931993.95ms1992.82ms return $self->should_coerce;
# spent 2.82ms making 199 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 14µs/call
594}
595
596
# spent 61µs within Moose::Meta::Attribute::_inline_copy_value which was called 3 times, avg 20µs/call: # 3 times (61µs+0s) by Moose::Meta::Attribute::_inline_set_value at line 565, avg 20µs/call
sub _inline_copy_value {
59738µs my $self = shift;
598314µs my ($value, $copy) = @_;
599
600383µs return 'my ' . $copy . ' = ' . $value . ';'
601}
602
603
# spent 2.06ms (1.13+922µs) within Moose::Meta::Attribute::_inline_check_required which was called 39 times, avg 53µs/call: # 39 times (1.13ms+922µs) by Moose::Meta::Attribute::_inline_set_value at line 570, avg 53µs/call
sub _inline_check_required {
60439122µs my $self = shift;
605
60639809µs39870µs return unless $self->is_required;
# spent 870µs making 39 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 22µs/call
607
608247µs212µs my $attr_name = quotemeta($self->name);
# spent 12µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 6µs/call
609
610 return (
611262µs240µs 'if (@_ < 2) {',
# spent 40µs making 2 calls to Moose::Meta::Attribute::_inline_throw_error, avg 20µs/call
612 $self->_inline_throw_error(
613 '"Attribute (' . $attr_name . ') is required, so cannot '
614 . 'be set to undef"' # defined $_[1] is not good enough
615 ) . ';',
616 '}',
617 );
618}
619
620
# spent 33.8ms (6.73+27.1) within Moose::Meta::Attribute::_inline_tc_code which was called 195 times, avg 173µs/call: # 195 times (6.73ms+27.1ms) by Moose::Meta::Attribute::_inline_set_value at line 573, avg 173µs/call
sub _inline_tc_code {
621195669µs my $self = shift;
622 return (
6231955.33ms39027.1ms $self->_inline_check_coercion(@_),
# spent 19.3ms making 195 calls to Moose::Meta::Attribute::_inline_check_constraint, avg 99µs/call # spent 7.72ms making 195 calls to Moose::Meta::Attribute::_inline_check_coercion, avg 40µs/call
624 $self->_inline_check_constraint(@_),
625 );
626}
627
628
# spent 8.50ms (5.91+2.59) within Moose::Meta::Attribute::_inline_check_coercion which was called 210 times, avg 40µs/call: # 195 times (5.35ms+2.37ms) by Moose::Meta::Attribute::_inline_tc_code at line 623, avg 40µs/call # 15 times (560µs+223µs) by Moose::Meta::Attribute::_inline_init_from_default at line 787, avg 52µs/call
sub _inline_check_coercion {
629210572µs my $self = shift;
630210839µs my ($value, $tc, $tc_obj) = @_;
631
6322103.95ms2182.59ms return unless $self->should_coerce && $self->type_constraint->has_coercion;
# spent 2.49ms making 210 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 12µs/call # spent 53µs making 4 calls to Moose::Meta::TypeConstraint::has_coercion, avg 13µs/call # spent 50µs making 4 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 13µs/call
633
634494µs return $value . ' = ' . $tc_obj . '->coerce(' . $value . ');';
635}
636
637
# spent 20.9ms (13.3+7.57) within Moose::Meta::Attribute::_inline_check_constraint which was called 210 times, avg 100µs/call: # 195 times (12.3ms+7.06ms) by Moose::Meta::Attribute::_inline_tc_code at line 623, avg 99µs/call # 15 times (1.05ms+513µs) by Moose::Meta::Attribute::_inline_init_from_default at line 787, avg 104µs/call
sub _inline_check_constraint {
638210592µs my $self = shift;
639210781µs my ($value, $tc, $tc_obj) = @_;
640
6412102.43ms2102.64ms return unless $self->has_type_constraint;
# spent 2.64ms making 210 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 13µs/call
642
6431903.74ms1901.11ms my $attr_name = quotemeta($self->name);
# spent 1.11ms making 190 calls to Class::MOP::Mixin::AttributeCore::name, avg 6µs/call
644
645 return (
6461906.07ms1903.83ms 'if (!' . $tc . '->(' . $value . ')) {',
# spent 3.83ms making 190 calls to Moose::Meta::Attribute::_inline_throw_error, avg 20µs/call
647 $self->_inline_throw_error(
648 '"Attribute (' . $attr_name . ') does not pass the type '
649 . 'constraint because: " . '
650 . $tc_obj . '->get_message(' . $value . ')',
651 'data => ' . $value
652 ) . ';',
653 '}',
654 );
655}
656
657
# spent 2.08ms (1.19+890µs) within Moose::Meta::Attribute::_inline_get_old_value_for_trigger which was called 39 times, avg 53µs/call: # 39 times (1.19ms+890µs) by Moose::Meta::Attribute::_inline_set_value at line 576, avg 53µs/call
sub _inline_get_old_value_for_trigger {
65839121µs my $self = shift;
65939152µs my ($instance, $old) = @_;
660
66139904µs39890µs return unless $self->has_trigger;
# spent 890µs making 39 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 23µs/call
662
663 return (
664 'my ' . $old . ' = ' . $self->_inline_instance_has($instance),
665 '? ' . $self->_inline_instance_get($instance),
666 ': ();',
667 );
668}
669
670
# spent 9.70ms (6.07+3.63) within Moose::Meta::Attribute::_inline_weaken_value which was called 195 times, avg 50µs/call: # 195 times (6.07ms+3.63ms) by Moose::Meta::Attribute::_inline_set_value at line 579, avg 50µs/call
sub _inline_weaken_value {
671195575µs my $self = shift;
672195715µs my ($instance, $value) = @_;
673
6741953.71ms1952.87ms return unless $self->is_weak_ref;
# spent 2.87ms making 195 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 15µs/call
675
67610261µs20213µs my $mi = $self->associated_class->get_meta_instance;
# spent 107µs making 9 calls to Class::MOP::Class::get_meta_instance, avg 12µs/call # spent 60µs making 10 calls to Class::MOP::Attribute::associated_class, avg 6µs/call # spent 46µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance
677 return (
67810431µs20546µs $mi->inline_weaken_slot_value($instance, $self->name, $value),
# spent 495µs making 10 calls to Class::MOP::Instance::inline_weaken_slot_value, avg 49µs/call # spent 52µs making 10 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call
679 'if ref ' . $value . ';',
680 );
681}
682
683
# spent 1.97ms (1.19+783µs) within Moose::Meta::Attribute::_inline_trigger which was called 41 times, avg 48µs/call: # 39 times (1.13ms+762µs) by Moose::Meta::Attribute::_inline_set_value at line 585, avg 49µs/call # 2 times (59µs+22µs) by Moose::Meta::Method::Accessor::_inline_trigger at line 117 of Moose/Meta/Method/Accessor.pm, avg 40µs/call
sub _inline_trigger {
68441127µs my $self = shift;
68541170µs my ($instance, $value, $old) = @_;
686
68741915µs41783µs return unless $self->has_trigger;
# spent 783µs making 41 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 19µs/call
688
689 return '$attr->trigger->(' . $instance . ', ' . $value . ', ' . $old . ');';
690}
691
692
# spent 421µs (150+271) within Moose::Meta::Attribute::_weaken_value which was called 2 times, avg 211µs/call: # 2 times (150µs+271µs) by Moose::Meta::Attribute::initialize_instance_slot at line 492, avg 211µs/call
sub _weaken_value {
69327µs my ( $self, $instance ) = @_;
694
695276µs6187µs my $meta_instance = Class::MOP::Class->initialize( blessed($instance) )
# spent 96µs making 2 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 48µs/call # spent 76µs making 2 calls to Class::MOP::Class::initialize, avg 38µs/call # spent 15µs making 2 calls to Scalar::Util::blessed, avg 8µs/call
696 ->get_meta_instance;
697
698278µs485µs $meta_instance->weaken_slot_value( $instance, $self->name );
# spent 74µs making 2 calls to Class::MOP::Instance::weaken_slot_value, avg 37µs/call # spent 11µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call
699}
700
701sub get_value {
702 my ($self, $instance, $for_trigger) = @_;
703
704 if ($self->is_lazy) {
705 unless ($self->has_value($instance)) {
706 my $value;
707 if ($self->has_default) {
708 $value = $self->default($instance);
709 } elsif ( $self->has_builder ) {
710 $value = $self->_call_builder($instance);
711 }
712
713 $value = $self->_coerce_and_verify( $value, $instance );
714
715 $self->set_initial_value($instance, $value);
716 }
717 }
718
719 if ( $self->should_auto_deref && ! $for_trigger ) {
720
721 my $type_constraint = $self->type_constraint;
722
723 if ($type_constraint->is_a_type_of('ArrayRef')) {
724 my $rv = $self->SUPER::get_value($instance);
725 return unless defined $rv;
726 return wantarray ? @{ $rv } : $rv;
727 }
728 elsif ($type_constraint->is_a_type_of('HashRef')) {
729 my $rv = $self->SUPER::get_value($instance);
730 return unless defined $rv;
731 return wantarray ? %{ $rv } : $rv;
732 }
733 else {
734 $self->throw_error("Can not auto de-reference the type constraint '" . $type_constraint->name . "'", object => $instance, type_constraint => $type_constraint);
735 }
736
737 }
738 else {
739
740 return $self->SUPER::get_value($instance);
741 }
742}
743
744
# spent 131ms (7.72+123) within Moose::Meta::Attribute::_inline_get_value which was called 123 times, avg 1.06ms/call: # 97 times (6.08ms+116ms) by Class::MOP::Method::Accessor::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Accessor.pm:152] at line 140 of Class/MOP/Method/Accessor.pm, avg 1.26ms/call # 26 times (1.64ms+7.06ms) by Class::MOP::Method::Accessor::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Accessor.pm:118] at line 110 of Class/MOP/Method/Accessor.pm, avg 335µs/call
sub _inline_get_value {
745123399µs my $self = shift;
746123472µs my ($instance, $tc, $tc_obj) = @_;
747
7481231.66ms12393.2ms my $slot_access = $self->_inline_instance_get($instance);
# spent 93.2ms making 123 calls to Class::MOP::Attribute::_inline_instance_get, avg 758µs/call
749123366µs $tc ||= '$type_constraint';
750123278µs $tc_obj ||= '$type_constraint_obj';
751
752 return (
7531234.29ms24629.7ms $self->_inline_check_lazy($instance, $tc, $tc_obj),
# spent 20.6ms making 123 calls to Moose::Meta::Attribute::_inline_check_lazy, avg 168µs/call # spent 9.06ms making 123 calls to Moose::Meta::Attribute::_inline_return_auto_deref, avg 74µs/call
754 $self->_inline_return_auto_deref($slot_access),
755 );
756}
757
758
# spent 20.9ms (4.93+15.9) within Moose::Meta::Attribute::_inline_check_lazy which was called 128 times, avg 163µs/call: # 123 times (4.75ms+15.9ms) by Moose::Meta::Attribute::_inline_get_value at line 753, avg 168µs/call # 5 times (175µs+74µs) by Moose::Meta::Method::Accessor::_inline_check_lazy at line 105 of Moose/Meta/Method/Accessor.pm, avg 50µs/call
sub _inline_check_lazy {
759128396µs my $self = shift;
760128632µs my ($instance, $tc, $tc_obj) = @_;
761
7621282.61ms1282.37ms return unless $self->is_lazy;
# spent 2.37ms making 128 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 18µs/call
763
76419266µs192.54ms my $slot_exists = $self->_inline_instance_has($instance);
# spent 2.54ms making 19 calls to Class::MOP::Attribute::_inline_instance_has, avg 134µs/call
765
766 return (
76719535µs1911.0ms 'if (!' . $slot_exists . ') {',
# spent 11.0ms making 19 calls to Moose::Meta::Attribute::_inline_init_from_default, avg 580µs/call
768 $self->_inline_init_from_default($instance, '$default', $tc, $tc_obj, 'lazy'),
769 '}',
770 );
771}
772
773
# spent 11.0ms (2.19+8.83) within Moose::Meta::Attribute::_inline_init_from_default which was called 19 times, avg 580µs/call: # 19 times (2.19ms+8.83ms) by Moose::Meta::Attribute::_inline_check_lazy at line 767, avg 580µs/call
sub _inline_init_from_default {
7741957µs my $self = shift;
77519110µs my ($instance, $default, $tc, $tc_obj, $for_lazy) = @_;
776
77719503µs38452µs if (!($self->has_default || $self->has_builder)) {
# spent 238µs making 19 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 13µs/call # spent 214µs making 19 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 11µs/call
778 $self->throw_error(
779 'You cannot have a lazy attribute '
780 . '(' . $self->name . ') '
781 . 'without specifying a default value for it',
782 attr => $self,
783 );
784 }
785
786 return (
787191.16ms878.38ms $self->_inline_generate_default($instance, $default),
# spent 3.72ms making 19 calls to Moose::Meta::Attribute::_inline_init_slot, avg 196µs/call # spent 2.07ms making 19 calls to Moose::Meta::Attribute::_inline_generate_default, avg 109µs/call # spent 1.56ms making 15 calls to Moose::Meta::Attribute::_inline_check_constraint, avg 104µs/call # spent 783µs making 15 calls to Moose::Meta::Attribute::_inline_check_coercion, avg 52µs/call # spent 241µs making 19 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 13µs/call
788 # intentionally not using _inline_tc_code, since that can be overridden
789 # to do things like possibly only do member tc checks, which isn't
790 # appropriate for checking the result of a default
791 $self->has_type_constraint
792 ? ($self->_inline_check_coercion($default, $tc, $tc_obj, $for_lazy),
793 $self->_inline_check_constraint($default, $tc, $tc_obj, $for_lazy))
794 : (),
795 $self->_inline_init_slot($instance, $default),
796 );
797}
798
799
# spent 2.07ms (1.34+730µs) within Moose::Meta::Attribute::_inline_generate_default which was called 19 times, avg 109µs/call: # 19 times (1.34ms+730µs) by Moose::Meta::Attribute::_inline_init_from_default at line 787, avg 109µs/call
sub _inline_generate_default {
8001958µs my $self = shift;
8011978µs my ($instance, $default) = @_;
802
803191.05ms57730µs if ($self->has_default) {
# spent 389µs making 19 calls to Moose::Meta::Attribute::_inline_throw_error, avg 20µs/call # spent 180µs making 19 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 9µs/call # spent 162µs making 19 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 9µs/call
804 return 'my ' . $default . ' = $attr->default(' . $instance . ');';
805 }
806 elsif ($self->has_builder) {
807 return (
808 'my ' . $default . ';',
809 'if (my $builder = ' . $instance . '->can($attr->builder)) {',
810 $default . ' = ' . $instance . '->$builder;',
811 '}',
812 'else {',
813 'my $class = ref(' . $instance . ') || ' . $instance . ';',
814 'my $builder_name = $attr->builder;',
815 'my $attr_name = $attr->name;',
816 $self->_inline_throw_error(
817 '"$class does not support builder method '
818 . '\'$builder_name\' for attribute \'$attr_name\'"'
819 ) . ';',
820 '}',
821 );
822 }
823 else {
824 $self->throw_error(
825 "Can't generate a default for " . $self->name
826 . " since no default or builder was specified"
827 );
828 }
829}
830
831
# spent 3.72ms (937µs+2.78) within Moose::Meta::Attribute::_inline_init_slot which was called 19 times, avg 196µs/call: # 19 times (937µs+2.78ms) by Moose::Meta::Attribute::_inline_init_from_default at line 787, avg 196µs/call
sub _inline_init_slot {
8321960µs my $self = shift;
8331974µs my ($inv, $value) = @_;
834
83519232µs19207µs if ($self->has_initializer) {
# spent 207µs making 19 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 11µs/call
836 return '$attr->set_initial_value(' . $inv . ', ' . $value . ');';
837 }
838 else {
83919486µs192.58ms return $self->_inline_instance_set($inv, $value) . ';';
# spent 2.58ms making 19 calls to Class::MOP::Attribute::_inline_instance_set, avg 136µs/call
840 }
841}
842
843
# spent 9.06ms (3.51+5.54) within Moose::Meta::Attribute::_inline_return_auto_deref which was called 123 times, avg 74µs/call: # 123 times (3.51ms+5.54ms) by Moose::Meta::Attribute::_inline_get_value at line 753, avg 74µs/call
sub _inline_return_auto_deref {
844123414µs my $self = shift;
845
8461232.76ms1235.54ms return 'return ' . $self->_auto_deref(@_) . ';';
# spent 5.54ms making 123 calls to Moose::Meta::Attribute::_auto_deref, avg 45µs/call
847}
848
849
# spent 5.54ms (3.62+1.92) within Moose::Meta::Attribute::_auto_deref which was called 123 times, avg 45µs/call: # 123 times (3.62ms+1.92ms) by Moose::Meta::Attribute::_inline_return_auto_deref at line 846, avg 45µs/call
sub _auto_deref {
850123348µs my $self = shift;
851123466µs my ($ref_value) = @_;
852
8531232.85ms1231.92ms return $ref_value unless $self->should_auto_deref;
# spent 1.92ms making 123 calls to Moose::Meta::Mixin::AttributeCore::should_auto_deref, avg 16µs/call
854
855 my $type_constraint = $self->type_constraint;
856
857 my $sigil;
858 if ($type_constraint->is_a_type_of('ArrayRef')) {
859 $sigil = '@';
860 }
861 elsif ($type_constraint->is_a_type_of('HashRef')) {
862 $sigil = '%';
863 }
864 else {
865 $self->throw_error(
866 'Can not auto de-reference the type constraint \''
867 . $type_constraint->name
868 . '\'',
869 type_constraint => $type_constraint,
870 );
871 }
872
873 return 'wantarray '
874 . '? ' . $sigil . '{ (' . $ref_value . ') || return } '
875 . ': (' . $ref_value . ')';
876}
877
878## installing accessors
879
8802032.89ms
# spent 1.87ms within Moose::Meta::Attribute::accessor_metaclass which was called 203 times, avg 9µs/call: # 193 times (1.76ms+0s) by Class::MOP::Attribute::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Attribute.pm:401] at line 393 of Class/MOP/Attribute.pm, avg 9µs/call # 10 times (111µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 173 of Moose/Meta/Attribute/Native/Trait.pm, avg 11µs/call
sub accessor_metaclass { 'Moose::Meta::Method::Accessor' }
881
882
# spent 1.04s (7.58ms+1.04) within Moose::Meta::Attribute::install_accessors which was called 125 times, avg 8.35ms/call: # 122 times (7.31ms+985ms) by Class::MOP::Class::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Class.pm:932] at line 931 of Class/MOP/Class.pm, avg 8.13ms/call # 2 times (212µs+44.5ms) by Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:43] at line 33 of Class/MOP/Method/Wrapped.pm, avg 22.4ms/call # once (60µs+6.30ms) by Class::MOP::Class::_inline_accessors at line 1446 of Class/MOP/Class.pm
sub install_accessors {
883125372µs my $self = shift;
8841253.21ms125968ms $self->SUPER::install_accessors(@_);
# spent 968ms making 125 calls to Class::MOP::Attribute::install_accessors, avg 7.75ms/call
8851252.00ms13467.2ms $self->install_delegation if $self->has_handles;
# spent 65.1ms making 9 calls to Moose::Meta::Attribute::install_delegation, avg 7.23ms/call # spent 2.09ms making 125 calls to Moose::Meta::Mixin::AttributeCore::has_handles, avg 17µs/call
8861251.52ms return;
887}
888
889
# spent 3.66ms (2.86+799µs) within Moose::Meta::Attribute::_check_associated_methods which was called 123 times, avg 30µs/call: # 123 times (2.86ms+799µs) by Moose::Meta::Class::add_attribute at line 491 of Moose/Meta/Class.pm, avg 30µs/call
sub _check_associated_methods {
890123403µs my $self = shift;
8911233.54ms123799µs unless (
# spent 799µs making 123 calls to Class::MOP::Attribute::associated_methods, avg 6µs/call
892 @{ $self->associated_methods }
893 || ($self->_is_metadata || '') eq 'bare'
894 ) {
895 Carp::cluck(
896 'Attribute (' . $self->name . ') of class '
897 . $self->associated_class->name
898 . ' has no associated methods'
899 . ' (did you mean to provide an "is" argument?)'
900 . "\n"
901 )
902 }
903}
904
905
# spent 848ms (24.5+824) within Moose::Meta::Attribute::_process_accessors which was called 193 times, avg 4.39ms/call: # 97 times (12.2ms+448ms) by Class::MOP::Attribute::install_accessors at line 419 of Class/MOP/Attribute.pm, avg 4.75ms/call # 30 times (3.94ms+99.6ms) by Class::MOP::Attribute::install_accessors at line 427 of Class/MOP/Attribute.pm, avg 3.45ms/call # 29 times (3.87ms+95.5ms) by Class::MOP::Attribute::install_accessors at line 431 of Class/MOP/Attribute.pm, avg 3.43ms/call # 26 times (3.20ms+137ms) by Class::MOP::Attribute::install_accessors at line 415 of Class/MOP/Attribute.pm, avg 5.41ms/call # 11 times (1.36ms+43.0ms) by Class::MOP::Attribute::install_accessors at line 423 of Class/MOP/Attribute.pm, avg 4.03ms/call
sub _process_accessors {
906193587µs my $self = shift;
907193931µs my ($type, $accessor, $generate_as_inline_methods) = @_;
908
909193638µs $accessor = ( keys %$accessor )[0] if ( ref($accessor) || '' ) eq 'HASH';
9101935.48ms38634.3ms my $method = $self->associated_class->get_method($accessor);
# spent 33.2ms making 193 calls to Class::MOP::Mixin::HasMethods::get_method, avg 172µs/call # spent 1.06ms making 193 calls to Class::MOP::Attribute::associated_class, avg 5µs/call
911
912193489µs429µs if ( $method
# spent 11µ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
913 && $method->isa('Class::MOP::Method::Accessor')
914 && $method->associated_attribute->name ne $self->name ) {
915
916 my $other_attr_name = $method->associated_attribute->name;
917 my $name = $self->name;
918
919 Carp::cluck(
920 "You are overwriting an accessor ($accessor) for the $other_attr_name attribute"
921 . " with a new accessor method for the $name attribute" );
922 }
923
924193460µs16µs if (
# spent 6µs making 1 call to UNIVERSAL::isa
925 $method
926 && !$method->isa('Class::MOP::Method::Accessor')
927 && ( !$self->definition_context
928 || $method->package_name eq $self->definition_context->{package} )
929 ) {
930
931 Carp::cluck(
932 "You are overwriting a locally defined method ($accessor) with "
933 . "an accessor" );
934 }
935
93619310.7ms77041.2ms if ( !$self->associated_class->has_method($accessor)
# spent 26.2ms making 193 calls to Class::MOP::Mixin::HasMethods::has_method, avg 136µs/call # spent 12.6ms making 192 calls to Class::MOP::Package::has_package_symbol, avg 65µs/call # spent 2.40ms making 385 calls to Class::MOP::Attribute::associated_class, avg 6µs/call
937 && $self->associated_class->has_package_symbol( '&' . $accessor ) ) {
938
939 Carp::cluck(
940 "You are overwriting a locally defined function ($accessor) with "
941 . "an accessor" );
942 }
943
9441937.27ms193748ms $self->SUPER::_process_accessors(@_);
# spent 748ms making 193 calls to Class::MOP::Attribute::_process_accessors, avg 3.88ms/call
945}
946
947sub remove_accessors {
948 my $self = shift;
949 $self->SUPER::remove_accessors(@_);
950 $self->remove_delegation if $self->has_handles;
951 return;
952}
953
954
# spent 65.1ms (4.77+60.3) within Moose::Meta::Attribute::install_delegation which was called 9 times, avg 7.23ms/call: # 9 times (4.77ms+60.3ms) by Moose::Meta::Attribute::install_accessors at line 885, avg 7.23ms/call
sub install_delegation {
955929µs my $self = shift;
956
957 # NOTE:
958 # Here we canonicalize the 'handles' option
959 # this will sort out any details and always
960 # return an hash of methods which we want
961 # to delagate to, see that method for details
9629181µs9752µs my %handles = $self->_canonicalize_handles;
# spent 481µs making 7 calls to Moose::Meta::Attribute::_canonicalize_handles, avg 69µs/call # spent 143µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::_canonicalize_handles # spent 128µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::_canonicalize_handles
963
964
965 # install the delegation ...
9669195µs965µs my $associated_class = $self->associated_class;
# spent 65µs making 9 calls to Class::MOP::Attribute::associated_class, avg 7µs/call
9679221µs foreach my $handle (keys %handles) {
96828119µs my $method_to_call = $handles{$handle};
96928530µs28146µs my $class_name = $associated_class->name;
# spent 146µs making 28 calls to Class::MOP::Package::name, avg 5µs/call
97028123µs my $name = "${class_name}::${handle}";
971
97228325µs284.05ms (!$associated_class->has_method($handle))
# spent 4.05ms making 28 calls to Class::MOP::Mixin::HasMethods::has_method, avg 145µs/call
973 || $self->throw_error("You cannot overwrite a locally defined method ($handle) with a delegation", method_name => $handle);
974
975 # NOTE:
976 # handles is not allowed to delegate
977 # any of these methods, as they will
978 # override the ones in your class, which
979 # is almost certainly not what you want.
980
981 # FIXME warn when $handle was explicitly specified, but not if the source is a regex or something
982 #cluck("Not delegating method '$handle' because it is a core method") and
983282.06ms841.02ms next if $class_name->isa("Moose::Object") and $handle =~ /^BUILD|DEMOLISH$/ || Moose::Object->can($handle);
# spent 475µs making 28 calls to UNIVERSAL::can, avg 17µs/call # spent 290µs making 28 calls to Moose::Meta::Attribute::CORE:match, avg 10µs/call # spent 253µs making 28 calls to UNIVERSAL::isa, avg 9µs/call
984
98528386µs2842.1ms my $method = $self->_make_delegation_method($handle, $method_to_call);
# spent 19.2ms making 3 calls to Class::MOP::Class::__ANON__::SERIAL::5::_make_delegation_method, avg 6.39ms/call # spent 12.5ms making 23 calls to Moose::Meta::Attribute::_make_delegation_method, avg 543µs/call # spent 10.4ms making 2 calls to Class::MOP::Class::__ANON__::SERIAL::2::_make_delegation_method, avg 5.20ms/call
986
987281.28ms8411.8ms $self->associated_class->add_method($method->name, $method);
# spent 11.4ms making 28 calls to Class::MOP::Mixin::HasMethods::add_method, avg 409µs/call # spent 189µs making 28 calls to Class::MOP::Attribute::associated_class, avg 7µs/call # spent 126µs making 28 calls to Class::MOP::Method::name, avg 5µs/call
98828528µs28459µs $self->associate_method($method);
# spent 459µs making 28 calls to Class::MOP::Attribute::associate_method, avg 16µs/call
989 }
990}
991
992sub remove_delegation {
993 my $self = shift;
994 my %handles = $self->_canonicalize_handles;
995 my $associated_class = $self->associated_class;
996 foreach my $handle (keys %handles) {
997 next unless any { $handle eq $_ }
998 map { $_->name }
999 @{ $self->associated_methods };
1000 $self->associated_class->remove_method($handle);
1001 }
1002}
1003
1004# private methods to help delegation ...
1005
1006
# spent 481µs (390+91) within Moose::Meta::Attribute::_canonicalize_handles which was called 7 times, avg 69µs/call: # 7 times (390µs+91µs) by Moose::Meta::Attribute::install_delegation at line 962, avg 69µs/call
sub _canonicalize_handles {
1007718µs my $self = shift;
10087152µs791µs my $handles = $self->handles;
# spent 91µs making 7 calls to Moose::Meta::Mixin::AttributeCore::handles, avg 13µs/call
1009735µs if (my $handle_type = ref($handles)) {
10107221µs if ($handle_type eq 'HASH') {
1011 return %{$handles};
1012 }
1013 elsif ($handle_type eq 'ARRAY') {
1014 return map { $_ => $_ } @{$handles};
1015 }
1016 elsif ($handle_type eq 'Regexp') {
1017 ($self->has_type_constraint)
1018 || $self->throw_error("Cannot delegate methods based on a Regexp without a type constraint (isa)", data => $handles);
1019 return map { ($_ => $_) }
1020 grep { /$handles/ } $self->_get_delegate_method_list;
1021 }
1022 elsif ($handle_type eq 'CODE') {
1023 return $handles->($self, $self->_find_delegate_metaclass);
1024 }
1025 elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::DuckType')) {
1026 return map { $_ => $_ } @{ $handles->methods };
1027 }
1028 elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::Role')) {
1029 $handles = $handles->role;
1030 }
1031 else {
1032 $self->throw_error("Unable to canonicalize the 'handles' option with $handles", data => $handles);
1033 }
1034 }
1035
1036 Class::MOP::load_class($handles);
1037 my $role_meta = Class::MOP::class_of($handles);
1038
1039 (blessed $role_meta && $role_meta->isa('Moose::Meta::Role'))
1040 || $self->throw_error("Unable to canonicalize the 'handles' option with $handles because its metaclass is not a Moose::Meta::Role", data => $handles);
1041
1042 return map { $_ => $_ }
1043 map { $_->name }
1044 grep { !$_->isa('Class::MOP::Method::Meta') } (
1045 $role_meta->_get_local_methods,
1046 $role_meta->get_required_method_list,
1047 );
1048}
1049
1050sub _get_delegate_method_list {
1051 my $self = shift;
1052 my $meta = $self->_find_delegate_metaclass;
1053 if ($meta->isa('Class::MOP::Class')) {
1054 return map { $_->name } # NOTE: !never! delegate &meta
1055 grep { $_->package_name ne 'Moose::Object' && !$_->isa('Class::MOP::Method::Meta') }
1056 $meta->get_all_methods;
1057 }
1058 elsif ($meta->isa('Moose::Meta::Role')) {
1059 return $meta->get_method_list;
1060 }
1061 else {
1062 $self->throw_error("Unable to recognize the delegate metaclass '$meta'", data => $meta);
1063 }
1064}
1065
1066sub _find_delegate_metaclass {
1067 my $self = shift;
1068 if (my $class = $self->_isa_metadata) {
1069 unless ( Class::MOP::is_class_loaded($class) ) {
1070 $self->throw_error(
1071 sprintf(
1072 'The %s attribute is trying to delegate to a class which has not been loaded - %s',
1073 $self->name, $class
1074 )
1075 );
1076 }
1077 # we might be dealing with a non-Moose class,
1078 # and need to make our own metaclass. if there's
1079 # already a metaclass, it will be returned
1080 return Class::MOP::Class->initialize($class);
1081 }
1082 elsif (my $role = $self->_does_metadata) {
1083 unless ( Class::MOP::is_class_loaded($class) ) {
1084 $self->throw_error(
1085 sprintf(
1086 'The %s attribute is trying to delegate to a role which has not been loaded - %s',
1087 $self->name, $role
1088 )
1089 );
1090 }
1091
1092 return Class::MOP::class_of($role);
1093 }
1094 else {
1095 $self->throw_error("Cannot find delegate metaclass for attribute " . $self->name);
1096 }
1097}
1098
109933415µs
# spent 279µs within Moose::Meta::Attribute::delegation_metaclass which was called 33 times, avg 8µs/call: # 23 times (190µs+0s) by Moose::Meta::Attribute::_make_delegation_method at line 1109, avg 8µs/call # 10 times (89µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 173 of Moose/Meta/Attribute/Native/Trait.pm, avg 9µs/call
sub delegation_metaclass { 'Moose::Meta::Method::Delegation' }
1100
1101
# spent 12.5ms (1.54+11.0) within Moose::Meta::Attribute::_make_delegation_method which was called 23 times, avg 543µs/call: # 23 times (1.54ms+11.0ms) by Moose::Meta::Attribute::install_delegation at line 985, avg 543µs/call
sub _make_delegation_method {
110223120µs my ( $self, $handle_name, $method_to_call ) = @_;
1103
11042352µs my @curried_arguments;
1105
11062363µs ($method_to_call, @curried_arguments) = @$method_to_call
1107 if 'ARRAY' eq ref($method_to_call);
1108
1109231.44ms9211.0ms return $self->delegation_metaclass->new(
# spent 10.5ms making 23 calls to Moose::Meta::Method::Delegation::new, avg 457µs/call # spent 190µs making 23 calls to Moose::Meta::Attribute::delegation_metaclass, avg 8µs/call # spent 143µs making 23 calls to Class::MOP::Attribute::associated_class, avg 6µs/call # spent 106µs making 23 calls to Class::MOP::Package::name, avg 5µs/call
1110 name => $handle_name,
1111 package_name => $self->associated_class->name,
1112 attribute => $self,
1113 delegate_to_method => $method_to_call,
1114 curried_arguments => \@curried_arguments,
1115 );
1116}
1117
1118
# spent 2.61ms (641µs+1.97) within Moose::Meta::Attribute::_coerce_and_verify which was called 11 times, avg 237µs/call: # 11 times (641µs+1.97ms) by Moose::Meta::Attribute::initialize_instance_slot at line 488, avg 237µs/call
sub _coerce_and_verify {
11191131µs my $self = shift;
11201125µs my $val = shift;
11211122µs my $instance = shift;
1122
112311164µs11115µs return $val unless $self->has_type_constraint;
# spent 115µs making 11 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 10µs/call
1124
1125998µs9103µs $val = $self->type_constraint->coerce($val)
# spent 103µs making 9 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 11µs/call
1126 if $self->should_coerce && $self->type_constraint->has_coercion;
1127
11289108µs91.75ms $self->verify_against_type_constraint($val, instance => $instance);
# spent 1.75ms making 9 calls to Moose::Meta::Attribute::verify_against_type_constraint, avg 195µs/call
1129
11309105µs return $val;
1131}
1132
1133
# spent 1.75ms (559µs+1.19) within Moose::Meta::Attribute::verify_against_type_constraint which was called 9 times, avg 195µs/call: # 9 times (559µs+1.19ms) by Moose::Meta::Attribute::_coerce_and_verify at line 1128, avg 195µs/call
sub verify_against_type_constraint {
1134926µs my $self = shift;
1135920µs my $val = shift;
1136
1137988µs980µs return 1 if !$self->has_type_constraint;
# spent 80µs making 9 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 9µs/call
1138
11399103µs9110µs my $type_constraint = $self->type_constraint;
# spent 110µs making 9 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 12µs/call
1140
11419197µs91.00ms $type_constraint->check($val)
# spent 1.00ms making 9 calls to Moose::Meta::TypeConstraint::check, avg 111µs/call
1142 || $self->throw_error("Attribute ("
1143 . $self->name
1144 . ") does not pass the type constraint because: "
1145 . $type_constraint->get_message($val), data => $val, @_);
1146}
1147
1148package Moose::Meta::Attribute::Custom::Moose;
1149sub register_implementation { 'Moose::Meta::Attribute' }
1150
1151130µs1;
1152
1153__END__
 
# spent 375µs within Moose::Meta::Attribute::CORE:match which was called 44 times, avg 9µs/call: # 28 times (290µs+0s) by Moose::Meta::Attribute::install_delegation at line 983, avg 10µs/call # 16 times (85µs+0s) by Moose::Meta::Attribute::_process_lazy_build_option at line 418, avg 5µs/call
sub Moose::Meta::Attribute::CORE:match; # opcode
# spent 558µs within Moose::Meta::Attribute::CORE:sort which was called 124 times, avg 4µs/call: # 124 times (558µs+0s) by Moose::Meta::Attribute::new at line 73, avg 4µs/call
sub Moose::Meta::Attribute::CORE:sort; # opcode