Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Class/MOP/Instance.pm |
Statements | Executed 3965 statements in 8.39ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
52 | 1 | 1 | 926µs | 1.52ms | BUILDARGS | Class::MOP::Instance::
405 | 1 | 1 | 693µs | 1.14ms | inline_set_slot_value | Class::MOP::Instance::
507 | 4 | 1 | 600µs | 600µs | inline_slot_access | Class::MOP::Instance::
185 | 1 | 1 | 486µs | 486µs | set_slot_value | Class::MOP::Instance::
52 | 1 | 1 | 318µs | 2.07ms | new | Class::MOP::Instance::
48 | 1 | 1 | 175µs | 175µs | _new | Class::MOP::Instance::
83 | 1 | 1 | 138µs | 262µs | inline_get_slot_value | Class::MOP::Instance::
35 | 1 | 1 | 110µs | 172µs | create_instance | Class::MOP::Instance::
17 | 1 | 1 | 42µs | 71µs | inline_is_slot_initialized | Class::MOP::Instance::
99 | 2 | 2 | 41µs | 41µs | is_inlinable | Class::MOP::Instance::
31 | 1 | 1 | 32µs | 32µs | inline_create_instance | Class::MOP::Instance::
52 | 1 | 1 | 28µs | 28µs | is_dependent_on_superclasses | Class::MOP::Instance::
12 | 1 | 1 | 14µs | 14µs | is_slot_initialized | Class::MOP::Instance::
12 | 1 | 1 | 10µs | 10µs | get_slot_value | Class::MOP::Instance::
1 | 1 | 1 | 7µs | 8µs | BEGIN@4 | Class::MOP::Instance::
2 | 1 | 1 | 7µs | 9µs | inline_weaken_slot_value | Class::MOP::Instance::
1 | 1 | 1 | 4µs | 18µs | BEGIN@9 | Class::MOP::Instance::
1 | 1 | 1 | 4µs | 6µs | BEGIN@5 | Class::MOP::Instance::
1 | 1 | 1 | 4µs | 37µ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_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 | package Class::MOP::Instance; | ||||
2 | 1 | 200ns | our $VERSION = '2.1605'; | ||
3 | |||||
4 | 2 | 16µs | 2 | 9µs | # spent 8µs (7+1) within Class::MOP::Instance::BEGIN@4 which was called:
# once (7µs+1µs) by Class::MOP::Class::BEGIN@7 at line 4 # spent 8µs making 1 call to Class::MOP::Instance::BEGIN@4
# spent 1µs making 1 call to strict::import |
5 | 2 | 15µs | 2 | 9µs | # spent 6µs (4+2) within Class::MOP::Instance::BEGIN@5 which was called:
# once (4µs+2µs) by Class::MOP::Class::BEGIN@7 at line 5 # spent 6µs making 1 call to Class::MOP::Instance::BEGIN@5
# spent 2µs making 1 call to warnings::import |
6 | |||||
7 | 2 | 25µs | 2 | 71µs | # spent 37µs (4+34) within Class::MOP::Instance::BEGIN@7 which was called:
# once (4µs+34µs) by Class::MOP::Class::BEGIN@7 at line 7 # spent 37µs making 1 call to Class::MOP::Instance::BEGIN@7
# spent 34µs making 1 call to Exporter::import |
8 | |||||
9 | 2 | 674µs | 2 | 31µs | # spent 18µs (4+14) within Class::MOP::Instance::BEGIN@9 which was called:
# once (4µs+14µs) by Class::MOP::Class::BEGIN@7 at line 9 # spent 18µs making 1 call to Class::MOP::Instance::BEGIN@9
# spent 14µs making 1 call to parent::import |
10 | |||||
11 | # make this not a valid method name, to avoid (most) attribute conflicts | ||||
12 | 1 | 200ns | my $RESERVED_MOP_SLOT = '<<MOP>>'; | ||
13 | |||||
14 | # spent 1.52ms (926µs+595µs) within Class::MOP::Instance::BUILDARGS which was called 52 times, avg 29µs/call:
# 52 times (926µs+595µs) by Class::MOP::Instance::new at line 35, avg 29µs/call | ||||
15 | 52 | 40µs | my ($class, @args) = @_; | ||
16 | |||||
17 | 52 | 111µs | 52 | 15µs | if ( @args == 1 ) { # spent 15µs making 52 calls to Scalar::Util::blessed, avg 288ns/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 | 52 | 42µs | my %options = @args; | ||
26 | # FIXME lazy_build | ||||
27 | 478 | 333µs | 426 | 580µs | $options{slots} ||= [ map { $_->slots } @{ $options{attributes} || [] } ]; # spent 580µs making 426 calls to Class::MOP::Attribute::slots, avg 1µs/call |
28 | 52 | 163µs | $options{slot_hash} = { map { $_ => undef } @{ $options{slots} } }; # FIXME lazy_build | ||
29 | |||||
30 | 52 | 77µs | return \%options; | ||
31 | } | ||||
32 | |||||
33 | # spent 2.07ms (318µs+1.76) within Class::MOP::Instance::new which was called 52 times, avg 40µs/call:
# 52 times (318µs+1.76ms) by Class::MOP::Class::_create_meta_instance at line 727 of Class/MOP/Class.pm, avg 40µs/call | ||||
34 | 52 | 10µs | my $class = shift; | ||
35 | 52 | 61µs | 52 | 1.52ms | my $options = $class->BUILDARGS(@_); # spent 1.52ms making 52 calls to Class::MOP::Instance::BUILDARGS, avg 29µs/call |
36 | |||||
37 | # FIXME replace with a proper constructor | ||||
38 | 52 | 86µs | 52 | 203µs | my $instance = $class->_new(%$options); # spent 175µs making 48 calls to Class::MOP::Instance::_new, avg 4µs/call
# spent 28µs making 4 calls to Moose::Meta::Instance::_new, avg 7µs/call |
39 | |||||
40 | # FIXME weak_ref => 1, | ||||
41 | 52 | 91µs | 52 | 31µs | weaken($instance->{'associated_metaclass'}); # spent 31µs making 52 calls to Scalar::Util::weaken, avg 596ns/call |
42 | |||||
43 | 52 | 87µs | return $instance; | ||
44 | } | ||||
45 | |||||
46 | # spent 175µs within Class::MOP::Instance::_new which was called 48 times, avg 4µs/call:
# 48 times (175µs+0s) by Class::MOP::Instance::new at line 38, avg 4µs/call | ||||
47 | 48 | 8µs | my $class = shift; | ||
48 | 48 | 11µs | return Class::MOP::Class->initialize($class)->new_object(@_) | ||
49 | if $class ne __PACKAGE__; | ||||
50 | |||||
51 | 48 | 42µs | 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 | 48 | 131µs | } => $class; | ||
68 | } | ||||
69 | |||||
70 | 35 | 82µs | 12 | 5µs | sub _class_name { $_[0]->{_class_name} ||= $_[0]->associated_metaclass->name } # spent 3µs making 6 calls to Class::MOP::Instance::associated_metaclass, avg 517ns/call
# spent 2µs making 6 calls to Class::MOP::Package::name, avg 283ns/call |
71 | |||||
72 | # spent 172µs (110+62) within Class::MOP::Instance::create_instance which was called 35 times, avg 5µs/call:
# 35 times (110µs+62µs) by Class::MOP::Class::_construct_instance at line 523 of Class/MOP/Class.pm, avg 5µs/call | ||||
73 | 35 | 12µs | my $self = shift; | ||
74 | 35 | 94µs | 35 | 62µs | bless {}, $self->_class_name; # spent 62µs making 35 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 10µs within Class::MOP::Instance::get_slot_value which was called 12 times, avg 867ns/call:
# 12 times (10µs+0s) by Class::MOP::Attribute::get_raw_value at line 312 of Class/MOP/Attribute.pm, avg 867ns/call | ||||
117 | 12 | 3µs | my ($self, $instance, $slot_name) = @_; | ||
118 | 12 | 14µs | $instance->{$slot_name}; | ||
119 | } | ||||
120 | |||||
121 | # spent 486µs within Class::MOP::Instance::set_slot_value which was called 185 times, avg 3µs/call:
# 185 times (486µs+0s) by Class::MOP::Attribute::_set_initial_slot_value at line 162 of Class/MOP/Attribute.pm, avg 3µs/call | ||||
122 | 185 | 40µs | my ($self, $instance, $slot_name, $value) = @_; | ||
123 | 185 | 544µs | $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 14µs within Class::MOP::Instance::is_slot_initialized which was called 12 times, avg 1µs/call:
# 12 times (14µs+0s) by Class::MOP::Attribute::has_value at line 333 of Class/MOP/Attribute.pm, avg 1µs/call | ||||
151 | 12 | 4µs | my ($self, $instance, $slot_name, $value) = @_; | ||
152 | 12 | 15µs | 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 28µs within Class::MOP::Instance::is_dependent_on_superclasses which was called 52 times, avg 548ns/call:
# 52 times (28µs+0s) by Class::MOP::Class::_create_meta_instance at line 732 of Class/MOP/Class.pm, avg 548ns/call | ||||
179 | 52 | 57µ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 | 99 | 95µs | # spent 41µs within Class::MOP::Instance::is_inlinable which was called 99 times, avg 416ns/call:
# 94 times (37µs+0s) by Class::MOP::Attribute::_process_accessors at line 402 of Class/MOP/Attribute.pm, avg 395ns/call
# 5 times (4µs+0s) by Moose::Meta::Method::Accessor::_instance_is_inlinable at line 51 of Moose/Meta/Method/Accessor.pm, avg 820ns/call | ||
205 | |||||
206 | # spent 32µs within Class::MOP::Instance::inline_create_instance which was called 31 times, avg 1µs/call:
# 31 times (32µs+0s) by Class::MOP::Class::_inline_create_instance at line 584 of Class/MOP/Class.pm, avg 1µs/call | ||||
207 | 31 | 7µs | my ($self, $class_variable) = @_; | ||
208 | 31 | 44µs | 'bless {} => ' . $class_variable; | ||
209 | } | ||||
210 | |||||
211 | # spent 600µs within Class::MOP::Instance::inline_slot_access which was called 507 times, avg 1µs/call:
# 405 times (445µs+0s) by Class::MOP::Instance::inline_set_slot_value at line 225, avg 1µs/call
# 83 times (124µs+0s) by Class::MOP::Instance::inline_get_slot_value at line 220, avg 1µs/call
# 17 times (29µs+0s) by Class::MOP::Instance::inline_is_slot_initialized at line 239, avg 2µs/call
# 2 times (2µs+0s) by Class::MOP::Instance::inline_weaken_slot_value at line 244, avg 1µs/call | ||||
212 | 507 | 79µs | my ($self, $instance, $slot_name) = @_; | ||
213 | 507 | 824µs | sprintf q[%s->{"%s"}], $instance, quotemeta($slot_name); | ||
214 | } | ||||
215 | |||||
216 | sub inline_get_is_lvalue { 1 } | ||||
217 | |||||
218 | # spent 262µs (138+124) within Class::MOP::Instance::inline_get_slot_value which was called 83 times, avg 3µs/call:
# 83 times (138µs+124µs) by Class::MOP::Attribute::_inline_instance_get at line 325 of Class/MOP/Attribute.pm, avg 3µs/call | ||||
219 | 83 | 17µs | my ($self, $instance, $slot_name) = @_; | ||
220 | 83 | 119µs | 83 | 124µs | $self->inline_slot_access($instance, $slot_name); # spent 124µs making 83 calls to Class::MOP::Instance::inline_slot_access, avg 1µs/call |
221 | } | ||||
222 | |||||
223 | # spent 1.14ms (693µs+445µs) within Class::MOP::Instance::inline_set_slot_value which was called 405 times, avg 3µs/call:
# 405 times (693µs+445µs) by Class::MOP::Attribute::_inline_instance_set at line 302 of Class/MOP/Attribute.pm, avg 3µs/call | ||||
224 | 405 | 79µs | my ($self, $instance, $slot_name, $value) = @_; | ||
225 | 405 | 4.19ms | 405 | 445µs | $self->inline_slot_access($instance, $slot_name) . " = $value", # spent 445µs making 405 calls to Class::MOP::Instance::inline_slot_access, avg 1µs/call |
226 | } | ||||
227 | |||||
228 | sub inline_initialize_slot { | ||||
229 | my ($self, $instance, $slot_name) = @_; | ||||
230 | return ''; | ||||
231 | } | ||||
232 | |||||
233 | sub inline_deinitialize_slot { | ||||
234 | my ($self, $instance, $slot_name) = @_; | ||||
235 | "delete " . $self->inline_slot_access($instance, $slot_name); | ||||
236 | } | ||||
237 | # spent 71µs (42+29) within Class::MOP::Instance::inline_is_slot_initialized which was called 17 times, avg 4µs/call:
# 17 times (42µs+29µs) by Class::MOP::Attribute::_inline_instance_has at line 346 of Class/MOP/Attribute.pm, avg 4µs/call | ||||
238 | 17 | 5µs | my ($self, $instance, $slot_name) = @_; | ||
239 | 17 | 35µs | 17 | 29µs | "exists " . $self->inline_slot_access($instance, $slot_name); # spent 29µs making 17 calls to Class::MOP::Instance::inline_slot_access, avg 2µs/call |
240 | } | ||||
241 | |||||
242 | # spent 9µs (7+2) within Class::MOP::Instance::inline_weaken_slot_value which was called 2 times, avg 5µs/call:
# 2 times (7µs+2µs) by Moose::Meta::Attribute::_inline_weaken_value at line 739 of Moose/Meta/Attribute.pm, avg 5µs/call | ||||
243 | 2 | 500ns | my ($self, $instance, $slot_name) = @_; | ||
244 | 2 | 5µs | 2 | 2µs | sprintf "Scalar::Util::weaken( %s )", $self->inline_slot_access($instance, $slot_name); # spent 2µs making 2 calls to Class::MOP::Instance::inline_slot_access, avg 1µ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 | 2µs | 1; | ||
273 | |||||
274 | # ABSTRACT: Instance Meta Object | ||||
275 | |||||
276 | __END__ |