Handel
view release on metacpan or search on metacpan
lib/Handel/Base.pm view on Meta::CPAN
-details => translate('COMPCLASS_NOT_LOADED', $field, $value)
);
};
};
};
$self->set_inherited($field, $value);
return;
};
sub _get_storage {
my $self = shift;
my $class = blessed $self ? blessed $self : $self;
no strict 'refs';
no warnings 'once';
my $storage = $self->{'storage'} || ${"$class\:\:_storage"};
if (!$storage) {
my ($super) = (Class::ISA::super_path($class));
if (${"$super\:\:_storage"}) {
$storage = ${"$super\:\:_storage"};
if (blessed($storage) eq $self->storage_class) {
$storage = $storage->clone;
# we want our own, not da clones item storage
if ($storage->_item_storage) {
$storage->_item_storage(undef);
};
} else {
$storage = $self->storage_class->new;
};
} else {
$storage = $self->storage_class->new;
};
$self->_set_storage($storage);
};
return $storage;
};
sub _set_storage {
my ($self, $storage) = @_;
my $class = blessed $self ? blessed $self : $self;
if (blessed $self) {
$self->{'storage'} = $storage;
} else {
no strict 'refs';
${"$class\:\:_storage"} = $storage;
};
return;
};
sub update {
my $self = shift;
return $self->result->update(@_);
};
1;
__END__
=head1 NAME
Handel::Base - Base class for Cart/Order/Item classes
=head1 SYNOPSIS
use MyCustomCart;
use strict;
use warnings;
use base qw/Handel::Base/;
__PACKAGE__->item_class('MyCustomCart::Item');
__PACKAGE__->storage({
schema_source => 'Carts',
constraints => {
id => {'Check Id' => \&constraint_uuid},
shopper => {'Check Shopper' => \&constraint_uuid},
type => {'Check Type' => \&constraint_cart_type},
name => {'Check Name' => \&constraint_cart_name}
},
default_values => {
id => __PACKAGE__->storage_class->can('new_uuid'),
type => CART_TYPE_TEMP
}
});
__PACKAGE__->create_accessors;
1;
=head1 DESCRIPTION
Handel::Base is a base class for the Cart/Order/Item classes that glues those
classes to a L<Handel::Storage|Handel::Storage> object.
=head1 METHODS
=head2 accessor_map
Returns a hashref containing the column/accessor mapping used when
C<create_accessors> was last called. This is used by C<get_column>/C<set_column>
to get the accessor name for any given column.
$schema->add_column('foo' => {accessor => 'bar');
...
$base->create_accessors;
$base->bar('newval'); # calls $base->set_column('foo', 'newval');
...
sub set_column {
my ($self, $column, $value) = @_;
my $accessor = $self->accessor_map->{$column} || $column;
( run in 1.364 second using v1.01-cache-2.11-cpan-39bf76dae61 )