NAME

Handel::Compat - Compatibility layer for pre 1.0 subclasses

SYNOPSIS

package MyCustomCart;
use strict;
use warnings;
use base qw/Handel::Compat Handel::Cart/;

__PACKAGE__->add_columns(qw/foo bar/);

1;

DESCRIPTION

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.

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.

METHODS

add_columns

Arguments: @columns

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/);

add_constraint

Arguments: $name, $column, \&constraint

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);

cart_class

Arguments: $cart_class

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');

item_class

Arguments: $item_class

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');

items

Arguments: \%filter, $wantiterator

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.

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.

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.

iterator_class

Arguments: $iterator_class

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');

load

Arguments: \%filter, $wantiterator

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.

my $iterator = Handel::Cart->load(undef, RETURNAS_ITERATOR);
while (my $item = $iterator->next) {
    print $item->sku;
};

See Handel::Contstants for the available RETURNAS options.

A Handel::Exception::Argument exception is thrown if the first parameter is not a hashref.

new

See "create" in Handel::Cart and "create" in Handel::Order.

subtotal

See "subtotal" in Handel::Cart and "create" in Handel::Order

table

Arguments: $table

Gets/sets the name of the table to be used. When upgrading, convert this like so:

#__PACKAGE__->table('foo');
__PACKAGE__->storage->table_name('foo');

FUNCTIONS

has_wildcard

Arguments: \%filter

Inspects the supplied search filter to determine whether it contains wildcard searching. Returns 1 if the filter contains SQL wildcards, otherwise it returns undef.

has_wildcard({sku => '12%'});  # 1
has_wildcard((sku => '123'));  # undef

uuid

Returns a new uuid string. When upgrading, convert this like so:

#__PACKAGE__->uuid;
__PACKAGE__->storage->new_uuid;

SEE ALSO

Handel::Base, Handel::Storage

AUTHOR

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