← Index
NYTProf Performance Profile   « line view »
For /home/ss5/perl5/perlbrew/perls/perl-5.22.0/bin/benchmarkanything-storage
  Run on Mon Jan 29 16:55:34 2018
Reported on Mon Jan 29 16:57:06 2018

Filename/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Class/MOP/Attribute.pm
StatementsExecuted 13694 statements in 24.4ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
405225.50ms17.8msClass::MOP::Attribute::::_inline_instance_setClass::MOP::Attribute::_inline_instance_set
193114.54ms34.0msClass::MOP::Attribute::::try {...} Class::MOP::Attribute::try {...}
263623.52ms42.7msClass::MOP::Attribute::::_process_accessorsClass::MOP::Attribute::_process_accessors
404533.32ms21.1msClass::MOP::Attribute::::_inline_set_valueClass::MOP::Attribute::_inline_set_value
211322.98ms70.3msClass::MOP::Attribute::::install_accessorsClass::MOP::Attribute::install_accessors
263211.47ms1.69msClass::MOP::Attribute::::_accessor_descriptionClass::MOP::Attribute::_accessor_description
135544977µs2.12msClass::MOP::Attribute::::newClass::MOP::Attribute::new
18511713µs1.33msClass::MOP::Attribute::::_set_initial_slot_valueClass::MOP::Attribute::_set_initial_slot_value
13111652µs1.01msClass::MOP::Attribute::::_newClass::MOP::Attribute::_new
24511559µs2.03msClass::MOP::Attribute::::initialize_instance_slotClass::MOP::Attribute::initialize_instance_slot
13511529µs680µsClass::MOP::Attribute::::attach_to_classClass::MOP::Attribute::attach_to_class
42611479µs580µsClass::MOP::Attribute::::slotsClass::MOP::Attribute::slots
8343439µs1.78msClass::MOP::Attribute::::_inline_instance_getClass::MOP::Attribute::_inline_instance_get
26532298µs298µsClass::MOP::Attribute::::associate_methodClass::MOP::Attribute::associate_method
7521146µs1.80msClass::MOP::Attribute::::_inline_get_valueClass::MOP::Attribute::_inline_get_value
25721104µs104µsClass::MOP::Attribute::::accessor_metaclassClass::MOP::Attribute::accessor_metaclass
173299µs248µsClass::MOP::Attribute::::_inline_instance_hasClass::MOP::Attribute::_inline_instance_has
121164µs175µsClass::MOP::Attribute::::get_raw_valueClass::MOP::Attribute::get_raw_value
121164µs174µsClass::MOP::Attribute::::has_valueClass::MOP::Attribute::has_value
151133µs197µsClass::MOP::Attribute::::_inline_has_valueClass::MOP::Attribute::_inline_has_value
121120µs195µsClass::MOP::Attribute::::get_valueClass::MOP::Attribute::get_value
11111µs14µsClass::MOP::Attribute::::BEGIN@4Class::MOP::Attribute::BEGIN@4
21110µs11µsClass::MOP::Attribute::::get_read_methodClass::MOP::Attribute::get_read_method
1118µs15µsClass::MOP::Attribute::::BEGIN@5Class::MOP::Attribute::BEGIN@5
1115µs39µsClass::MOP::Attribute::::BEGIN@9Class::MOP::Attribute::BEGIN@9
1115µs31µsClass::MOP::Attribute::::BEGIN@13Class::MOP::Attribute::BEGIN@13
1115µs22µsClass::MOP::Attribute::::BEGIN@10Class::MOP::Attribute::BEGIN@10
1114µs23µsClass::MOP::Attribute::::BEGIN@11Class::MOP::Attribute::BEGIN@11
1113µs3µsClass::MOP::Attribute::::BEGIN@7Class::MOP::Attribute::BEGIN@7
0000s0sClass::MOP::Attribute::::__ANON__[:181]Class::MOP::Attribute::__ANON__[:181]
0000s0sClass::MOP::Attribute::::__ANON__[:210]Class::MOP::Attribute::__ANON__[:210]
0000s0sClass::MOP::Attribute::::__ANON__[:230]Class::MOP::Attribute::__ANON__[:230]
0000s0sClass::MOP::Attribute::::__ANON__[:416]Class::MOP::Attribute::__ANON__[:416]
0000s0sClass::MOP::Attribute::::__ANON__[:423]Class::MOP::Attribute::__ANON__[:423]
0000s0sClass::MOP::Attribute::::__ANON__[:478]Class::MOP::Attribute::__ANON__[:478]
0000s0sClass::MOP::Attribute::::_inline_clear_valueClass::MOP::Attribute::_inline_clear_value
0000s0sClass::MOP::Attribute::::_inline_instance_clearClass::MOP::Attribute::_inline_instance_clear
0000s0sClass::MOP::Attribute::::_make_initializer_writer_callbackClass::MOP::Attribute::_make_initializer_writer_callback
0000s0sClass::MOP::Attribute::::catch {...} Class::MOP::Attribute::catch {...}
0000s0sClass::MOP::Attribute::::clear_valueClass::MOP::Attribute::clear_value
0000s0sClass::MOP::Attribute::::detach_from_classClass::MOP::Attribute::detach_from_class
0000s0sClass::MOP::Attribute::::get_read_method_refClass::MOP::Attribute::get_read_method_ref
0000s0sClass::MOP::Attribute::::get_write_methodClass::MOP::Attribute::get_write_method
0000s0sClass::MOP::Attribute::::get_write_method_refClass::MOP::Attribute::get_write_method_ref
0000s0sClass::MOP::Attribute::::remove_accessorsClass::MOP::Attribute::remove_accessors
0000s0sClass::MOP::Attribute::::set_initial_valueClass::MOP::Attribute::set_initial_value
0000s0sClass::MOP::Attribute::::set_raw_valueClass::MOP::Attribute::set_raw_value
0000s0sClass::MOP::Attribute::::set_valueClass::MOP::Attribute::set_value
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Class::MOP::Attribute;
21300nsour $VERSION = '2.1605';
3
4219µs216µs
# spent 14µs (11+3) within Class::MOP::Attribute::BEGIN@4 which was called: # once (11µs+3µs) by Class::MOP::BEGIN@19 at line 4
use strict;
# spent 14µs making 1 call to Class::MOP::Attribute::BEGIN@4 # spent 3µs making 1 call to strict::import
5215µs223µs
# spent 15µs (8+8) within Class::MOP::Attribute::BEGIN@5 which was called: # once (8µs+8µs) by Class::MOP::BEGIN@19 at line 5
use warnings;
# spent 15µs making 1 call to Class::MOP::Attribute::BEGIN@5 # spent 8µs making 1 call to warnings::import
6
7213µs13µs
# spent 3µs within Class::MOP::Attribute::BEGIN@7 which was called: # once (3µs+0s) by Class::MOP::BEGIN@19 at line 7
use Class::MOP::Method::Accessor;
# spent 3µs making 1 call to Class::MOP::Attribute::BEGIN@7
8
9217µs272µs
# spent 39µs (5+34) within Class::MOP::Attribute::BEGIN@9 which was called: # once (5µs+34µs) by Class::MOP::BEGIN@19 at line 9
use Carp 'confess';
# spent 39µs making 1 call to Class::MOP::Attribute::BEGIN@9 # spent 34µs making 1 call to Exporter::import
10213µs239µs
# spent 22µs (5+17) within Class::MOP::Attribute::BEGIN@10 which was called: # once (5µs+17µs) by Class::MOP::BEGIN@19 at line 10
use Scalar::Util 'blessed', 'weaken';
# spent 22µs making 1 call to Class::MOP::Attribute::BEGIN@10 # spent 17µs making 1 call to Exporter::import
11215µs242µs
# spent 23µs (4+19) within Class::MOP::Attribute::BEGIN@11 which was called: # once (4µs+19µs) by Class::MOP::BEGIN@19 at line 11
use Try::Tiny;
# spent 23µs making 1 call to Class::MOP::Attribute::BEGIN@11 # spent 19µs making 1 call to Exporter::import
12
1321.14ms258µs
# spent 31µs (5+26) within Class::MOP::Attribute::BEGIN@13 which was called: # once (5µs+26µs) by Class::MOP::BEGIN@19 at line 13
use parent 'Class::MOP::Object', 'Class::MOP::Mixin::AttributeCore';
# spent 31µs making 1 call to Class::MOP::Attribute::BEGIN@13 # spent 26µs making 1 call to parent::import
14
15# NOTE: (meta-circularity)
16# This method will be replaced in the
17# boostrap section of Class::MOP, by
18# a new version which uses the
19# &Class::MOP::Class::construct_instance
20# method to build an attribute meta-object
21# which itself is described with attribute
22# meta-objects.
23# - Ain't meta-circularity grand? :)
24
# spent 2.12ms (977µs+1.14) within Class::MOP::Attribute::new which was called 135 times, avg 16µs/call: # 74 times (550µs+408µs) by Class::MOP::Mixin::HasAttributes::add_attribute at line 14 of Class/MOP/Mixin/HasAttributes.pm, avg 13µs/call # 5 times (55µs+436µs) by Moose::Meta::Attribute::new at line 84 of Moose/Meta/Attribute.pm, avg 98µs/call # 5 times (27µs+27µs) by Moose::Exporter::BEGIN@8 at line 646 of Class/MOP.pm, avg 11µs/call # once (21µs+15µs) by Moose::Exporter::BEGIN@8 at line 140 of Class/MOP.pm # once (15µs+16µs) by Moose::Exporter::BEGIN@8 at line 407 of Class/MOP.pm # once (10µs+8µs) by Moose::Exporter::BEGIN@8 at line 500 of Class/MOP.pm # once (9µs+8µs) by Moose::Exporter::BEGIN@8 at line 212 of Class/MOP.pm # once (9µs+7µs) by Moose::Exporter::BEGIN@8 at line 618 of Class/MOP.pm # once (9µs+6µs) by Moose::Exporter::BEGIN@8 at line 244 of Class/MOP.pm # once (8µs+7µs) by Moose::Exporter::BEGIN@8 at line 470 of Class/MOP.pm # once (8µs+6µs) by Moose::Exporter::BEGIN@8 at line 185 of Class/MOP.pm # once (6µs+9µs) by Moose::Exporter::BEGIN@8 at line 481 of Class/MOP.pm # once (8µs+6µs) by Moose::Exporter::BEGIN@8 at line 271 of Class/MOP.pm # once (8µs+5µs) by Moose::Exporter::BEGIN@8 at line 328 of Class/MOP.pm # once (8µs+6µs) by Moose::Exporter::BEGIN@8 at line 308 of Class/MOP.pm # once (5µs+8µs) by Moose::Exporter::BEGIN@8 at line 438 of Class/MOP.pm # once (8µs+5µs) by Moose::Exporter::BEGIN@8 at line 144 of Class/MOP.pm # once (7µs+5µs) by Moose::Exporter::BEGIN@8 at line 291 of Class/MOP.pm # once (9µs+4µs) by Moose::Exporter::BEGIN@8 at line 511 of Class/MOP.pm # once (6µs+7µs) by Moose::Exporter::BEGIN@8 at line 454 of Class/MOP.pm # once (7µs+6µs) by Moose::Exporter::BEGIN@8 at line 564 of Class/MOP.pm # once (5µs+7µs) by Moose::Exporter::BEGIN@8 at line 583 of Class/MOP.pm # once (5µs+7µs) by Moose::Exporter::BEGIN@8 at line 525 of Class/MOP.pm # once (6µs+6µs) by Moose::Exporter::BEGIN@8 at line 189 of Class/MOP.pm # once (7µs+4µs) by Moose::Exporter::BEGIN@8 at line 157 of Class/MOP.pm # once (6µs+5µs) by Moose::Exporter::BEGIN@8 at line 555 of Class/MOP.pm # once (6µs+5µs) by Moose::Exporter::BEGIN@8 at line 622 of Class/MOP.pm # once (6µs+5µs) by Moose::Exporter::BEGIN@8 at line 415 of Class/MOP.pm # once (6µs+4µs) by Moose::BEGIN@24 at line 38 of Moose/Meta/Class.pm # once (7µs+4µs) by Moose::Exporter::BEGIN@8 at line 312 of Class/MOP.pm # once (6µs+4µs) by Moose::Exporter::BEGIN@8 at line 635 of Class/MOP.pm # once (6µs+4µs) by Moose::Exporter::BEGIN@8 at line 219 of Class/MOP.pm # once (6µs+4µs) by Moose::Exporter::BEGIN@8 at line 446 of Class/MOP.pm # once (6µs+4µs) by Moose::Exporter::BEGIN@8 at line 348 of Class/MOP.pm # once (6µs+4µs) by Moose::Exporter::BEGIN@8 at line 338 of Class/MOP.pm # once (6µs+4µs) by Moose::Exporter::BEGIN@8 at line 399 of Class/MOP.pm # once (5µs+4µs) by Moose::Exporter::BEGIN@8 at line 422 of Class/MOP.pm # once (6µs+3µs) by Moose::Exporter::BEGIN@8 at line 539 of Class/MOP.pm # once (6µs+4µs) by Moose::Exporter::BEGIN@8 at line 593 of Class/MOP.pm # once (6µs+4µs) by Moose::Exporter::BEGIN@8 at line 462 of Class/MOP.pm # once (5µs+4µs) by Moose::Exporter::BEGIN@8 at line 602 of Class/MOP.pm # once (5µs+4µs) by Moose::Exporter::BEGIN@8 at line 391 of Class/MOP.pm # once (5µs+4µs) by Moose::Exporter::BEGIN@8 at line 572 of Class/MOP.pm # once (5µs+4µs) by Moose::Exporter::BEGIN@8 at line 430 of Class/MOP.pm # once (5µs+4µs) by Moose::Exporter::BEGIN@8 at line 679 of Class/MOP.pm # once (5µs+4µs) by Moose::Exporter::BEGIN@8 at line 376 of Class/MOP.pm # once (5µs+4µs) by Moose::Exporter::BEGIN@8 at line 710 of Class/MOP.pm # once (5µs+4µs) by Moose::Exporter::BEGIN@8 at line 518 of Class/MOP.pm # once (5µs+3µs) by Moose::Exporter::BEGIN@8 at line 686 of Class/MOP.pm # once (5µs+3µs) by Moose::Exporter::BEGIN@8 at line 696 of Class/MOP.pm # once (5µs+4µs) by Moose::Exporter::BEGIN@8 at line 661 of Class/MOP.pm # once (5µs+3µs) by Moose::Exporter::BEGIN@8 at line 532 of Class/MOP.pm # once (5µs+3µs) by Moose::Exporter::BEGIN@8 at line 359 of Class/MOP.pm # once (4µs+3µs) by Moose::Exporter::BEGIN@8 at line 703 of Class/MOP.pm
sub new {
25135105µs my ( $class, @args ) = @_;
26
27135107µs unshift @args, "name" if @args % 2 == 1;
28135149µs my %options = @args;
29
3013539µs my $name = $options{name};
31
3213521µs (defined $name)
33 || $class->_throw_exception( MOPAttributeNewNeedsAttributeName => class => $class,
34 params => \%options
35 );
36
37 $options{init_arg} = $name
3813556µs if not exists $options{init_arg};
3913541µs if(exists $options{builder}){
40 $class->_throw_exception( BuilderMustBeAMethodName => class => $class,
41 params => \%options
42 )
43 if ref $options{builder} || !(defined $options{builder});
44 $class->_throw_exception( BothBuilderAndDefaultAreNotAllowed => class => $class,
45 params => \%options
46 )
47 if exists $options{default};
48 } else {
49 ($class->is_default_a_coderef(\%options))
50 || $class->_throw_exception( ReferencesAreNotAllowedAsDefault => class => $class,
51 params => \%options,
52 attribute_name => $options{name}
53 )
5413585µs3062µs if exists $options{default} && ref $options{default};
# spent 62µs making 30 calls to Class::MOP::Mixin::AttributeCore::is_default_a_coderef, avg 2µs/call
55 }
56
5713539µs if( $options{required} and not( defined($options{builder}) || defined($options{init_arg}) || exists $options{default} ) ) {
58 $class->_throw_exception( RequiredAttributeLacksInitialization => class => $class,
59 params => \%options
60 );
61 }
62
63135335µs1351.08ms $class->_new(\%options);
# spent 1.01ms making 131 calls to Class::MOP::Attribute::_new, avg 8µs/call # spent 65µs making 4 calls to Moose::Meta::Attribute::_new, avg 16µs/call
64}
65
66
# spent 1.01ms (652µs+361µs) within Class::MOP::Attribute::_new which was called 131 times, avg 8µs/call: # 131 times (652µs+361µs) by Class::MOP::Attribute::new at line 63, avg 8µs/call
sub _new {
6713121µs my $class = shift;
68
6913137µs2361µs return Class::MOP::Class->initialize($class)->new_object(@_)
# spent 358µs making 1 call to Class::MOP::Class::new_object # spent 2µs making 1 call to Class::MOP::Class::initialize
70 if $class ne __PACKAGE__;
71
7213042µs my $options = @_ == 1 ? $_[0] : {@_};
73
74 bless {
75 'name' => $options->{name},
76 'accessor' => $options->{accessor},
77 'reader' => $options->{reader},
78 'writer' => $options->{writer},
79 'predicate' => $options->{predicate},
80 'clearer' => $options->{clearer},
81 'builder' => $options->{builder},
82 'init_arg' => $options->{init_arg},
83 exists $options->{default}
84 ? ('default' => $options->{default})
85 : (),
86 'initializer' => $options->{initializer},
87 'definition_context' => $options->{definition_context},
88 # keep a weakened link to the
89 # class we are associated with
90130627µs 'associated_class' => undef,
91 # and a list of the methods
92 # associated with this attr
93 'associated_methods' => [],
94 # this let's us keep track of
95 # our order inside the associated
96 # class
97 'insertion_order' => undef,
98 }, $class;
99}
100
101# NOTE:
102# this is a primitive (and kludgy) clone operation
103# for now, it will be replaced in the Class::MOP
104# bootstrap with a proper one, however we know
105# that this one will work fine for now.
106sub clone {
107 my $self = shift;
108 my %options = @_;
109 (blessed($self))
110 || confess "Can only clone an instance";
111 # this implementation is overwritten by the bootstrap process,
112 # so this exception will never trigger. If it ever does occur,
113 # it indicates a gigantic problem with the most internal parts
114 # of Moose, so we wouldn't want a Moose-based exception object anyway
115
116 return bless { %{$self}, %options } => ref($self);
117}
118
119
# spent 2.03ms (559µs+1.47) within Class::MOP::Attribute::initialize_instance_slot which was called 245 times, avg 8µs/call: # 245 times (559µs+1.47ms) by Class::MOP::Class::_construct_instance at line 526 of Class/MOP/Class.pm, avg 8µs/call
sub initialize_instance_slot {
12024542µs my ($self, $meta_instance, $instance, $params) = @_;
121245102µs my $init_arg = $self->{'init_arg'};
122
123 # try to fetch the init arg from the %params ...
124
125 # if nothing was in the %params, we can use the
126 # attribute's default value (if it has one)
127245428µs2151.47ms if(defined $init_arg and exists $params->{$init_arg}){
# spent 1.33ms making 185 calls to Class::MOP::Attribute::_set_initial_slot_value, avg 7µs/call # spent 133µs making 30 calls to Class::MOP::Mixin::AttributeCore::default, avg 4µs/call
128 $self->_set_initial_slot_value(
129 $meta_instance,
130 $instance,
131 $params->{$init_arg},
132 );
133 }
134 elsif (exists $self->{'default'}) {
135 $self->_set_initial_slot_value(
136 $meta_instance,
137 $instance,
138 $self->default($instance),
139 );
140 }
141 elsif (defined( my $builder = $self->{'builder'})) {
142 if ($builder = $instance->can($builder)) {
143 $self->_set_initial_slot_value(
144 $meta_instance,
145 $instance,
146 $instance->$builder,
147 );
148 }
149 else {
150 $self->_throw_exception( BuilderMethodNotSupportedForAttribute => attribute => $self,
151 instance => $instance
152 );
153 }
154 }
155}
156
157
# spent 1.33ms (713µs+622µs) within Class::MOP::Attribute::_set_initial_slot_value which was called 185 times, avg 7µs/call: # 185 times (713µs+622µs) by Class::MOP::Attribute::initialize_instance_slot at line 127, avg 7µs/call
sub _set_initial_slot_value {
15818537µs my ($self, $meta_instance, $instance, $value) = @_;
159
160185249µs18547µs my $slot_name = $self->name;
# spent 47µs making 185 calls to Class::MOP::Mixin::AttributeCore::name, avg 256ns/call
161
162185375µs370575µs return $meta_instance->set_slot_value($instance, $slot_name, $value)
# spent 486µs making 185 calls to Class::MOP::Instance::set_slot_value, avg 3µs/call # spent 89µs making 185 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 480ns/call
163 unless $self->has_initializer;
164
165 my $callback = $self->_make_initializer_writer_callback(
166 $meta_instance, $instance, $slot_name
167 );
168
169 my $initializer = $self->initializer;
170
171 # most things will just want to set a value, so make it first arg
172 $instance->$initializer($value, $callback, $self);
173}
174
175sub _make_initializer_writer_callback {
176 my $self = shift;
177 my ($meta_instance, $instance, $slot_name) = @_;
178
179 return sub {
180 $meta_instance->set_slot_value($instance, $slot_name, $_[0]);
181 };
182}
183
184
# spent 11µs (10+1) within Class::MOP::Attribute::get_read_method which was called 2 times, avg 6µs/call: # 2 times (10µs+1µs) by Moose::Meta::Method::Delegation::_get_delegate_accessor at line 127 of Moose/Meta/Method/Delegation.pm, avg 6µs/call
sub get_read_method {
1852500ns my $self = shift;
18629µs41µs my $reader = $self->reader || $self->accessor;
# spent 500ns making 2 calls to Class::MOP::Mixin::AttributeCore::accessor, avg 250ns/call # spent 500ns making 2 calls to Class::MOP::Mixin::AttributeCore::reader, avg 250ns/call
187 # normal case ...
18823µs return $reader unless ref $reader;
189 # the HASH ref case
190 my ($name) = %$reader;
191 return $name;
192}
193
194sub get_write_method {
195 my $self = shift;
196 my $writer = $self->writer || $self->accessor;
197 # normal case ...
198 return $writer unless ref $writer;
199 # the HASH ref case
200 my ($name) = %$writer;
201 return $name;
202}
203
204sub get_read_method_ref {
205 my $self = shift;
206 if ((my $reader = $self->get_read_method) && $self->associated_class) {
207 return $self->associated_class->get_method($reader);
208 }
209 else {
210 my $code = sub { $self->get_value(@_) };
211 if (my $class = $self->associated_class) {
212 return $class->method_metaclass->wrap(
213 $code,
214 package_name => $class->name,
215 name => '__ANON__'
216 );
217 }
218 else {
219 return $code;
220 }
221 }
222}
223
224sub get_write_method_ref {
225 my $self = shift;
226 if ((my $writer = $self->get_write_method) && $self->associated_class) {
227 return $self->associated_class->get_method($writer);
228 }
229 else {
230 my $code = sub { $self->set_value(@_) };
231 if (my $class = $self->associated_class) {
232 return $class->method_metaclass->wrap(
233 $code,
234 package_name => $class->name,
235 name => '__ANON__'
236 );
237 }
238 else {
239 return $code;
240 }
241 }
242}
243
244# slots
245
246426779µs426102µs
# spent 580µs (479+102) within Class::MOP::Attribute::slots which was called 426 times, avg 1µs/call: # 426 times (479µs+102µs) by Class::MOP::Instance::BUILDARGS at line 27 of Class/MOP/Instance.pm, avg 1µs/call
sub slots { (shift)->name }
# spent 102µs making 426 calls to Class::MOP::Mixin::AttributeCore::name, avg 239ns/call
247
248# class association
249
250
# spent 680µs (529+151) within Class::MOP::Attribute::attach_to_class which was called 135 times, avg 5µs/call: # 135 times (529µs+151µs) by Class::MOP::Class::_attach_attribute at line 888 of Class/MOP/Class.pm, avg 5µs/call
sub attach_to_class {
25113517µs my ($self, $class) = @_;
252135364µs27085µs (blessed($class) && $class->isa('Class::MOP::Class'))
# spent 44µs making 135 calls to Scalar::Util::blessed, avg 327ns/call # spent 41µs making 135 calls to UNIVERSAL::isa, avg 301ns/call
253 || $self->_throw_exception( AttachToClassNeedsAClassMOPClassInstanceOrASubclass => attribute => $self,
254 class => $class
255 );
256135371µs13566µs weaken($self->{'associated_class'} = $class);
# spent 66µs making 135 calls to Scalar::Util::weaken, avg 489ns/call
257}
258
259sub detach_from_class {
260 my $self = shift;
261 $self->{'associated_class'} = undef;
262}
263
264# method association
265
266
# spent 298µs within Class::MOP::Attribute::associate_method which was called 265 times, avg 1µs/call: # 193 times (225µs+0s) by Class::MOP::Attribute::_process_accessors at line 424, avg 1µs/call # 70 times (70µs+0s) by Class::MOP::Attribute::_process_accessors at line 398, avg 1µs/call # 2 times (2µs+0s) by Moose::Meta::Attribute::install_delegation at line 1106 of Moose/Meta/Attribute.pm, avg 1µs/call
sub associate_method {
26726554µs my ($self, $method) = @_;
268265396µs push @{$self->{'associated_methods'}} => $method;
269}
270
271## Slot management
272
273sub set_initial_value {
274 my ($self, $instance, $value) = @_;
275 $self->_set_initial_slot_value(
276 Class::MOP::Class->initialize(ref($instance))->get_meta_instance,
277 $instance,
278 $value
279 );
280}
281
282sub set_value { shift->set_raw_value(@_) }
283
284sub set_raw_value {
285 my $self = shift;
286 my ($instance, $value) = @_;
287
288 my $mi = Class::MOP::Class->initialize(ref($instance))->get_meta_instance;
289 return $mi->set_slot_value($instance, $self->name, $value);
290}
291
292
# spent 21.1ms (3.32+17.8) within Class::MOP::Attribute::_inline_set_value which was called 404 times, avg 52µs/call: # 269 times (435µs+11.2ms) by Class::MOP::Class::_inline_init_attr_from_constructor at line 631 of Class/MOP/Class.pm, avg 43µs/call # 99 times (2.81ms+5.43ms) by Class::MOP::Class::_inline_init_attr_from_default at line 652 of Class/MOP/Class.pm, avg 83µs/call # 21 times (41µs+760µs) by Class::MOP::Method::Accessor::try {...} at line 113 of Class/MOP/Method/Accessor.pm, avg 38µs/call # 12 times (30µs+351µs) by Moose::Meta::Attribute::_inline_set_value at line 602 of Moose/Meta/Attribute.pm, avg 32µs/call # 3 times (5µs+32µs) by Class::MOP::Method::Accessor::try {...} at line 191 of Class/MOP/Method/Accessor.pm, avg 12µs/call
sub _inline_set_value {
29340430µs my $self = shift;
294404605µs40417.8ms return $self->_inline_instance_set(@_) . ';';
# spent 17.8ms making 404 calls to Class::MOP::Attribute::_inline_instance_set, avg 44µs/call
295}
296
297
# spent 17.8ms (5.50+12.3) within Class::MOP::Attribute::_inline_instance_set which was called 405 times, avg 44µs/call: # 404 times (5.50ms+12.3ms) by Class::MOP::Attribute::_inline_set_value at line 294, avg 44µs/call # once (4µs+4µs) by Moose::Meta::Attribute::_inline_init_slot at line 951 of Moose/Meta/Attribute.pm
sub _inline_instance_set {
29840539µs my $self = shift;
29940558µs my ($instance, $value) = @_;
300
301405709µs81011.1ms my $mi = $self->associated_class->get_meta_instance;
# spent 10.0ms making 251 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 40µs/call # spent 962µs making 154 calls to Class::MOP::Class::get_meta_instance, avg 6µs/call # spent 107µs making 405 calls to Class::MOP::Attribute::associated_class, avg 265ns/call
3024053.70ms8101.23ms return $mi->inline_set_slot_value($instance, $self->name, $value);
# spent 1.14ms making 405 calls to Class::MOP::Instance::inline_set_slot_value, avg 3µs/call # spent 96µs making 405 calls to Class::MOP::Mixin::AttributeCore::name, avg 238ns/call
303}
304
3051220µs12175µs
# spent 195µs (20+175) within Class::MOP::Attribute::get_value which was called 12 times, avg 16µs/call: # 12 times (20µs+175µs) by Moose::Meta::Mixin::AttributeCore::is_lazy or Moose::Meta::Mixin::AttributeCore::is_required or Moose::Meta::Mixin::AttributeCore::is_weak_ref or Moose::Meta::Mixin::AttributeCore::should_auto_deref or Moose::Meta::Mixin::AttributeCore::should_coerce at line 141 of Class/MOP/Method/Accessor.pm, avg 16µs/call
sub get_value { shift->get_raw_value(@_) }
# spent 175µs making 12 calls to Class::MOP::Attribute::get_raw_value, avg 15µs/call
306
307
# spent 175µs (64+111) within Class::MOP::Attribute::get_raw_value which was called 12 times, avg 15µs/call: # 12 times (64µs+111µs) by Class::MOP::Attribute::get_value at line 305, avg 15µs/call
sub get_raw_value {
308121µs my $self = shift;
309122µs my ($instance) = @_;
310
3111216µs2498µs my $mi = Class::MOP::Class->initialize(ref($instance))->get_meta_instance;
# spent 70µs making 10 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 7µs/call # spent 27µs making 12 calls to Class::MOP::Class::initialize, avg 2µs/call # spent 1µs making 2 calls to Class::MOP::Class::get_meta_instance, avg 550ns/call
3121235µs2413µs return $mi->get_slot_value($instance, $self->name);
# spent 10µs making 12 calls to Class::MOP::Instance::get_slot_value, avg 867ns/call # spent 3µs making 12 calls to Class::MOP::Mixin::AttributeCore::name, avg 225ns/call
313}
314
315
# spent 1.80ms (146µs+1.65) within Class::MOP::Attribute::_inline_get_value which was called 75 times, avg 24µs/call: # 54 times (105µs+1.48ms) by Class::MOP::Method::Accessor::try {...} at line 151 of Class/MOP/Method/Accessor.pm, avg 29µs/call # 21 times (41µs+176µs) by Class::MOP::Method::Accessor::try {...} at line 113 of Class/MOP/Method/Accessor.pm, avg 10µs/call
sub _inline_get_value {
3167511µs my $self = shift;
31775143µs751.65ms return $self->_inline_instance_get(@_) . ';';
# spent 1.65ms making 75 calls to Class::MOP::Attribute::_inline_instance_get, avg 22µs/call
318}
319
320
# spent 1.78ms (439µs+1.34) within Class::MOP::Attribute::_inline_instance_get which was called 83 times, avg 21µs/call: # 75 times (389µs+1.26ms) by Class::MOP::Attribute::_inline_get_value at line 317, avg 22µs/call # 6 times (38µs+69µs) by Moose::Meta::Attribute::_inline_get_value at line 856 of Moose/Meta/Attribute.pm, avg 18µs/call # once (6µs+4µs) by Moose::Meta::Attribute::_inline_get_old_value_for_trigger at line 725 of Moose/Meta/Attribute.pm # once (5µs+4µs) by Moose::Meta::Class::_inline_triggers at line 468 of Moose/Meta/Class.pm
sub _inline_instance_get {
3218311µs my $self = shift;
3228316µs my ($instance) = @_;
323
32483152µs1661.06ms my $mi = $self->associated_class->get_meta_instance;
# spent 1.04ms making 83 calls to Class::MOP::Class::get_meta_instance, avg 13µs/call # spent 18µs making 83 calls to Class::MOP::Attribute::associated_class, avg 223ns/call
32583232µs166279µs return $mi->inline_get_slot_value($instance, $self->name);
# spent 262µs making 83 calls to Class::MOP::Instance::inline_get_slot_value, avg 3µs/call # spent 17µs making 83 calls to Class::MOP::Mixin::AttributeCore::name, avg 202ns/call
326}
327
328
# spent 174µs (64+110) within Class::MOP::Attribute::has_value which was called 12 times, avg 14µs/call: # 12 times (64µs+110µs) by Moose::Meta::Mixin::AttributeCore::has_handles or Moose::Meta::Mixin::AttributeCore::has_trigger or Moose::Meta::Mixin::AttributeCore::has_type_constraint at line 210 of Class/MOP/Method/Accessor.pm, avg 14µs/call
sub has_value {
329121µs my $self = shift;
330123µs my ($instance) = @_;
331
3321220µs2493µs my $mi = Class::MOP::Class->initialize(ref($instance))->get_meta_instance;
# spent 63µs making 9 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 7µs/call # spent 28µs making 12 calls to Class::MOP::Class::initialize, avg 2µs/call # spent 2µs making 3 calls to Class::MOP::Class::get_meta_instance, avg 500ns/call
3331238µs2417µs return $mi->is_slot_initialized($instance, $self->name);
# spent 14µs making 12 calls to Class::MOP::Instance::is_slot_initialized, avg 1µs/call # spent 3µs making 12 calls to Class::MOP::Mixin::AttributeCore::name, avg 242ns/call
334}
335
336
# spent 197µs (33+164) within Class::MOP::Attribute::_inline_has_value which was called 15 times, avg 13µs/call: # 15 times (33µs+164µs) by Class::MOP::Method::Accessor::try {...} at line 219 of Class/MOP/Method/Accessor.pm, avg 13µs/call
sub _inline_has_value {
337153µs my $self = shift;
3381528µs15164µs return $self->_inline_instance_has(@_) . ';';
# spent 164µs making 15 calls to Class::MOP::Attribute::_inline_instance_has, avg 11µs/call
339}
340
341
# spent 248µs (99+148) within Class::MOP::Attribute::_inline_instance_has which was called 17 times, avg 15µs/call: # 15 times (86µs+78µs) by Class::MOP::Attribute::_inline_has_value at line 338, avg 11µs/call # once (9µs+67µs) by Moose::Meta::Attribute::_inline_get_old_value_for_trigger at line 725 of Moose/Meta/Attribute.pm # once (4µs+4µs) by Moose::Meta::Attribute::_inline_check_lazy at line 873 of Moose/Meta/Attribute.pm
sub _inline_instance_has {
342173µs my $self = shift;
343174µs my ($instance) = @_;
344
3451734µs3474µs my $mi = $self->associated_class->get_meta_instance;
# spent 70µs making 17 calls to Class::MOP::Class::get_meta_instance, avg 4µs/call # spent 4µs making 17 calls to Class::MOP::Attribute::associated_class, avg 218ns/call
3461759µs3475µs return $mi->inline_is_slot_initialized($instance, $self->name);
# spent 71µs making 17 calls to Class::MOP::Instance::inline_is_slot_initialized, avg 4µs/call # spent 4µs making 17 calls to Class::MOP::Mixin::AttributeCore::name, avg 218ns/call
347}
348
349sub clear_value {
350 my $self = shift;
351 my ($instance) = @_;
352
353 my $mi = Class::MOP::Class->initialize(ref($instance))->get_meta_instance;
354 return $mi->deinitialize_slot($instance, $self->name);
355}
356
357sub _inline_clear_value {
358 my $self = shift;
359 return $self->_inline_instance_clear(@_) . ';';
360}
361
362sub _inline_instance_clear {
363 my $self = shift;
364 my ($instance) = @_;
365
366 my $mi = $self->associated_class->get_meta_instance;
367 return $mi->inline_deinitialize_slot($instance, $self->name);
368}
369
370## load em up ...
371
3722573.37ms
# spent 104µs within Class::MOP::Attribute::accessor_metaclass which was called 257 times, avg 404ns/call: # 187 times (74µs+0s) by Class::MOP::Attribute::try {...} at line 407, avg 398ns/call # 70 times (29µs+0s) by Class::MOP::Attribute::_process_accessors at line 390, avg 420ns/call
sub accessor_metaclass { 'Class::MOP::Method::Accessor' }
373
374
# spent 42.7ms (3.52+39.2) within Class::MOP::Attribute::_process_accessors which was called 263 times, avg 163µs/call: # 160 times (2.14ms+20.2ms) by Class::MOP::Attribute::install_accessors at line 450, avg 140µs/call # 45 times (550µs+6.90ms) by Class::MOP::Attribute::install_accessors at line 458, avg 165µs/call # 43 times (620µs+6.24ms) by Class::MOP::Attribute::install_accessors at line 446, avg 160µs/call # 8 times (101µs+777µs) by Class::MOP::Attribute::install_accessors at line 454, avg 110µs/call # 6 times (95µs+4.97ms) by Moose::Meta::Attribute::_process_accessors at line 1056 of Moose/Meta/Attribute.pm, avg 844µs/call # once (21µs+100µs) by Class::MOP::Attribute::install_accessors at line 462
sub _process_accessors {
375263100µs my ($self, $type, $accessor, $generate_as_inline_methods) = @_;
376
377263820µs26393µs my $method_ctx = { %{ $self->definition_context || {} } };
# spent 93µs making 263 calls to Class::MOP::Mixin::AttributeCore::definition_context, avg 353ns/call
378
37926362µs if (ref($accessor)) {
3807015µs (ref($accessor) eq 'HASH')
381 || $self->_throw_exception( BadOptionFormat => attribute => $self,
382 option_value => $accessor,
383 option_name => $type
384 );
385
3867041µs my ($name, $method) = %{$accessor};
387
3887060µs70442µs $method_ctx->{description} = $self->_accessor_description($name, $type);
# spent 442µs making 70 calls to Class::MOP::Attribute::_accessor_description, avg 6µs/call
389
39070344µs3501.48ms $method = $self->accessor_metaclass->wrap(
# spent 1.40ms making 70 calls to Class::MOP::Method::wrap, avg 20µs/call # spent 30µs making 140 calls to Class::MOP::Attribute::associated_class, avg 216ns/call # spent 29µs making 70 calls to Class::MOP::Attribute::accessor_metaclass, avg 420ns/call # spent 15µs making 70 calls to Class::MOP::Package::name, avg 211ns/call
391 $method,
392 attribute => $self,
393 package_name => $self->associated_class->name,
394 name => $name,
395 associated_metaclass => $self->associated_class,
396 definition_context => $method_ctx,
397 );
3987045µs7070µs $self->associate_method($method);
# spent 70µs making 70 calls to Class::MOP::Attribute::associate_method, avg 1µs/call
39970109µs return ($name, $method);
400 }
401 else {
402193342µs28280µs my $inline_me = ($generate_as_inline_methods && $self->associated_class->instance_metaclass->is_inlinable);
# spent 37µs making 94 calls to Class::MOP::Instance::is_inlinable, avg 395ns/call # spent 22µs making 94 calls to Class::MOP::Attribute::associated_class, avg 233ns/call # spent 22µs making 94 calls to Class::MOP::Class::instance_metaclass, avg 229ns/call
40319317µs my $method;
404
# spent 34.0ms (4.54+29.5) within Class::MOP::Attribute::try {...} which was called 193 times, avg 176µs/call: # 193 times (4.54ms+29.5ms) by Try::Tiny::try at line 92 of Try/Tiny.pm, avg 176µs/call
try {
405193184µs1931.25ms $method_ctx->{description} = $self->_accessor_description($accessor, $type);
# spent 1.25ms making 193 calls to Class::MOP::Attribute::_accessor_description, avg 6µs/call
406
4071931.13ms96523.5ms $method = $self->accessor_metaclass->new(
# spent 23.3ms making 187 calls to Class::MOP::Method::Accessor::new, avg 124µs/call # spent 84µs making 386 calls to Class::MOP::Attribute::associated_class, avg 219ns/call # spent 74µs making 187 calls to Class::MOP::Attribute::accessor_metaclass, avg 398ns/call # spent 39µs making 193 calls to Class::MOP::Package::name, avg 202ns/call # spent 13µs making 6 calls to Moose::Meta::Method::Accessor::new, avg 2µs/call # spent 4µs making 6 calls to Moose::Meta::Attribute::accessor_metaclass, avg 633ns/call
408 attribute => $self,
409 is_inline => $inline_me,
410 accessor_type => $type,
411 package_name => $self->associated_class->name,
412 name => $accessor,
413 associated_metaclass => $self->associated_class,
414 definition_context => $method_ctx,
415 );
416 }
417 catch {
418 $self->_throw_exception( CouldNotCreateMethod => attribute => $self,
419 option_value => $accessor,
420 option_name => $type,
421 error => $_
422 );
423193954µs38627.7ms };
# spent 35.8ms making 193 calls to Try::Tiny::try, avg 185µs/call, recursion: max depth 1, sum of overlapping time 9.12ms # spent 1.05ms making 193 calls to Try::Tiny::catch, avg 5µs/call
424193156µs193225µs $self->associate_method($method);
# spent 225µs making 193 calls to Class::MOP::Attribute::associate_method, avg 1µs/call
425193313µs return ($accessor, $method);
426 }
427}
428
429
# spent 1.69ms (1.47+222µs) within Class::MOP::Attribute::_accessor_description which was called 263 times, avg 6µs/call: # 193 times (1.08ms+166µs) by Class::MOP::Attribute::try {...} at line 405, avg 6µs/call # 70 times (386µs+56µs) by Class::MOP::Attribute::_process_accessors at line 388, avg 6µs/call
sub _accessor_description {
43026339µs my $self = shift;
43126357µs my ($name, $type) = @_;
432
433263877µs526141µs my $desc = "$type " . $self->associated_class->name . "::$name";
# spent 76µs making 263 calls to Class::MOP::Package::name, avg 287ns/call # spent 66µs making 263 calls to Class::MOP::Attribute::associated_class, avg 249ns/call
434263537µs37581µs if ( $name ne $self->name ) {
# spent 81µs making 375 calls to Class::MOP::Mixin::AttributeCore::name, avg 215ns/call
435 $desc .= " of attribute " . $self->name;
436 }
437
438263349µs return $desc;
439}
440
441
# spent 70.3ms (2.98+67.3) within Class::MOP::Attribute::install_accessors which was called 211 times, avg 333µs/call: # 130 times (1.87ms+25.0ms) by Class::MOP::Class::try {...} at line 899 of Class/MOP/Class.pm, avg 206µs/call # 75 times (1.00ms+32.5ms) by Class::MOP::Class::_inline_accessors at line 1425 of Class/MOP/Class.pm, avg 447µs/call # 6 times (109µs+9.88ms) by Moose::Meta::Attribute::install_accessors at line 995 of Moose/Meta/Attribute.pm, avg 1.66ms/call
sub install_accessors {
44221133µs my $self = shift;
44321134µs my $inline = shift;
444211352µs21176µs my $class = $self->associated_class;
# spent 76µs making 211 calls to Class::MOP::Attribute::associated_class, avg 359ns/call
445
446211354µs35217.0ms $class->add_method(
# spent 7.81ms making 4 calls to Moose::Meta::Attribute::_process_accessors, avg 1.95ms/call # spent 6.86ms making 43 calls to Class::MOP::Attribute::_process_accessors, avg 160µs/call # spent 2.13ms making 47 calls to Class::MOP::Mixin::HasMethods::add_method, avg 45µs/call # spent 165µs making 211 calls to Class::MOP::Mixin::AttributeCore::has_accessor, avg 784ns/call # spent 19µs making 47 calls to Class::MOP::Mixin::AttributeCore::accessor, avg 402ns/call
447 $self->_process_accessors('accessor' => $self->accessor(), $inline)
448 ) if $self->has_accessor();
449
450211629µs69735.3ms $class->add_method(
# spent 22.4ms making 160 calls to Class::MOP::Attribute::_process_accessors, avg 140µs/call # spent 11.0ms making 162 calls to Class::MOP::Mixin::HasMethods::add_method, avg 68µs/call # spent 1.74ms making 2 calls to Moose::Meta::Attribute::_process_accessors, avg 872µs/call # spent 138µs making 211 calls to Class::MOP::Mixin::AttributeCore::has_reader, avg 656ns/call # spent 49µs making 162 calls to Class::MOP::Mixin::AttributeCore::reader, avg 301ns/call
451 $self->_process_accessors('reader' => $self->reader(), $inline)
452 ) if $self->has_reader();
453
454211200µs2351.31ms $class->add_method(
# spent 878µs making 8 calls to Class::MOP::Attribute::_process_accessors, avg 110µs/call # spent 294µs making 8 calls to Class::MOP::Mixin::HasMethods::add_method, avg 37µs/call # spent 138µs making 211 calls to Class::MOP::Mixin::AttributeCore::has_writer, avg 652ns/call # spent 4µs making 8 calls to Class::MOP::Mixin::AttributeCore::writer, avg 450ns/call
455 $self->_process_accessors('writer' => $self->writer(), $inline)
456 ) if $self->has_writer();
457
458211278µs34613.4ms $class->add_method(
# spent 7.45ms making 45 calls to Class::MOP::Attribute::_process_accessors, avg 165µs/call # spent 5.80ms making 45 calls to Class::MOP::Mixin::HasMethods::add_method, avg 129µs/call # spent 100µs making 211 calls to Class::MOP::Mixin::AttributeCore::has_predicate, avg 476ns/call # spent 14µs making 45 calls to Class::MOP::Mixin::AttributeCore::predicate, avg 313ns/call
459 $self->_process_accessors('predicate' => $self->predicate(), $inline)
460 ) if $self->has_predicate();
461
462211154µs214287µs $class->add_method(
# spent 121µs making 1 call to Class::MOP::Attribute::_process_accessors # spent 103µs making 211 calls to Class::MOP::Mixin::AttributeCore::has_clearer, avg 488ns/call # spent 63µs making 1 call to Class::MOP::Mixin::HasMethods::add_method # spent 300ns making 1 call to Class::MOP::Mixin::AttributeCore::clearer
463 $self->_process_accessors('clearer' => $self->clearer(), $inline)
464 ) if $self->has_clearer();
465
466211292µs return;
467}
468
469{
470 my $_remove_accessor = sub {
471 my ($accessor, $class) = @_;
472 if (ref($accessor) && ref($accessor) eq 'HASH') {
473 ($accessor) = keys %{$accessor};
474 }
475 my $method = $class->get_method($accessor);
476 $class->remove_method($accessor)
477 if (ref($method) && $method->isa('Class::MOP::Method::Accessor'));
47812µs };
479
480 sub remove_accessors {
481 my $self = shift;
482 # TODO:
483 # we really need to make sure to remove from the
484 # associates methods here as well. But this is
485 # such a slimly used method, I am not worried
486 # about it right now.
487 $_remove_accessor->($self->accessor(), $self->associated_class()) if $self->has_accessor();
488 $_remove_accessor->($self->reader(), $self->associated_class()) if $self->has_reader();
489 $_remove_accessor->($self->writer(), $self->associated_class()) if $self->has_writer();
490 $_remove_accessor->($self->predicate(), $self->associated_class()) if $self->has_predicate();
491 $_remove_accessor->($self->clearer(), $self->associated_class()) if $self->has_clearer();
492 return;
493 }
494
495}
496
49724µs1;
498
499# ABSTRACT: Attribute Meta Object
500
501__END__