NAME
Handel::Storage - Generic storage layer for cart/order reads/writes
SYNOPSIS
use MyCustomCart;
use strict;
use warnings;
use base qw/Handel::Storage/;
__PACKAGE__->schema_class('MyCartSchema');
__PACKAGE__->schema_source('Carts');
__PACKAGE__->item_class('MyCustomCart::Items');
__PACKAGE__->setup_column_accessors;
1;
DESCRIPTION
Handel::Storage is used as an intermediary between Handel::Cart/Handel::Order and the schema classes used for reading/writing to the database.
METHODS
add_columns(@columns)
Adds a list of columns to the current schema_source in the current schema_class and maps the new columns to accessors in the current class.
Be careful to always use the column names, not their accessor aliases.
add_constraint($name, $column, \&sub)
Adds a constraint for the given column to the current schema_source in the current schema_class. During intert/update operations, the constraint subs will be called upon to validation the specified columns data.
autoupdate([0|1])
Gets/sets the autoupdate flag for the current schema_source. When set to 1, an update request will be made to the database for every field change. When set to 0, no updated data will be sent to the database until update
is called.
The default is 1.
connection_info([$dsn, $username, $password, \%attr])
Gets/sets the connection information used when connecting to the database.
item_class([$class])
Gets/sets the item class to be used when returning cart/order items.
cart_class([$class])
Gets/sets the cart class to be used when creating orders from carts.
item_relationship([$relationship])
Gets/sets the name of the schema relationship between carts and items. The default item relationship is 'items'.
inflate_result
This method is called by Handel::Iterator to inflate objects returned by first/next into the current class.
iterator_class([$class])
Gets/sets the class used for iterative resultset operations. The default iterator is Handel::Iterator.
remove_columns(@columns)
Removes a list of columns from the current schema_source in the current schema_class and removes the autogenerated accessors from the current class. This is useful if you want to just subclass an existing schema and only need to remove and/or add a few fields, rather than create the entire news schema from scratch.
Be careful to always use the column names, not their accessor aliases.
schema_class([$class])
Gets/sets the schema class to be used for database reading/writing.
schema_instance([$instance])
Gets/sets the schema instance to be used for database reading/writing. If no instance exists, a new one will be created from the specified schema class.
schema_source([$source])
Gets/sets the result source name in the current schema class to use for the current class.
__PACKAGE__->schema_source('Foo');
See "source_name" in DBIx::Class::ResultSource for more information about setting the source name of schema classes. By default, this will be the short name of the schema class.
By default, Handel::Storage looks for the "Carts" source when working with Handel::Cart, and the "Orders" source when working with Handel::Order.
setup_column_accessors
This method loops through the existing columns in the schema source for the current schema class and maps them to accessors in the current class.
If you have defined columns in your schema to have an accessor that is different than the column name, that will be used instead.
See "add_columns" in DBIx::Class::ResultSource for more information on aliasing column accessors.
storage
Returns the storage object for the current class instance. There should be no need currently to access this directly.
update
Sends all of the column updates to the database. If autoupdate
is off, you mist call this to save your changes or they will be lost when the object goes out of scope.
uuid
Returns a new uuid/guid string in the form of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
See <DBIx::Class::UUIDColumns> for more information on how uuids are generated.
validation_profile([\%profile])
Gets/sets the profile to be used for validating the column data before inserts/updates. This is an alternative approach to constraints that uses DBIx::Class::Validation and FormValidator::Simple.
SEE ALSO
Handel::Cart::Schema, Handel::Order::Schema, Handel::Schema, DBIx::Class::UUIDColumns, DBIx::Class::ResultSource, DBIx::Class::Validation, FormValidator::Simple
AUTHOR
Christopher H. Laco
CPAN ID: CLACO
claco@chrislaco.com
http://today.icantfocus.com/blog/