Filename | /Users/ap13/perl5/lib/perl5/darwin-2level/Class/MOP/Instance.pm |
Statements | Executed 14707 statements in 30.9ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
237 | 1 | 1 | 8.27ms | 14.0ms | BUILDARGS | Class::MOP::Instance::
1956 | 1 | 1 | 4.35ms | 4.35ms | set_slot_value | Class::MOP::Instance::
271 | 1 | 1 | 3.56ms | 4.04ms | create_instance | Class::MOP::Instance::
774 | 1 | 1 | 3.38ms | 5.42ms | inline_set_slot_value | Class::MOP::Instance::
1137 | 5 | 1 | 3.18ms | 3.18ms | inline_slot_access | Class::MOP::Instance::
237 | 1 | 1 | 3.13ms | 20.1ms | new | Class::MOP::Instance::
266 | 1 | 1 | 1.13ms | 2.05ms | inline_get_slot_value | Class::MOP::Instance::
87 | 1 | 1 | 430µs | 628µs | inline_is_slot_initialized | Class::MOP::Instance::
48 | 1 | 1 | 380µs | 380µs | _new | Class::MOP::Instance::
300 | 2 | 2 | 355µs | 355µs | is_inlinable | Class::MOP::Instance::
237 | 1 | 1 | 286µs | 286µs | is_dependent_on_superclasses | Class::MOP::Instance::
46 | 1 | 1 | 142µs | 142µs | inline_create_instance | Class::MOP::Instance::
8 | 1 | 1 | 43µs | 65µs | inline_deinitialize_slot | Class::MOP::Instance::
12 | 1 | 1 | 27µs | 27µs | is_slot_initialized | Class::MOP::Instance::
12 | 1 | 1 | 25µs | 25µs | get_slot_value | Class::MOP::Instance::
2 | 1 | 1 | 13µs | 18µs | inline_weaken_slot_value | Class::MOP::Instance::
1 | 1 | 1 | 13µs | 17µs | BEGIN@5 | Class::MOP::Instance::
1 | 1 | 1 | 13µs | 26µs | BEGIN@4 | Class::MOP::Instance::
1 | 1 | 1 | 9µs | 37µs | BEGIN@9 | Class::MOP::Instance::
1 | 1 | 1 | 9µs | 50µs | BEGIN@7 | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | _clear_mop_slot | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | _get_mop_slot | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | _has_mop_slot | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | _inline_clear_mop_slot | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | _inline_get_mop_slot | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | _inline_set_mop_slot | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | _set_mop_slot | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | clone_instance | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | deinitialize_all_slots | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | deinitialize_slot | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | get_all_attributes | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | get_all_slots | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | initialize_all_slots | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | initialize_slot | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | inline_get_is_lvalue | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | inline_initialize_slot | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | inline_rebless_instance_structure | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | inline_strengthen_slot_value | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | is_valid_slot | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | rebless_instance_structure | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | slot_value_is_weak | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | strengthen_slot_value | Class::MOP::Instance::
0 | 0 | 0 | 0s | 0s | weaken_slot_value | Class::MOP::Instance::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Class::MOP::Instance; | ||||
2 | 1 | 600ns | our $VERSION = '2.1403'; | ||
3 | |||||
4 | 2 | 23µs | 2 | 39µs | # spent 26µs (13+13) within Class::MOP::Instance::BEGIN@4 which was called:
# once (13µs+13µs) by Class::MOP::Class::BEGIN@7 at line 4 # spent 26µs making 1 call to Class::MOP::Instance::BEGIN@4
# spent 13µs making 1 call to strict::import |
5 | 2 | 27µs | 2 | 21µs | # spent 17µs (13+4) within Class::MOP::Instance::BEGIN@5 which was called:
# once (13µs+4µs) by Class::MOP::Class::BEGIN@7 at line 5 # spent 17µs making 1 call to Class::MOP::Instance::BEGIN@5
# spent 4µs making 1 call to warnings::import |
6 | |||||
7 | 2 | 27µs | 2 | 92µs | # spent 50µs (9+42) within Class::MOP::Instance::BEGIN@7 which was called:
# once (9µs+42µs) by Class::MOP::Class::BEGIN@7 at line 7 # spent 50µs making 1 call to Class::MOP::Instance::BEGIN@7
# spent 42µs making 1 call to Exporter::import |
8 | |||||
9 | 2 | 1.24ms | 2 | 66µs | # spent 37µs (9+28) within Class::MOP::Instance::BEGIN@9 which was called:
# once (9µs+28µs) by Class::MOP::Class::BEGIN@7 at line 9 # spent 37µs making 1 call to Class::MOP::Instance::BEGIN@9
# spent 28µs making 1 call to parent::import |
10 | |||||
11 | # make this not a valid method name, to avoid (most) attribute conflicts | ||||
12 | 1 | 300ns | my $RESERVED_MOP_SLOT = '<<MOP>>'; | ||
13 | |||||
14 | # spent 14.0ms (8.27+5.75) within Class::MOP::Instance::BUILDARGS which was called 237 times, avg 59µs/call:
# 237 times (8.27ms+5.75ms) by Class::MOP::Instance::new at line 35, avg 59µs/call | ||||
15 | 3369 | 6.94ms | my ($class, @args) = @_; | ||
16 | |||||
17 | 237 | 156µs | if ( @args == 1 ) { # spent 156µs making 237 calls to Scalar::Util::blessed, avg 658ns/call | ||
18 | unshift @args, "associated_metaclass"; | ||||
19 | } elsif ( @args >= 2 && blessed($args[0]) && $args[0]->isa("Class::MOP::Class") ) { | ||||
20 | # compat mode | ||||
21 | my ( $meta, @attrs ) = @args; | ||||
22 | @args = ( associated_metaclass => $meta, attributes => \@attrs ); | ||||
23 | } | ||||
24 | |||||
25 | my %options = @args; | ||||
26 | # FIXME lazy_build | ||||
27 | 1947 | 5.60ms | $options{slots} ||= [ map { $_->slots } @{ $options{attributes} || [] } ]; # spent 5.60ms making 1947 calls to Class::MOP::Attribute::slots, avg 3µs/call | ||
28 | $options{slot_hash} = { map { $_ => undef } @{ $options{slots} } }; # FIXME lazy_build | ||||
29 | |||||
30 | return \%options; | ||||
31 | } | ||||
32 | |||||
33 | # spent 20.1ms (3.13+17.0) within Class::MOP::Instance::new which was called 237 times, avg 85µs/call:
# 237 times (3.13ms+17.0ms) by Class::MOP::Class::_create_meta_instance at line 727 of Class/MOP/Class.pm, avg 85µs/call | ||||
34 | 1185 | 2.95ms | my $class = shift; | ||
35 | 237 | 14.0ms | my $options = $class->BUILDARGS(@_); # spent 14.0ms making 237 calls to Class::MOP::Instance::BUILDARGS, avg 59µs/call | ||
36 | |||||
37 | # FIXME replace with a proper constructor | ||||
38 | 237 | 2.73ms | my $instance = $class->_new(%$options); # spent 2.35ms making 189 calls to Moose::Meta::Instance::_new, avg 12µs/call
# spent 380µs making 48 calls to Class::MOP::Instance::_new, avg 8µs/call | ||
39 | |||||
40 | # FIXME weak_ref => 1, | ||||
41 | 237 | 214µs | weaken($instance->{'associated_metaclass'}); # spent 214µs making 237 calls to Scalar::Util::weaken, avg 904ns/call | ||
42 | |||||
43 | return $instance; | ||||
44 | } | ||||
45 | |||||
46 | # spent 380µs within Class::MOP::Instance::_new which was called 48 times, avg 8µs/call:
# 48 times (380µs+0s) by Class::MOP::Instance::new at line 38, avg 8µs/call | ||||
47 | 192 | 407µs | my $class = shift; | ||
48 | return Class::MOP::Class->initialize($class)->new_object(@_) | ||||
49 | if $class ne __PACKAGE__; | ||||
50 | |||||
51 | my $params = @_ == 1 ? $_[0] : {@_}; | ||||
52 | return bless { | ||||
53 | # NOTE: | ||||
54 | # I am not sure that it makes | ||||
55 | # sense to pass in the meta | ||||
56 | # The ideal would be to just | ||||
57 | # pass in the class name, but | ||||
58 | # that is placing too much of | ||||
59 | # an assumption on bless(), | ||||
60 | # which is *probably* a safe | ||||
61 | # assumption,.. but you can | ||||
62 | # never tell <:) | ||||
63 | 'associated_metaclass' => $params->{associated_metaclass}, | ||||
64 | 'attributes' => $params->{attributes}, | ||||
65 | 'slots' => $params->{slots}, | ||||
66 | 'slot_hash' => $params->{slot_hash}, | ||||
67 | } => $class; | ||||
68 | } | ||||
69 | |||||
70 | 271 | 749µs | 12 | 10µs | sub _class_name { $_[0]->{_class_name} ||= $_[0]->associated_metaclass->name } # spent 7µs making 6 calls to Class::MOP::Instance::associated_metaclass, avg 1µs/call
# spent 4µs making 6 calls to Class::MOP::Package::name, avg 633ns/call |
71 | |||||
72 | # spent 4.04ms (3.56+482µs) within Class::MOP::Instance::create_instance which was called 271 times, avg 15µs/call:
# 271 times (3.56ms+482µs) by Class::MOP::Class::_construct_instance at line 523 of Class/MOP/Class.pm, avg 15µs/call | ||||
73 | 542 | 3.40ms | my $self = shift; | ||
74 | 271 | 482µs | bless {}, $self->_class_name; # spent 482µs making 271 calls to Class::MOP::Instance::_class_name, avg 2µs/call | ||
75 | } | ||||
76 | |||||
77 | sub clone_instance { | ||||
78 | my ($self, $instance) = @_; | ||||
79 | |||||
80 | my $clone = $self->create_instance; | ||||
81 | for my $attr ($self->get_all_attributes) { | ||||
82 | next unless $attr->has_value($instance); | ||||
83 | for my $slot ($attr->slots) { | ||||
84 | my $val = $self->get_slot_value($instance, $slot); | ||||
85 | $self->set_slot_value($clone, $slot, $val); | ||||
86 | $self->weaken_slot_value($clone, $slot) | ||||
87 | if $self->slot_value_is_weak($instance, $slot); | ||||
88 | } | ||||
89 | } | ||||
90 | |||||
91 | $self->_set_mop_slot($clone, $self->_get_mop_slot($instance)) | ||||
92 | if $self->_has_mop_slot($instance); | ||||
93 | |||||
94 | return $clone; | ||||
95 | } | ||||
96 | |||||
97 | # operations on meta instance | ||||
98 | |||||
99 | sub get_all_slots { | ||||
100 | my $self = shift; | ||||
101 | return @{$self->{'slots'}}; | ||||
102 | } | ||||
103 | |||||
104 | sub get_all_attributes { | ||||
105 | my $self = shift; | ||||
106 | return @{$self->{attributes}}; | ||||
107 | } | ||||
108 | |||||
109 | sub is_valid_slot { | ||||
110 | my ($self, $slot_name) = @_; | ||||
111 | exists $self->{'slot_hash'}->{$slot_name}; | ||||
112 | } | ||||
113 | |||||
114 | # operations on created instances | ||||
115 | |||||
116 | # spent 25µs within Class::MOP::Instance::get_slot_value which was called 12 times, avg 2µs/call:
# 12 times (25µs+0s) by Class::MOP::Attribute::get_raw_value at line 312 of Class/MOP/Attribute.pm, avg 2µs/call | ||||
117 | 24 | 31µs | my ($self, $instance, $slot_name) = @_; | ||
118 | $instance->{$slot_name}; | ||||
119 | } | ||||
120 | |||||
121 | # spent 4.35ms within Class::MOP::Instance::set_slot_value which was called 1956 times, avg 2µs/call:
# 1956 times (4.35ms+0s) by Class::MOP::Attribute::_set_initial_slot_value at line 162 of Class/MOP/Attribute.pm, avg 2µs/call | ||||
122 | 3912 | 5.62ms | my ($self, $instance, $slot_name, $value) = @_; | ||
123 | $instance->{$slot_name} = $value; | ||||
124 | } | ||||
125 | |||||
126 | sub initialize_slot { | ||||
127 | my ($self, $instance, $slot_name) = @_; | ||||
128 | return; | ||||
129 | } | ||||
130 | |||||
131 | sub deinitialize_slot { | ||||
132 | my ( $self, $instance, $slot_name ) = @_; | ||||
133 | delete $instance->{$slot_name}; | ||||
134 | } | ||||
135 | |||||
136 | sub initialize_all_slots { | ||||
137 | my ($self, $instance) = @_; | ||||
138 | foreach my $slot_name ($self->get_all_slots) { | ||||
139 | $self->initialize_slot($instance, $slot_name); | ||||
140 | } | ||||
141 | } | ||||
142 | |||||
143 | sub deinitialize_all_slots { | ||||
144 | my ($self, $instance) = @_; | ||||
145 | foreach my $slot_name ($self->get_all_slots) { | ||||
146 | $self->deinitialize_slot($instance, $slot_name); | ||||
147 | } | ||||
148 | } | ||||
149 | |||||
150 | # spent 27µs within Class::MOP::Instance::is_slot_initialized which was called 12 times, avg 2µs/call:
# 12 times (27µs+0s) by Class::MOP::Attribute::has_value at line 333 of Class/MOP/Attribute.pm, avg 2µs/call | ||||
151 | 24 | 34µs | my ($self, $instance, $slot_name, $value) = @_; | ||
152 | exists $instance->{$slot_name}; | ||||
153 | } | ||||
154 | |||||
155 | sub weaken_slot_value { | ||||
156 | my ($self, $instance, $slot_name) = @_; | ||||
157 | weaken $instance->{$slot_name}; | ||||
158 | } | ||||
159 | |||||
160 | sub slot_value_is_weak { | ||||
161 | my ($self, $instance, $slot_name) = @_; | ||||
162 | isweak $instance->{$slot_name}; | ||||
163 | } | ||||
164 | |||||
165 | sub strengthen_slot_value { | ||||
166 | my ($self, $instance, $slot_name) = @_; | ||||
167 | $self->set_slot_value($instance, $slot_name, $self->get_slot_value($instance, $slot_name)); | ||||
168 | } | ||||
169 | |||||
170 | sub rebless_instance_structure { | ||||
171 | my ($self, $instance, $metaclass) = @_; | ||||
172 | |||||
173 | # we use $_[1] here because of t/cmop/rebless_overload.t regressions | ||||
174 | # on 5.8.8 | ||||
175 | bless $_[1], $metaclass->name; | ||||
176 | } | ||||
177 | |||||
178 | # spent 286µs within Class::MOP::Instance::is_dependent_on_superclasses which was called 237 times, avg 1µs/call:
# 237 times (286µs+0s) by Class::MOP::Class::_create_meta_instance at line 732 of Class/MOP/Class.pm, avg 1µs/call | ||||
179 | 237 | 432µs | return; # for meta instances that require updates on inherited slot changes | ||
180 | } | ||||
181 | |||||
182 | sub _get_mop_slot { | ||||
183 | my ($self, $instance) = @_; | ||||
184 | $self->get_slot_value($instance, $RESERVED_MOP_SLOT); | ||||
185 | } | ||||
186 | |||||
187 | sub _has_mop_slot { | ||||
188 | my ($self, $instance) = @_; | ||||
189 | $self->is_slot_initialized($instance, $RESERVED_MOP_SLOT); | ||||
190 | } | ||||
191 | |||||
192 | sub _set_mop_slot { | ||||
193 | my ($self, $instance, $value) = @_; | ||||
194 | $self->set_slot_value($instance, $RESERVED_MOP_SLOT, $value); | ||||
195 | } | ||||
196 | |||||
197 | sub _clear_mop_slot { | ||||
198 | my ($self, $instance) = @_; | ||||
199 | $self->deinitialize_slot($instance, $RESERVED_MOP_SLOT); | ||||
200 | } | ||||
201 | |||||
202 | # inlinable operation snippets | ||||
203 | |||||
204 | 300 | 556µs | # spent 355µs within Class::MOP::Instance::is_inlinable which was called 300 times, avg 1µs/call:
# 206 times (261µs+0s) by Moose::Meta::Method::Accessor::_instance_is_inlinable at line 51 of Moose/Meta/Method/Accessor.pm, avg 1µs/call
# 94 times (94µs+0s) by Class::MOP::Attribute::_process_accessors at line 402 of Class/MOP/Attribute.pm, avg 1µs/call | ||
205 | |||||
206 | # spent 142µs within Class::MOP::Instance::inline_create_instance which was called 46 times, avg 3µs/call:
# 46 times (142µs+0s) by Class::MOP::Class::_inline_create_instance at line 584 of Class/MOP/Class.pm, avg 3µs/call | ||||
207 | 92 | 163µs | my ($self, $class_variable) = @_; | ||
208 | 'bless {} => ' . $class_variable; | ||||
209 | } | ||||
210 | |||||
211 | # spent 3.18ms within Class::MOP::Instance::inline_slot_access which was called 1137 times, avg 3µs/call:
# 774 times (2.04ms+0s) by Class::MOP::Instance::inline_set_slot_value at line 225, avg 3µs/call
# 266 times (920µs+0s) by Class::MOP::Instance::inline_get_slot_value at line 220, avg 3µs/call
# 87 times (198µs+0s) by Class::MOP::Instance::inline_is_slot_initialized at line 239, avg 2µs/call
# 8 times (22µs+0s) by Class::MOP::Instance::inline_deinitialize_slot at line 235, avg 3µs/call
# 2 times (4µs+0s) by Class::MOP::Instance::inline_weaken_slot_value at line 244, avg 2µs/call | ||||
212 | 2274 | 4.18ms | my ($self, $instance, $slot_name) = @_; | ||
213 | sprintf q[%s->{"%s"}], $instance, quotemeta($slot_name); | ||||
214 | } | ||||
215 | |||||
216 | sub inline_get_is_lvalue { 1 } | ||||
217 | |||||
218 | # spent 2.05ms (1.13+920µs) within Class::MOP::Instance::inline_get_slot_value which was called 266 times, avg 8µs/call:
# 266 times (1.13ms+920µs) by Class::MOP::Attribute::_inline_instance_get at line 325 of Class/MOP/Attribute.pm, avg 8µs/call | ||||
219 | 532 | 951µs | my ($self, $instance, $slot_name) = @_; | ||
220 | 266 | 920µs | $self->inline_slot_access($instance, $slot_name); # spent 920µs making 266 calls to Class::MOP::Instance::inline_slot_access, avg 3µs/call | ||
221 | } | ||||
222 | |||||
223 | # spent 5.42ms (3.38+2.04) within Class::MOP::Instance::inline_set_slot_value which was called 774 times, avg 7µs/call:
# 774 times (3.38ms+2.04ms) by Class::MOP::Attribute::_inline_instance_set at line 302 of Class/MOP/Attribute.pm, avg 7µs/call | ||||
224 | 1548 | 2.80ms | my ($self, $instance, $slot_name, $value) = @_; | ||
225 | 774 | 2.04ms | $self->inline_slot_access($instance, $slot_name) . " = $value", # spent 2.04ms making 774 calls to Class::MOP::Instance::inline_slot_access, avg 3µs/call | ||
226 | } | ||||
227 | |||||
228 | sub inline_initialize_slot { | ||||
229 | my ($self, $instance, $slot_name) = @_; | ||||
230 | return ''; | ||||
231 | } | ||||
232 | |||||
233 | # spent 65µs (43+22) within Class::MOP::Instance::inline_deinitialize_slot which was called 8 times, avg 8µs/call:
# 8 times (43µs+22µs) by Class::MOP::Attribute::_inline_instance_clear at line 367 of Class/MOP/Attribute.pm, avg 8µs/call | ||||
234 | 16 | 35µs | my ($self, $instance, $slot_name) = @_; | ||
235 | 8 | 22µs | "delete " . $self->inline_slot_access($instance, $slot_name); # spent 22µs making 8 calls to Class::MOP::Instance::inline_slot_access, avg 3µs/call | ||
236 | } | ||||
237 | # spent 628µs (430+198) within Class::MOP::Instance::inline_is_slot_initialized which was called 87 times, avg 7µs/call:
# 87 times (430µs+198µs) by Class::MOP::Attribute::_inline_instance_has at line 346 of Class/MOP/Attribute.pm, avg 7µs/call | ||||
238 | 174 | 359µs | my ($self, $instance, $slot_name) = @_; | ||
239 | 87 | 198µs | "exists " . $self->inline_slot_access($instance, $slot_name); # spent 198µs making 87 calls to Class::MOP::Instance::inline_slot_access, avg 2µs/call | ||
240 | } | ||||
241 | |||||
242 | # spent 18µs (13+4) within Class::MOP::Instance::inline_weaken_slot_value which was called 2 times, avg 9µs/call:
# 2 times (13µs+4µs) by Moose::Meta::Attribute::_inline_weaken_value at line 739 of Moose/Meta/Attribute.pm, avg 9µs/call | ||||
243 | 4 | 11µs | my ($self, $instance, $slot_name) = @_; | ||
244 | 2 | 4µs | sprintf "Scalar::Util::weaken( %s )", $self->inline_slot_access($instance, $slot_name); # spent 4µs making 2 calls to Class::MOP::Instance::inline_slot_access, avg 2µs/call | ||
245 | } | ||||
246 | |||||
247 | sub inline_strengthen_slot_value { | ||||
248 | my ($self, $instance, $slot_name) = @_; | ||||
249 | $self->inline_set_slot_value($instance, $slot_name, $self->inline_slot_access($instance, $slot_name)); | ||||
250 | } | ||||
251 | |||||
252 | sub inline_rebless_instance_structure { | ||||
253 | my ($self, $instance, $class_variable) = @_; | ||||
254 | "bless $instance => $class_variable"; | ||||
255 | } | ||||
256 | |||||
257 | sub _inline_get_mop_slot { | ||||
258 | my ($self, $instance) = @_; | ||||
259 | $self->inline_get_slot_value($instance, $RESERVED_MOP_SLOT); | ||||
260 | } | ||||
261 | |||||
262 | sub _inline_set_mop_slot { | ||||
263 | my ($self, $instance, $value) = @_; | ||||
264 | $self->inline_set_slot_value($instance, $RESERVED_MOP_SLOT, $value); | ||||
265 | } | ||||
266 | |||||
267 | sub _inline_clear_mop_slot { | ||||
268 | my ($self, $instance) = @_; | ||||
269 | $self->inline_deinitialize_slot($instance, $RESERVED_MOP_SLOT); | ||||
270 | } | ||||
271 | |||||
272 | 1 | 4µs | 1; | ||
273 | |||||
274 | # ABSTRACT: Instance Meta Object | ||||
275 | |||||
276 | __END__ |