2 package # hide the package from PAUSE
3 ArrayBasedStorage::Instance;
10 our $VERSION = '0.01';
12 use base 'Class::MOP::Instance';
15 my ($class, $meta, @attrs) = @_;
16 my $self = $class->SUPER::new($meta, @attrs);
18 $self->{slot_index_map} = { map { $_ => $index++ } $self->get_all_slots };
24 $self->bless_instance_structure([]);
27 # operations on meta instance
31 return sort @{$self->{slots}};
35 my ($self, $instance, $slot_name) = @_;
36 return $instance->[ $self->{slot_index_map}->{$slot_name} ];
40 my ($self, $instance, $slot_name, $value) = @_;
41 $instance->[ $self->{slot_index_map}->{$slot_name} ] = $value;
45 my ($self, $instance, $slot_name) = @_;
46 $instance->[ $self->{slot_index_map}->{$slot_name} ] = undef;
49 sub is_slot_initialized {
51 # maybe use CLOS's *special-unbound-value*
53 confess "Cannot really tell this for sure";
64 ArrayBasedStorage - An example of an Array based instance storage
70 use metaclass 'Class::MOP::Class' => (
71 ':instance_metaclass' => 'ArrayBasedStorage::Instance'
74 __PACKAGE__->meta->add_attribute('foo' => (
81 $class->meta->new_object(@_);
84 # now you can just use the class as normal
88 This is a proof of concept using the Instance sub-protocol
89 which uses ARRAY refs to store the instance data.
93 Stevan Little E<lt>stevan@iinteractive.comE<gt>
97 =head1 COPYRIGHT AND LICENSE
99 Copyright 2006 by Infinity Interactive, Inc.
101 L<http://www.iinteractive.com>
103 This library is free software; you can redistribute it and/or modify
104 it under the same terms as Perl itself.