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
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.
91 This is very similar now to the InsideOutClass example, and
92 in fact, they both share the exact same test suite, with
93 the only difference being the Instance metaclass they use.
97 Stevan Little E<lt>stevan@iinteractive.comE<gt>
101 =head1 COPYRIGHT AND LICENSE
103 Copyright 2006 by Infinity Interactive, Inc.
105 L<http://www.iinteractive.com>
107 This library is free software; you can redistribute it and/or modify
108 it under the same terms as Perl itself.