| File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP/Instance.pm |
| Statements Executed | 9464 |
| Statement Execution Time | 18.4ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 124 | 1 | 1 | 5.52ms | 9.96ms | Class::MOP::Instance::BUILDARGS |
| 1289 | 3 | 2 | 3.03ms | 3.03ms | Class::MOP::Instance::set_slot_value |
| 442 | 5 | 4 | 1.65ms | 2.51ms | Class::MOP::Instance::inline_set_slot_value |
| 97 | 1 | 1 | 1.43ms | 1.78ms | Class::MOP::Instance::create_instance |
| 124 | 1 | 1 | 1.42ms | 12.6ms | Class::MOP::Instance::new |
| 656 | 4 | 1 | 1.38ms | 1.38ms | Class::MOP::Instance::inline_slot_access |
| 154 | 1 | 1 | 1.19ms | 1.44ms | Class::MOP::Instance::clone_instance |
| 157 | 4 | 3 | 612µs | 1.01ms | Class::MOP::Instance::inline_get_slot_value |
| 251 | 2 | 1 | 569µs | 607µs | Class::MOP::Instance::_class_name |
| 54 | 3 | 2 | 241µs | 357µs | Class::MOP::Instance::inline_is_slot_initialized |
| 34 | 1 | 1 | 221µs | 221µs | Class::MOP::Instance::_new |
| 124 | 1 | 1 | 122µs | 122µs | Class::MOP::Instance::is_dependent_on_superclasses |
| 37 | 2 | 2 | 79µs | 79µs | Class::MOP::Instance::inline_create_instance |
| 84 | 1 | 1 | 63µs | 63µs | Class::MOP::Instance::is_inlinable |
| 11 | 1 | 1 | 41µs | 58µs | Class::MOP::Instance::weaken_slot_value |
| 18 | 1 | 1 | 26µs | 26µs | Class::MOP::Instance::associated_metaclass |
| 3 | 1 | 1 | 20µs | 27µs | Class::MOP::Instance::inline_deinitialize_slot |
| 1 | 1 | 1 | 13µs | 16µs | Class::MOP::Instance::BEGIN@4 |
| 6 | 1 | 1 | 12µs | 12µs | Class::MOP::Instance::get_slot_value |
| 2 | 1 | 1 | 8µs | 8µs | Class::MOP::Instance::is_slot_initialized |
| 1 | 1 | 1 | 7µs | 36µs | Class::MOP::Instance::BEGIN@7 |
| 1 | 1 | 1 | 6µs | 385µs | Class::MOP::Instance::BEGIN@13 |
| 1 | 1 | 1 | 6µs | 14µs | Class::MOP::Instance::BEGIN@5 |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::deinitialize_all_slots |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::deinitialize_slot |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::get_all_attributes |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::get_all_slots |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::initialize_all_slots |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::initialize_slot |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::inline_initialize_slot |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::inline_rebless_instance_structure |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::inline_strengthen_slot_value |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::inline_weaken_slot_value |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::is_valid_slot |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::rebless_instance_structure |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Instance::strengthen_slot_value |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Class::MOP::Instance; | ||||
| 3 | |||||
| 4 | 3 | 19µs | 2 | 18µs | # spent 16µs (13+3) within Class::MOP::Instance::BEGIN@4 which was called
# once (13µs+3µs) by Class::MOP::Class::BEGIN@7 at line 4 # spent 16µs making 1 call to Class::MOP::Instance::BEGIN@4
# spent 3µs making 1 call to strict::import |
| 5 | 3 | 20µs | 2 | 22µs | # spent 14µs (6+8) within Class::MOP::Instance::BEGIN@5 which was called
# once (6µs+8µs) by Class::MOP::Class::BEGIN@7 at line 5 # spent 14µs making 1 call to Class::MOP::Instance::BEGIN@5
# spent 8µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 3 | 46µs | 2 | 65µs | # spent 36µs (7+29) within Class::MOP::Instance::BEGIN@7 which was called
# once (7µs+29µs) by Class::MOP::Class::BEGIN@7 at line 7 # spent 36µs making 1 call to Class::MOP::Instance::BEGIN@7
# spent 29µs making 1 call to Exporter::import |
| 8 | |||||
| 9 | 1 | 600ns | our $VERSION = '0.98'; | ||
| 10 | 1 | 13µs | $VERSION = eval $VERSION; | ||
| 11 | 1 | 300ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 12 | |||||
| 13 | 3 | 813µs | 2 | 764µs | # spent 385µs (6+379) within Class::MOP::Instance::BEGIN@13 which was called
# once (6µs+379µs) by Class::MOP::Class::BEGIN@7 at line 13 # spent 385µs making 1 call to Class::MOP::Instance::BEGIN@13
# spent 379µs making 1 call to base::import |
| 14 | |||||
| 15 | # spent 9.96ms (5.52+4.44) within Class::MOP::Instance::BUILDARGS which was called 124 times, avg 80µs/call:
# 124 times (5.52ms+4.44ms) by Class::MOP::Instance::new at line 36, avg 80µs/call | ||||
| 16 | 2399 | 4.14ms | my ($class, @args) = @_; | ||
| 17 | |||||
| 18 | if ( @args == 1 ) { # spent 90µs making 124 calls to Scalar::Util::blessed, avg 727ns/call | ||||
| 19 | unshift @args, "associated_metaclass"; | ||||
| 20 | } elsif ( @args >= 2 && blessed($args[0]) && $args[0]->isa("Class::MOP::Class") ) { | ||||
| 21 | # compat mode | ||||
| 22 | my ( $meta, @attrs ) = @args; | ||||
| 23 | @args = ( associated_metaclass => $meta, attributes => \@attrs ); | ||||
| 24 | } | ||||
| 25 | |||||
| 26 | my %options = @args; | ||||
| 27 | # FIXME lazy_build | ||||
| 28 | $options{slots} ||= [ map { $_->slots } @{ $options{attributes} || [] } ]; # spent 4.35ms making 1655 calls to Class::MOP::Attribute::slots, avg 3µs/call | ||||
| 29 | $options{slot_hash} = { map { $_ => undef } @{ $options{slots} } }; # FIXME lazy_build | ||||
| 30 | |||||
| 31 | return \%options; | ||||
| 32 | } | ||||
| 33 | |||||
| 34 | # spent 12.6ms (1.42+11.2) within Class::MOP::Instance::new which was called 124 times, avg 101µs/call:
# 124 times (1.42ms+11.2ms) by Class::MOP::Class::_create_meta_instance at line 390 of Class/MOP/Class.pm, avg 101µs/call | ||||
| 35 | 620 | 1.29ms | my $class = shift; | ||
| 36 | my $options = $class->BUILDARGS(@_); # spent 9.96ms making 124 calls to Class::MOP::Instance::BUILDARGS, avg 80µs/call | ||||
| 37 | |||||
| 38 | # FIXME replace with a proper constructor | ||||
| 39 | my $instance = $class->_new(%$options); # spent 866µs making 90 calls to Moose::Meta::Instance::_new, avg 10µs/call
# spent 221µs making 34 calls to Class::MOP::Instance::_new, avg 6µs/call | ||||
| 40 | |||||
| 41 | # FIXME weak_ref => 1, | ||||
| 42 | weaken($instance->{'associated_metaclass'}); # spent 119µs making 124 calls to Scalar::Util::weaken, avg 958ns/call | ||||
| 43 | |||||
| 44 | return $instance; | ||||
| 45 | } | ||||
| 46 | |||||
| 47 | # spent 221µs within Class::MOP::Instance::_new which was called 34 times, avg 6µs/call:
# 34 times (221µs+0s) by Class::MOP::Instance::new at line 39, avg 6µs/call | ||||
| 48 | 136 | 237µs | my $class = shift; | ||
| 49 | return Class::MOP::Class->initialize($class)->new_object(@_) | ||||
| 50 | if $class ne __PACKAGE__; | ||||
| 51 | |||||
| 52 | my $params = @_ == 1 ? $_[0] : {@_}; | ||||
| 53 | return bless { | ||||
| 54 | # NOTE: | ||||
| 55 | # I am not sure that it makes | ||||
| 56 | # sense to pass in the meta | ||||
| 57 | # The ideal would be to just | ||||
| 58 | # pass in the class name, but | ||||
| 59 | # that is placing too much of | ||||
| 60 | # an assumption on bless(), | ||||
| 61 | # which is *probably* a safe | ||||
| 62 | # assumption,.. but you can | ||||
| 63 | # never tell <:) | ||||
| 64 | 'associated_metaclass' => $params->{associated_metaclass}, | ||||
| 65 | 'attributes' => $params->{attributes}, | ||||
| 66 | 'slots' => $params->{slots}, | ||||
| 67 | 'slot_hash' => $params->{slot_hash}, | ||||
| 68 | } => $class; | ||||
| 69 | } | ||||
| 70 | |||||
| 71 | 251 | 768µs | 36 | 38µs | sub _class_name { $_[0]->{_class_name} ||= $_[0]->associated_metaclass->name } # spent 26µs making 18 calls to Class::MOP::Instance::associated_metaclass, avg 1µs/call
# spent 12µs making 18 calls to Class::MOP::Package::name, avg 650ns/call |
| 72 | |||||
| 73 | 18 | 58µs | # spent 26µs within Class::MOP::Instance::associated_metaclass which was called 18 times, avg 1µs/call:
# 18 times (26µs+0s) by Class::MOP::Instance::_class_name at line 71, avg 1µs/call | ||
| 74 | |||||
| 75 | # spent 1.78ms (1.43+352µs) within Class::MOP::Instance::create_instance which was called 97 times, avg 18µs/call:
# 97 times (1.43ms+352µs) by Class::MOP::Class::_construct_instance at line 362 of Class/MOP/Class.pm, avg 18µs/call | ||||
| 76 | 194 | 1.37ms | my $self = shift; | ||
| 77 | bless {}, $self->_class_name; # spent 352µs making 97 calls to Class::MOP::Instance::_class_name, avg 4µs/call | ||||
| 78 | } | ||||
| 79 | |||||
| 80 | # spent 1.44ms (1.19+254µs) within Class::MOP::Instance::clone_instance which was called 154 times, avg 9µs/call:
# 154 times (1.19ms+254µs) by Class::MOP::Class::_clone_instance at line 420 of Class/MOP/Class.pm, avg 9µs/call | ||||
| 81 | 308 | 1.11ms | my ($self, $instance) = @_; | ||
| 82 | bless { %$instance }, $self->_class_name; # spent 255µs making 154 calls to Class::MOP::Instance::_class_name, avg 2µs/call | ||||
| 83 | } | ||||
| 84 | |||||
| 85 | # operations on meta instance | ||||
| 86 | |||||
| 87 | sub get_all_slots { | ||||
| 88 | my $self = shift; | ||||
| 89 | return @{$self->{'slots'}}; | ||||
| 90 | } | ||||
| 91 | |||||
| 92 | sub get_all_attributes { | ||||
| 93 | my $self = shift; | ||||
| 94 | return @{$self->{attributes}}; | ||||
| 95 | } | ||||
| 96 | |||||
| 97 | sub is_valid_slot { | ||||
| 98 | my ($self, $slot_name) = @_; | ||||
| 99 | exists $self->{'slot_hash'}->{$slot_name}; | ||||
| 100 | } | ||||
| 101 | |||||
| 102 | # operations on created instances | ||||
| 103 | |||||
| 104 | # spent 12µs within Class::MOP::Instance::get_slot_value which was called 6 times, avg 2µs/call:
# 6 times (12µs+0s) by Class::MOP::Attribute::get_raw_value at line 272 of Class/MOP/Attribute.pm, avg 2µs/call | ||||
| 105 | 12 | 20µs | my ($self, $instance, $slot_name) = @_; | ||
| 106 | $instance->{$slot_name}; | ||||
| 107 | } | ||||
| 108 | |||||
| 109 | # spent 3.03ms within Class::MOP::Instance::set_slot_value which was called 1289 times, avg 2µs/call:
# 664 times (1.49ms+0s) by Class::MOP::Attribute::_set_initial_slot_value at line 146 of Class/MOP/Attribute.pm, avg 2µs/call
# 335 times (856µs+0s) by Moose::Meta::Attribute::_set_initial_slot_value at line 437 of Moose/Meta/Attribute.pm, avg 3µs/call
# 290 times (675µs+0s) by Class::MOP::Attribute::set_raw_value at line 264 of Class/MOP/Attribute.pm, avg 2µs/call | ||||
| 110 | 2578 | 3.85ms | my ($self, $instance, $slot_name, $value) = @_; | ||
| 111 | $instance->{$slot_name} = $value; | ||||
| 112 | } | ||||
| 113 | |||||
| 114 | sub initialize_slot { | ||||
| 115 | my ($self, $instance, $slot_name) = @_; | ||||
| 116 | return; | ||||
| 117 | } | ||||
| 118 | |||||
| 119 | sub deinitialize_slot { | ||||
| 120 | my ( $self, $instance, $slot_name ) = @_; | ||||
| 121 | delete $instance->{$slot_name}; | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | sub initialize_all_slots { | ||||
| 125 | my ($self, $instance) = @_; | ||||
| 126 | foreach my $slot_name ($self->get_all_slots) { | ||||
| 127 | $self->initialize_slot($instance, $slot_name); | ||||
| 128 | } | ||||
| 129 | } | ||||
| 130 | |||||
| 131 | sub deinitialize_all_slots { | ||||
| 132 | my ($self, $instance) = @_; | ||||
| 133 | foreach my $slot_name ($self->get_all_slots) { | ||||
| 134 | $self->deinitialize_slot($instance, $slot_name); | ||||
| 135 | } | ||||
| 136 | } | ||||
| 137 | |||||
| 138 | # spent 8µs within Class::MOP::Instance::is_slot_initialized which was called 2 times, avg 4µs/call:
# 2 times (8µs+0s) by Class::MOP::Attribute::has_value at line 280 of Class/MOP/Attribute.pm, avg 4µs/call | ||||
| 139 | 4 | 9µs | my ($self, $instance, $slot_name, $value) = @_; | ||
| 140 | exists $instance->{$slot_name}; | ||||
| 141 | } | ||||
| 142 | |||||
| 143 | # spent 58µs (41+17) within Class::MOP::Instance::weaken_slot_value which was called 11 times, avg 5µs/call:
# 11 times (41µs+17µs) by Moose::Meta::Attribute::_weaken_value at line 492 of Moose/Meta/Attribute.pm, avg 5µs/call | ||||
| 144 | 22 | 62µs | my ($self, $instance, $slot_name) = @_; | ||
| 145 | weaken $instance->{$slot_name}; # spent 17µs making 11 calls to Scalar::Util::weaken, avg 2µs/call | ||||
| 146 | } | ||||
| 147 | |||||
| 148 | sub strengthen_slot_value { | ||||
| 149 | my ($self, $instance, $slot_name) = @_; | ||||
| 150 | $self->set_slot_value($instance, $slot_name, $self->get_slot_value($instance, $slot_name)); | ||||
| 151 | } | ||||
| 152 | |||||
| 153 | sub rebless_instance_structure { | ||||
| 154 | my ($self, $instance, $metaclass) = @_; | ||||
| 155 | |||||
| 156 | # we use $_[1] here because of t/306_rebless_overload.t regressions on 5.8.8 | ||||
| 157 | bless $_[1], $metaclass->name; | ||||
| 158 | } | ||||
| 159 | |||||
| 160 | # spent 122µs within Class::MOP::Instance::is_dependent_on_superclasses which was called 124 times, avg 981ns/call:
# 124 times (122µs+0s) by Class::MOP::Class::_create_meta_instance at line 395 of Class/MOP/Class.pm, avg 981ns/call | ||||
| 161 | 124 | 206µs | return; # for meta instances that require updates on inherited slot changes | ||
| 162 | } | ||||
| 163 | |||||
| 164 | # inlinable operation snippets | ||||
| 165 | |||||
| 166 | 84 | 113µs | # spent 63µs within Class::MOP::Instance::is_inlinable which was called 84 times, avg 755ns/call:
# 84 times (63µs+0s) by Class::MOP::Attribute::_process_accessors at line 320 of Class/MOP/Attribute.pm, avg 755ns/call | ||
| 167 | |||||
| 168 | # spent 79µs within Class::MOP::Instance::inline_create_instance which was called 37 times, avg 2µs/call:
# 31 times (59µs+0s) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 113 of Class/MOP/Method/Constructor.pm, avg 2µs/call
# 6 times (19µs+0s) by Moose::Meta::Method::Constructor::_generate_instance at line 121 of Moose/Meta/Method/Constructor.pm, avg 3µs/call | ||||
| 169 | 74 | 110µs | my ($self, $class_variable) = @_; | ||
| 170 | 'bless {} => ' . $class_variable; | ||||
| 171 | } | ||||
| 172 | |||||
| 173 | # spent 1.38ms within Class::MOP::Instance::inline_slot_access which was called 656 times, avg 2µs/call:
# 442 times (858µs+0s) by Class::MOP::Instance::inline_set_slot_value at line 185, avg 2µs/call
# 157 times (400µs+0s) by Class::MOP::Instance::inline_get_slot_value at line 180, avg 3µs/call
# 54 times (116µs+0s) by Class::MOP::Instance::inline_is_slot_initialized at line 199, avg 2µs/call
# 3 times (7µs+0s) by Class::MOP::Instance::inline_deinitialize_slot at line 195, avg 2µs/call | ||||
| 174 | 1312 | 1.93ms | my ($self, $instance, $slot_name) = @_; | ||
| 175 | sprintf q[%s->{"%s"}], $instance, quotemeta($slot_name); | ||||
| 176 | } | ||||
| 177 | |||||
| 178 | # spent 1.01ms (612µs+400µs) within Class::MOP::Instance::inline_get_slot_value which was called 157 times, avg 6µs/call:
# 89 times (377µs+242µs) by Moose::Meta::Method::Accessor::_inline_get at line 254 of Moose/Meta/Method/Accessor.pm, avg 7µs/call
# 52 times (178µs+131µs) by Class::MOP::Method::Accessor::_generate_reader_method_inline at line 157 of Class/MOP/Method/Accessor.pm, avg 6µs/call
# 15 times (51µs+23µs) by Class::MOP::Method::Accessor::_generate_accessor_method_inline at line 138 of Class/MOP/Method/Accessor.pm, avg 5µs/call
# once (5µs+3µs) by Moose::Meta::Method::Constructor::_generate_triggers at line 171 of Moose/Meta/Method/Constructor.pm | ||||
| 179 | 314 | 488µs | my ($self, $instance, $slot_name) = @_; | ||
| 180 | $self->inline_slot_access($instance, $slot_name); # spent 400µs making 157 calls to Class::MOP::Instance::inline_slot_access, avg 3µs/call | ||||
| 181 | } | ||||
| 182 | |||||
| 183 | # spent 2.51ms (1.65+858µs) within Class::MOP::Instance::inline_set_slot_value which was called 442 times, avg 6µs/call:
# 343 times (1.20ms+638µs) by Class::MOP::Method::Constructor::_generate_slot_initializer at line 159 of Class/MOP/Method/Constructor.pm, avg 5µs/call
# 42 times (209µs+93µs) by Moose::Meta::Method::Accessor::_inline_store at line 220 of Moose/Meta/Method/Accessor.pm, avg 7µs/call
# 39 times (165µs+82µs) by Moose::Meta::Method::Constructor::_generate_slot_assignment at line 272 of Moose/Meta/Method/Constructor.pm, avg 6µs/call
# 15 times (66µs+38µs) by Class::MOP::Method::Accessor::_generate_accessor_method_inline at line 138 of Class/MOP/Method/Accessor.pm, avg 7µs/call
# 3 times (12µs+7µs) by Class::MOP::Method::Accessor::_generate_writer_method_inline at line 175 of Class/MOP/Method/Accessor.pm, avg 6µs/call | ||||
| 184 | 884 | 1.45ms | my ($self, $instance, $slot_name, $value) = @_; | ||
| 185 | $self->inline_slot_access($instance, $slot_name) . " = $value", # spent 858µs making 442 calls to Class::MOP::Instance::inline_slot_access, avg 2µs/call | ||||
| 186 | } | ||||
| 187 | |||||
| 188 | sub inline_initialize_slot { | ||||
| 189 | my ($self, $instance, $slot_name) = @_; | ||||
| 190 | return ''; | ||||
| 191 | } | ||||
| 192 | |||||
| 193 | # spent 27µs (20+7) within Class::MOP::Instance::inline_deinitialize_slot which was called 3 times, avg 9µs/call:
# 3 times (20µs+7µs) by Class::MOP::Method::Accessor::_generate_clearer_method_inline at line 209 of Class/MOP/Method/Accessor.pm, avg 9µs/call | ||||
| 194 | 6 | 17µs | my ($self, $instance, $slot_name) = @_; | ||
| 195 | "delete " . $self->inline_slot_access($instance, $slot_name); # spent 7µs making 3 calls to Class::MOP::Instance::inline_slot_access, avg 2µs/call | ||||
| 196 | } | ||||
| 197 | # spent 357µs (241+116) within Class::MOP::Instance::inline_is_slot_initialized which was called 54 times, avg 7µs/call:
# 31 times (135µs+74µs) by Class::MOP::Method::Accessor::_generate_predicate_method_inline at line 192 of Class/MOP/Method/Accessor.pm, avg 7µs/call
# 22 times (102µs+40µs) by Moose::Meta::Method::Accessor::_inline_has at line 272 of Moose/Meta/Method/Accessor.pm, avg 6µs/call
# once (4µs+2µs) by Moose::Meta::Method::Accessor::_inline_get_old_value_for_trigger at line 233 of Moose/Meta/Method/Accessor.pm | ||||
| 198 | 108 | 208µs | my ($self, $instance, $slot_name) = @_; | ||
| 199 | "exists " . $self->inline_slot_access($instance, $slot_name); # spent 116µs making 54 calls to Class::MOP::Instance::inline_slot_access, avg 2µs/call | ||||
| 200 | } | ||||
| 201 | |||||
| 202 | sub inline_weaken_slot_value { | ||||
| 203 | my ($self, $instance, $slot_name) = @_; | ||||
| 204 | sprintf "Scalar::Util::weaken( %s )", $self->inline_slot_access($instance, $slot_name); | ||||
| 205 | } | ||||
| 206 | |||||
| 207 | sub inline_strengthen_slot_value { | ||||
| 208 | my ($self, $instance, $slot_name) = @_; | ||||
| 209 | $self->inline_set_slot_value($instance, $slot_name, $self->inline_slot_access($instance, $slot_name)); | ||||
| 210 | } | ||||
| 211 | |||||
| 212 | sub inline_rebless_instance_structure { | ||||
| 213 | my ($self, $instance, $class_variable) = @_; | ||||
| 214 | "bless $instance => $class_variable"; | ||||
| 215 | } | ||||
| 216 | |||||
| 217 | 1 | 4µs | 1; | ||
| 218 | |||||
| 219 | __END__ | ||||
| 220 | |||||
| 221 | =pod | ||||
| 222 | |||||
| 223 | =head1 NAME | ||||
| 224 | |||||
| 225 | Class::MOP::Instance - Instance Meta Object | ||||
| 226 | |||||
| 227 | =head1 DESCRIPTION | ||||
| 228 | |||||
| 229 | The Instance Protocol controls the creation of object instances, and | ||||
| 230 | the storage of attribute values in those instances. | ||||
| 231 | |||||
| 232 | Using this API directly in your own code violates encapsulation, and | ||||
| 233 | we recommend that you use the appropriate APIs in L<Class::MOP::Class> | ||||
| 234 | and L<Class::MOP::Attribute> instead. Those APIs in turn call the | ||||
| 235 | methods in this class as appropriate. | ||||
| 236 | |||||
| 237 | This class also participates in generating inlined code by providing | ||||
| 238 | snippets of code to access an object instance. | ||||
| 239 | |||||
| 240 | =head1 METHODS | ||||
| 241 | |||||
| 242 | =head2 Object construction | ||||
| 243 | |||||
| 244 | =over 4 | ||||
| 245 | |||||
| 246 | =item B<< Class::MOP::Instance->new(%options) >> | ||||
| 247 | |||||
| 248 | This method creates a new meta-instance object. | ||||
| 249 | |||||
| 250 | It accepts the following keys in C<%options>: | ||||
| 251 | |||||
| 252 | =over 8 | ||||
| 253 | |||||
| 254 | =item * associated_metaclass | ||||
| 255 | |||||
| 256 | The L<Class::MOP::Class> object for which instances will be created. | ||||
| 257 | |||||
| 258 | =item * attributes | ||||
| 259 | |||||
| 260 | An array reference of L<Class::MOP::Attribute> objects. These are the | ||||
| 261 | attributes which can be stored in each instance. | ||||
| 262 | |||||
| 263 | =back | ||||
| 264 | |||||
| 265 | =back | ||||
| 266 | |||||
| 267 | =head2 Creating and altering instances | ||||
| 268 | |||||
| 269 | =over 4 | ||||
| 270 | |||||
| 271 | =item B<< $metainstance->create_instance >> | ||||
| 272 | |||||
| 273 | This method returns a reference blessed into the associated | ||||
| 274 | metaclass's class. | ||||
| 275 | |||||
| 276 | The default is to use a hash reference. Subclasses can override this. | ||||
| 277 | |||||
| 278 | =item B<< $metainstance->clone_instance($instance) >> | ||||
| 279 | |||||
| 280 | Given an instance, this method creates a new object by making | ||||
| 281 | I<shallow> clone of the original. | ||||
| 282 | |||||
| 283 | =back | ||||
| 284 | |||||
| 285 | =head2 Introspection | ||||
| 286 | |||||
| 287 | =over 4 | ||||
| 288 | |||||
| 289 | =item B<< $metainstance->associated_metaclass >> | ||||
| 290 | |||||
| 291 | This returns the L<Class::MOP::Class> object associated with the | ||||
| 292 | meta-instance object. | ||||
| 293 | |||||
| 294 | =item B<< $metainstance->get_all_slots >> | ||||
| 295 | |||||
| 296 | This returns a list of slot names stored in object instances. In | ||||
| 297 | almost all cases, slot names correspond directly attribute names. | ||||
| 298 | |||||
| 299 | =item B<< $metainstance->is_valid_slot($slot_name) >> | ||||
| 300 | |||||
| 301 | This will return true if C<$slot_name> is a valid slot name. | ||||
| 302 | |||||
| 303 | =item B<< $metainstance->get_all_attributes >> | ||||
| 304 | |||||
| 305 | This returns a list of attributes corresponding to the attributes | ||||
| 306 | passed to the constructor. | ||||
| 307 | |||||
| 308 | =back | ||||
| 309 | |||||
| 310 | =head2 Operations on Instance Structures | ||||
| 311 | |||||
| 312 | It's important to understand that the meta-instance object is a | ||||
| 313 | different entity from the actual instances it creates. For this | ||||
| 314 | reason, any operations on the C<$instance_structure> always require | ||||
| 315 | that the object instance be passed to the method. | ||||
| 316 | |||||
| 317 | =over 4 | ||||
| 318 | |||||
| 319 | =item B<< $metainstance->get_slot_value($instance_structure, $slot_name) >> | ||||
| 320 | |||||
| 321 | =item B<< $metainstance->set_slot_value($instance_structure, $slot_name, $value) >> | ||||
| 322 | |||||
| 323 | =item B<< $metainstance->initialize_slot($instance_structure, $slot_name) >> | ||||
| 324 | |||||
| 325 | =item B<< $metainstance->deinitialize_slot($instance_structure, $slot_name) >> | ||||
| 326 | |||||
| 327 | =item B<< $metainstance->initialize_all_slots($instance_structure) >> | ||||
| 328 | |||||
| 329 | =item B<< $metainstance->deinitialize_all_slots($instance_structure) >> | ||||
| 330 | |||||
| 331 | =item B<< $metainstance->is_slot_initialized($instance_structure, $slot_name) >> | ||||
| 332 | |||||
| 333 | =item B<< $metainstance->weaken_slot_value($instance_structure, $slot_name) >> | ||||
| 334 | |||||
| 335 | =item B<< $metainstance->strengthen_slot_value($instance_structure, $slot_name) >> | ||||
| 336 | |||||
| 337 | =item B<< $metainstance->rebless_instance_structure($instance_structure, $new_metaclass) >> | ||||
| 338 | |||||
| 339 | The exact details of what each method does should be fairly obvious | ||||
| 340 | from the method name. | ||||
| 341 | |||||
| 342 | =back | ||||
| 343 | |||||
| 344 | =head2 Inlinable Instance Operations | ||||
| 345 | |||||
| 346 | =over 4 | ||||
| 347 | |||||
| 348 | =item B<< $metainstance->is_inlinable >> | ||||
| 349 | |||||
| 350 | This is a boolean that indicates whether or not slot access operations | ||||
| 351 | can be inlined. By default it is true, but subclasses can override | ||||
| 352 | this. | ||||
| 353 | |||||
| 354 | =item B<< $metainstance->inline_create_instance($class_variable) >> | ||||
| 355 | |||||
| 356 | This method expects a string that, I<when inlined>, will become a | ||||
| 357 | class name. This would literally be something like C<'$class'>, not an | ||||
| 358 | actual class name. | ||||
| 359 | |||||
| 360 | It returns a snippet of code that creates a new object for the | ||||
| 361 | class. This is something like C< bless {}, $class_name >. | ||||
| 362 | |||||
| 363 | =item B<< $metainstance->inline_slot_access($instance_variable, $slot_name) >> | ||||
| 364 | |||||
| 365 | =item B<< $metainstance->inline_get_slot_value($instance_variable, $slot_name) >> | ||||
| 366 | |||||
| 367 | =item B<< $metainstance->inline_set_slot_value($instance_variable, $slot_name, $value) >> | ||||
| 368 | |||||
| 369 | =item B<< $metainstance->inline_initialize_slot($instance_variable, $slot_name) >> | ||||
| 370 | |||||
| 371 | =item B<< $metainstance->inline_deinitialize_slot($instance_variable, $slot_name) >> | ||||
| 372 | |||||
| 373 | =item B<< $metainstance->inline_is_slot_initialized($instance_variable, $slot_name) >> | ||||
| 374 | |||||
| 375 | =item B<< $metainstance->inline_weaken_slot_value($instance_variable, $slot_name) >> | ||||
| 376 | |||||
| 377 | =item B<< $metainstance->inline_strengthen_slot_value($instance_variable, $slot_name) >> | ||||
| 378 | |||||
| 379 | These methods all expect two arguments. The first is the name of a | ||||
| 380 | variable, than when inlined, will represent the object | ||||
| 381 | instance. Typically this will be a literal string like C<'$_[0]'>. | ||||
| 382 | |||||
| 383 | The second argument is a slot name. | ||||
| 384 | |||||
| 385 | The method returns a snippet of code that, when inlined, performs some | ||||
| 386 | operation on the instance. | ||||
| 387 | |||||
| 388 | =item B<< $metainstance->inline_rebless_instance_structure($instance_variable, $class_variable) >> | ||||
| 389 | |||||
| 390 | This takes the name of a variable that will, when inlined, represent the object | ||||
| 391 | instance, and the name of a variable that will represent the class to rebless | ||||
| 392 | into, and returns code to rebless an instance into a class. | ||||
| 393 | |||||
| 394 | =back | ||||
| 395 | |||||
| 396 | =head2 Introspection | ||||
| 397 | |||||
| 398 | =over 4 | ||||
| 399 | |||||
| 400 | =item B<< Class::MOP::Instance->meta >> | ||||
| 401 | |||||
| 402 | This will return a L<Class::MOP::Class> instance for this class. | ||||
| 403 | |||||
| 404 | It should also be noted that L<Class::MOP> will actually bootstrap | ||||
| 405 | this module by installing a number of attribute meta-objects into its | ||||
| 406 | metaclass. | ||||
| 407 | |||||
| 408 | =back | ||||
| 409 | |||||
| 410 | =head1 AUTHORS | ||||
| 411 | |||||
| 412 | Yuval Kogman E<lt>nothingmuch@woobling.comE<gt> | ||||
| 413 | |||||
| 414 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
| 415 | |||||
| 416 | =head1 COPYRIGHT AND LICENSE | ||||
| 417 | |||||
| 418 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
| 419 | |||||
| 420 | L<http://www.iinteractive.com> | ||||
| 421 | |||||
| 422 | This library is free software; you can redistribute it and/or modify | ||||
| 423 | it under the same terms as Perl itself. | ||||
| 424 | |||||
| 425 | =cut | ||||
| 426 |