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([]);
28 my ($self, $instance) = shift;
29 $self->bless_instance_structure([ @$instance ]);
32 # operations on meta instance
34 sub get_slot_index_map { (shift)->{slot_index_map} }
38 return sort $self->SUPER::get_all_slots;
42 my ($self, $instance, $slot_name) = @_;
43 return $instance->[ $self->{slot_index_map}->{$slot_name} ];
47 my ($self, $instance, $slot_name, $value) = @_;
48 $instance->[ $self->{slot_index_map}->{$slot_name} ] = $value;
51 sub is_slot_initialized {
53 # maybe use CLOS's *special-unbound-value*
55 confess "Cannot really tell this for sure";
66 ArrayBasedStorage - An example of an Array based instance storage
73 ':instance_metaclass' => 'ArrayBasedStorage::Instance'
76 __PACKAGE__->meta->add_attribute('foo' => (
83 $class->meta->new_object(@_);
86 # now you can just use the class as normal
90 This is a proof of concept using the Instance sub-protocol
91 which uses ARRAY refs to store the instance data.
93 This is very similar now to the InsideOutClass example, and
94 in fact, they both share the exact same test suite, with
95 the only difference being the Instance metaclass they use.
99 Stevan Little E<lt>stevan@iinteractive.comE<gt>
101 Yuval Kogman E<lt>nothingmuch@woobling.comE<gt>
105 =head1 COPYRIGHT AND LICENSE
107 Copyright 2006 by Infinity Interactive, Inc.
109 L<http://www.iinteractive.com>
111 This library is free software; you can redistribute it and/or modify
112 it under the same terms as Perl itself.