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 initialize_all_slots {
71 my ($self, $instance) = @_;
72 foreach my $slot_name ($self->get_all_slots) {
73 $self->initialize_slot($instance, $slot_name);
77 sub is_slot_initialized {
78 my ($self, $instance, $slot_name, $value) = @_;
79 exists $instance->{$slot_name} ? 1 : 0;
90 Class::MOP::Instance - Instance Meta Object
102 =item B<create_instance>
104 =item B<bless_instance_structure>
106 =item B<get_all_slots>
108 =item B<initialize_all_slots>
110 =item B<get_slot_value>
112 =item B<set_slot_value>
114 =item B<initialize_slot>
116 =item B<is_slot_initialized>
126 This will return a B<Class::MOP::Class> instance which is related
133 Stevan Little E<lt>stevan@iinteractive.comE<gt>
135 =head1 COPYRIGHT AND LICENSE
137 Copyright 2006 by Infinity Interactive, Inc.
139 L<http://www.iinteractive.com>
141 This library is free software; you can redistribute it and/or modify
142 it under the same terms as Perl itself.