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 { $_->name } @attrs;
28 $self->bless_instance_structure({});
31 sub bless_instance_structure {
32 my ($self, $instance_structure) = @_;
33 bless $instance_structure, $self->{meta}->name;
36 # operations on meta instance
40 return @{$self->{slots}};
43 # operations on created instances
46 my ($self, $instance, $slot_name) = @_;
47 return $instance->{$slot_name};
51 my ($self, $instance, $slot_name, $value) = @_;
52 $instance->{$slot_name} = $value;
56 my ($self, $instance, $slot_name) = @_;
57 $instance->{$slot_name} = undef;
60 sub is_slot_initialized {
61 my ($self, $instance, $slot_name, $value) = @_;
62 exists $instance->{$slot_name} ? 1 : 0;
65 # inlinable operation snippets
67 sub inline_get_slot_value {
68 my ($self, $instance_var_name, $slot_name) = @_;
69 return ($instance_var_name . '->{\'' . $slot_name . '\'}');
72 sub inline_set_slot_value {
73 my ($self, $instance_var_name, $slot_name, $value_name) = @_;
74 return ($self->inline_get_slot_value($instance_var_name, $slot_name) . ' = ' . $value_name);
77 sub inline_initialize_slot {
78 my ($self, $instance_var_name, $slot_name) = @_;
79 $self->inline_set_slot_value($instance_var_name, $slot_name, 'undef');
82 sub inline_is_slot_initialized {
83 my ($self, $instance_var_name, $slot_name) = @_;
84 return ('exists ' . $self->inline_get_slot_value($instance_var_name, $slot_name) . ' ? 1 : 0');
95 Class::MOP::Instance - Instance Meta Object
107 =item B<bless_instance_structure>
109 =item B<compute_layout_from_class>
111 =item B<create_instance>
113 =item B<get_all_slots>
115 =item B<get_slot_value>
117 =item B<set_slot_value>
119 =item B<initialize_slot>
121 =item B<is_slot_initialized>
123 =item B<inline_get_slot_value>
125 =item B<inline_set_slot_value>
127 =item B<inline_initialize_slot>
129 =item B<inline_is_slot_initialized>
139 This will return a B<Class::MOP::Class> instance which is related
146 Stevan Little E<lt>stevan@iinteractive.comE<gt>
148 =head1 COPYRIGHT AND LICENSE
150 Copyright 2006 by Infinity Interactive, Inc.
152 L<http://www.iinteractive.com>
154 This library is free software; you can redistribute it and/or modify
155 it under the same terms as Perl itself.