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

Filename/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Attribute.pm
StatementsExecuted 14312 statements in 209ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1243284.5ms354msMoose::Meta::Attribute::::new Moose::Meta::Attribute::new
1935126.7ms716msMoose::Meta::Attribute::::_process_accessors Moose::Meta::Attribute::_process_accessors
11120.0ms270msMoose::Meta::Attribute::::BEGIN@20 Moose::Meta::Attribute::BEGIN@20
1222218.2ms145msMoose::Meta::Attribute::::_process_options Moose::Meta::Attribute::_process_options
1973317.4ms64.2msMoose::Meta::Attribute::::inline_set Moose::Meta::Attribute::inline_set
121227.83ms2.85sMoose::Meta::Attribute::::interpolate_class_and_new Moose::Meta::Attribute::interpolate_class_and_new (recurses: max depth 1, inclusive time 8.16ms)
125327.58ms928msMoose::Meta::Attribute::::install_accessors Moose::Meta::Attribute::install_accessors
1116.51ms7.19msMoose::Meta::Attribute::::BEGIN@17 Moose::Meta::Attribute::BEGIN@17
122115.24ms102msMoose::Meta::Attribute::::_process_isa_option Moose::Meta::Attribute::_process_isa_option
9115.03ms69.7msMoose::Meta::Attribute::::install_delegation Moose::Meta::Attribute::install_delegation
123214.13ms2.51sMoose::Meta::Attribute::::interpolate_class Moose::Meta::Attribute::interpolate_class (recurses: max depth 1, inclusive time 120µs)
123113.39ms4.74msMoose::Meta::Attribute::::_check_associated_methods Moose::Meta::Attribute::_check_associated_methods
122113.07ms3.07msMoose::Meta::Attribute::::_process_is_option Moose::Meta::Attribute::_process_is_option
1112.77ms3.89msMoose::Meta::Attribute::::BEGIN@18 Moose::Meta::Attribute::BEGIN@18
124212.38ms2.45msMoose::Meta::Attribute::::_process_lazy_build_option Moose::Meta::Attribute::_process_lazy_build_option
122112.15ms10.7msMoose::Meta::Attribute::::_process_does_option Moose::Meta::Attribute::_process_does_option
2112.14ms17.8msMoose::Meta::Attribute::::clone Moose::Meta::Attribute::clone
203221.94ms1.94msMoose::Meta::Attribute::::accessor_metaclass Moose::Meta::Attribute::accessor_metaclass
122111.82ms1.82msMoose::Meta::Attribute::::_process_required_option Moose::Meta::Attribute::_process_required_option
122111.72ms1.75msMoose::Meta::Attribute::::_process_coerce_option Moose::Meta::Attribute::_process_coerce_option
14111.71ms7.88msMoose::Meta::Attribute::::initialize_instance_slot Moose::Meta::Attribute::initialize_instance_slot
122111.61ms1.61msMoose::Meta::Attribute::::_process_lazy_option Moose::Meta::Attribute::_process_lazy_option
122111.61ms1.61msMoose::Meta::Attribute::::_process_trigger_option Moose::Meta::Attribute::_process_trigger_option
122111.60ms1.60msMoose::Meta::Attribute::::_process_auto_deref_option Moose::Meta::Attribute::_process_auto_deref_option
23111.60ms13.4msMoose::Meta::Attribute::::_make_delegation_method Moose::Meta::Attribute::_make_delegation_method
1111641µs2.63msMoose::Meta::Attribute::::_coerce_and_verify Moose::Meta::Attribute::_coerce_and_verify
1111612µs973µsMoose::Meta::Attribute::::_set_initial_slot_value Moose::Meta::Attribute::_set_initial_slot_value
12411547µs547µsMoose::Meta::Attribute::::CORE:sort Moose::Meta::Attribute::CORE:sort (opcode)
911472µs1.78msMoose::Meta::Attribute::::verify_against_type_constraint Moose::Meta::Attribute::verify_against_type_constraint
211430µs18.4msMoose::Meta::Attribute::::clone_and_inherit_options Moose::Meta::Attribute::clone_and_inherit_options
4421383µs383µsMoose::Meta::Attribute::::CORE:match Moose::Meta::Attribute::CORE:match (opcode)
711336µs422µsMoose::Meta::Attribute::::_canonicalize_handles Moose::Meta::Attribute::_canonicalize_handles
511327µs4.75msMoose::Meta::Attribute::::does Moose::Meta::Attribute::does
3322281µs281µsMoose::Meta::Attribute::::delegation_metaclass Moose::Meta::Attribute::delegation_metaclass
211180µs464µsMoose::Meta::Attribute::::_weaken_value Moose::Meta::Attribute::_weaken_value
51199µs3.52msMoose::Meta::Attribute::::__ANON__[:40] Moose::Meta::Attribute::__ANON__[:40]
11177µs96µsMoose::Meta::Attribute::::BEGIN@4 Moose::Meta::Attribute::BEGIN@4
11139µs107µsMoose::Meta::Attribute::::BEGIN@5 Moose::Meta::Attribute::BEGIN@5
11139µs218µsMoose::Meta::Attribute::::BEGIN@10 Moose::Meta::Attribute::BEGIN@10
11139µs73µsMoose::Meta::Attribute::::BEGIN@16 Moose::Meta::Attribute::BEGIN@16
11137µs164µsMoose::Meta::Attribute::::BEGIN@9 Moose::Meta::Attribute::BEGIN@9
11137µs41.0msMoose::Meta::Attribute::::BEGIN@23 Moose::Meta::Attribute::BEGIN@23
11136µs222µsMoose::Meta::Attribute::::BEGIN@8 Moose::Meta::Attribute::BEGIN@8
11131µs31µsMoose::Meta::Attribute::::BEGIN@21 Moose::Meta::Attribute::BEGIN@21
21126µs26µsMoose::Meta::Attribute::::illegal_options_for_inheritance Moose::Meta::Attribute::illegal_options_for_inheritance
11125µs25µsMoose::Meta::Attribute::::BEGIN@19 Moose::Meta::Attribute::BEGIN@19
11119µs19µ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__[:306] Moose::Meta::Attribute::__ANON__[:306]
0000s0sMoose::Meta::Attribute::::__ANON__[:529] Moose::Meta::Attribute::__ANON__[:529]
0000s0sMoose::Meta::Attribute::::__ANON__[:752] Moose::Meta::Attribute::__ANON__[:752]
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::::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
43103µs2114µs
# spent 96µs (77+19) within Moose::Meta::Attribute::BEGIN@4 which was called: # once (77µs+19µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 4
use strict;
# spent 96µs making 1 call to Moose::Meta::Attribute::BEGIN@4 # spent 19µs making 1 call to strict::import
5398µs2176µs
# spent 107µs (39+68) within Moose::Meta::Attribute::BEGIN@5 which was called: # once (39µs+68µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 5
use warnings;
# spent 107µs making 1 call to Moose::Meta::Attribute::BEGIN@5 # spent 68µs making 1 call to warnings::import
6
7391µ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
83106µs2408µs
# spent 222µs (36+186) within Moose::Meta::Attribute::BEGIN@8 which was called: # once (36µs+186µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 8
use Scalar::Util 'blessed', 'weaken';
# spent 222µs making 1 call to Moose::Meta::Attribute::BEGIN@8 # spent 186µs making 1 call to Exporter::import
9397µs2291µs
# spent 164µs (37+127) within Moose::Meta::Attribute::BEGIN@9 which was called: # once (37µs+127µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 9
use List::MoreUtils 'any';
# spent 164µs making 1 call to Moose::Meta::Attribute::BEGIN@9 # spent 127µs making 1 call to Exporter::import
10393µs2398µs
# spent 218µs (39+179) within Moose::Meta::Attribute::BEGIN@10 which was called: # once (39µs+179µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 10
use Try::Tiny;
# spent 218µs making 1 call to Moose::Meta::Attribute::BEGIN@10 # spent 180µs making 1 call to Exporter::import
113159µs119µs
# spent 19µs within Moose::Meta::Attribute::BEGIN@11 which was called: # once (19µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 11
use overload ();
# spent 19µs making 1 call to Moose::Meta::Attribute::BEGIN@11
12
1315µsour $VERSION = '1.19';
1414µsour $AUTHORITY = 'cpan:STEVAN';
15
163117µs2107µs
# spent 73µs (39+34) within Moose::Meta::Attribute::BEGIN@16 which was called: # once (39µs+34µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 16
use Moose::Deprecated;
173506µs17.19ms
# spent 7.19ms (6.51+682µs) within Moose::Meta::Attribute::BEGIN@17 which was called: # once (6.51ms+682µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 17
use Moose::Meta::Method::Accessor;
# spent 7.19ms making 1 call to Moose::Meta::Attribute::BEGIN@17
183459µs13.89ms
# spent 3.89ms (2.77+1.12) within Moose::Meta::Attribute::BEGIN@18 which was called: # once (2.77ms+1.12ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 18
use Moose::Meta::Method::Delegation;
# spent 3.89ms making 1 call to Moose::Meta::Attribute::BEGIN@18
19380µs125µs
# spent 25µs within Moose::Meta::Attribute::BEGIN@19 which was called: # once (25µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 19
use Moose::Util ();
# spent 25µs making 1 call to Moose::Meta::Attribute::BEGIN@19
203455µs1270ms
# spent 270ms (20.0+250) within Moose::Meta::Attribute::BEGIN@20 which was called: # once (20.0ms+250ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 20
use Moose::Util::TypeConstraints ();
# spent 270ms making 1 call to Moose::Meta::Attribute::BEGIN@20
213111µs131µs
# spent 31µs within Moose::Meta::Attribute::BEGIN@21 which was called: # once (31µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 21
use Class::MOP::MiniTrait;
# spent 31µs making 1 call to Moose::Meta::Attribute::BEGIN@21
22
23314.2ms281.9ms
# spent 41.0ms (37µs+40.9) within Moose::Meta::Attribute::BEGIN@23 which was called: # once (37µs+40.9ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 23
use base 'Class::MOP::Attribute', 'Moose::Meta::Mixin::AttributeCore';
# spent 41.0ms making 1 call to Moose::Meta::Attribute::BEGIN@23 # spent 40.9ms making 1 call to base::import
24
25116µs111.3msClass::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
# spent 11.3ms making 1 call to Class::MOP::MiniTrait::apply
26
27145µs23.30ms__PACKAGE__->meta->add_attribute('traits' => (
# spent 3.22ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 84µs making 1 call to Class::MOP::Object::meta
28 reader => 'applied_traits',
29 predicate => 'has_applied_traits',
30));
31
32# we need to have a ->does method in here to
33# more easily support traits, and the introspection
34# of those traits. We extend the does check to look
35# for metatrait aliases.
36
# spent 4.75ms (327µs+4.43) within Moose::Meta::Attribute::does which was called 5 times, avg 951µs/call: # 5 times (327µs+4.43ms) by Moose::Meta::Attribute::interpolate_class at line 114, avg 951µs/call
sub does {
37527µs my ($self, $role_name) = @_;
38
# spent 3.52ms (99µs+3.42) within Moose::Meta::Attribute::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Attribute.pm:40] which was called 5 times, avg 705µs/call: # 5 times (99µs+3.42ms) by Try::Tiny::try at line 71 of Try/Tiny.pm, avg 705µs/call
my $name = try {
39597µs53.42ms Moose::Util::resolve_metatrait_alias(Attribute => $role_name)
# spent 3.42ms making 5 calls to Moose::Util::resolve_metatrait_alias, avg 685µs/call
405120µs53.89ms };
# spent 3.89ms making 5 calls to Try::Tiny::try, avg 779µs/call
41515µs return 0 if !defined($name); # failed to load class
425149µs5532µs return $self->Moose::Object::does($name);
# spent 532µs making 5 calls to Moose::Object::does, avg 106µ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 354ms (84.5+269) within Moose::Meta::Attribute::new which was called 124 times, avg 2.85ms/call: # 121 times (82.5ms+262ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 83, avg 2.85ms/call # 2 times (1.30ms+1.24ms) by Moose::Meta::Attribute::clone at line 239, avg 1.27ms/call # once (702µs+5.77ms) by Moose::BEGIN@21 at line 20 of Moose/Meta/TypeCoercion.pm
sub new {
561241.47ms my ($class, $name, %options) = @_;
571241.84ms122147ms $class->_process_options($name, \%options) unless $options{__hack_no_process_options}; # used from clone()... YECHKKK FIXME ICKY YUCK GROSS
# spent 143ms making 120 calls to Moose::Meta::Attribute::_process_options, avg 1.19ms/call # spent 1.70ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::_process_options # spent 1.61ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::_process_options
58
59124483µs delete $options{__hack_no_process_options};
60
61 my %attrs =
62 ( map { $_ => 1 }
63347634.8ms347634.6ms grep { defined }
# spent 34.6ms making 3476 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call
6412423.6ms24825.7ms map { $_->init_arg() }
# spent 11.4ms making 119 calls to Class::MOP::Object::meta, avg 96µs/call # spent 9.46ms making 118 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 80µs/call # spent 4.37ms making 6 calls to Class::MOP::Class::get_all_attributes, avg 728µs/call # spent 287µs making 3 calls to Class::MOP::Class::__ANON__::SERIAL::1::meta, avg 96µs/call # spent 136µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::meta # spent 97µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::meta
65 $class->meta()->get_all_attributes()
66 );
67
681243.95ms124547µs my @bad = sort grep { ! $attrs{$_} } keys %options;
# spent 547µs making 124 calls to Moose::Meta::Attribute::CORE:sort, avg 4µs/call
69
70124360µs if (@bad)
71 {
72 Carp::cluck "Found unknown argument(s) passed to '$name' attribute constructor in '$class': @bad";
73 }
74
751247.23ms12461.6ms return $class->SUPER::new($name, %options);
# spent 61.6ms making 124 calls to Class::MOP::Attribute::new, avg 497µs/call
76}
77
78
# spent 2.85s (7.83ms+2.84) within Moose::Meta::Attribute::interpolate_class_and_new which was called 121 times, avg 23.6ms/call: # 114 times (7.37ms+2.84s) by Moose::Meta::Class::_process_new_attribute at line 438 of Moose/Meta/Class.pm, avg 25.0ms/call # 7 times (465µs+5.15ms) by Moose::Meta::Role::Attribute::attribute_for_class at line 67 of Moose/Meta/Role/Attribute.pm, avg 803µs/call
sub interpolate_class_and_new {
791211.39ms my ($class, $name, %args) = @_;
80
811211.97ms1212.51s my ( $new_class, @traits ) = $class->interpolate_class(\%args);
# spent 2.51s making 121 calls to Moose::Meta::Attribute::interpolate_class, avg 20.7ms/call, recursion: max depth 1, sum of overlapping time 120µs
82
831213.95ms121345ms $new_class->new($name, %args, ( scalar(@traits) ? ( traits => \@traits ) : () ) );
# spent 345ms making 121 calls to Moose::Meta::Attribute::new, avg 2.85ms/call
84}
85
86
# spent 2.51s (4.13ms+2.50) within Moose::Meta::Attribute::interpolate_class which was called 123 times, avg 20.4ms/call: # 121 times (4.08ms+2.50s) by Moose::Meta::Attribute::interpolate_class_and_new at line 81, avg 20.7ms/call # 2 times (59µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 209, avg 30µs/call
sub interpolate_class {
87123420µs my ($class, $options) = @_;
88
89123336µs $class = ref($class) || $class;
90
91123598µs if ( my $metaclass_name = delete $options->{metaclass} ) {
92 my $new_class = Moose::Util::resolve_metaclass_alias( Attribute => $metaclass_name );
93
94 if ( $class ne $new_class ) {
95 if ( $new_class->can("interpolate_class") ) {
96 return $new_class->interpolate_class($options);
97 } else {
98 $class = $new_class;
99 }
100 }
101 }
102
103123257µs my @traits;
104
105123419µs if (my $traits = $options->{traits}) {
106511µs my $i = 0;
107526µs while ($i < @$traits) {
108519µs my $trait = $traits->[$i++];
109510µs next if ref($trait); # options to a trait we discarded
110
111567µs52.37s $trait = Moose::Util::resolve_metatrait_alias(Attribute => $trait)
# spent 2.37s making 5 calls to Moose::Util::resolve_metatrait_alias, avg 474ms/call
112 || $trait;
113
114572µs54.75ms next if $class->does($trait);
# spent 4.75ms making 5 calls to Moose::Meta::Attribute::does, avg 951µs/call
115
116523µs push @traits, $trait;
117
118 # are there options?
119537µs push @traits, $traits->[$i++]
120 if $traits->[$i] && ref($traits->[$i]);
121 }
122
123525µs if (@traits) {
1245115µs5129ms my $anon_class = Moose::Meta::Class->create_anon_class(
# spent 129ms making 5 calls to Moose::Meta::Class::create_anon_class, avg 25.8ms/call
125 superclasses => [ $class ],
126 roles => [ @traits ],
127 cache => 1,
128 );
129
1305119µs537µs $class = $anon_class->name;
# spent 37µs making 5 calls to Class::MOP::Package::name, avg 7µs/call
131 }
132 }
133
1341232.17ms return ( wantarray ? ( $class, @traits ) : $class );
135}
136
137# ...
138
139# method-generating options shouldn't be overridden
140
# spent 26µs within Moose::Meta::Attribute::illegal_options_for_inheritance which was called 2 times, avg 13µs/call: # 2 times (26µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 168, avg 13µs/call
sub illegal_options_for_inheritance {
141238µs qw(reader writer accessor clearer predicate)
142}
143
144# NOTE/TODO
145# This method *must* be able to handle
146# Class::MOP::Attribute instances as
147# well. Yes, I know that is wrong, but
148# apparently we didn't realize it was
149# doing that and now we have some code
150# which is dependent on it. The real
151# solution of course is to push this
152# feature back up into Class::MOP::Attribute
153# but I not right now, I am too lazy.
154# However if you are reading this and
155# looking for something to do,.. please
156# be my guest.
157# - stevan
158
# spent 18.4ms (430µs+18.0) within Moose::Meta::Attribute::clone_and_inherit_options which was called 2 times, avg 9.22ms/call: # 2 times (430µs+18.0ms) by Moose::Meta::Class::_process_inherited_attribute at line 446 of Moose/Meta/Class.pm, avg 9.22ms/call
sub clone_and_inherit_options {
159215µs my ($self, %options) = @_;
160
161 # NOTE:
162 # we may want to extends a Class::MOP::Attribute
163 # in which case we need to be able to use the
164 # core set of legal options that have always
165 # been here. But we allows Moose::Meta::Attribute
166 # instances to changes them.
167 # - SL
168277µs440µs my @illegal_options = $self->can('illegal_options_for_inheritance')
# spent 26µs making 2 calls to Moose::Meta::Attribute::illegal_options_for_inheritance, avg 13µs/call # spent 14µs making 2 calls to UNIVERSAL::can, avg 7µs/call
169 ? $self->illegal_options_for_inheritance
170 : ();
171
172218µs my @found_illegal_options = grep { exists $options{$_} && exists $self->{$_} ? $_ : undef } @illegal_options;
17327µs (scalar @found_illegal_options == 0)
174 || $self->throw_error("Illegal inherited options => (" . (join ', ' => @found_illegal_options) . ")", data => \%options);
175
17625µs if ($options{isa}) {
177 my $type_constraint;
178 if (blessed($options{isa}) && $options{isa}->isa('Moose::Meta::TypeConstraint')) {
179 $type_constraint = $options{isa};
180 }
181 else {
182 $type_constraint = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($options{isa});
183 (defined $type_constraint)
184 || $self->throw_error("Could not find the type constraint '" . $options{isa} . "'", data => $options{isa});
185 }
186
187 $options{type_constraint} = $type_constraint;
188 }
189
19026µs if ($options{does}) {
191 my $type_constraint;
192 if (blessed($options{does}) && $options{does}->isa('Moose::Meta::TypeConstraint')) {
193 $type_constraint = $options{does};
194 }
195 else {
196 $type_constraint = Moose::Util::TypeConstraints::find_or_create_does_type_constraint($options{does});
197 (defined $type_constraint)
198 || $self->throw_error("Could not find the type constraint '" . $options{does} . "'", data => $options{does});
199 }
200
201 $options{type_constraint} = $type_constraint;
202 }
203
204 # NOTE:
205 # this doesn't apply to Class::MOP::Attributes,
206 # so we can ignore it for them.
207 # - SL
208246µs213µs if ($self->can('interpolate_class')) {
# spent 13µs making 2 calls to UNIVERSAL::can, avg 7µs/call
209235µs259µs ( $options{metaclass}, my @traits ) = $self->interpolate_class(\%options);
# spent 59µs making 2 calls to Moose::Meta::Attribute::interpolate_class, avg 30µs/call
210
21124µs my %seen;
212231µs226µs my @all_traits = grep { $seen{$_}++ } @{ $self->applied_traits || [] }, @traits;
# spent 26µs making 2 calls to Moose::Meta::Attribute::applied_traits, avg 13µs/call
21328µs $options{traits} = \@all_traits if @all_traits;
214 }
215
216 # This method can be called on a CMOP::Attribute object, so we need to
217 # make sure we can call this method.
2182113µs658µs $self->_process_lazy_build_option( $self->name, \%options )
# spent 31µs making 2 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 16µs/call # spent 14µs making 2 calls to UNIVERSAL::can, avg 7µs/call # spent 13µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 7µs/call
219 if $self->can('_process_lazy_build_option');
220
221270µs217.8ms $self->clone(%options);
# spent 17.8ms making 2 calls to Moose::Meta::Attribute::clone, avg 8.90ms/call
222}
223
224
# spent 17.8ms (2.14+15.7) within Moose::Meta::Attribute::clone which was called 2 times, avg 8.90ms/call: # 2 times (2.14ms+15.7ms) by Moose::Meta::Attribute::clone_and_inherit_options at line 221, avg 8.90ms/call
sub clone {
225216µs my ( $self, %params ) = @_;
226
227211µs my $class = delete $params{metaclass} || ref $self;
228
22925µs my ( @init, @non_init );
230
23158816µs609.15ms foreach my $attr ( grep { $_->has_value($self) } Class::MOP::class_of($self)->get_all_attributes ) {
# spent 8.94ms making 56 calls to Class::MOP::Attribute::has_value, avg 160µs/call # spent 144µs making 2 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 72µs/call # spent 68µs making 2 calls to Class::MOP::class_of, avg 34µs/call
23221336µ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
233 }
234
23523504µs423.77ms my %new_params = ( ( map { $_->init_arg => $_->get_value($self) } @init ), %params );
# spent 3.56ms making 21 calls to Class::MOP::Attribute::get_value, avg 170µs/call # spent 206µs making 21 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call
236
237212µs my $name = delete $new_params{name};
238
239262µs22.55ms my $clone = $class->new($name, %new_params, __hack_no_process_options => 1 );
# spent 2.55ms making 2 calls to Moose::Meta::Attribute::new, avg 1.27ms/call
240
241215µs foreach my $attr ( @non_init ) {
242 $attr->set_value($clone, $attr->get_value($self));
243 }
244
245246µs return $clone;
246}
247
248
# spent 145ms (18.2+126) within Moose::Meta::Attribute::_process_options which was called 122 times, avg 1.18ms/call: # 120 times (17.7ms+126ms) by Moose::Meta::Attribute::new at line 57, avg 1.19ms/call # 2 times (463µs+825µs) by Class::MOP::Method::Wrapped::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm:49] at line 48 of Class/MOP/Method/Wrapped.pm, avg 644µs/call
sub _process_options {
249122509µs my ( $class, $name, $options ) = @_;
250
2511221.32ms1223.07ms $class->_process_is_option( $name, $options );
# spent 3.07ms making 122 calls to Moose::Meta::Attribute::_process_is_option, avg 25µs/call
2521221.56ms122102ms $class->_process_isa_option( $name, $options );
# spent 102ms making 122 calls to Moose::Meta::Attribute::_process_isa_option, avg 834µs/call
2531221.60ms12210.7ms $class->_process_does_option( $name, $options );
# spent 10.7ms making 122 calls to Moose::Meta::Attribute::_process_does_option, avg 87µs/call
2541221.45ms1221.75ms $class->_process_coerce_option( $name, $options );
# spent 1.75ms making 122 calls to Moose::Meta::Attribute::_process_coerce_option, avg 14µs/call
2551221.39ms1221.61ms $class->_process_trigger_option( $name, $options );
# spent 1.61ms making 122 calls to Moose::Meta::Attribute::_process_trigger_option, avg 13µs/call
2561221.46ms1221.60ms $class->_process_auto_deref_option( $name, $options );
# spent 1.60ms making 122 calls to Moose::Meta::Attribute::_process_auto_deref_option, avg 13µs/call
2571221.44ms1222.42ms $class->_process_lazy_build_option( $name, $options );
# spent 2.42ms making 122 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 20µs/call
2581221.39ms1221.61ms $class->_process_lazy_option( $name, $options );
# spent 1.61ms making 122 calls to Moose::Meta::Attribute::_process_lazy_option, avg 13µs/call
2591222.61ms1221.82ms $class->_process_required_option( $name, $options );
# spent 1.82ms making 122 calls to Moose::Meta::Attribute::_process_required_option, avg 15µs/call
260}
261
262
# spent 3.07ms within Moose::Meta::Attribute::_process_is_option which was called 122 times, avg 25µs/call: # 122 times (3.07ms+0s) by Moose::Meta::Attribute::_process_options at line 251, avg 25µs/call
sub _process_is_option {
263122434µs my ( $class, $name, $options ) = @_;
264
265122457µs return unless $options->{is};
266
267 ### -------------------------
268 ## is => ro, writer => _foo # turns into (reader => foo, writer => _foo) as before
269 ## is => rw, writer => _foo # turns into (reader => foo, writer => _foo)
270 ## is => rw, accessor => _foo # turns into (accessor => _foo)
271 ## is => ro, accessor => _foo # error, accesor is rw
272 ### -------------------------
273
2741151.95ms if ( $options->{is} eq 'ro' ) {
27591242µs $class->throw_error(
276 "Cannot define an accessor name on a read-only attribute, accessors are read/write",
277 data => $options )
278 if exists $options->{accessor};
27991510µs $options->{reader} ||= $name;
280 }
281 elsif ( $options->{is} eq 'rw' ) {
282 if ( $options->{writer} ) {
283 $options->{reader} ||= $name;
284 }
285 else {
28624130µs $options->{accessor} ||= $name;
287 }
288 }
289 elsif ( $options->{is} eq 'bare' ) {
290 return;
291 # do nothing, but don't complain (later) about missing methods
292 }
293 else {
294 $class->throw_error( "I do not understand this option (is => "
295 . $options->{is}
296 . ") on attribute ($name)", data => $options->{is} );
297 }
298}
299
300
# spent 102ms (5.24+96.6) within Moose::Meta::Attribute::_process_isa_option which was called 122 times, avg 834µs/call: # 122 times (5.24ms+96.6ms) by Moose::Meta::Attribute::_process_options at line 252, avg 834µs/call
sub _process_isa_option {
301122541µs my ( $class, $name, $options ) = @_;
302
303122595µs return unless exists $options->{isa};
304
305100234µs if ( exists $options->{does} ) {
306 if ( try { $options->{isa}->can('does') } ) {
307 ( $options->{isa}->does( $options->{does} ) )
308 || $class->throw_error(
309 "Cannot have an isa option and a does option if the isa does not do the does on attribute ($name)",
310 data => $options );
311 }
312 else {
313 $class->throw_error(
314 "Cannot have an isa option which cannot ->does() on attribute ($name)",
315 data => $options );
316 }
317 }
318
319 # allow for anon-subtypes here ...
3201003.12ms100550µs if ( blessed( $options->{isa} )
# spent 550µs making 100 calls to Scalar::Util::blessed, avg 5µs/call
321 && $options->{isa}->isa('Moose::Meta::TypeConstraint') ) {
322 $options->{type_constraint} = $options->{isa};
323 }
324 else {
3251001.70ms10096.0ms $options->{type_constraint}
# spent 96.0ms making 100 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 960µs/call
326 = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint(
327 $options->{isa} );
328 }
329}
330
331
# spent 10.7ms (2.15+8.50) within Moose::Meta::Attribute::_process_does_option which was called 122 times, avg 87µs/call: # 122 times (2.15ms+8.50ms) by Moose::Meta::Attribute::_process_options at line 253, avg 87µs/call
sub _process_does_option {
332122548µs my ( $class, $name, $options ) = @_;
333
3341221.45ms return unless exists $options->{does} && ! exists $options->{isa};
335
336 # allow for anon-subtypes here ...
33711325µs1157µs if ( blessed( $options->{does} )
# spent 57µs making 11 calls to Scalar::Util::blessed, avg 5µs/call
338 && $options->{does}->isa('Moose::Meta::TypeConstraint') ) {
339 $options->{type_constraint} = $options->{does};
340 }
341 else {
34211169µs118.45ms $options->{type_constraint}
# spent 8.45ms making 11 calls to Moose::Util::TypeConstraints::find_or_create_does_type_constraint, avg 768µs/call
343 = Moose::Util::TypeConstraints::find_or_create_does_type_constraint(
344 $options->{does} );
345 }
346}
347
348
# spent 1.75ms (1.72+25µs) within Moose::Meta::Attribute::_process_coerce_option which was called 122 times, avg 14µs/call: # 122 times (1.72ms+25µs) by Moose::Meta::Attribute::_process_options at line 254, avg 14µs/call
sub _process_coerce_option {
349122535µs my ( $class, $name, $options ) = @_;
350
3511221.47ms return unless $options->{coerce};
352
35326µs ( exists $options->{type_constraint} )
354 || $class->throw_error(
355 "You cannot have coercion without specifying a type constraint on attribute ($name)",
356 data => $options );
357
35826µs $class->throw_error(
359 "You cannot have a weak reference to a coerced value on attribute ($name)",
360 data => $options )
361 if $options->{weak_ref};
362
363240µs225µs unless ( $options->{type_constraint}->has_coercion ) {
# spent 25µs making 2 calls to Moose::Meta::TypeConstraint::has_coercion, avg 12µs/call
364 my $type = $options->{type_constraint}->name;
365
366 Moose::Deprecated::deprecated(
367 feature => 'coerce without coercion',
368 message =>
369 "You cannot coerce an attribute ($name) unless its type ($type) has a coercion"
370 );
371 }
372}
373
374
# spent 1.61ms within Moose::Meta::Attribute::_process_trigger_option which was called 122 times, avg 13µs/call: # 122 times (1.61ms+0s) by Moose::Meta::Attribute::_process_options at line 255, avg 13µs/call
sub _process_trigger_option {
375122491µs my ( $class, $name, $options ) = @_;
376
3771221.43ms return unless exists $options->{trigger};
378
379 ( 'CODE' eq ref $options->{trigger} )
380 || $class->throw_error("Trigger must be a CODE ref on attribute ($name)", data => $options->{trigger});
381}
382
383
# spent 1.60ms within Moose::Meta::Attribute::_process_auto_deref_option which was called 122 times, avg 13µs/call: # 122 times (1.60ms+0s) by Moose::Meta::Attribute::_process_options at line 256, avg 13µs/call
sub _process_auto_deref_option {
384122476µs my ( $class, $name, $options ) = @_;
385
3861221.54ms return unless $options->{auto_deref};
387
388 ( exists $options->{type_constraint} )
389 || $class->throw_error(
390 "You cannot auto-dereference without specifying a type constraint on attribute ($name)",
391 data => $options );
392
393 ( $options->{type_constraint}->is_a_type_of('ArrayRef')
394 || $options->{type_constraint}->is_a_type_of('HashRef') )
395 || $class->throw_error(
396 "You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute ($name)",
397 data => $options );
398}
399
400
# spent 2.45ms (2.38+75µs) within Moose::Meta::Attribute::_process_lazy_build_option which was called 124 times, avg 20µs/call: # 122 times (2.34ms+75µs) by Moose::Meta::Attribute::_process_options at line 257, avg 20µs/call # 2 times (31µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 218, avg 16µs/call
sub _process_lazy_build_option {
401124520µs my ( $class, $name, $options ) = @_;
402
4031241.46ms return unless $options->{lazy_build};
404
4051643µs $class->throw_error(
406 "You can not use lazy_build and default for the same attribute ($name)",
407 data => $options )
408 if exists $options->{default};
409
4101664µs $options->{lazy} = 1;
41116110µs $options->{builder} ||= "_build_${name}";
412
41316454µs1676µs if ( $name =~ /^_/ ) {
# spent 76µs making 16 calls to Moose::Meta::Attribute::CORE:match, avg 5µs/call
414214µs $options->{clearer} ||= "_clear${name}";
415213µs $options->{predicate} ||= "_has${name}";
416 }
417 else {
4181496µs $options->{clearer} ||= "clear_${name}";
4191485µs $options->{predicate} ||= "has_${name}";
420 }
421}
422
423
# spent 1.61ms within Moose::Meta::Attribute::_process_lazy_option which was called 122 times, avg 13µs/call: # 122 times (1.61ms+0s) by Moose::Meta::Attribute::_process_options at line 258, avg 13µs/call
sub _process_lazy_option {
424122461µs my ( $class, $name, $options ) = @_;
425
4261221.33ms return unless $options->{lazy};
427
42819233µs ( exists $options->{default} || defined $options->{builder} )
429 || $class->throw_error(
430 "You cannot have a lazy attribute ($name) without specifying a default value for it",
431 data => $options );
432}
433
434
# spent 1.82ms within Moose::Meta::Attribute::_process_required_option which was called 122 times, avg 15µs/call: # 122 times (1.82ms+0s) by Moose::Meta::Attribute::_process_options at line 259, avg 15µs/call
sub _process_required_option {
435122524µs my ( $class, $name, $options ) = @_;
436
4371221.69ms if (
438 $options->{required}
439 && !(
440 ( !exists $options->{init_arg} || defined $options->{init_arg} )
441 || exists $options->{default}
442 || defined $options->{builder}
443 )
444 ) {
445 $class->throw_error(
446 "You cannot have a required attribute ($name) without a default, builder, or an init_arg",
447 data => $options );
448 }
449}
450
451
# spent 7.88ms (1.71+6.17) within Moose::Meta::Attribute::initialize_instance_slot which was called 14 times, avg 563µs/call: # 14 times (1.71ms+6.17ms) by Class::MOP::Class::_construct_instance at line 603 of Class/MOP/Class.pm, avg 563µs/call
sub initialize_instance_slot {
4521452µs my ($self, $meta_instance, $instance, $params) = @_;
45314167µs14135µs my $init_arg = $self->init_arg();
# spent 135µs making 14 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call
454 # try to fetch the init arg from the %params ...
455
4561423µs my $val;
4571423µs my $value_is_set;
4581473µs if ( defined($init_arg) and exists $params->{$init_arg}) {
45927µs $val = $params->{$init_arg};
46025µs $value_is_set = 1;
461 }
462 else {
463 # skip it if it's lazy
46412221µs12151µs return if $self->is_lazy;
# spent 151µs making 12 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 13µs/call
465 # and die if it's required and doesn't have a default value
46610118µs11124µs $self->throw_error("Attribute (" . $self->name . ") is required", object => $instance, data => $params)
# spent 114µs making 10 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 11µs/call # spent 11µs making 1 call to Class::MOP::Mixin::AttributeCore::has_default
467 if $self->is_required && !$self->has_default && !$self->has_builder;
468
469 # if nothing was in the %params, we can use the
470 # attribute's default value (if it has one)
47110132µs11105µs if ($self->has_default) {
# spent 95µs making 10 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 9µs/call # spent 10µs making 1 call to Class::MOP::Mixin::AttributeCore::has_builder
472997µs9352µs $val = $self->default($instance);
# spent 352µs making 9 calls to Class::MOP::Mixin::AttributeCore::default, avg 39µs/call
473922µs $value_is_set = 1;
474 }
475 elsif ($self->has_builder) {
476 $val = $self->_call_builder($instance);
477 $value_is_set = 1;
478 }
479 }
480
4811230µs return unless $value_is_set;
482
48311126µs112.63ms $val = $self->_coerce_and_verify( $val, $instance );
# spent 2.63ms making 11 calls to Moose::Meta::Attribute::_coerce_and_verify, avg 240µs/call
484
48511141µs112.18ms $self->set_initial_value($instance, $val);
# spent 2.18ms making 11 calls to Class::MOP::Attribute::set_initial_value, avg 198µs/call
486
48711182µs4493µs if ( ref $val && $self->is_weak_ref ) {
# spent 464µs making 2 calls to Moose::Meta::Attribute::_weaken_value, avg 232µs/call # spent 29µs making 2 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 14µs/call
488 $self->_weaken_value($instance);
489 }
490}
491
492sub _call_builder {
493 my ( $self, $instance ) = @_;
494
495 my $builder = $self->builder();
496
497 return $instance->$builder()
498 if $instance->can( $self->builder );
499
500 $self->throw_error( blessed($instance)
501 . " does not support builder method '"
502 . $self->builder
503 . "' for attribute '"
504 . $self->name
505 . "'",
506 object => $instance,
507 );
508}
509
510## Slot management
511
512# FIXME:
513# this duplicates too much code from
514# Class::MOP::Attribute, we need to
515# refactor these bits eventually.
516# - SL
517
# spent 973µs (612+361) within Moose::Meta::Attribute::_set_initial_slot_value which was called 11 times, avg 88µs/call: # 11 times (612µs+361µs) by Class::MOP::Attribute::set_initial_value at line 253 of Class/MOP/Attribute.pm, avg 88µs/call
sub _set_initial_slot_value {
5181146µs my ($self, $meta_instance, $instance, $value) = @_;
519
52011227µs1166µs my $slot_name = $self->name;
# spent 66µs making 11 calls to Class::MOP::Mixin::AttributeCore::name, avg 6µs/call
521
52211336µs22295µs return $meta_instance->set_slot_value($instance, $slot_name, $value)
# spent 179µs making 11 calls to Class::MOP::Instance::set_slot_value, avg 16µs/call # spent 116µs making 11 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 11µs/call
523 unless $self->has_initializer;
524
525 my $callback = sub {
526 my $val = $self->_coerce_and_verify( shift, $instance );;
527
528 $meta_instance->set_slot_value($instance, $slot_name, $val);
529 };
530
531 my $initializer = $self->initializer;
532
533 # most things will just want to set a value, so make it first arg
534 $instance->$initializer($value, $callback, $self);
535}
536
537sub set_value {
538 my ($self, $instance, @args) = @_;
539 my $value = $args[0];
540
541 my $attr_name = $self->name;
542
543 if ($self->is_required and not @args) {
544 $self->throw_error("Attribute ($attr_name) is required", object => $instance);
545 }
546
547 $value = $self->_coerce_and_verify( $value, $instance );
548
549 my @old;
550 if ( $self->has_trigger && $self->has_value($instance) ) {
551 @old = $self->get_value($instance, 'for trigger');
552 }
553
554 $self->SUPER::set_value($instance, $value);
555
556 if ( ref $value && $self->is_weak_ref ) {
557 $self->_weaken_value($instance);
558 }
559
560 if ($self->has_trigger) {
561 $self->trigger->($instance, $value, @old);
562 }
563}
564
565
# spent 464µs (180+284) within Moose::Meta::Attribute::_weaken_value which was called 2 times, avg 232µs/call: # 2 times (180µs+284µs) by Moose::Meta::Attribute::initialize_instance_slot at line 487, avg 232µs/call
sub _weaken_value {
56627µs my ( $self, $instance ) = @_;
567
568275µs6186µs my $meta_instance = Class::MOP::Class->initialize( blessed($instance) )
# spent 100µs making 2 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 50µs/call # spent 73µs making 2 calls to Class::MOP::Class::initialize, avg 37µs/call # spent 14µs making 2 calls to Scalar::Util::blessed, avg 7µs/call
569 ->get_meta_instance;
570
571276µs498µs $meta_instance->weaken_slot_value( $instance, $self->name );
# spent 87µs making 2 calls to Class::MOP::Instance::weaken_slot_value, avg 43µs/call # spent 11µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 6µs/call
572}
573
574sub get_value {
575 my ($self, $instance, $for_trigger) = @_;
576
577 if ($self->is_lazy) {
578 unless ($self->has_value($instance)) {
579 my $value;
580 if ($self->has_default) {
581 $value = $self->default($instance);
582 } elsif ( $self->has_builder ) {
583 $value = $self->_call_builder($instance);
584 }
585
586 $value = $self->_coerce_and_verify( $value, $instance );
587
588 $self->set_initial_value($instance, $value);
589 }
590 }
591
592 if ( $self->should_auto_deref && ! $for_trigger ) {
593
594 my $type_constraint = $self->type_constraint;
595
596 if ($type_constraint->is_a_type_of('ArrayRef')) {
597 my $rv = $self->SUPER::get_value($instance);
598 return unless defined $rv;
599 return wantarray ? @{ $rv } : $rv;
600 }
601 elsif ($type_constraint->is_a_type_of('HashRef')) {
602 my $rv = $self->SUPER::get_value($instance);
603 return unless defined $rv;
604 return wantarray ? %{ $rv } : $rv;
605 }
606 else {
607 $self->throw_error("Can not auto de-reference the type constraint '" . $type_constraint->name . "'", object => $instance, type_constraint => $type_constraint);
608 }
609
610 }
611 else {
612
613 return $self->SUPER::get_value($instance);
614 }
615}
616
617## installing accessors
618
6192033.04ms
# spent 1.94ms within Moose::Meta::Attribute::accessor_metaclass which was called 203 times, avg 10µs/call: # 193 times (1.84ms+0s) by Class::MOP::Attribute::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Attribute.pm:342] at line 334 of Class/MOP/Attribute.pm, avg 10µs/call # 10 times (101µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 172 of Moose/Meta/Attribute/Native/Trait.pm, avg 10µs/call
sub accessor_metaclass { 'Moose::Meta::Method::Accessor' }
620
621
# spent 928ms (7.58+920) within Moose::Meta::Attribute::install_accessors which was called 125 times, avg 7.42ms/call: # 122 times (7.29ms+872ms) by Class::MOP::Class::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Class.pm:790] at line 789 of Class/MOP/Class.pm, avg 7.21ms/call # 2 times (222µs+41.3ms) by Class::MOP::Method::Wrapped::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm:43] at line 33 of Class/MOP/Method/Wrapped.pm, avg 20.8ms/call # once (64µs+6.58ms) by Class::MOP::Class::_inline_accessors at line 1305 of Class/MOP/Class.pm
sub install_accessors {
622125411µs my $self = shift;
6231253.28ms125848ms $self->SUPER::install_accessors(@_);
# spent 848ms making 125 calls to Class::MOP::Attribute::install_accessors, avg 6.79ms/call
6241252.09ms13471.7ms $self->install_delegation if $self->has_handles;
# spent 69.7ms making 9 calls to Moose::Meta::Attribute::install_delegation, avg 7.75ms/call # spent 2.00ms making 125 calls to Moose::Meta::Mixin::AttributeCore::has_handles, avg 16µs/call
6251251.56ms return;
626}
627
628
# spent 4.74ms (3.39+1.35) within Moose::Meta::Attribute::_check_associated_methods which was called 123 times, avg 39µs/call: # 123 times (3.39ms+1.35ms) by Moose::Meta::Class::add_attribute at line 307 of Moose/Meta/Class.pm, avg 39µs/call
sub _check_associated_methods {
629123424µs my $self = shift;
6301232.71ms1231.35ms unless (
# spent 1.35ms making 123 calls to Class::MOP::Attribute::associated_methods, avg 11µs/call
631 @{ $self->associated_methods }
632 || ($self->_is_metadata || '') eq 'bare'
633 ) {
634 Carp::cluck(
635 'Attribute (' . $self->name . ') of class '
636 . $self->associated_class->name
637 . ' has no associated methods'
638 . ' (did you mean to provide an "is" argument?)'
639 . "\n"
640 )
641 }
642}
643
644
# spent 716ms (26.7+690) within Moose::Meta::Attribute::_process_accessors which was called 193 times, avg 3.71ms/call: # 97 times (13.4ms+397ms) by Class::MOP::Attribute::install_accessors at line 360 of Class/MOP/Attribute.pm, avg 4.23ms/call # 30 times (4.15ms+60.7ms) by Class::MOP::Attribute::install_accessors at line 368 of Class/MOP/Attribute.pm, avg 2.16ms/call # 29 times (4.15ms+60.4ms) by Class::MOP::Attribute::install_accessors at line 372 of Class/MOP/Attribute.pm, avg 2.23ms/call # 26 times (3.48ms+132ms) by Class::MOP::Attribute::install_accessors at line 356 of Class/MOP/Attribute.pm, avg 5.22ms/call # 11 times (1.48ms+39.1ms) by Class::MOP::Attribute::install_accessors at line 364 of Class/MOP/Attribute.pm, avg 3.69ms/call
sub _process_accessors {
645193570µs my $self = shift;
646193866µs my ($type, $accessor, $generate_as_inline_methods) = @_;
647
648193628µs $accessor = ( keys %$accessor )[0] if ( ref($accessor) || '' ) eq 'HASH';
6491934.11ms38662.3ms my $method = $self->associated_class->get_method($accessor);
# spent 60.5ms making 193 calls to Class::MOP::Mixin::HasMethods::get_method, avg 314µs/call # spent 1.75ms making 193 calls to Class::MOP::Attribute::associated_class, avg 9µs/call
650
651193508µs429µs if ( $method
# spent 11µs making 1 call to Class::MOP::Method::Accessor::associated_attribute # spent 11µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call # spent 7µs making 1 call to UNIVERSAL::isa
652 && $method->isa('Class::MOP::Method::Accessor')
653 && $method->associated_attribute->name ne $self->name ) {
654
655 my $other_attr_name = $method->associated_attribute->name;
656 my $name = $self->name;
657
658 Carp::cluck(
659 "You are overwriting an accessor ($accessor) for the $other_attr_name attribute"
660 . " with a new accessor method for the $name attribute" );
661 }
662
663193472µs15µs if (
# spent 5µs making 1 call to UNIVERSAL::isa
664 $method
665 && !$method->isa('Class::MOP::Method::Accessor')
666 && ( !$self->definition_context
667 || $method->package_name eq $self->definition_context->{package} )
668 ) {
669
670 Carp::cluck(
671 "You are overwriting a locally defined method ($accessor) with "
672 . "an accessor" );
673 }
674
6751938.32ms77070.4ms if ( !$self->associated_class->has_method($accessor)
# spent 37.5ms making 193 calls to Class::MOP::Mixin::HasMethods::has_method, avg 195µs/call # spent 29.2ms making 192 calls to Class::MOP::Package::has_package_symbol, avg 152µs/call # spent 3.66ms making 385 calls to Class::MOP::Attribute::associated_class, avg 10µs/call
676 && $self->associated_class->has_package_symbol( '&' . $accessor ) ) {
677
678 Carp::cluck(
679 "You are overwriting a locally defined function ($accessor) with "
680 . "an accessor" );
681 }
682
6831937.69ms193557ms $self->SUPER::_process_accessors(@_);
# spent 557ms making 193 calls to Class::MOP::Attribute::_process_accessors, avg 2.89ms/call
684}
685
686sub remove_accessors {
687 my $self = shift;
688 $self->SUPER::remove_accessors(@_);
689 $self->remove_delegation if $self->has_handles;
690 return;
691}
692
693
# spent 64.2ms (17.4+46.8) within Moose::Meta::Attribute::inline_set which was called 197 times, avg 326µs/call: # 139 times (11.9ms+14.5ms) by Moose::Meta::Method::Constructor::_generate_slot_assignment at line 302 of Moose/Meta/Method/Constructor.pm, avg 190µs/call # 56 times (5.18ms+31.4ms) by Moose::Meta::Method::Accessor::_inline_store at line 248 of Moose/Meta/Method/Accessor.pm, avg 653µs/call # 2 times (286µs+854µs) by Class::MOP::Method::Constructor::_generate_slot_initializer at line 145 of Class/MOP/Method/Constructor.pm, avg 570µs/call
sub inline_set {
694197640µs my $self = shift;
695197688µs my ( $instance, $value ) = @_;
696
6971973.87ms39429.0ms my $mi = $self->associated_class->get_meta_instance;
# spent 27.2ms making 196 calls to Class::MOP::Class::get_meta_instance, avg 139µs/call # spent 1.75ms making 197 calls to Class::MOP::Attribute::associated_class, avg 9µs/call # spent 79µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance
698
6991974.45ms39414.1ms my $code
# spent 9.32ms making 197 calls to Class::MOP::Instance::inline_set_slot_value, avg 47µs/call # spent 4.77ms making 197 calls to Class::MOP::Attribute::slots, avg 24µs/call
700 = $mi->inline_set_slot_value( $instance, $self->slots, $value ) . ";";
7011972.74ms2173.68ms $code
# spent 3.03ms making 197 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 15µs/call # spent 426µs making 10 calls to Class::MOP::Instance::inline_weaken_slot_value, avg 43µs/call # spent 218µs making 10 calls to Class::MOP::Attribute::slots, avg 22µs/call
702 .= $mi->inline_weaken_slot_value( $instance, $self->slots, $value )
703 . " if ref $value;"
704 if $self->is_weak_ref;
705
7061972.69ms return $code;
707}
708
709
# spent 69.7ms (5.03+64.7) within Moose::Meta::Attribute::install_delegation which was called 9 times, avg 7.75ms/call: # 9 times (5.03ms+64.7ms) by Moose::Meta::Attribute::install_accessors at line 624, avg 7.75ms/call
sub install_delegation {
710930µs my $self = shift;
711
712 # NOTE:
713 # Here we canonicalize the 'handles' option
714 # this will sort out any details and always
715 # return an hash of methods which we want
716 # to delagate to, see that method for details
7179181µs9686µs my %handles = $self->_canonicalize_handles;
# spent 422µs making 7 calls to Moose::Meta::Attribute::_canonicalize_handles, avg 60µs/call # spent 139µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::_canonicalize_handles # spent 126µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::_canonicalize_handles
718
719
720 # install the delegation ...
7219124µs9104µs my $associated_class = $self->associated_class;
# spent 104µs making 9 calls to Class::MOP::Attribute::associated_class, avg 12µs/call
7229225µs foreach my $handle (keys %handles) {
72328119µs my $method_to_call = $handles{$handle};
72428557µs28169µs my $class_name = $associated_class->name;
# spent 169µs making 28 calls to Class::MOP::Package::name, avg 6µs/call
72528113µs my $name = "${class_name}::${handle}";
726
72728333µs288.35ms (!$associated_class->has_method($handle))
# spent 8.35ms making 28 calls to Class::MOP::Mixin::HasMethods::has_method, avg 298µs/call
728 || $self->throw_error("You cannot overwrite a locally defined method ($handle) with a delegation", method_name => $handle);
729
730 # NOTE:
731 # handles is not allowed to delegate
732 # any of these methods, as they will
733 # override the ones in your class, which
734 # is almost certainly not what you want.
735
736 # FIXME warn when $handle was explicitly specified, but not if the source is a regex or something
737 #cluck("Not delegating method '$handle' because it is a core method") and
738282.04ms841.03ms next if $class_name->isa("Moose::Object") and $handle =~ /^BUILD|DEMOLISH$/ || Moose::Object->can($handle);
# spent 459µs making 28 calls to UNIVERSAL::can, avg 16µs/call # spent 308µs making 28 calls to Moose::Meta::Attribute::CORE:match, avg 11µs/call # spent 259µs making 28 calls to UNIVERSAL::isa, avg 9µs/call
739
74028381µs2840.0ms my $method = $self->_make_delegation_method($handle, $method_to_call);
# spent 17.9ms making 3 calls to Class::MOP::Class::__ANON__::SERIAL::5::_make_delegation_method, avg 5.96ms/call # spent 13.4ms making 23 calls to Moose::Meta::Attribute::_make_delegation_method, avg 581µs/call # spent 8.75ms making 2 calls to Class::MOP::Class::__ANON__::SERIAL::2::_make_delegation_method, avg 4.37ms/call
741
742281.26ms8413.9ms $self->associated_class->add_method($method->name, $method);
# spent 13.4ms making 28 calls to Class::MOP::Mixin::HasMethods::add_method, avg 480µs/call # spent 297µs making 28 calls to Class::MOP::Attribute::associated_class, avg 11µs/call # spent 155µs making 28 calls to Class::MOP::Method::name, avg 6µs/call
74328535µs28451µs $self->associate_method($method);
# spent 451µs making 28 calls to Class::MOP::Attribute::associate_method, avg 16µs/call
744 }
745}
746
747sub remove_delegation {
748 my $self = shift;
749 my %handles = $self->_canonicalize_handles;
750 my $associated_class = $self->associated_class;
751 foreach my $handle (keys %handles) {
752 next unless any { $handle eq $_ }
753 map { $_->name }
754 @{ $self->associated_methods };
755 $self->associated_class->remove_method($handle);
756 }
757}
758
759# private methods to help delegation ...
760
761
# spent 422µs (336+86) within Moose::Meta::Attribute::_canonicalize_handles which was called 7 times, avg 60µs/call: # 7 times (336µs+86µs) by Moose::Meta::Attribute::install_delegation at line 717, avg 60µs/call
sub _canonicalize_handles {
762721µs my $self = shift;
7637108µs786µs my $handles = $self->handles;
# spent 86µs making 7 calls to Moose::Meta::Mixin::AttributeCore::handles, avg 12µs/call
764728µs if (my $handle_type = ref($handles)) {
7657181µs if ($handle_type eq 'HASH') {
766 return %{$handles};
767 }
768 elsif ($handle_type eq 'ARRAY') {
769 return map { $_ => $_ } @{$handles};
770 }
771 elsif ($handle_type eq 'Regexp') {
772 ($self->has_type_constraint)
773 || $self->throw_error("Cannot delegate methods based on a Regexp without a type constraint (isa)", data => $handles);
774 return map { ($_ => $_) }
775 grep { /$handles/ } $self->_get_delegate_method_list;
776 }
777 elsif ($handle_type eq 'CODE') {
778 return $handles->($self, $self->_find_delegate_metaclass);
779 }
780 elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::DuckType')) {
781 return map { $_ => $_ } @{ $handles->methods };
782 }
783 elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::Role')) {
784 $handles = $handles->role;
785 }
786 else {
787 $self->throw_error("Unable to canonicalize the 'handles' option with $handles", data => $handles);
788 }
789 }
790
791 Class::MOP::load_class($handles);
792 my $role_meta = Class::MOP::class_of($handles);
793
794 (blessed $role_meta && $role_meta->isa('Moose::Meta::Role'))
795 || $self->throw_error("Unable to canonicalize the 'handles' option with $handles because its metaclass is not a Moose::Meta::Role", data => $handles);
796
797 return map { $_ => $_ }
798 map { $_->name }
799 grep { !$_->isa('Class::MOP::Method::Meta') } (
800 $role_meta->_get_local_methods,
801 $role_meta->get_required_method_list,
802 );
803}
804
805sub _get_delegate_method_list {
806 my $self = shift;
807 my $meta = $self->_find_delegate_metaclass;
808 if ($meta->isa('Class::MOP::Class')) {
809 return map { $_->name } # NOTE: !never! delegate &meta
810 grep { $_->package_name ne 'Moose::Object' && !$_->isa('Class::MOP::Method::Meta') }
811 $meta->get_all_methods;
812 }
813 elsif ($meta->isa('Moose::Meta::Role')) {
814 return $meta->get_method_list;
815 }
816 else {
817 $self->throw_error("Unable to recognize the delegate metaclass '$meta'", data => $meta);
818 }
819}
820
821sub _find_delegate_metaclass {
822 my $self = shift;
823 if (my $class = $self->_isa_metadata) {
824 unless ( Class::MOP::is_class_loaded($class) ) {
825 $self->throw_error(
826 sprintf(
827 'The %s attribute is trying to delegate to a class which has not been loaded - %s',
828 $self->name, $class
829 )
830 );
831 }
832 # we might be dealing with a non-Moose class,
833 # and need to make our own metaclass. if there's
834 # already a metaclass, it will be returned
835 return Class::MOP::Class->initialize($class);
836 }
837 elsif (my $role = $self->_does_metadata) {
838 unless ( Class::MOP::is_class_loaded($class) ) {
839 $self->throw_error(
840 sprintf(
841 'The %s attribute is trying to delegate to a role which has not been loaded - %s',
842 $self->name, $role
843 )
844 );
845 }
846
847 return Class::MOP::class_of($role);
848 }
849 else {
850 $self->throw_error("Cannot find delegate metaclass for attribute " . $self->name);
851 }
852}
853
85433437µs
# spent 281µs within Moose::Meta::Attribute::delegation_metaclass which was called 33 times, avg 9µs/call: # 23 times (188µs+0s) by Moose::Meta::Attribute::_make_delegation_method at line 864, avg 8µs/call # 10 times (93µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 172 of Moose/Meta/Attribute/Native/Trait.pm, avg 9µs/call
sub delegation_metaclass { 'Moose::Meta::Method::Delegation' }
855
856
# spent 13.4ms (1.60+11.8) within Moose::Meta::Attribute::_make_delegation_method which was called 23 times, avg 581µs/call: # 23 times (1.60ms+11.8ms) by Moose::Meta::Attribute::install_delegation at line 740, avg 581µs/call
sub _make_delegation_method {
85723127µs my ( $self, $handle_name, $method_to_call ) = @_;
858
8592349µs my @curried_arguments;
860
8612360µs ($method_to_call, @curried_arguments) = @$method_to_call
862 if 'ARRAY' eq ref($method_to_call);
863
864231.33ms9211.8ms return $self->delegation_metaclass->new(
# spent 11.2ms making 23 calls to Moose::Meta::Method::Delegation::new, avg 487µs/call # spent 228µs making 23 calls to Class::MOP::Attribute::associated_class, avg 10µs/call # spent 188µs making 23 calls to Moose::Meta::Attribute::delegation_metaclass, avg 8µs/call # spent 136µs making 23 calls to Class::MOP::Package::name, avg 6µs/call
865 name => $handle_name,
866 package_name => $self->associated_class->name,
867 attribute => $self,
868 delegate_to_method => $method_to_call,
869 curried_arguments => \@curried_arguments,
870 );
871}
872
873
# spent 2.63ms (641µs+1.99) within Moose::Meta::Attribute::_coerce_and_verify which was called 11 times, avg 240µs/call: # 11 times (641µs+1.99ms) by Moose::Meta::Attribute::initialize_instance_slot at line 483, avg 240µs/call
sub _coerce_and_verify {
8741132µs my $self = shift;
8751126µs my $val = shift;
8761124µs my $instance = shift;
877
87811194µs11111µs return $val unless $self->has_type_constraint;
# spent 111µs making 11 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 10µs/call
879
880994µs998µs $val = $self->type_constraint->coerce($val)
# spent 98µs making 9 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 11µs/call
881 if $self->should_coerce && $self->type_constraint->has_coercion;
882
883996µs91.78ms $self->verify_against_type_constraint($val, instance => $instance);
# spent 1.78ms making 9 calls to Moose::Meta::Attribute::verify_against_type_constraint, avg 198µs/call
884
8859101µs return $val;
886}
887
888
# spent 1.78ms (472µs+1.31) within Moose::Meta::Attribute::verify_against_type_constraint which was called 9 times, avg 198µs/call: # 9 times (472µs+1.31ms) by Moose::Meta::Attribute::_coerce_and_verify at line 883, avg 198µs/call
sub verify_against_type_constraint {
889926µs my $self = shift;
890921µs my $val = shift;
891
892983µs976µs return 1 if !$self->has_type_constraint;
# spent 76µs making 9 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 8µs/call
893
894997µs9102µs my $type_constraint = $self->type_constraint;
# spent 102µs making 9 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 11µs/call
895
8969170µs91.13ms $type_constraint->check($val)
# spent 1.13ms making 9 calls to Moose::Meta::TypeConstraint::check, avg 126µs/call
897 || $self->throw_error("Attribute ("
898 . $self->name
899 . ") does not pass the type constraint because: "
900 . $type_constraint->get_message($val), data => $val, @_);
901}
902
903package Moose::Meta::Attribute::Custom::Moose;
904sub register_implementation { 'Moose::Meta::Attribute' }
905
906132µs1;
907
908__END__
 
# spent 383µs within Moose::Meta::Attribute::CORE:match which was called 44 times, avg 9µs/call: # 28 times (308µs+0s) by Moose::Meta::Attribute::install_delegation at line 738, avg 11µs/call # 16 times (76µs+0s) by Moose::Meta::Attribute::_process_lazy_build_option at line 413, avg 5µs/call
sub Moose::Meta::Attribute::CORE:match; # opcode
# spent 547µs within Moose::Meta::Attribute::CORE:sort which was called 124 times, avg 4µs/call: # 124 times (547µs+0s) by Moose::Meta::Attribute::new at line 68, avg 4µs/call
sub Moose::Meta::Attribute::CORE:sort; # opcode