| Handel documentation | Contained in the Handel distribution. |
Handel::Storage::Result - Generic result object returned by storage operations
use Handel::Storage::DBIC::Cart;
my $storage = Handel::Storage::DBIC::Cart->new;
my $result = $storage->create({
shopper => '11111111-1111-1111-1111-111111111111'
});
print $result->id;
print $result->name;
Handel::Storage::Result is a generic wrapper around objects returned by various Handel::Storage operations. Its main purpose is to abstract storage result objects away from the Cart/Order/Item classes that use them. Each result is assumed to exposed methods for each 'property' or 'column' it has, as well as support the methods described below.
Maps undefined method calls to the underlying result object.
my $storage = Handel::Storage::DBIC::Cart->new;
my $result = $storage->create({
shopper => '11111111-1111-1111-1111-111111111111'
});
print $result->shopper;
#is really this:
print $result->storage_result->shopper;
Adds a new item to the current result, returning a storage result object.
my $storage = Handel::Storage::DBIC::Cart->new;
my $result = $storage->create({
shopper => '11111111-1111-1111-1111-111111111111'
});
my $item = $result->add_item({
sku => 'ABC123'
});
print $item->sku;
This method is just a convenience method that forwards to the implementation in the current storage object. See add_item in Handel::Storage for more details.
Redirects can requests to the internal storage result object, bypassing
AUTOLOAD and returns the code reference if a method is found.
Returns the number of items associated with the current result.
my $storage = Handel::Storage::DBIC::Cart->new;
my $result = $storage->create({
shopper => '11111111-1111-1111-1111-111111111111'
});
$result->add_item({
sku => 'ABC123'
});
print $result->count_items; # 1
This method is just a convenience method that forwards to the implementation in the current storage object. See count_items in Handel::Storage for more details.
Creates a new instance of Handel::Storage::Result, storing the underlying result
for use by AUTOLOAD.
my $schema = $storage->schema_instance;
my $row = $schema->resultset($storage->schema_source)->create({
col1 => 'foo',
col2 => 'bar'
});
my $result = $storage->result_class->create_instance($dbresult, $storage);
print $result->foo;
This method is used by the storage object to create storage results from resultset results and assign the generic results with the given storage object.
Deletes the current result and all of it's associated items from the current storage.
my $storage = Handel::Storage::DBIC::Cart->new;
my $result = $storage->create({
shopper => '11111111-1111-1111-1111-111111111111'
});
$result->add_item({
sku => 'ABC123'
});
$result->delete;
This method must be implemented in custom subclasses.
Deletes items matching the filter from the current result.
my $storage = Handel::Storage::DBIC::Cart->new;
my $result = $storage->create({
shopper => '11111111-1111-1111-1111-111111111111'
});
$result->add_item({
sku => 'ABC123'
});
$result->delete_items({
sku => 'ABC%'
});
This method is just a convenience method that forwards to the implementation in the current storage object. See delete_items in Handel::Storage for more details.
Discards all changes made since the last successful update.
This method must be implemented in custom subclasses.
Returns true if the column exists in the current result object.
Same as search_items.
Returns items matching the filter associated with the current result.
my $storage = Handel::Storage::DBIC::Cart->new;
my $result = $storage->search({
id => '11111111-1111-1111-1111-111111111111'
});
my $iterator = $result->search_items;
This method is just a convenience method that forwards to the implementation in the current storage object. See search_items in Handel::Storage for more details.
Returns the original result created by the underlying storage mechanism. This will be the DBIx::Class::Row result returned from the current schema.
my $storage = Handel::Storage::DBIC::Cart->new;
my $result = $storage->create({
shopper => '11111111-1111-1111-1111-111111111111'
});
my @columns = $result->storage_result->columns;
It is probably unwise to use the storage result directly anywhere outside of the current result object.
Returns a reference to the storage object used to create the current storage result.
my $storage = Handel::Storage::DBIC::Cart->new;
my $result = $storage->create({
shopper => '11111111-1111-1111-1111-111111111111'
});
print $result->storage; # Handel::Storage::DBIC::Cart
Starts a transaction on the current storage object.
Commits the current transaction on the current storage object.
Rolls back the current transaction on the current storage object.
Updates the current result with the data specified.
my $storage = Handel::Storage::DBIC::Cart->new;
my $result = $storage->create({
shopper => '11111111-1111-1111-1111-111111111111'
});
$result->update({
name => 'My Cart'
});
This method must be implemented in custom subclasses.
Christopher H. Laco
CPAN ID: CLACO
claco@chrislaco.com
http://today.icantfocus.com/blog/
| Handel documentation | Contained in the Handel distribution. |
# $Id$ ## no critic (RequireFinalReturn) package Handel::Storage::Result; use strict; use warnings; BEGIN { use base qw/Class::Accessor::Grouped/; use Scalar::Util (); __PACKAGE__->mk_group_accessors('simple', qw/storage_result storage/); }; sub can { return unless Scalar::Util::blessed($_[0]); return shift->storage_result->can(shift); }; sub delete { Handel::Exception::Virtual->throw; }; sub discard_changes { Handel::Exception::Virtual->throw; }; sub has_column { my ($self, $column) = @_; if ($self->can($column)) { return 1; } else { return; }; }; sub update { Handel::Exception::Virtual->throw; }; sub add_item { return $_[0]->storage->add_item(@_) }; sub delete_items { return $_[0]->storage->delete_items(@_); }; sub count_items { return $_[0]->storage->count_items(@_); }; sub search_items { return $_[0]->storage->search_items(@_); }; sub items { return shift->search_items(@_); }; sub create_instance { my ($self, $result, $storage) = @_; my $class = Scalar::Util::blessed $self ? Scalar::Util::blessed $self : $self; return bless { storage_result => $result, storage => $storage }, $class; }; sub txn_begin { return shift->storage->txn_begin; }; sub txn_commit { return shift->storage->txn_commit; }; sub txn_rollback { return shift->storage->txn_rollback; }; sub AUTOLOAD { my $self = shift; return if (our $AUTOLOAD) =~ /::DESTROY$/; $AUTOLOAD =~ s/^.*:://; return $self->storage_result->$AUTOLOAD(@_); }; 1; __END__