Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Class/MOP/Instance.pm |
Statements | Executed 3803 statements in 9.77ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
48 | 1 | 1 | 1.87ms | 3.19ms | BUILDARGS | Class::MOP::Instance::
398 | 1 | 1 | 1.64ms | 2.56ms | inline_set_slot_value | Class::MOP::Instance::
494 | 4 | 1 | 1.20ms | 1.20ms | inline_slot_access | Class::MOP::Instance::
164 | 1 | 1 | 1.18ms | 1.18ms | set_slot_value | Class::MOP::Instance::
48 | 1 | 1 | 589µs | 4.19ms | new | Class::MOP::Instance::
47 | 1 | 1 | 328µs | 328µs | _new | Class::MOP::Instance::
78 | 1 | 1 | 303µs | 523µs | inline_get_slot_value | Class::MOP::Instance::
32 | 1 | 1 | 152µs | 244µs | create_instance | Class::MOP::Instance::
97 | 2 | 2 | 89µs | 89µs | is_inlinable | Class::MOP::Instance::
16 | 1 | 1 | 78µs | 126µs | inline_is_slot_initialized | Class::MOP::Instance::
31 | 1 | 1 | 58µs | 58µs | inline_create_instance | Class::MOP::Instance::
48 | 1 | 1 | 47µs | 47µs | is_dependent_on_superclasses | Class::MOP::Instance::
12 | 1 | 1 | 25µs | 25µs | is_slot_initialized | Class::MOP::Instance::
12 | 1 | 1 | 22µs | 22µs | get_slot_value | Class::MOP::Instance::
1 | 1 | 1 | 17µs | 21µs | BEGIN@11 | Class::MOP::Instance::
2 | 1 | 1 | 12µs | 18µs | inline_weaken_slot_value | Class::MOP::Instance::
1 | 1 | 1 | 11µs | 11µs | BEGIN@3 | Class::MOP::Instance::
1 | 1 | 1 | 9µs | 55µs | BEGIN@13 | Class::MOP::Instance::
1 | 1 | 1 | 8µs | 28µs | BEGIN@10 | Class::MOP::Instance::
1 | 1 | 1 | 8µs | 78µs | BEGIN@15 | 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_deinitialize_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 | |||||
2 | package Class::MOP::Instance; | ||||
3 | # spent 11µs within Class::MOP::Instance::BEGIN@3 which was called:
# once (11µs+0s) by Class::MOP::Class::BEGIN@13 at line 5 | ||||
4 | 1 | 7µs | $Class::MOP::Instance::AUTHORITY = 'cpan:STEVAN'; | ||
5 | 1 | 39µs | 1 | 11µs | } # spent 11µs making 1 call to Class::MOP::Instance::BEGIN@3 |
6 | { | ||||
7 | 2 | 1µs | $Class::MOP::Instance::VERSION = '2.1005'; | ||
8 | } | ||||
9 | |||||
10 | 2 | 30µs | 2 | 49µs | # spent 28µs (8+20) within Class::MOP::Instance::BEGIN@10 which was called:
# once (8µs+20µs) by Class::MOP::Class::BEGIN@13 at line 10 # spent 28µs making 1 call to Class::MOP::Instance::BEGIN@10
# spent 20µs making 1 call to strict::import |
11 | 2 | 37µs | 2 | 26µs | # spent 21µs (17+4) within Class::MOP::Instance::BEGIN@11 which was called:
# once (17µs+4µs) by Class::MOP::Class::BEGIN@13 at line 11 # spent 21µs making 1 call to Class::MOP::Instance::BEGIN@11
# spent 4µs making 1 call to warnings::import |
12 | |||||
13 | 2 | 35µs | 2 | 100µs | # spent 55µs (9+46) within Class::MOP::Instance::BEGIN@13 which was called:
# once (9µs+46µs) by Class::MOP::Class::BEGIN@13 at line 13 # spent 55µs making 1 call to Class::MOP::Instance::BEGIN@13
# spent 46µs making 1 call to Exporter::import |
14 | |||||
15 | 2 | 1.79ms | 2 | 148µs | # spent 78µs (8+70) within Class::MOP::Instance::BEGIN@15 which was called:
# once (8µs+70µs) by Class::MOP::Class::BEGIN@13 at line 15 # spent 78µs making 1 call to Class::MOP::Instance::BEGIN@15
# spent 70µs making 1 call to base::import |
16 | |||||
17 | # make this not a valid method name, to avoid (most) attribute conflicts | ||||
18 | 1 | 300ns | my $RESERVED_MOP_SLOT = '<<MOP>>'; | ||
19 | |||||
20 | # spent 3.19ms (1.87+1.31) within Class::MOP::Instance::BUILDARGS which was called 48 times, avg 66µs/call:
# 48 times (1.87ms+1.31ms) by Class::MOP::Instance::new at line 41, avg 66µs/call | ||||
21 | 48 | 51µs | my ($class, @args) = @_; | ||
22 | |||||
23 | 48 | 177µs | 48 | 32µs | if ( @args == 1 ) { # spent 32µs making 48 calls to Scalar::Util::blessed, avg 658ns/call |
24 | unshift @args, "associated_metaclass"; | ||||
25 | } elsif ( @args >= 2 && blessed($args[0]) && $args[0]->isa("Class::MOP::Class") ) { | ||||
26 | # compat mode | ||||
27 | my ( $meta, @attrs ) = @args; | ||||
28 | @args = ( associated_metaclass => $meta, attributes => \@attrs ); | ||||
29 | } | ||||
30 | |||||
31 | 48 | 60µs | my %options = @args; | ||
32 | # FIXME lazy_build | ||||
33 | 467 | 631µs | 419 | 1.28ms | $options{slots} ||= [ map { $_->slots } @{ $options{attributes} || [] } ]; # spent 1.28ms making 419 calls to Class::MOP::Attribute::slots, avg 3µs/call |
34 | 48 | 402µs | $options{slot_hash} = { map { $_ => undef } @{ $options{slots} } }; # FIXME lazy_build | ||
35 | |||||
36 | 48 | 156µs | return \%options; | ||
37 | } | ||||
38 | |||||
39 | # spent 4.19ms (589µs+3.60) within Class::MOP::Instance::new which was called 48 times, avg 87µs/call:
# 48 times (589µs+3.60ms) by Class::MOP::Class::_create_meta_instance at line 726 of Class/MOP/Class.pm, avg 87µs/call | ||||
40 | 48 | 17µs | my $class = shift; | ||
41 | 48 | 71µs | 48 | 3.19ms | my $options = $class->BUILDARGS(@_); # spent 3.19ms making 48 calls to Class::MOP::Instance::BUILDARGS, avg 66µs/call |
42 | |||||
43 | # FIXME replace with a proper constructor | ||||
44 | 48 | 156µs | 48 | 350µs | my $instance = $class->_new(%$options); # spent 328µs making 47 calls to Class::MOP::Instance::_new, avg 7µs/call
# spent 22µs making 1 call to Moose::Meta::Instance::_new |
45 | |||||
46 | # FIXME weak_ref => 1, | ||||
47 | 48 | 157µs | 48 | 62µs | weaken($instance->{'associated_metaclass'}); # spent 62µs making 48 calls to Scalar::Util::weaken, avg 1µs/call |
48 | |||||
49 | 48 | 139µs | return $instance; | ||
50 | } | ||||
51 | |||||
52 | # spent 328µs within Class::MOP::Instance::_new which was called 47 times, avg 7µs/call:
# 47 times (328µs+0s) by Class::MOP::Instance::new at line 44, avg 7µs/call | ||||
53 | 47 | 10µs | my $class = shift; | ||
54 | 47 | 17µs | return Class::MOP::Class->initialize($class)->new_object(@_) | ||
55 | if $class ne __PACKAGE__; | ||||
56 | |||||
57 | 47 | 80µs | my $params = @_ == 1 ? $_[0] : {@_}; | ||
58 | 47 | 253µs | return bless { | ||
59 | # NOTE: | ||||
60 | # I am not sure that it makes | ||||
61 | # sense to pass in the meta | ||||
62 | # The ideal would be to just | ||||
63 | # pass in the class name, but | ||||
64 | # that is placing too much of | ||||
65 | # an assumption on bless(), | ||||
66 | # which is *probably* a safe | ||||
67 | # assumption,.. but you can | ||||
68 | # never tell <:) | ||||
69 | 'associated_metaclass' => $params->{associated_metaclass}, | ||||
70 | 'attributes' => $params->{attributes}, | ||||
71 | 'slots' => $params->{slots}, | ||||
72 | 'slot_hash' => $params->{slot_hash}, | ||||
73 | } => $class; | ||||
74 | } | ||||
75 | |||||
76 | 32 | 124µs | 12 | 9µs | sub _class_name { $_[0]->{_class_name} ||= $_[0]->associated_metaclass->name } # spent 5µs making 6 calls to Class::MOP::Instance::associated_metaclass, avg 800ns/call
# spent 4µs making 6 calls to Class::MOP::Package::name, avg 667ns/call |
77 | |||||
78 | # spent 244µs (152+92) within Class::MOP::Instance::create_instance which was called 32 times, avg 8µs/call:
# 32 times (152µs+92µs) by Class::MOP::Class::_construct_instance at line 522 of Class/MOP/Class.pm, avg 8µs/call | ||||
79 | 32 | 6µs | my $self = shift; | ||
80 | 32 | 133µs | 32 | 92µs | bless {}, $self->_class_name; # spent 92µs making 32 calls to Class::MOP::Instance::_class_name, avg 3µs/call |
81 | } | ||||
82 | |||||
83 | sub clone_instance { | ||||
84 | my ($self, $instance) = @_; | ||||
85 | |||||
86 | my $clone = $self->create_instance; | ||||
87 | for my $attr ($self->get_all_attributes) { | ||||
88 | next unless $attr->has_value($instance); | ||||
89 | for my $slot ($attr->slots) { | ||||
90 | my $val = $self->get_slot_value($instance, $slot); | ||||
91 | $self->set_slot_value($clone, $slot, $val); | ||||
92 | $self->weaken_slot_value($clone, $slot) | ||||
93 | if $self->slot_value_is_weak($instance, $slot); | ||||
94 | } | ||||
95 | } | ||||
96 | |||||
97 | $self->_set_mop_slot($clone, $self->_get_mop_slot($instance)) | ||||
98 | if $self->_has_mop_slot($instance); | ||||
99 | |||||
100 | return $clone; | ||||
101 | } | ||||
102 | |||||
103 | # operations on meta instance | ||||
104 | |||||
105 | sub get_all_slots { | ||||
106 | my $self = shift; | ||||
107 | return @{$self->{'slots'}}; | ||||
108 | } | ||||
109 | |||||
110 | sub get_all_attributes { | ||||
111 | my $self = shift; | ||||
112 | return @{$self->{attributes}}; | ||||
113 | } | ||||
114 | |||||
115 | sub is_valid_slot { | ||||
116 | my ($self, $slot_name) = @_; | ||||
117 | exists $self->{'slot_hash'}->{$slot_name}; | ||||
118 | } | ||||
119 | |||||
120 | # operations on created instances | ||||
121 | |||||
122 | # spent 22µs within Class::MOP::Instance::get_slot_value which was called 12 times, avg 2µs/call:
# 12 times (22µs+0s) by Class::MOP::Attribute::get_raw_value at line 298 of Class/MOP/Attribute.pm, avg 2µs/call | ||||
123 | 12 | 5µs | my ($self, $instance, $slot_name) = @_; | ||
124 | 12 | 27µs | $instance->{$slot_name}; | ||
125 | } | ||||
126 | |||||
127 | # spent 1.18ms within Class::MOP::Instance::set_slot_value which was called 164 times, avg 7µs/call:
# 164 times (1.18ms+0s) by Class::MOP::Attribute::_set_initial_slot_value at line 150 of Class/MOP/Attribute.pm, avg 7µs/call | ||||
128 | 164 | 68µs | my ($self, $instance, $slot_name, $value) = @_; | ||
129 | 164 | 1.26ms | $instance->{$slot_name} = $value; | ||
130 | } | ||||
131 | |||||
132 | sub initialize_slot { | ||||
133 | my ($self, $instance, $slot_name) = @_; | ||||
134 | return; | ||||
135 | } | ||||
136 | |||||
137 | sub deinitialize_slot { | ||||
138 | my ( $self, $instance, $slot_name ) = @_; | ||||
139 | delete $instance->{$slot_name}; | ||||
140 | } | ||||
141 | |||||
142 | sub initialize_all_slots { | ||||
143 | my ($self, $instance) = @_; | ||||
144 | foreach my $slot_name ($self->get_all_slots) { | ||||
145 | $self->initialize_slot($instance, $slot_name); | ||||
146 | } | ||||
147 | } | ||||
148 | |||||
149 | sub deinitialize_all_slots { | ||||
150 | my ($self, $instance) = @_; | ||||
151 | foreach my $slot_name ($self->get_all_slots) { | ||||
152 | $self->deinitialize_slot($instance, $slot_name); | ||||
153 | } | ||||
154 | } | ||||
155 | |||||
156 | # spent 25µs within Class::MOP::Instance::is_slot_initialized which was called 12 times, avg 2µs/call:
# 12 times (25µs+0s) by Class::MOP::Attribute::has_value at line 319 of Class/MOP/Attribute.pm, avg 2µs/call | ||||
157 | 12 | 6µs | my ($self, $instance, $slot_name, $value) = @_; | ||
158 | 12 | 29µs | exists $instance->{$slot_name}; | ||
159 | } | ||||
160 | |||||
161 | sub weaken_slot_value { | ||||
162 | my ($self, $instance, $slot_name) = @_; | ||||
163 | weaken $instance->{$slot_name}; | ||||
164 | } | ||||
165 | |||||
166 | sub slot_value_is_weak { | ||||
167 | my ($self, $instance, $slot_name) = @_; | ||||
168 | isweak $instance->{$slot_name}; | ||||
169 | } | ||||
170 | |||||
171 | sub strengthen_slot_value { | ||||
172 | my ($self, $instance, $slot_name) = @_; | ||||
173 | $self->set_slot_value($instance, $slot_name, $self->get_slot_value($instance, $slot_name)); | ||||
174 | } | ||||
175 | |||||
176 | sub rebless_instance_structure { | ||||
177 | my ($self, $instance, $metaclass) = @_; | ||||
178 | |||||
179 | # we use $_[1] here because of t/cmop/rebless_overload.t regressions | ||||
180 | # on 5.8.8 | ||||
181 | bless $_[1], $metaclass->name; | ||||
182 | } | ||||
183 | |||||
184 | # spent 47µs within Class::MOP::Instance::is_dependent_on_superclasses which was called 48 times, avg 981ns/call:
# 48 times (47µs+0s) by Class::MOP::Class::_create_meta_instance at line 731 of Class/MOP/Class.pm, avg 981ns/call | ||||
185 | 48 | 90µs | return; # for meta instances that require updates on inherited slot changes | ||
186 | } | ||||
187 | |||||
188 | sub _get_mop_slot { | ||||
189 | my ($self, $instance) = @_; | ||||
190 | $self->get_slot_value($instance, $RESERVED_MOP_SLOT); | ||||
191 | } | ||||
192 | |||||
193 | sub _has_mop_slot { | ||||
194 | my ($self, $instance) = @_; | ||||
195 | $self->is_slot_initialized($instance, $RESERVED_MOP_SLOT); | ||||
196 | } | ||||
197 | |||||
198 | sub _set_mop_slot { | ||||
199 | my ($self, $instance, $value) = @_; | ||||
200 | $self->set_slot_value($instance, $RESERVED_MOP_SLOT, $value); | ||||
201 | } | ||||
202 | |||||
203 | sub _clear_mop_slot { | ||||
204 | my ($self, $instance) = @_; | ||||
205 | $self->deinitialize_slot($instance, $RESERVED_MOP_SLOT); | ||||
206 | } | ||||
207 | |||||
208 | # inlinable operation snippets | ||||
209 | |||||
210 | 97 | 179µs | # spent 89µs within Class::MOP::Instance::is_inlinable which was called 97 times, avg 919ns/call:
# 95 times (86µs+0s) by Class::MOP::Attribute::_process_accessors at line 384 of Class/MOP/Attribute.pm, avg 907ns/call
# 2 times (3µs+0s) by Moose::Meta::Method::Accessor::_instance_is_inlinable at line 57 of Moose/Meta/Method/Accessor.pm, avg 1µs/call | ||
211 | |||||
212 | # spent 58µs within Class::MOP::Instance::inline_create_instance which was called 31 times, avg 2µs/call:
# 31 times (58µs+0s) by Class::MOP::Class::_inline_create_instance at line 583 of Class/MOP/Class.pm, avg 2µs/call | ||||
213 | 31 | 9µs | my ($self, $class_variable) = @_; | ||
214 | 31 | 72µs | 'bless {} => ' . $class_variable; | ||
215 | } | ||||
216 | |||||
217 | # spent 1.20ms within Class::MOP::Instance::inline_slot_access which was called 494 times, avg 2µs/call:
# 398 times (922µs+0s) by Class::MOP::Instance::inline_set_slot_value at line 231, avg 2µs/call
# 78 times (221µs+0s) by Class::MOP::Instance::inline_get_slot_value at line 226, avg 3µs/call
# 16 times (48µs+0s) by Class::MOP::Instance::inline_is_slot_initialized at line 245, avg 3µs/call
# 2 times (5µs+0s) by Class::MOP::Instance::inline_weaken_slot_value at line 250, avg 2µs/call | ||||
218 | 494 | 114µs | my ($self, $instance, $slot_name) = @_; | ||
219 | 494 | 1.69ms | sprintf q[%s->{"%s"}], $instance, quotemeta($slot_name); | ||
220 | } | ||||
221 | |||||
222 | sub inline_get_is_lvalue { 1 } | ||||
223 | |||||
224 | # spent 523µs (303+221) within Class::MOP::Instance::inline_get_slot_value which was called 78 times, avg 7µs/call:
# 78 times (303µs+221µs) by Class::MOP::Attribute::_inline_instance_get at line 311 of Class/MOP/Attribute.pm, avg 7µs/call | ||||
225 | 78 | 33µs | my ($self, $instance, $slot_name) = @_; | ||
226 | 78 | 199µs | 78 | 221µs | $self->inline_slot_access($instance, $slot_name); # spent 221µs making 78 calls to Class::MOP::Instance::inline_slot_access, avg 3µs/call |
227 | } | ||||
228 | |||||
229 | # spent 2.56ms (1.64+922µs) within Class::MOP::Instance::inline_set_slot_value which was called 398 times, avg 6µs/call:
# 398 times (1.64ms+922µs) by Class::MOP::Attribute::_inline_instance_set at line 288 of Class/MOP/Attribute.pm, avg 6µs/call | ||||
230 | 398 | 143µs | my ($self, $instance, $slot_name, $value) = @_; | ||
231 | 398 | 1.18ms | 398 | 922µs | $self->inline_slot_access($instance, $slot_name) . " = $value", # spent 922µs making 398 calls to Class::MOP::Instance::inline_slot_access, avg 2µs/call |
232 | } | ||||
233 | |||||
234 | sub inline_initialize_slot { | ||||
235 | my ($self, $instance, $slot_name) = @_; | ||||
236 | return ''; | ||||
237 | } | ||||
238 | |||||
239 | sub inline_deinitialize_slot { | ||||
240 | my ($self, $instance, $slot_name) = @_; | ||||
241 | "delete " . $self->inline_slot_access($instance, $slot_name); | ||||
242 | } | ||||
243 | # spent 126µs (78+48) within Class::MOP::Instance::inline_is_slot_initialized which was called 16 times, avg 8µs/call:
# 16 times (78µs+48µs) by Class::MOP::Attribute::_inline_instance_has at line 332 of Class/MOP/Attribute.pm, avg 8µs/call | ||||
244 | 16 | 8µs | my ($self, $instance, $slot_name) = @_; | ||
245 | 16 | 54µs | 16 | 48µs | "exists " . $self->inline_slot_access($instance, $slot_name); # spent 48µs making 16 calls to Class::MOP::Instance::inline_slot_access, avg 3µs/call |
246 | } | ||||
247 | |||||
248 | # spent 18µs (12+5) within Class::MOP::Instance::inline_weaken_slot_value which was called 2 times, avg 9µs/call:
# 2 times (12µs+5µs) by Moose::Meta::Attribute::_inline_weaken_value at line 762 of Moose/Meta/Attribute.pm, avg 9µs/call | ||||
249 | 2 | 1µs | my ($self, $instance, $slot_name) = @_; | ||
250 | 2 | 10µs | 2 | 5µs | sprintf "Scalar::Util::weaken( %s )", $self->inline_slot_access($instance, $slot_name); # spent 5µs making 2 calls to Class::MOP::Instance::inline_slot_access, avg 2µs/call |
251 | } | ||||
252 | |||||
253 | sub inline_strengthen_slot_value { | ||||
254 | my ($self, $instance, $slot_name) = @_; | ||||
255 | $self->inline_set_slot_value($instance, $slot_name, $self->inline_slot_access($instance, $slot_name)); | ||||
256 | } | ||||
257 | |||||
258 | sub inline_rebless_instance_structure { | ||||
259 | my ($self, $instance, $class_variable) = @_; | ||||
260 | "bless $instance => $class_variable"; | ||||
261 | } | ||||
262 | |||||
263 | sub _inline_get_mop_slot { | ||||
264 | my ($self, $instance) = @_; | ||||
265 | $self->inline_get_slot_value($instance, $RESERVED_MOP_SLOT); | ||||
266 | } | ||||
267 | |||||
268 | sub _inline_set_mop_slot { | ||||
269 | my ($self, $instance, $value) = @_; | ||||
270 | $self->inline_set_slot_value($instance, $RESERVED_MOP_SLOT, $value); | ||||
271 | } | ||||
272 | |||||
273 | sub _inline_clear_mop_slot { | ||||
274 | my ($self, $instance) = @_; | ||||
275 | $self->inline_deinitialize_slot($instance, $RESERVED_MOP_SLOT); | ||||
276 | } | ||||
277 | |||||
278 | 1 | 4µs | 1; | ||
279 | |||||
280 | # ABSTRACT: Instance Meta Object | ||||
281 | |||||
282 | __END__ |