Profile of Class/MOP/Instance.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:23:28 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Instance.pm
Statements | Executed 4480 statements in 12.7ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
58 | 1 | 1 | 3.27ms | 3.45ms | Class::MOP::Instance::::create_instanceClass::MOP::Instance::create_instance
56 | 1 | 1 | 1.82ms | 3.17ms | Class::MOP::Instance::::BUILDARGSClass::MOP::Instance::BUILDARGS
403 | 1 | 1 | 1.61ms | 2.47ms | Class::MOP::Instance::::inline_set_slot_valueClass::MOP::Instance::inline_set_slot_value
506 | 4 | 1 | 1.15ms | 1.15ms | Class::MOP::Instance::::inline_slot_accessClass::MOP::Instance::inline_slot_access
376 | 1 | 1 | 998µs | 998µs | Class::MOP::Instance::::set_slot_valueClass::MOP::Instance::set_slot_value
56 | 1 | 1 | 667µs | 4.44ms | Class::MOP::Instance::::newClass::MOP::Instance::new
47 | 1 | 1 | 376µs | 376µs | Class::MOP::Instance::::_newClass::MOP::Instance::_new
84 | 1 | 1 | 340µs | 572µs | Class::MOP::Instance::::inline_get_slot_valueClass::MOP::Instance::inline_get_slot_value
103 | 2 | 2 | 106µs | 106µs | Class::MOP::Instance::::is_inlinableClass::MOP::Instance::is_inlinable
17 | 1 | 1 | 80µs | 125µs | Class::MOP::Instance::::inline_is_slot_initializedClass::MOP::Instance::inline_is_slot_initialized
56 | 1 | 1 | 72µs | 72µs | Class::MOP::Instance::::is_dependent_on_superclassesClass::MOP::Instance::is_dependent_on_superclasses
30 | 1 | 1 | 71µs | 71µs | Class::MOP::Instance::::inline_create_instanceClass::MOP::Instance::inline_create_instance
12 | 1 | 1 | 25µs | 25µs | Class::MOP::Instance::::is_slot_initializedClass::MOP::Instance::is_slot_initialized
12 | 1 | 1 | 23µs | 23µs | Class::MOP::Instance::::get_slot_valueClass::MOP::Instance::get_slot_value
2 | 1 | 1 | 12µs | 16µs | Class::MOP::Instance::::inline_weaken_slot_valueClass::MOP::Instance::inline_weaken_slot_value
1 | 1 | 1 | 8µs | 8µs | Class::MOP::Instance::::BEGIN@3Class::MOP::Instance::BEGIN@3
1 | 1 | 1 | 8µs | 51µs | Class::MOP::Instance::::BEGIN@13Class::MOP::Instance::BEGIN@13
1 | 1 | 1 | 6µs | 69µs | Class::MOP::Instance::::BEGIN@15Class::MOP::Instance::BEGIN@15
1 | 1 | 1 | 6µs | 8µs | Class::MOP::Instance::::BEGIN@10Class::MOP::Instance::BEGIN@10
1 | 1 | 1 | 6µs | 14µs | Class::MOP::Instance::::BEGIN@11Class::MOP::Instance::BEGIN@11
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::_clear_mop_slotClass::MOP::Instance::_clear_mop_slot
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::_get_mop_slotClass::MOP::Instance::_get_mop_slot
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::_has_mop_slotClass::MOP::Instance::_has_mop_slot
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::_inline_clear_mop_slotClass::MOP::Instance::_inline_clear_mop_slot
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::_inline_get_mop_slotClass::MOP::Instance::_inline_get_mop_slot
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::_inline_set_mop_slotClass::MOP::Instance::_inline_set_mop_slot
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::_set_mop_slotClass::MOP::Instance::_set_mop_slot
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::clone_instanceClass::MOP::Instance::clone_instance
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::deinitialize_all_slotsClass::MOP::Instance::deinitialize_all_slots
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::deinitialize_slotClass::MOP::Instance::deinitialize_slot
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::get_all_attributesClass::MOP::Instance::get_all_attributes
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::get_all_slotsClass::MOP::Instance::get_all_slots
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::initialize_all_slotsClass::MOP::Instance::initialize_all_slots
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::initialize_slotClass::MOP::Instance::initialize_slot
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::inline_deinitialize_slotClass::MOP::Instance::inline_deinitialize_slot
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::inline_get_is_lvalueClass::MOP::Instance::inline_get_is_lvalue
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::inline_initialize_slotClass::MOP::Instance::inline_initialize_slot
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::inline_rebless_instance_structureClass::MOP::Instance::inline_rebless_instance_structure
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::inline_strengthen_slot_valueClass::MOP::Instance::inline_strengthen_slot_value
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::is_valid_slotClass::MOP::Instance::is_valid_slot
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::rebless_instance_structureClass::MOP::Instance::rebless_instance_structure
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::slot_value_is_weakClass::MOP::Instance::slot_value_is_weak
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::strengthen_slot_valueClass::MOP::Instance::strengthen_slot_value
0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::::weaken_slot_valueClass::MOP::Instance::weaken_slot_value

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  |
2 |  |  |  |  | package Class::MOP::Instance;
3 |  |  |  |  | # spent 8µs within Class::MOP::Instance::BEGIN@3 which was called: # once (8µs+0s) by Class::MOP::Class::BEGIN@13 at line 5 BEGIN {
4 | 1 | 7µs |  |  | $Class::MOP::Instance::AUTHORITY = 'cpan:STEVAN';
5 | 1 | 22µs | 1 | 8µs | } # spent 8µs making 1 call to Class::MOP::Instance::BEGIN@3
6 |  |  |  |  | {
7 | 2 | 1µs |  |  | $Class::MOP::Instance::VERSION = '2.0602';
8 |  |  |  |  | }
9 |  |  |  |  |
10 | 3 | 15µs | 2 | 10µs | # spent 8µs (6+2) within Class::MOP::Instance::BEGIN@10 which was called: # once (6µs+2µs) by Class::MOP::Class::BEGIN@13 at line 10 use strict; # spent 8µs making 1 call to Class::MOP::Instance::BEGIN@10 # spent 2µs making 1 call to strict::import
11 | 3 | 19µs | 2 | 22µs | # spent 14µs (6+8) within Class::MOP::Instance::BEGIN@11 which was called: # once (6µs+8µs) by Class::MOP::Class::BEGIN@13 at line 11 use warnings; # spent 14µs making 1 call to Class::MOP::Instance::BEGIN@11 # spent 8µs making 1 call to warnings::import
12 |  |  |  |  |
13 | 3 | 20µs | 2 | 95µs | # spent 51µs (8+44) within Class::MOP::Instance::BEGIN@13 which was called: # once (8µs+44µs) by Class::MOP::Class::BEGIN@13 at line 13 use Scalar::Util 'isweak', 'weaken', 'blessed'; # spent 51µs making 1 call to Class::MOP::Instance::BEGIN@13 # spent 44µs making 1 call to Exporter::import
14 |  |  |  |  |
15 | 3 | 1.17ms | 2 | 131µs | # spent 69µs (6+62) within Class::MOP::Instance::BEGIN@15 which was called: # once (6µs+62µs) by Class::MOP::Class::BEGIN@13 at line 15 use base 'Class::MOP::Object'; # spent 69µs making 1 call to Class::MOP::Instance::BEGIN@15 # spent 62µs making 1 call to base::import
16 |  |  |  |  |
17 |  |  |  |  | # make this not a valid method name, to avoid (most) attribute conflicts
18 | 1 | 400ns |  |  | my $RESERVED_MOP_SLOT = '<<MOP>>';
19 |  |  |  |  |
20 |  |  |  |  | # spent 3.17ms (1.82+1.35) within Class::MOP::Instance::BUILDARGS which was called 56 times, avg 57µs/call: # 56 times (1.82ms+1.35ms) by Class::MOP::Instance::new at line 41, avg 57µs/call sub BUILDARGS {
21 | 56 | 85µs |  |  | my ($class, @args) = @_;
22 |  |  |  |  |
23 | 56 | 225µs | 56 | 42µs | if ( @args == 1 ) { # spent 42µs making 56 calls to Scalar::Util::blessed, avg 746ns/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 | 56 | 75µs |  |  | my %options = @args;
32 |  |  |  |  | # FIXME lazy_build
33 | 498 | 760µs | 442 | 1.31ms | $options{slots} ||= [ map { $_->slots } @{ $options{attributes} || [] } ]; # spent 1.31ms making 442 calls to Class::MOP::Attribute::slots, avg 3µs/call
34 | 56 | 317µs |  |  | $options{slot_hash} = { map { $_ => undef } @{ $options{slots} } }; # FIXME lazy_build
35 |  |  |  |  |
36 | 56 | 151µs |  |  | return \%options;
37 |  |  |  |  | }
38 |  |  |  |  |
39 |  |  |  |  | # spent 4.44ms (667µs+3.78) within Class::MOP::Instance::new which was called 56 times, avg 79µs/call: # 56 times (667µs+3.78ms) by Class::MOP::Class::_create_meta_instance at line 726 of Class/MOP/Class.pm, avg 79µs/call sub new {
40 | 56 | 40µs |  |  | my $class = shift;
41 | 56 | 142µs | 56 | 3.17ms | my $options = $class->BUILDARGS(@_); # spent 3.17ms making 56 calls to Class::MOP::Instance::BUILDARGS, avg 57µs/call
42 |  |  |  |  |
43 |  |  |  |  | # FIXME replace with a proper constructor
44 | 56 | 189µs | 56 | 545µs | my $instance = $class->_new(%$options); # spent 376µs making 47 calls to Class::MOP::Instance::_new, avg 8µs/call # spent 168µs making 9 calls to Moose::Meta::Instance::_new, avg 19µs/call
45 |  |  |  |  |
46 |  |  |  |  | # FIXME weak_ref => 1,
47 | 56 | 164µs | 56 | 61µs | weaken($instance->{'associated_metaclass'}); # spent 61µs making 56 calls to Scalar::Util::weaken, avg 1µs/call
48 |  |  |  |  |
49 | 56 | 138µs |  |  | return $instance;
50 |  |  |  |  | }
51 |  |  |  |  |
52 |  |  |  |  | # spent 376µs within Class::MOP::Instance::_new which was called 47 times, avg 8µs/call: # 47 times (376µs+0s) by Class::MOP::Instance::new at line 44, avg 8µs/call sub _new {
53 | 47 | 22µs |  |  | my $class = shift;
54 | 47 | 28µs |  |  | return Class::MOP::Class->initialize($class)->new_object(@_)
55 |  |  |  |  | if $class ne __PACKAGE__;
56 |  |  |  |  |
57 | 47 | 72µs |  |  | my $params = @_ == 1 ? $_[0] : {@_};
58 | 47 | 287µ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 | 58 | 241µs | 18 | 15µs | sub _class_name { $_[0]->{_class_name} ||= $_[0]->associated_metaclass->name } # spent 10µs making 9 calls to Class::MOP::Instance::associated_metaclass, avg 1µs/call # spent 5µs making 9 calls to Class::MOP::Package::name, avg 567ns/call
77 |  |  |  |  |
78 |  |  |  |  | # spent 3.45ms (3.27+183µs) within Class::MOP::Instance::create_instance which was called 58 times, avg 60µs/call: # 58 times (3.27ms+183µs) by Class::MOP::Class::_construct_instance at line 522 of Class/MOP/Class.pm, avg 60µs/call sub create_instance {
79 | 58 | 24µs |  |  | my $self = shift;
80 | 58 | 3.22ms | 58 | 182µs | bless {}, $self->_class_name; # spent 182µs making 58 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 23µs within Class::MOP::Instance::get_slot_value which was called 12 times, avg 2µs/call: # 12 times (23µs+0s) by Class::MOP::Attribute::get_raw_value at line 298 of Class/MOP/Attribute.pm, avg 2µs/call sub get_slot_value {
123 | 12 | 7µs |  |  | my ($self, $instance, $slot_name) = @_;
124 | 12 | 24µs |  |  | $instance->{$slot_name};
125 |  |  |  |  | }
126 |  |  |  |  |
127 |  |  |  |  | # spent 998µs within Class::MOP::Instance::set_slot_value which was called 376 times, avg 3µs/call: # 376 times (998µs+0s) by Class::MOP::Attribute::_set_initial_slot_value at line 150 of Class/MOP/Attribute.pm, avg 3µs/call sub set_slot_value {
128 | 376 | 273µs |  |  | my ($self, $instance, $slot_name, $value) = @_;
129 | 376 | 1.06ms |  |  | $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 sub is_slot_initialized {
157 | 12 | 8µs |  |  | my ($self, $instance, $slot_name, $value) = @_;
158 | 12 | 25µ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 72µs within Class::MOP::Instance::is_dependent_on_superclasses which was called 56 times, avg 1µs/call: # 56 times (72µs+0s) by Class::MOP::Class::_create_meta_instance at line 731 of Class/MOP/Class.pm, avg 1µs/call sub is_dependent_on_superclasses {
185 | 56 | 109µ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 | 103 | 185µs |  |  | # spent 106µs within Class::MOP::Instance::is_inlinable which was called 103 times, avg 1µs/call: # 95 times (94µs+0s) by Class::MOP::Attribute::_process_accessors at line 384 of Class/MOP/Attribute.pm, avg 992ns/call # 8 times (12µs+0s) by Moose::Meta::Method::Accessor::_instance_is_inlinable at line 57 of Moose/Meta/Method/Accessor.pm, avg 1µs/call sub is_inlinable { 1 }
211 |  |  |  |  |
212 |  |  |  |  | # spent 71µs within Class::MOP::Instance::inline_create_instance which was called 30 times, avg 2µs/call: # 30 times (71µs+0s) by Class::MOP::Class::_inline_create_instance at line 583 of Class/MOP/Class.pm, avg 2µs/call sub inline_create_instance {
213 | 30 | 19µs |  |  | my ($self, $class_variable) = @_;
214 | 30 | 79µs |  |  | 'bless {} => ' . $class_variable;
215 |  |  |  |  | }
216 |  |  |  |  |
217 |  |  |  |  | # spent 1.15ms within Class::MOP::Instance::inline_slot_access which was called 506 times, avg 2µs/call: # 403 times (868µs+0s) by Class::MOP::Instance::inline_set_slot_value at line 231, avg 2µs/call # 84 times (231µs+0s) by Class::MOP::Instance::inline_get_slot_value at line 226, avg 3µs/call # 17 times (44µs+0s) by Class::MOP::Instance::inline_is_slot_initialized at line 245, avg 3µs/call # 2 times (4µs+0s) by Class::MOP::Instance::inline_weaken_slot_value at line 250, avg 2µs/call sub inline_slot_access {
218 | 506 | 223µs |  |  | my ($self, $instance, $slot_name) = @_;
219 | 506 | 1.44ms |  |  | sprintf q[%s->{"%s"}], $instance, quotemeta($slot_name);
220 |  |  |  |  | }
221 |  |  |  |  |
222 |  |  |  |  | sub inline_get_is_lvalue { 1 }
223 |  |  |  |  |
224 |  |  |  |  | # spent 572µs (340+231) within Class::MOP::Instance::inline_get_slot_value which was called 84 times, avg 7µs/call: # 84 times (340µs+231µs) by Class::MOP::Attribute::_inline_instance_get at line 311 of Class/MOP/Attribute.pm, avg 7µs/call sub inline_get_slot_value {
225 | 84 | 59µs |  |  | my ($self, $instance, $slot_name) = @_;
226 | 84 | 233µs | 84 | 231µs | $self->inline_slot_access($instance, $slot_name); # spent 231µs making 84 calls to Class::MOP::Instance::inline_slot_access, avg 3µs/call
227 |  |  |  |  | }
228 |  |  |  |  |
229 |  |  |  |  | # spent 2.47ms (1.61+868µs) within Class::MOP::Instance::inline_set_slot_value which was called 403 times, avg 6µs/call: # 403 times (1.61ms+868µs) by Class::MOP::Attribute::_inline_instance_set at line 288 of Class/MOP/Attribute.pm, avg 6µs/call sub inline_set_slot_value {
230 | 403 | 249µs |  |  | my ($self, $instance, $slot_name, $value) = @_;
231 | 403 | 1.17ms | 403 | 868µs | $self->inline_slot_access($instance, $slot_name) . " = $value", # spent 868µs making 403 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 125µs (80+44) within Class::MOP::Instance::inline_is_slot_initialized which was called 17 times, avg 7µs/call: # 17 times (80µs+44µs) by Class::MOP::Attribute::_inline_instance_has at line 332 of Class/MOP/Attribute.pm, avg 7µs/call sub inline_is_slot_initialized {
244 | 17 | 12µs |  |  | my ($self, $instance, $slot_name) = @_;
245 | 17 | 66µs | 17 | 44µs | "exists " . $self->inline_slot_access($instance, $slot_name); # spent 44µs making 17 calls to Class::MOP::Instance::inline_slot_access, avg 3µs/call
246 |  |  |  |  | }
247 |  |  |  |  |
248 |  |  |  |  | # spent 16µs (12+4) within Class::MOP::Instance::inline_weaken_slot_value which was called 2 times, avg 8µs/call: # 2 times (12µs+4µs) by Moose::Meta::Attribute::_inline_weaken_value at line 758 of Moose/Meta/Attribute.pm, avg 8µs/call sub inline_weaken_slot_value {
249 | 2 | 2µs |  |  | my ($self, $instance, $slot_name) = @_;
250 | 2 | 8µs | 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
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 | 3µs |  |  | 1;
279 |  |  |  |  |
280 |  |  |  |  | # ABSTRACT: Instance Meta Object
281 |  |  |  |  |
- - |  |  |  |  |
284 |  |  |  |  | =pod
285 |  |  |  |  |
286 |  |  |  |  | =head1 NAME
287 |  |  |  |  |
288 |  |  |  |  | Class::MOP::Instance - Instance Meta Object
289 |  |  |  |  |
290 |  |  |  |  | =head1 VERSION
291 |  |  |  |  |
292 |  |  |  |  | version 2.0602
293 |  |  |  |  |
294 |  |  |  |  | =head1 DESCRIPTION
295 |  |  |  |  |
296 |  |  |  |  | The Instance Protocol controls the creation of object instances, and
297 |  |  |  |  | the storage of attribute values in those instances.
298 |  |  |  |  |
299 |  |  |  |  | Using this API directly in your own code violates encapsulation, and
300 |  |  |  |  | we recommend that you use the appropriate APIs in L<Class::MOP::Class>
301 |  |  |  |  | and L<Class::MOP::Attribute> instead. Those APIs in turn call the
302 |  |  |  |  | methods in this class as appropriate.
303 |  |  |  |  |
304 |  |  |  |  | This class also participates in generating inlined code by providing
305 |  |  |  |  | snippets of code to access an object instance.
306 |  |  |  |  |
307 |  |  |  |  | =head1 METHODS
308 |  |  |  |  |
309 |  |  |  |  | =head2 Object construction
310 |  |  |  |  |
311 |  |  |  |  | =over 4
312 |  |  |  |  |
313 |  |  |  |  | =item B<< Class::MOP::Instance->new(%options) >>
314 |  |  |  |  |
315 |  |  |  |  | This method creates a new meta-instance object.
316 |  |  |  |  |
317 |  |  |  |  | It accepts the following keys in C<%options>:
318 |  |  |  |  |
319 |  |  |  |  | =over 8
320 |  |  |  |  |
321 |  |  |  |  | =item * associated_metaclass
322 |  |  |  |  |
323 |  |  |  |  | The L<Class::MOP::Class> object for which instances will be created.
324 |  |  |  |  |
325 |  |  |  |  | =item * attributes
326 |  |  |  |  |
327 |  |  |  |  | An array reference of L<Class::MOP::Attribute> objects. These are the
328 |  |  |  |  | attributes which can be stored in each instance.
329 |  |  |  |  |
330 |  |  |  |  | =back
331 |  |  |  |  |
332 |  |  |  |  | =back
333 |  |  |  |  |
334 |  |  |  |  | =head2 Creating and altering instances
335 |  |  |  |  |
336 |  |  |  |  | =over 4
337 |  |  |  |  |
338 |  |  |  |  | =item B<< $metainstance->create_instance >>
339 |  |  |  |  |
340 |  |  |  |  | This method returns a reference blessed into the associated
341 |  |  |  |  | metaclass's class.
342 |  |  |  |  |
343 |  |  |  |  | The default is to use a hash reference. Subclasses can override this.
344 |  |  |  |  |
345 |  |  |  |  | =item B<< $metainstance->clone_instance($instance) >>
346 |  |  |  |  |
347 |  |  |  |  | Given an instance, this method creates a new object by making
348 |  |  |  |  | I<shallow> clone of the original.
349 |  |  |  |  |
350 |  |  |  |  | =back
351 |  |  |  |  |
352 |  |  |  |  | =head2 Introspection
353 |  |  |  |  |
354 |  |  |  |  | =over 4
355 |  |  |  |  |
356 |  |  |  |  | =item B<< $metainstance->associated_metaclass >>
357 |  |  |  |  |
358 |  |  |  |  | This returns the L<Class::MOP::Class> object associated with the
359 |  |  |  |  | meta-instance object.
360 |  |  |  |  |
361 |  |  |  |  | =item B<< $metainstance->get_all_slots >>
362 |  |  |  |  |
363 |  |  |  |  | This returns a list of slot names stored in object instances. In
364 |  |  |  |  | almost all cases, slot names correspond directly attribute names.
365 |  |  |  |  |
366 |  |  |  |  | =item B<< $metainstance->is_valid_slot($slot_name) >>
367 |  |  |  |  |
368 |  |  |  |  | This will return true if C<$slot_name> is a valid slot name.
369 |  |  |  |  |
370 |  |  |  |  | =item B<< $metainstance->get_all_attributes >>
371 |  |  |  |  |
372 |  |  |  |  | This returns a list of attributes corresponding to the attributes
373 |  |  |  |  | passed to the constructor.
374 |  |  |  |  |
375 |  |  |  |  | =back
376 |  |  |  |  |
377 |  |  |  |  | =head2 Operations on Instance Structures
378 |  |  |  |  |
379 |  |  |  |  | It's important to understand that the meta-instance object is a
380 |  |  |  |  | different entity from the actual instances it creates. For this
381 |  |  |  |  | reason, any operations on the C<$instance_structure> always require
382 |  |  |  |  | that the object instance be passed to the method.
383 |  |  |  |  |
384 |  |  |  |  | =over 4
385 |  |  |  |  |
386 |  |  |  |  | =item B<< $metainstance->get_slot_value($instance_structure, $slot_name) >>
387 |  |  |  |  |
388 |  |  |  |  | =item B<< $metainstance->set_slot_value($instance_structure, $slot_name, $value) >>
389 |  |  |  |  |
390 |  |  |  |  | =item B<< $metainstance->initialize_slot($instance_structure, $slot_name) >>
391 |  |  |  |  |
392 |  |  |  |  | =item B<< $metainstance->deinitialize_slot($instance_structure, $slot_name) >>
393 |  |  |  |  |
394 |  |  |  |  | =item B<< $metainstance->initialize_all_slots($instance_structure) >>
395 |  |  |  |  |
396 |  |  |  |  | =item B<< $metainstance->deinitialize_all_slots($instance_structure) >>
397 |  |  |  |  |
398 |  |  |  |  | =item B<< $metainstance->is_slot_initialized($instance_structure, $slot_name) >>
399 |  |  |  |  |
400 |  |  |  |  | =item B<< $metainstance->weaken_slot_value($instance_structure, $slot_name) >>
401 |  |  |  |  |
402 |  |  |  |  | =item B<< $metainstance->slot_value_is_weak($instance_structure, $slot_name) >>
403 |  |  |  |  |
404 |  |  |  |  | =item B<< $metainstance->strengthen_slot_value($instance_structure, $slot_name) >>
405 |  |  |  |  |
406 |  |  |  |  | =item B<< $metainstance->rebless_instance_structure($instance_structure, $new_metaclass) >>
407 |  |  |  |  |
408 |  |  |  |  | The exact details of what each method does should be fairly obvious
409 |  |  |  |  | from the method name.
410 |  |  |  |  |
411 |  |  |  |  | =back
412 |  |  |  |  |
413 |  |  |  |  | =head2 Inlinable Instance Operations
414 |  |  |  |  |
415 |  |  |  |  | =over 4
416 |  |  |  |  |
417 |  |  |  |  | =item B<< $metainstance->is_inlinable >>
418 |  |  |  |  |
419 |  |  |  |  | This is a boolean that indicates whether or not slot access operations
420 |  |  |  |  | can be inlined. By default it is true, but subclasses can override
421 |  |  |  |  | this.
422 |  |  |  |  |
423 |  |  |  |  | =item B<< $metainstance->inline_create_instance($class_variable) >>
424 |  |  |  |  |
425 |  |  |  |  | This method expects a string that, I<when inlined>, will become a
426 |  |  |  |  | class name. This would literally be something like C<'$class'>, not an
427 |  |  |  |  | actual class name.
428 |  |  |  |  |
429 |  |  |  |  | It returns a snippet of code that creates a new object for the
430 |  |  |  |  | class. This is something like C< bless {}, $class_name >.
431 |  |  |  |  |
432 |  |  |  |  | =item B<< $metainstance->inline_get_is_lvalue >>
433 |  |  |  |  |
434 |  |  |  |  | Returns whether or not C<inline_get_slot_value> is a valid lvalue. This can be
435 |  |  |  |  | used to do extra optimizations when generating inlined methods.
436 |  |  |  |  |
437 |  |  |  |  | =item B<< $metainstance->inline_slot_access($instance_variable, $slot_name) >>
438 |  |  |  |  |
439 |  |  |  |  | =item B<< $metainstance->inline_get_slot_value($instance_variable, $slot_name) >>
440 |  |  |  |  |
441 |  |  |  |  | =item B<< $metainstance->inline_set_slot_value($instance_variable, $slot_name, $value) >>
442 |  |  |  |  |
443 |  |  |  |  | =item B<< $metainstance->inline_initialize_slot($instance_variable, $slot_name) >>
444 |  |  |  |  |
445 |  |  |  |  | =item B<< $metainstance->inline_deinitialize_slot($instance_variable, $slot_name) >>
446 |  |  |  |  |
447 |  |  |  |  | =item B<< $metainstance->inline_is_slot_initialized($instance_variable, $slot_name) >>
448 |  |  |  |  |
449 |  |  |  |  | =item B<< $metainstance->inline_weaken_slot_value($instance_variable, $slot_name) >>
450 |  |  |  |  |
451 |  |  |  |  | =item B<< $metainstance->inline_strengthen_slot_value($instance_variable, $slot_name) >>
452 |  |  |  |  |
453 |  |  |  |  | These methods all expect two arguments. The first is the name of a
454 |  |  |  |  | variable, than when inlined, will represent the object
455 |  |  |  |  | instance. Typically this will be a literal string like C<'$_[0]'>.
456 |  |  |  |  |
457 |  |  |  |  | The second argument is a slot name.
458 |  |  |  |  |
459 |  |  |  |  | The method returns a snippet of code that, when inlined, performs some
460 |  |  |  |  | operation on the instance.
461 |  |  |  |  |
462 |  |  |  |  | =item B<< $metainstance->inline_rebless_instance_structure($instance_variable, $class_variable) >>
463 |  |  |  |  |
464 |  |  |  |  | This takes the name of a variable that will, when inlined, represent the object
465 |  |  |  |  | instance, and the name of a variable that will represent the class to rebless
466 |  |  |  |  | into, and returns code to rebless an instance into a class.
467 |  |  |  |  |
468 |  |  |  |  | =back
469 |  |  |  |  |
470 |  |  |  |  | =head2 Introspection
471 |  |  |  |  |
472 |  |  |  |  | =over 4
473 |  |  |  |  |
474 |  |  |  |  | =item B<< Class::MOP::Instance->meta >>
475 |  |  |  |  |
476 |  |  |  |  | This will return a L<Class::MOP::Class> instance for this class.
477 |  |  |  |  |
478 |  |  |  |  | It should also be noted that L<Class::MOP> will actually bootstrap
479 |  |  |  |  | this module by installing a number of attribute meta-objects into its
480 |  |  |  |  | metaclass.
481 |  |  |  |  |
482 |  |  |  |  | =back
483 |  |  |  |  |
484 |  |  |  |  | =head1 AUTHOR
485 |  |  |  |  |
486 |  |  |  |  | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details.
487 |  |  |  |  |
488 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
489 |  |  |  |  |
490 |  |  |  |  | This software is copyright (c) 2012 by Infinity Interactive, Inc..
491 |  |  |  |  |
492 |  |  |  |  | This is free software; you can redistribute it and/or modify it under
493 |  |  |  |  | the same terms as the Perl 5 programming language system itself.
494 |  |  |  |  |
495 |  |  |  |  | =cut
496 |  |  |  |  |
497 |  |  |  |  |
498 |  |  |  |  | __END__