2 package Class::MOP::Instance;
8 use Scalar::Util 'blessed', 'reftype', 'weaken';
10 our $VERSION = '0.01';
13 require Class::MOP::Class;
14 Class::MOP::Class->initialize(blessed($_[0]) || $_[0]);
18 my ($class, $meta, @attrs) = @_;
19 my @slots = map { $_->slots } @attrs;
22 # I am not sure that it makes
23 # sense to pass in the meta
24 # The ideal would be to just
25 # pass in the class name, but
26 # that is placing too much of
27 # an assumption on bless(),
28 # which is *probably* a safe
29 # assumption,.. but you can
38 $self->bless_instance_structure({});
41 sub bless_instance_structure {
42 my ($self, $instance_structure) = @_;
43 bless $instance_structure, $self->{meta}->name;
46 # operations on meta instance
50 return @{$self->{slots}};
53 # operations on created instances
56 my ($self, $instance, $slot_name) = @_;
57 return $instance->{$slot_name};
61 my ($self, $instance, $slot_name, $value) = @_;
62 $instance->{$slot_name} = $value;
66 my ($self, $instance, $slot_name) = @_;
67 $instance->{$slot_name} = undef;
70 sub is_slot_initialized {
71 my ($self, $instance, $slot_name, $value) = @_;
72 exists $instance->{$slot_name} ? 1 : 0;
75 # inlinable operation snippets
77 sub inline_get_slot_value {
78 my ($self, $instance_var_name, $slot_name) = @_;
79 return ($instance_var_name . '->{\'' . $slot_name . '\'}');
82 sub inline_set_slot_value {
83 my ($self, $instance_var_name, $slot_name, $value_name) = @_;
84 return ($self->inline_get_slot_value($instance_var_name, $slot_name) . ' = ' . $value_name);
87 sub inline_initialize_slot {
88 my ($self, $instance_var_name, $slot_name) = @_;
89 $self->inline_set_slot_value($instance_var_name, $slot_name, 'undef');
92 sub inline_is_slot_initialized {
93 my ($self, $instance_var_name, $slot_name) = @_;
94 return ('exists ' . $self->inline_get_slot_value($instance_var_name, $slot_name) . ' ? 1 : 0');
105 Class::MOP::Instance - Instance Meta Object
117 =item B<bless_instance_structure>
119 =item B<compute_layout_from_class>
121 =item B<create_instance>
123 =item B<get_all_slots>
125 =item B<get_slot_value>
127 =item B<set_slot_value>
129 =item B<initialize_slot>
131 =item B<is_slot_initialized>
133 =item B<inline_get_slot_value>
135 =item B<inline_set_slot_value>
137 =item B<inline_initialize_slot>
139 =item B<inline_is_slot_initialized>
149 This will return a B<Class::MOP::Class> instance which is related
156 Stevan Little E<lt>stevan@iinteractive.comE<gt>
158 =head1 COPYRIGHT AND LICENSE
160 Copyright 2006 by Infinity Interactive, Inc.
162 L<http://www.iinteractive.com>
164 This library is free software; you can redistribute it and/or modify
165 it under the same terms as Perl itself.