NAME
Handel::Storage::Result - Generic result object returned by storage operations
SYNOPSIS
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;
DESCRIPTION
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.
METHODS
AUTOLOAD
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;
add_item
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.
can
Redirects can
requests to the internal storage result object, bypassing AUTOLOAD and returns the code reference if a method is found.
count_items
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.
create_instance
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.
delete
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.
delete_items
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.
discard_changes
Discards all changes made since the last successful update.
This method must be implemented in custom subclasses.
has_column
Returns true if the column exists in the current result object.
items
Same as "search_items".
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.
storage_result
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.
storage
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
txn_begin
Starts a transaction on the current storage object.
txn_commit
Commits the current transaction on the current storage object.
txn_rollback
Rolls back the current transaction on the current storage object.
update
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.
SEE ALSO
AUTHOR
Christopher H. Laco
CPAN ID: CLACO
claco@chrislaco.com
http://today.icantfocus.com/blog/