Handel::Compat - Compatibility layer for pre 1.0 subclasses
package MyCustomCart; use strict; use warnings; use base qw/Handel::Compat Handel::Cart/; __PACKAGE__->add_columns(qw/foo bar/); 1;
Handel::Compat is a thin compatibility layer to ease the process of migrating existing Cart/Order/Item subclasses. Simply load it before you load the base class and it will remap your calls to things like add_columns/add_constraints to the new storage layer.
add_columns
add_constraints
This class is deprecated and will cease to be in some future version. Please upgrade your code to use Handel::Base and Handel::Storage as soon as possible.
Adds the specified columns to the current storage object. When upgrading, convert this like so:
#__PACKAGE__->add_columns(qw/foo bar baz/); __PACKAGE__->storage->add_columns(qw/foo bar baz/);
Adds a new constraint to the current storage object. When upgrading, convert this like so:
#__PACKAGE__->add_constraint('Check Id', id => \&constraint); __PACKAGE__->storage->add_constraint('id', 'Check Name', \&constraint);
Sets the name of the class to be used when returning or creating carts. When upgrading, convert this like so:
#__PACKAGE__->cart_class('MyCustomCart'); __PACKAGE__->storage->cart_class('MyCustomCart');
Sets the name of the class to be used when returning or creating cart items. When upgrading, convert this like so:
#__PACKAGE__->item_class('MyCustomCart'); __PACKAGE__->storage->item_class('MyCustomCart');
You can retrieve all or some of the items contained in the via the items method. In a scalar context, items returns an iterator object which can be used to cycle through items one at a time. In list context, it will return an array containing all items.
items
my $iterator = $cart->items; while (my $item = $iterator->next) { print $item->sku; }; my @items = $cart->items; ... dosomething(\@items);
When filtering the items in the in scalar context, a item object will be returned if there is only one result. If there are multiple results, a Handel::Iterator object will be returned instead. You can force items to always return a Handel::Iterator object even if only one item exists by setting the $wantiterator parameter to RETURNAS_ITERATOR.
RETURNAS_ITERATOR
my $item = $cart->items({sku => 'SKU1234'}, RETURNAS_ITERATOR); if ($item->isa('Handel::Cart::Item)) { print $item->sku; } else { while ($item->next) { print $_->sku; }; };
In list context, filtered items return an array of items just as when items is called without a filter specified.
my @items - $cart->items((sku -> 'SKU1%'});
A Handel::Exception::Argument exception is thrown if parameter one isn't a hashref or undef.
Gets/sets the name of the class to be used when iterating through results using first/next. When upgrading, convert this like so:
#__PACKAGE__->iterator_class('MyIterator'); __PACKAGE__->storage->iterator_class('MyIterator');
Returns cart matching the supplied filter.
my $cart = Handel::Cart->load({ id => 'D597DEED-5B9F-11D1-8DD2-00AA004ABD5E' });
You can also omit \%filter to load all available carts.
my @carts = Handel::Cart->load();
In scalar context load returns a Handel::Cart object if there is a single result, or a Handel::Iterator object if there are multiple results. You can force load to always return an iterator even if only one cart exists by setting the $wantiterator parameter to RETURNAS_ITERATOR.
load
$wantiterator
my $iterator = Handel::Cart->load(undef, RETURNAS_ITERATOR); while (my $item = $iterator->next) { print $item->sku; };
See Handel::Contstants for the available RETURNAS options.
RETURNAS
A Handel::Exception::Argument exception is thrown if the first parameter is not a hashref.
See "create" in Handel::Cart and "create" in Handel::Order.
See "subtotal" in Handel::Cart and "create" in Handel::Order
Gets/sets the name of the table to be used. When upgrading, convert this like so:
#__PACKAGE__->table('foo'); __PACKAGE__->storage->table_name('foo');
Inspects the supplied search filter to determine whether it contains wildcard searching. Returns 1 if the filter contains SQL wildcards, otherwise it returns undef.
undef
has_wildcard({sku => '12%'}); # 1 has_wildcard((sku => '123')); # undef
Returns a new uuid string. When upgrading, convert this like so:
#__PACKAGE__->uuid; __PACKAGE__->storage->new_uuid;
Handel::Base, Handel::Storage
Christopher H. Laco CPAN ID: CLACO claco@chrislaco.com http://today.icantfocus.com/blog/
To install Handel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Handel
CPAN shell
perl -MCPAN -e shell install Handel
For more information on module installation, please visit the detailed CPAN module installation guide.