NAME

Handel::Storage::Result - Generic result object returned by storage operations

SYNOPSIS

use Handel::Storage::Cart;

my $storage = Handel::Storage::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.

While Handel::Storage currently operates on DBIx::Class schemas and uses DBIC resultset results, it should be possible to use a custom storage object to return results based on other operations, like SOAP/XMLRPC calls.

METHODS

AUTOLOAD

Maps undefined method calls to the underlying result object.

my $storage = Handel::Storage::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

Arguments: \%data

Adds a new item to the current result, returning a storage result object.

my $storage = Handel::Storage::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.

count_items

Returns the number of items associated with the current result.

my $storage = Handel::Storage::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

Arguments: $result, $storage

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::Cart->new;
my $result = $storage->create({
    shopper => '11111111-1111-1111-1111-111111111111'
});

$result->add_item({
    sku => 'ABC123'
});

$result->delete;

delete_items

Arguments: \%filter

Deletes items matching the filter from the current result.

my $storage = Handel::Storage::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.

inflate_result

This method is called by the iterator class to create a new storage result for first/next operations. This method is only used by DBIC resultset-based iterators. For non DBIC iterators, and other result creation, use create_instance instead.

items

Same as "search_items".

search_items

Arguments: \%filter

Returns items matching the filter associated with the current result.

my $storage = Handel::Storage::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::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::Cart->new;
my $result = $storage->create({
    shopper => '11111111-1111-1111-1111-111111111111'
});

print $result->storage; # Handel::Storage::Cart

update

Arguments: \%data

Updates the current result with the date specified.

my $storage = Handel::Storage::Cart->new;
my $result = $storage->create({
    shopper => '11111111-1111-1111-1111-111111111111'
});

$result->update({
    name => 'My Cart'
});

SEE ALSO

Handel::Storage

AUTHOR

Christopher H. Laco
CPAN ID: CLACO
claco@chrislaco.com
http://today.icantfocus.com/blog/