package # hide the package from PAUSE
- ArrayBasedStorage::Attribute;
-
-use strict;
-use warnings;
-
-use Carp 'confess';
-
-our $VERSION = '0.01';
-
-use base 'Class::MOP::Attribute';
-
-sub generate_accessor_method {
- my $self = shift;
- my $attr_name = $self->name;
- return sub {
- my $meta_instance = $_[0]->meta->get_meta_instance;
- $meta_instance->set_slot_value($_[0], $attr_name, $_[1]) if scalar(@_) == 2;
- $meta_instance->get_slot_value($_[0], $attr_name);
- };
-}
-
-sub generate_reader_method {
- my $self = shift;
- my $attr_name = $self->name;
- return sub {
- confess "Cannot assign a value to a read-only accessor" if @_ > 1;
- $_[0]->meta
- ->get_meta_instance
- ->get_slot_value($_[0], $attr_name);
- };
-}
-
-sub generate_writer_method {
- my $self = shift;
- my $attr_name = $self->name;
- return sub {
- $_[0]->meta
- ->get_meta_instance
- ->set_slot_value($_[0], $attr_name, $_[1]);
- };
-}
-
-sub generate_predicate_method {
- my $self = shift;
- my $attr_name = $self->name;
- return sub {
- defined $_[0]->meta
- ->get_meta_instance
- ->get_slot_value($_[0], $attr_name) ? 1 : 0;
- };
-}
-
-package # hide the package from PAUSE
ArrayBasedStorage::Instance;
use strict;
package Foo;
use metaclass 'Class::MOP::Class' => (
- ':attribute_metaclass' => 'ArrayBasedStorage::Attribute'
':instance_metaclass' => 'ArrayBasedStorage::Instance'
);