← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 21:45:08 2010
Reported on Wed Nov 17 22:13:47 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 10308 statements in 148ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
722249.2ms280msMoose::Meta::Attribute::::new Moose::Meta::Attribute::new
11120.4ms272msMoose::Meta::Attribute::::BEGIN@20 Moose::Meta::Attribute::BEGIN@20
894112.6ms400msMoose::Meta::Attribute::::_process_accessors Moose::Meta::Attribute::_process_accessors
723311.6ms38.0msMoose::Meta::Attribute::::_process_options Moose::Meta::Attribute::_process_options
1101110.2ms67.0msMoose::Meta::Attribute::::initialize_instance_slot Moose::Meta::Attribute::initialize_instance_slot
94338.75ms37.6msMoose::Meta::Attribute::::inline_set Moose::Meta::Attribute::inline_set
1116.70ms7.39msMoose::Meta::Attribute::::BEGIN@17 Moose::Meta::Attribute::BEGIN@17
98116.07ms30.4msMoose::Meta::Attribute::::_coerce_and_verify Moose::Meta::Attribute::_coerce_and_verify
98115.72ms21.9msMoose::Meta::Attribute::::verify_against_type_constraint Moose::Meta::Attribute::verify_against_type_constraint
98115.13ms8.30msMoose::Meta::Attribute::::_set_initial_slot_value Moose::Meta::Attribute::_set_initial_slot_value
71224.99ms3.91sMoose::Meta::Attribute::::interpolate_class_and_new Moose::Meta::Attribute::interpolate_class_and_new (recurses: max depth 1, inclusive time 20.5ms)
73324.68ms587msMoose::Meta::Attribute::::install_accessors Moose::Meta::Attribute::install_accessors
7113.50ms116msMoose::Meta::Attribute::::install_delegation Moose::Meta::Attribute::install_delegation
72113.09ms14.8msMoose::Meta::Attribute::::_process_isa_option Moose::Meta::Attribute::_process_isa_option
71112.89ms3.65sMoose::Meta::Attribute::::interpolate_class Moose::Meta::Attribute::interpolate_class (recurses: max depth 1, inclusive time 285µs)
1112.68ms3.80msMoose::Meta::Attribute::::BEGIN@18 Moose::Meta::Attribute::BEGIN@18
71111.96ms2.73msMoose::Meta::Attribute::::_check_associated_methods Moose::Meta::Attribute::_check_associated_methods
72111.59ms1.59msMoose::Meta::Attribute::::_process_is_option Moose::Meta::Attribute::_process_is_option
72111.35ms4.04msMoose::Meta::Attribute::::_process_does_option Moose::Meta::Attribute::_process_does_option
117221.23ms1.23msMoose::Meta::Attribute::::accessor_metaclass Moose::Meta::Attribute::accessor_metaclass
72111.08ms1.08msMoose::Meta::Attribute::::_process_coerce_option Moose::Meta::Attribute::_process_coerce_option
72111.04ms1.04msMoose::Meta::Attribute::::_process_required_option Moose::Meta::Attribute::_process_required_option
72111.04ms1.04msMoose::Meta::Attribute::::_process_lazy_option Moose::Meta::Attribute::_process_lazy_option
7211997µs997µsMoose::Meta::Attribute::::_process_lazy_build_option Moose::Meta::Attribute::_process_lazy_build_option
7211974µs974µsMoose::Meta::Attribute::::_process_auto_deref_option Moose::Meta::Attribute::_process_auto_deref_option
7211957µs957µsMoose::Meta::Attribute::::_process_trigger_option Moose::Meta::Attribute::_process_trigger_option
611416µs14.4msMoose::Meta::Attribute::::does Moose::Meta::Attribute::does
7211314µs314µsMoose::Meta::Attribute::::CORE:sort Moose::Meta::Attribute::CORE:sort (opcode)
2922281µs281µsMoose::Meta::Attribute::::delegation_metaclass Moose::Meta::Attribute::delegation_metaclass
1411232µs232µsMoose::Meta::Attribute::::CORE:match Moose::Meta::Attribute::CORE:match (opcode)
611126µs5.47msMoose::Meta::Attribute::::__ANON__[:40] Moose::Meta::Attribute::__ANON__[:40]
111105µs1.60msMoose::Meta::Attribute::::clone_and_inherit_options Moose::Meta::Attribute::clone_and_inherit_options
11187µs1.26msMoose::Meta::Attribute::::_make_delegation_method Moose::Meta::Attribute::_make_delegation_method
11178µs91µsMoose::Meta::Attribute::::_canonicalize_handles Moose::Meta::Attribute::_canonicalize_handles
11172µs89µsMoose::Meta::Attribute::::BEGIN@4 Moose::Meta::Attribute::BEGIN@4
11149µs88µsMoose::Meta::Attribute::::BEGIN@16 Moose::Meta::Attribute::BEGIN@16
11138µs106µsMoose::Meta::Attribute::::BEGIN@5 Moose::Meta::Attribute::BEGIN@5
11138µs219µsMoose::Meta::Attribute::::BEGIN@10 Moose::Meta::Attribute::BEGIN@10
11138µs167µsMoose::Meta::Attribute::::BEGIN@9 Moose::Meta::Attribute::BEGIN@9
11137µs38.4msMoose::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
11124µs24µsMoose::Meta::Attribute::::BEGIN@19 Moose::Meta::Attribute::BEGIN@19
11120µs20µsMoose::Meta::Attribute::::BEGIN@7 Moose::Meta::Attribute::BEGIN@7
11120µs20µsMoose::Meta::Attribute::::BEGIN@11 Moose::Meta::Attribute::BEGIN@11
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::::_weaken_value Moose::Meta::Attribute::_weaken_value
0000s0sMoose::Meta::Attribute::::clone Moose::Meta::Attribute::clone
0000s0sMoose::Meta::Attribute::::get_value Moose::Meta::Attribute::get_value
0000s0sMoose::Meta::Attribute::::illegal_options_for_inheritance Moose::Meta::Attribute::illegal_options_for_inheritance
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
43102µs2106µs
# spent 89µs (72+17) within Moose::Meta::Attribute::BEGIN@4 which was called: # once (72µs+17µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 4
use strict;
# spent 89µs making 1 call to Moose::Meta::Attribute::BEGIN@4 # spent 17µs making 1 call to strict::import
5395µs2173µs
# spent 106µs (38+67) within Moose::Meta::Attribute::BEGIN@5 which was called: # once (38µs+67µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 5
use warnings;
# spent 106µs making 1 call to Moose::Meta::Attribute::BEGIN@5 # spent 67µs making 1 call to warnings::import
6
7389µs120µs
# spent 20µs within Moose::Meta::Attribute::BEGIN@7 which was called: # once (20µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 7
use Class::MOP ();
# spent 20µs making 1 call to Moose::Meta::Attribute::BEGIN@7
83104µ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
9396µs2297µs
# spent 167µs (38+130) within Moose::Meta::Attribute::BEGIN@9 which was called: # once (38µs+130µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 9
use List::MoreUtils 'any';
# spent 167µs making 1 call to Moose::Meta::Attribute::BEGIN@9 # spent 130µs making 1 call to Exporter::import
10391µs2399µs
# spent 219µs (38+180) within Moose::Meta::Attribute::BEGIN@10 which was called: # once (38µs+180µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 10
use Try::Tiny;
# spent 219µs making 1 call to Moose::Meta::Attribute::BEGIN@10 # spent 180µs making 1 call to Exporter::import
113189µ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
1315µsour $VERSION = '1.19';
1414µsour $AUTHORITY = 'cpan:STEVAN';
15
163115µs2127µs
# spent 88µs (49+39) within Moose::Meta::Attribute::BEGIN@16 which was called: # once (49µs+39µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 16
use Moose::Deprecated;
173513µs17.39ms
# spent 7.39ms (6.70+685µs) within Moose::Meta::Attribute::BEGIN@17 which was called: # once (6.70ms+685µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 17
use Moose::Meta::Method::Accessor;
# spent 7.39ms making 1 call to Moose::Meta::Attribute::BEGIN@17
183473µs13.80ms
# spent 3.80ms (2.68+1.12) within Moose::Meta::Attribute::BEGIN@18 which was called: # once (2.68ms+1.12ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 18
use Moose::Meta::Method::Delegation;
# spent 3.80ms making 1 call to Moose::Meta::Attribute::BEGIN@18
19380µs124µs
# spent 24µs within Moose::Meta::Attribute::BEGIN@19 which was called: # once (24µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 19
use Moose::Util ();
# spent 24µs making 1 call to Moose::Meta::Attribute::BEGIN@19
203431µs1272ms
# spent 272ms (20.4+252) within Moose::Meta::Attribute::BEGIN@20 which was called: # once (20.4ms+252ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 20
use Moose::Util::TypeConstraints ();
# spent 272ms making 1 call to Moose::Meta::Attribute::BEGIN@20
213107µ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.1ms276.8ms
# spent 38.4ms (37µs+38.4) within Moose::Meta::Attribute::BEGIN@23 which was called: # once (37µs+38.4ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 23
use base 'Class::MOP::Attribute', 'Moose::Meta::Mixin::AttributeCore';
# spent 38.4ms making 1 call to Moose::Meta::Attribute::BEGIN@23 # spent 38.4ms 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
27143µs23.34ms__PACKAGE__->meta->add_attribute('traits' => (
# spent 3.26ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 81µs making 1 call to Class::MOP::Object::meta
28 reader => 'applied_traits',
29 predicate => 'has_applied_traits',
30));
31
32# we need to have a ->does method in here to
33# more easily support traits, and the introspection
34# of those traits. We extend the does check to look
35# for metatrait aliases.
36
# spent 14.4ms (416µs+14.0) within Moose::Meta::Attribute::does which was called 6 times, avg 2.40ms/call: # 6 times (416µs+14.0ms) by Moose::Meta::Attribute::interpolate_class at line 114, avg 2.40ms/call
sub does {
37636µs my ($self, $role_name) = @_;
38
# spent 5.47ms (126µs+5.34) within Moose::Meta::Attribute::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Attribute.pm:40] which was called 6 times, avg 911µs/call: # 6 times (126µs+5.34ms) by Try::Tiny::try at line 71 of Try/Tiny.pm, avg 911µs/call
my $name = try {
396127µs65.34ms Moose::Util::resolve_metatrait_alias(Attribute => $role_name)
# spent 5.34ms making 6 calls to Moose::Util::resolve_metatrait_alias, avg 890µs/call
406155µs65.93ms };
# spent 5.93ms making 6 calls to Try::Tiny::try, avg 989µs/call
41619µs return 0 if !defined($name); # failed to load class
426179µs68.05ms return $self->Moose::Object::does($name);
# spent 8.05ms making 6 calls to Moose::Object::does, avg 1.34ms/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 280ms (49.2+231) within Moose::Meta::Attribute::new which was called 72 times, avg 3.89ms/call: # 71 times (48.5ms+225ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 83, avg 3.85ms/call # once (694µs+5.82ms) by Moose::BEGIN@21 at line 20 of Moose/Meta/TypeCoercion.pm
sub new {
5672824µs my ($class, $name, %options) = @_;
57721.10ms7249.6ms $class->_process_options($name, \%options) unless $options{__hack_no_process_options}; # used from clone()... YECHKKK FIXME ICKY YUCK GROSS
# spent 23.4ms making 47 calls to Moose::Meta::Attribute::_process_options, avg 498µs/call # spent 13.2ms making 18 calls to Class::MOP::Class::__ANON__::SERIAL::1::_process_options, avg 733µs/call # spent 4.24ms making 2 calls to Class::MOP::Class::__ANON__::SERIAL::5::_process_options, avg 2.12ms/call # spent 2.37ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::8::_process_options # spent 2.12ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::15::_process_options # spent 1.79ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::11::_process_options # spent 1.77ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::19::_process_options # spent 677µs making 1 call to MooseX::Role::Parameterized::Meta::Parameter::_process_options
58
5972277µs delete $options{__hack_no_process_options};
60
61 my %attrs =
62 ( map { $_ => 1 }
63202820.7ms202820.2ms grep { defined }
# spent 20.2ms making 2028 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call
647213.3ms14430.7ms map { $_->init_arg() }
# spent 18.7ms making 25 calls to Class::MOP::Class::get_all_attributes, avg 747µs/call # spent 4.50ms making 47 calls to Class::MOP::Object::meta, avg 96µs/call # spent 4.19ms making 46 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 91µs/call # spent 1.71ms making 18 calls to Class::MOP::Class::__ANON__::SERIAL::1::meta, avg 95µs/call # spent 916µs making 1 call to Class::MOP::Class::Immutable::Moose::Meta::Class::get_all_attributes # spent 184µs making 2 calls to Class::MOP::Class::__ANON__::SERIAL::5::meta, avg 92µs/call # spent 101µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::15::meta # spent 100µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::11::meta # spent 99µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::19::meta # spent 98µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::8::meta # spent 94µs making 1 call to MooseX::Role::Parameterized::Meta::Parameter::meta
65 $class->meta()->get_all_attributes()
66 );
67
68722.26ms72314µs my @bad = sort grep { ! $attrs{$_} } keys %options;
# spent 314µs making 72 calls to Moose::Meta::Attribute::CORE:sort, avg 4µs/call
69
7072198µs if (@bad)
71 {
72 Carp::cluck "Found unknown argument(s) passed to '$name' attribute constructor in '$class': @bad";
73 }
74
75724.33ms72130ms return $class->SUPER::new($name, %options);
# spent 130ms making 72 calls to Class::MOP::Attribute::new, avg 1.80ms/call
76}
77
78
# spent 3.91s (4.99ms+3.90) within Moose::Meta::Attribute::interpolate_class_and_new which was called 71 times, avg 55.0ms/call: # 50 times (3.48ms+3.83s) by Moose::Meta::Class::_process_new_attribute at line 438 of Moose/Meta/Class.pm, avg 76.7ms/call # 21 times (1.50ms+72.0ms) by Moose::Meta::Role::Attribute::attribute_for_class at line 67 of Moose/Meta/Role/Attribute.pm, avg 3.50ms/call
sub interpolate_class_and_new {
7971862µs my ($class, $name, %args) = @_;
80
81711.24ms713.65s my ( $new_class, @traits ) = $class->interpolate_class(\%args);
# spent 3.65s making 71 calls to Moose::Meta::Attribute::interpolate_class, avg 51.4ms/call, recursion: max depth 1, sum of overlapping time 285µs
82
83712.57ms71273ms $new_class->new($name, %args, ( scalar(@traits) ? ( traits => \@traits ) : () ) );
# spent 273ms making 71 calls to Moose::Meta::Attribute::new, avg 3.85ms/call
84}
85
86
# spent 3.65s (2.89ms+3.65) within Moose::Meta::Attribute::interpolate_class which was called 71 times, avg 51.4ms/call: # 71 times (2.89ms+3.65s) by Moose::Meta::Attribute::interpolate_class_and_new at line 81, avg 51.4ms/call
sub interpolate_class {
8771272µs my ($class, $options) = @_;
88
8971160µs $class = ref($class) || $class;
90
9171331µ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
10371140µs my @traits;
104
10571227µs if (my $traits = $options->{traits}) {
106614µs my $i = 0;
107633µs while ($i < @$traits) {
108624µs my $trait = $traits->[$i++];
109611µs next if ref($trait); # options to a trait we discarded
110
111683µs63.35s $trait = Moose::Util::resolve_metatrait_alias(Attribute => $trait)
# spent 3.35s making 6 calls to Moose::Util::resolve_metatrait_alias, avg 558ms/call
112 || $trait;
113
1146153µs614.4ms next if $class->does($trait);
# spent 14.4ms making 6 calls to Moose::Meta::Attribute::does, avg 2.40ms/call
115
116694µs push @traits, $trait;
117
118 # are there options?
119642µs push @traits, $traits->[$i++]
120 if $traits->[$i] && ref($traits->[$i]);
121 }
122
123630µs if (@traits) {
1246195µs6286ms my $anon_class = Moose::Meta::Class->create_anon_class(
# spent 286ms making 6 calls to Moose::Meta::Class::create_anon_class, avg 47.6ms/call
125 superclasses => [ $class ],
126 roles => [ @traits ],
127 cache => 1,
128 );
129
1306138µs640µs $class = $anon_class->name;
# spent 40µs making 6 calls to Class::MOP::Package::name, avg 7µs/call
131 }
132 }
133
134711.27ms return ( wantarray ? ( $class, @traits ) : $class );
135}
136
137# ...
138
139# method-generating options shouldn't be overridden
140sub illegal_options_for_inheritance {
141 qw(reader writer accessor clearer predicate)
142}
143
144# NOTE/TODO
145# This method *must* be able to handle
146# Class::MOP::Attribute instances as
147# well. Yes, I know that is wrong, but
148# apparently we didn't realize it was
149# doing that and now we have some code
150# which is dependent on it. The real
151# solution of course is to push this
152# feature back up into Class::MOP::Attribute
153# but I not right now, I am too lazy.
154# However if you are reading this and
155# looking for something to do,.. please
156# be my guest.
157# - stevan
158
# spent 1.60ms (105µs+1.49) within Moose::Meta::Attribute::clone_and_inherit_options which was called: # once (105µs+1.49ms) by Moose::Meta::Class::_process_inherited_attribute at line 452 of Moose/Meta/Class.pm
sub clone_and_inherit_options {
15918µ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
168144µs124µs my @illegal_options = $self->can('illegal_options_for_inheritance')
# spent 24µs making 1 call to UNIVERSAL::can
169 ? $self->illegal_options_for_inheritance
170 : ();
171
17213µs my @found_illegal_options = grep { exists $options{$_} && exists $self->{$_} ? $_ : undef } @illegal_options;
17313µs (scalar @found_illegal_options == 0)
174 || $self->throw_error("Illegal inherited options => (" . (join ', ' => @found_illegal_options) . ")", data => \%options);
175
17613µ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
19013µ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
208133µs118µs if ($self->can('interpolate_class')) {
# spent 18µs making 1 call to UNIVERSAL::can
209 ( $options{metaclass}, my @traits ) = $self->interpolate_class(\%options);
210
211 my %seen;
212 my @all_traits = grep { $seen{$_}++ } @{ $self->applied_traits || [] }, @traits;
213 $options{traits} = \@all_traits if @all_traits;
214 }
215
216 # This method can be called on a CMOP::Attribute object, so we need to
217 # make sure we can call this method.
218134µs117µs $self->_process_lazy_build_option( $self->name, \%options )
# spent 17µs making 1 call to UNIVERSAL::can
219 if $self->can('_process_lazy_build_option');
220
221134µs11.43ms $self->clone(%options);
# spent 1.43ms making 1 call to Class::MOP::Attribute::clone
222}
223
224sub clone {
225 my ( $self, %params ) = @_;
226
227 my $class = delete $params{metaclass} || ref $self;
228
229 my ( @init, @non_init );
230
231 foreach my $attr ( grep { $_->has_value($self) } Class::MOP::class_of($self)->get_all_attributes ) {
232 push @{ $attr->has_init_arg ? \@init : \@non_init }, $attr;
233 }
234
235 my %new_params = ( ( map { $_->init_arg => $_->get_value($self) } @init ), %params );
236
237 my $name = delete $new_params{name};
238
239 my $clone = $class->new($name, %new_params, __hack_no_process_options => 1 );
240
241 foreach my $attr ( @non_init ) {
242 $attr->set_value($clone, $attr->get_value($self));
243 }
244
245 return $clone;
246}
247
248
# spent 38.0ms (11.6+26.5) within Moose::Meta::Attribute::_process_options which was called 72 times, avg 528µs/call: # 47 times (6.86ms+16.6ms) by Moose::Meta::Attribute::new at line 57, avg 498µs/call # 24 times (4.44ms+9.61ms) by Class::MOP::Method::Wrapped::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm:49] at line 48 of Class/MOP/Method/Wrapped.pm, avg 586µs/call # once (280µs+291µs) by Class::MOP::Class:::around at line 19 of MooseX/Role/Parameterized/Meta/Parameter.pm
sub _process_options {
24972309µs my ( $class, $name, $options ) = @_;
250
25172935µs721.59ms $class->_process_is_option( $name, $options );
# spent 1.59ms making 72 calls to Moose::Meta::Attribute::_process_is_option, avg 22µs/call
252721.06ms7214.8ms $class->_process_isa_option( $name, $options );
# spent 14.8ms making 72 calls to Moose::Meta::Attribute::_process_isa_option, avg 205µs/call
25372998µs724.04ms $class->_process_does_option( $name, $options );
# spent 4.04ms making 72 calls to Moose::Meta::Attribute::_process_does_option, avg 56µs/call
25472989µs721.08ms $class->_process_coerce_option( $name, $options );
# spent 1.08ms making 72 calls to Moose::Meta::Attribute::_process_coerce_option, avg 15µs/call
25572951µs72957µs $class->_process_trigger_option( $name, $options );
# spent 957µs making 72 calls to Moose::Meta::Attribute::_process_trigger_option, avg 13µs/call
25672949µs72974µs $class->_process_auto_deref_option( $name, $options );
# spent 974µs making 72 calls to Moose::Meta::Attribute::_process_auto_deref_option, avg 14µs/call
25772897µs72997µs $class->_process_lazy_build_option( $name, $options );
# spent 997µs making 72 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 14µs/call
25872928µs721.04ms $class->_process_lazy_option( $name, $options );
# spent 1.04ms making 72 calls to Moose::Meta::Attribute::_process_lazy_option, avg 14µs/call
259721.62ms721.04ms $class->_process_required_option( $name, $options );
# spent 1.04ms making 72 calls to Moose::Meta::Attribute::_process_required_option, avg 14µs/call
260}
261
262
# spent 1.59ms within Moose::Meta::Attribute::_process_is_option which was called 72 times, avg 22µs/call: # 72 times (1.59ms+0s) by Moose::Meta::Attribute::_process_options at line 251, avg 22µs/call
sub _process_is_option {
26372271µs my ( $class, $name, $options ) = @_;
264
26572542µ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
27447866µs if ( $options->{is} eq 'ro' ) {
27539101µ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};
27939207µs $options->{reader} ||= $name;
280 }
281 elsif ( $options->{is} eq 'rw' ) {
282 if ( $options->{writer} ) {
283 $options->{reader} ||= $name;
284 }
285 else {
286843µs $options->{accessor} ||= $name;
287 }
288 }
289 elsif ( $options->{is} eq 'bare' ) {
290 return;
291 # do nothing, but don't complain (later) about missing methods
292 }
293 else {
294 $class->throw_error( "I do not understand this option (is => "
295 . $options->{is}
296 . ") on attribute ($name)", data => $options->{is} );
297 }
298}
299
300
# spent 14.8ms (3.09+11.7) within Moose::Meta::Attribute::_process_isa_option which was called 72 times, avg 205µs/call: # 72 times (3.09ms+11.7ms) by Moose::Meta::Attribute::_process_options at line 252, avg 205µs/call
sub _process_isa_option {
30172314µs my ( $class, $name, $options ) = @_;
302
30372346µs return unless exists $options->{isa};
304
30562155µ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 ...
320622.49ms1064.74ms if ( blessed( $options->{isa} )
# spent 4.27ms making 44 calls to MooseX::Types::TypeDecorator::isa, avg 97µs/call # spent 468µs making 62 calls to Scalar::Util::blessed, avg 8µs/call
321 && $options->{isa}->isa('Moose::Meta::TypeConstraint') ) {
322 $options->{type_constraint} = $options->{isa};
323 }
324 else {
32518294µs186.93ms $options->{type_constraint}
# spent 6.93ms making 18 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 385µs/call
326 = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint(
327 $options->{isa} );
328 }
329}
330
331
# spent 4.04ms (1.35+2.69) within Moose::Meta::Attribute::_process_does_option which was called 72 times, avg 56µs/call: # 72 times (1.35ms+2.69ms) by Moose::Meta::Attribute::_process_options at line 253, avg 56µs/call
sub _process_does_option {
33272320µs my ( $class, $name, $options ) = @_;
333
33472834µs return unless exists $options->{does} && ! exists $options->{isa};
335
336 # allow for anon-subtypes here ...
3379317µs12355µs if ( blessed( $options->{does} )
# spent 296µs making 3 calls to MooseX::Types::TypeDecorator::isa, avg 99µs/call # spent 59µs making 9 calls to Scalar::Util::blessed, avg 7µs/call
338 && $options->{does}->isa('Moose::Meta::TypeConstraint') ) {
339 $options->{type_constraint} = $options->{does};
340 }
341 else {
342692µs62.34ms $options->{type_constraint}
# spent 2.34ms making 6 calls to Moose::Util::TypeConstraints::find_or_create_does_type_constraint, avg 389µs/call
343 = Moose::Util::TypeConstraints::find_or_create_does_type_constraint(
344 $options->{does} );
345 }
346}
347
348
# spent 1.08ms within Moose::Meta::Attribute::_process_coerce_option which was called 72 times, avg 15µs/call: # 72 times (1.08ms+0s) by Moose::Meta::Attribute::_process_options at line 254, avg 15µs/call
sub _process_coerce_option {
34972362µs my ( $class, $name, $options ) = @_;
350
35172939µs return unless $options->{coerce};
352
353 ( exists $options->{type_constraint} )
354 || $class->throw_error(
355 "You cannot have coercion without specifying a type constraint on attribute ($name)",
356 data => $options );
357
358 $class->throw_error(
359 "You cannot have a weak reference to a coerced value on attribute ($name)",
360 data => $options )
361 if $options->{weak_ref};
362
363 unless ( $options->{type_constraint}->has_coercion ) {
364 my $type = $options->{type_constraint}->name;
365
366 Moose::Deprecated::deprecated(
367 feature => 'coerce without coercion',
368 message =>
369 "You cannot coerce an attribute ($name) unless its type ($type) has a coercion"
370 );
371 }
372}
373
374
# spent 957µs within Moose::Meta::Attribute::_process_trigger_option which was called 72 times, avg 13µs/call: # 72 times (957µs+0s) by Moose::Meta::Attribute::_process_options at line 255, avg 13µs/call
sub _process_trigger_option {
37572292µs my ( $class, $name, $options ) = @_;
376
37772869µs return unless exists $options->{trigger};
378
379 ( 'CODE' eq ref $options->{trigger} )
380 || $class->throw_error("Trigger must be a CODE ref on attribute ($name)", data => $options->{trigger});
381}
382
383
# spent 974µs within Moose::Meta::Attribute::_process_auto_deref_option which was called 72 times, avg 14µs/call: # 72 times (974µs+0s) by Moose::Meta::Attribute::_process_options at line 256, avg 14µs/call
sub _process_auto_deref_option {
38472295µs my ( $class, $name, $options ) = @_;
385
38672898µs return unless $options->{auto_deref};
387
388 ( exists $options->{type_constraint} )
389 || $class->throw_error(
390 "You cannot auto-dereference without specifying a type constraint on attribute ($name)",
391 data => $options );
392
393 ( $options->{type_constraint}->is_a_type_of('ArrayRef')
394 || $options->{type_constraint}->is_a_type_of('HashRef') )
395 || $class->throw_error(
396 "You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute ($name)",
397 data => $options );
398}
399
400
# spent 997µs within Moose::Meta::Attribute::_process_lazy_build_option which was called 72 times, avg 14µs/call: # 72 times (997µs+0s) by Moose::Meta::Attribute::_process_options at line 257, avg 14µs/call
sub _process_lazy_build_option {
40172314µs my ( $class, $name, $options ) = @_;
402
40372912µs return unless $options->{lazy_build};
404
405 $class->throw_error(
406 "You can not use lazy_build and default for the same attribute ($name)",
407 data => $options )
408 if exists $options->{default};
409
410 $options->{lazy} = 1;
411 $options->{builder} ||= "_build_${name}";
412
413 if ( $name =~ /^_/ ) {
414 $options->{clearer} ||= "_clear${name}";
415 $options->{predicate} ||= "_has${name}";
416 }
417 else {
418 $options->{clearer} ||= "clear_${name}";
419 $options->{predicate} ||= "has_${name}";
420 }
421}
422
423
# spent 1.04ms within Moose::Meta::Attribute::_process_lazy_option which was called 72 times, avg 14µs/call: # 72 times (1.04ms+0s) by Moose::Meta::Attribute::_process_options at line 258, avg 14µs/call
sub _process_lazy_option {
42472300µs my ( $class, $name, $options ) = @_;
425
42672817µs return unless $options->{lazy};
427
42811136µs ( exists $options->{default} || defined $options->{builder} )
429 || $class->throw_error(
430 "You cannot have a lazy attribute ($name) without specifying a default value for it",
431 data => $options );
432}
433
434
# spent 1.04ms within Moose::Meta::Attribute::_process_required_option which was called 72 times, avg 14µs/call: # 72 times (1.04ms+0s) by Moose::Meta::Attribute::_process_options at line 259, avg 14µs/call
sub _process_required_option {
43572304µs my ( $class, $name, $options ) = @_;
436
43772940µs if (
438 $options->{required}
439 && !(
440 ( !exists $options->{init_arg} || defined $options->{init_arg} )
441 || exists $options->{default}
442 || defined $options->{builder}
443 )
444 ) {
445 $class->throw_error(
446 "You cannot have a required attribute ($name) without a default, builder, or an init_arg",
447 data => $options );
448 }
449}
450
451
# spent 67.0ms (10.2+56.8) within Moose::Meta::Attribute::initialize_instance_slot which was called 110 times, avg 609µs/call: # 110 times (10.2ms+56.8ms) by Class::MOP::Class::_construct_instance at line 603 of Class/MOP/Class.pm, avg 609µs/call
sub initialize_instance_slot {
452110474µs my ($self, $meta_instance, $instance, $params) = @_;
4531101.42ms1101.22ms my $init_arg = $self->init_arg();
# spent 1.22ms making 110 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 11µs/call
454 # try to fetch the init arg from the %params ...
455
456110200µs my $val;
457110204µs my $value_is_set;
458110592µs if ( defined($init_arg) and exists $params->{$init_arg}) {
45990238µs $val = $params->{$init_arg};
46090216µs $value_is_set = 1;
461 }
462 else {
463 # skip it if it's lazy
46420358µs20313µs return if $self->is_lazy;
# spent 313µs making 20 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 16µs/call
465 # and die if it's required and doesn't have a default value
46612207µs12147µs $self->throw_error("Attribute (" . $self->name . ") is required", object => $instance, data => $params)
# spent 147µs making 12 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 12µs/call
467 if $self->is_required && !$self->has_default && !$self->has_builder;
468
469 # if nothing was in the %params, we can use the
470 # attribute's default value (if it has one)
47112231µs16174µs if ($self->has_default) {
# spent 130µs making 12 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 11µs/call # spent 44µs making 4 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 11µs/call
472887µs8324µs $val = $self->default($instance);
# spent 324µs making 8 calls to Class::MOP::Mixin::AttributeCore::default, avg 41µs/call
473819µ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
481102220µs return unless $value_is_set;
482
483981.27ms9830.4ms $val = $self->_coerce_and_verify( $val, $instance );
# spent 30.4ms making 98 calls to Moose::Meta::Attribute::_coerce_and_verify, avg 310µs/call
484
485981.27ms9823.0ms $self->set_initial_value($instance, $val);
# spent 23.0ms making 98 calls to Class::MOP::Attribute::set_initial_value, avg 234µs/call
486
487982.25ms901.24ms if ( ref $val && $self->is_weak_ref ) {
# spent 1.24ms making 90 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 14µs/call
488 $self->_weaken_value($instance);
489 }
490}
491
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 8.30ms (5.13+3.17) within Moose::Meta::Attribute::_set_initial_slot_value which was called 98 times, avg 85µs/call: # 98 times (5.13ms+3.17ms) by Class::MOP::Attribute::set_initial_value at line 253 of Class/MOP/Attribute.pm, avg 85µs/call
sub _set_initial_slot_value {
51898401µs my ($self, $meta_instance, $instance, $value) = @_;
519
520981.93ms98597µs my $slot_name = $self->name;
# spent 597µs making 98 calls to Class::MOP::Mixin::AttributeCore::name, avg 6µs/call
521
522982.83ms1962.58ms return $meta_instance->set_slot_value($instance, $slot_name, $value)
# spent 1.54ms making 98 calls to Class::MOP::Instance::set_slot_value, avg 16µs/call # spent 1.04ms making 98 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 11µs/call
523 unless $self->has_initializer;
524
525 my $callback = sub {
526 my $val = $self->_coerce_and_verify( shift, $instance );;
527
528 $meta_instance->set_slot_value($instance, $slot_name, $val);
529 };
530
531 my $initializer = $self->initializer;
532
533 # most things will just want to set a value, so make it first arg
534 $instance->$initializer($value, $callback, $self);
535}
536
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
565sub _weaken_value {
566 my ( $self, $instance ) = @_;
567
568 my $meta_instance = Class::MOP::Class->initialize( blessed($instance) )
569 ->get_meta_instance;
570
571 $meta_instance->weaken_slot_value( $instance, $self->name );
572}
573
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
6191171.72ms
# spent 1.23ms within Moose::Meta::Attribute::accessor_metaclass which was called 117 times, avg 11µs/call: # 89 times (951µs+0s) by Class::MOP::Attribute::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Attribute.pm:342] at line 334 of Class/MOP/Attribute.pm, avg 11µs/call # 28 times (283µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 172 of Moose/Meta/Attribute/Native/Trait.pm, avg 10µs/call
sub accessor_metaclass { 'Moose::Meta::Method::Accessor' }
620
621
# spent 587ms (4.68+583) within Moose::Meta::Attribute::install_accessors which was called 73 times, avg 8.04ms/call: # 66 times (3.92ms+420ms) by Class::MOP::Class::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Class.pm:790] at line 789 of Class/MOP/Class.pm, avg 6.43ms/call # 6 times (681µs+155ms) by Class::MOP::Method::Wrapped::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm:43] at line 33 of Class/MOP/Method/Wrapped.pm, avg 26.0ms/call # once (75µs+6.59ms) by Class::MOP::Class::_inline_accessors at line 1305 of Class/MOP/Class.pm
sub install_accessors {
62273220µs my $self = shift;
623731.97ms73465ms $self->SUPER::install_accessors(@_);
# spent 465ms making 73 calls to Class::MOP::Attribute::install_accessors, avg 6.37ms/call
624731.35ms80117ms $self->install_delegation if $self->has_handles;
# spent 116ms making 7 calls to Moose::Meta::Attribute::install_delegation, avg 16.6ms/call # spent 1.44ms making 73 calls to Moose::Meta::Mixin::AttributeCore::has_handles, avg 20µs/call
62573936µs return;
626}
627
628
# spent 2.73ms (1.96+775µs) within Moose::Meta::Attribute::_check_associated_methods which was called 71 times, avg 38µs/call: # 71 times (1.96ms+775µs) by Moose::Meta::Class::add_attribute at line 307 of Moose/Meta/Class.pm, avg 38µs/call
sub _check_associated_methods {
62971242µs my $self = shift;
630711.75ms71775µs unless (
# spent 775µs making 71 calls to Class::MOP::Attribute::associated_methods, avg 11µs/call
631 @{ $self->associated_methods }
632 || ($self->_is_metadata || '') eq 'bare'
633 ) {
634 Carp::cluck(
635 'Attribute (' . $self->name . ') of class '
636 . $self->associated_class->name
637 . ' has no associated methods'
638 . ' (did you mean to provide an "is" argument?)'
639 . "\n"
640 )
641 }
642}
643
644
# spent 400ms (12.6+388) within Moose::Meta::Attribute::_process_accessors which was called 89 times, avg 4.50ms/call: # 65 times (9.22ms+287ms) by Class::MOP::Attribute::install_accessors at line 360 of Class/MOP/Attribute.pm, avg 4.56ms/call # 9 times (1.32ms+34.6ms) by Class::MOP::Attribute::install_accessors at line 364 of Class/MOP/Attribute.pm, avg 3.99ms/call # 8 times (1.07ms+51.9ms) by Class::MOP::Attribute::install_accessors at line 356 of Class/MOP/Attribute.pm, avg 6.62ms/call # 7 times (993µs+14.2ms) by Class::MOP::Attribute::install_accessors at line 368 of Class/MOP/Attribute.pm, avg 2.17ms/call
sub _process_accessors {
64589263µs my $self = shift;
64689412µs my ($type, $accessor, $generate_as_inline_methods) = @_;
647
64889266µs $accessor = ( keys %$accessor )[0] if ( ref($accessor) || '' ) eq 'HASH';
649891.87ms17829.7ms my $method = $self->associated_class->get_method($accessor);
# spent 29.0ms making 89 calls to Class::MOP::Mixin::HasMethods::get_method, avg 325µs/call # spent 757µs making 89 calls to Class::MOP::Attribute::associated_class, avg 9µs/call
650
65189265µs430µs if ( $method
# spent 12µs making 1 call to Class::MOP::Method::Accessor::associated_attribute # spent 10µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call # spent 8µs making 1 call to UNIVERSAL::isa
652 && $method->isa('Class::MOP::Method::Accessor')
653 && $method->associated_attribute->name ne $self->name ) {
654
655 my $other_attr_name = $method->associated_attribute->name;
656 my $name = $self->name;
657
658 Carp::cluck(
659 "You are overwriting an accessor ($accessor) for the $other_attr_name attribute"
660 . " with a new accessor method for the $name attribute" );
661 }
662
66389226µ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
675894.11ms35433.0ms if ( !$self->associated_class->has_method($accessor)
# spent 17.4ms making 89 calls to Class::MOP::Mixin::HasMethods::has_method, avg 196µs/call # spent 13.9ms making 88 calls to Class::MOP::Package::has_package_symbol, avg 158µs/call # spent 1.68ms making 177 calls to Class::MOP::Attribute::associated_class, avg 10µs/call
676 && $self->associated_class->has_package_symbol( '&' . $accessor ) ) {
677
678 Carp::cluck(
679 "You are overwriting a locally defined function ($accessor) with "
680 . "an accessor" );
681 }
682
683893.52ms89325ms $self->SUPER::_process_accessors(@_);
# spent 325ms making 89 calls to Class::MOP::Attribute::_process_accessors, avg 3.65ms/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 37.6ms (8.75+28.9) within Moose::Meta::Attribute::inline_set which was called 94 times, avg 400µs/call: # 64 times (5.72ms+6.88ms) by Moose::Meta::Method::Constructor::_generate_slot_assignment at line 302 of Moose/Meta/Method/Constructor.pm, avg 197µs/call # 28 times (2.67ms+21.2ms) by Moose::Meta::Method::Accessor::_inline_store at line 248 of Moose/Meta/Method/Accessor.pm, avg 852µs/call # 2 times (367µs+823µs) by Class::MOP::Method::Constructor::_generate_slot_initializer at line 145 of Class/MOP/Method/Constructor.pm, avg 595µs/call
sub inline_set {
69494316µs my $self = shift;
69594373µs my ( $instance, $value ) = @_;
696
697941.95ms18820.3ms my $mi = $self->associated_class->get_meta_instance;
# spent 19.3ms making 93 calls to Class::MOP::Class::get_meta_instance, avg 208µs/call # spent 865µs making 94 calls to Class::MOP::Attribute::associated_class, avg 9µs/call # spent 83µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance
698
699942.21ms1886.87ms my $code
# spent 4.57ms making 94 calls to Class::MOP::Instance::inline_set_slot_value, avg 49µs/call # spent 2.30ms making 94 calls to Class::MOP::Attribute::slots, avg 24µs/call
700 = $mi->inline_set_slot_value( $instance, $self->slots, $value ) . ";";
701941.39ms981.75ms $code
# spent 1.61ms making 94 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 17µs/call # spent 89µs making 2 calls to Class::MOP::Instance::inline_weaken_slot_value, avg 44µs/call # spent 43µs making 2 calls to Class::MOP::Attribute::slots, avg 21µs/call
702 .= $mi->inline_weaken_slot_value( $instance, $self->slots, $value )
703 . " if ref $value;"
704 if $self->is_weak_ref;
705
706941.33ms return $code;
707}
708
709
# spent 116ms (3.50+112) within Moose::Meta::Attribute::install_delegation which was called 7 times, avg 16.6ms/call: # 7 times (3.50ms+112ms) by Moose::Meta::Attribute::install_accessors at line 624, avg 16.6ms/call
sub install_delegation {
710725µ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
7177128µs7939µs my %handles = $self->_canonicalize_handles;
718
719
720 # install the delegation ...
721795µs780µs my $associated_class = $self->associated_class;
# spent 80µs making 7 calls to Class::MOP::Attribute::associated_class, avg 11µs/call
7227183µs foreach my $handle (keys %handles) {
7231555µs my $method_to_call = $handles{$handle};
72415327µs15103µs my $class_name = $associated_class->name;
# spent 103µs making 15 calls to Class::MOP::Package::name, avg 7µs/call
7251564µs my $name = "${class_name}::${handle}";
726
72715194µs154.83ms (!$associated_class->has_method($handle))
# spent 4.83ms making 15 calls to Class::MOP::Mixin::HasMethods::has_method, avg 322µs/call
728 || $self->throw_error("You cannot overwrite a locally defined method ($handle) with a delegation", method_name => $handle);
729
730 # NOTE:
731 # handles is not allowed to delegate
732 # any of these methods, as they will
733 # override the ones in your class, which
734 # is almost certainly not what you want.
735
736 # FIXME warn when $handle was explicitly specified, but not if the source is a regex or something
737 #cluck("Not delegating method '$handle' because it is a core method") and
738151.29ms43683µs next if $class_name->isa("Moose::Object") and $handle =~ /^BUILD|DEMOLISH$/ || Moose::Object->can($handle);
# spent 279µs making 14 calls to UNIVERSAL::can, avg 20µs/call # spent 232µs making 14 calls to Moose::Meta::Attribute::CORE:match, avg 17µs/call # spent 172µs making 15 calls to UNIVERSAL::isa, avg 11µs/call
739
74015262µs1597.3ms my $method = $self->_make_delegation_method($handle, $method_to_call);
# spent 27.9ms making 4 calls to Class::MOP::Class::__ANON__::SERIAL::5::_make_delegation_method, avg 6.98ms/call # spent 22.2ms making 3 calls to Class::MOP::Class::__ANON__::SERIAL::15::_make_delegation_method, avg 7.41ms/call # spent 17.3ms making 3 calls to Class::MOP::Class::__ANON__::SERIAL::19::_make_delegation_method, avg 5.78ms/call # spent 15.7ms making 2 calls to Class::MOP::Class::__ANON__::SERIAL::11::_make_delegation_method, avg 7.83ms/call # spent 12.9ms making 2 calls to Class::MOP::Class::__ANON__::SERIAL::8::_make_delegation_method, avg 6.43ms/call # spent 1.26ms making 1 call to Moose::Meta::Attribute::_make_delegation_method
741
742151.05ms458.28ms $self->associated_class->add_method($method->name, $method);
# spent 7.96ms making 15 calls to Class::MOP::Mixin::HasMethods::add_method, avg 531µs/call # spent 212µs making 15 calls to Class::MOP::Attribute::associated_class, avg 14µs/call # spent 108µs making 15 calls to Class::MOP::Method::name, avg 7µs/call
74315362µs15265µs $self->associate_method($method);
# spent 265µs making 15 calls to Class::MOP::Attribute::associate_method, avg 18µ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 91µs (78+13) within Moose::Meta::Attribute::_canonicalize_handles which was called: # once (78µs+13µs) by Moose::Meta::Attribute::install_delegation at line 717
sub _canonicalize_handles {
76213µs my $self = shift;
763142µs113µs my $handles = $self->handles;
# spent 13µs making 1 call to Moose::Meta::Mixin::AttributeCore::handles
76414µs if (my $handle_type = ref($handles)) {
765126µ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
85429392µs
# spent 281µs within Moose::Meta::Attribute::delegation_metaclass which was called 29 times, avg 10µs/call: # 28 times (274µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 172 of Moose/Meta/Attribute/Native/Trait.pm, avg 10µs/call # once (8µs+0s) by Moose::Meta::Attribute::_make_delegation_method at line 864
sub delegation_metaclass { 'Moose::Meta::Method::Delegation' }
855
856
# spent 1.26ms (87µs+1.17) within Moose::Meta::Attribute::_make_delegation_method which was called: # once (87µs+1.17ms) by Moose::Meta::Attribute::install_delegation at line 740
sub _make_delegation_method {
85715µs my ( $self, $handle_name, $method_to_call ) = @_;
858
85912µs my @curried_arguments;
860
86112µs ($method_to_call, @curried_arguments) = @$method_to_call
862 if 'ARRAY' eq ref($method_to_call);
863
864181µs41.17ms return $self->delegation_metaclass->new(
# spent 1.15ms making 1 call to Moose::Meta::Method::Delegation::new # spent 10µs making 1 call to Class::MOP::Attribute::associated_class # spent 8µs making 1 call to Moose::Meta::Attribute::delegation_metaclass # spent 6µs making 1 call to Class::MOP::Package::name
865 name => $handle_name,
866 package_name => $self->associated_class->name,
867 attribute => $self,
868 delegate_to_method => $method_to_call,
869 curried_arguments => \@curried_arguments,
870 );
871}
872
873
# spent 30.4ms (6.07+24.3) within Moose::Meta::Attribute::_coerce_and_verify which was called 98 times, avg 310µs/call: # 98 times (6.07ms+24.3ms) by Moose::Meta::Attribute::initialize_instance_slot at line 483, avg 310µs/call
sub _coerce_and_verify {
87498295µs my $self = shift;
87598210µs my $val = shift;
87698207µs my $instance = shift;
877
878981.18ms981.09ms return $val unless $self->has_type_constraint;
# spent 1.09ms making 98 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 11µs/call
879
880981.21ms981.32ms $val = $self->type_constraint->coerce($val)
# spent 1.32ms making 98 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 13µs/call
881 if $self->should_coerce && $self->type_constraint->has_coercion;
882
883981.12ms9821.9ms $self->verify_against_type_constraint($val, instance => $instance);
# spent 21.9ms making 98 calls to Moose::Meta::Attribute::verify_against_type_constraint, avg 223µs/call
884
885981.11ms return $val;
886}
887
888
# spent 21.9ms (5.72+16.2) within Moose::Meta::Attribute::verify_against_type_constraint which was called 98 times, avg 223µs/call: # 98 times (5.72ms+16.2ms) by Moose::Meta::Attribute::_coerce_and_verify at line 883, avg 223µs/call
sub verify_against_type_constraint {
88998362µs my $self = shift;
89098229µs my $val = shift;
891
89298928µs98852µs return 1 if !$self->has_type_constraint;
# spent 852µs making 98 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 9µs/call
893
894981.14ms981.27ms my $type_constraint = $self->type_constraint;
# spent 1.27ms making 98 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 13µs/call
895
896982.25ms9814.1ms $type_constraint->check($val)
# spent 12.0ms making 92 calls to Moose::Meta::TypeConstraint::check, avg 131µs/call # spent 2.05ms making 6 calls to MooseX::Types::TypeDecorator::AUTOLOAD, avg 342µs/call
897 || $self->throw_error("Attribute ("
898 . $self->name
899 . ") does not pass the type constraint because: "
900 . $type_constraint->get_message($val), data => $val, @_);
901}
902
903package Moose::Meta::Attribute::Custom::Moose;
904sub register_implementation { 'Moose::Meta::Attribute' }
905
906131µs1;
907
908__END__
 
# spent 232µs within Moose::Meta::Attribute::CORE:match which was called 14 times, avg 17µs/call: # 14 times (232µs+0s) by Moose::Meta::Attribute::install_delegation at line 738, avg 17µs/call
sub Moose::Meta::Attribute::CORE:match; # opcode
# spent 314µs within Moose::Meta::Attribute::CORE:sort which was called 72 times, avg 4µs/call: # 72 times (314µs+0s) by Moose::Meta::Attribute::new at line 68, avg 4µs/call
sub Moose::Meta::Attribute::CORE:sort; # opcode