Business-Cart-Generic
view release on metacpan or search on metacpan
lib/Business/Cart/Generic/Database.pm view on Meta::CPAN
use DBIx::Admin::CreateTable;
use DBIx::Connector;
use List::Util 'min';
use Moose;
extends 'Business::Cart::Generic::Base';
has online =>
(
default => 1,
is => 'ro',
isa => 'Int',
required => 0,
);
has order =>
(
is => 'rw',
isa => 'Business::Cart::Generic::Database::Order',
required => 0,
);
has product =>
(
is => 'rw',
isa => 'Business::Cart::Generic::Database::Product',
required => 0,
);
has query =>
(
is => 'ro',
isa => 'Any',
required => 1,
);
has schema =>
(
is => 'rw',
isa => 'Business::Cart::Generic::Schema',
required => 0,
);
has search =>
(
is => 'rw',
isa => 'Business::Cart::Generic::Database::Search',
required => 0,
);
has session =>
(
is => 'rw',
isa => 'Data::Session',
required => 0,
);
use namespace::autoclean;
our $VERSION = '0.85';
# -----------------------------------------------
sub BUILD
{
my($self) = @_;
my($config) = $self -> config;
my($attr) = {AutoCommit => $$config{AutoCommit}, RaiseError => $$config{RaiseError} };
if ( ($$config{dsn} =~ /SQLite/i) && $$config{sqlite_unicode})
{
$$attr{sqlite_unicode} = 1;
}
$self -> connector(DBIx::Connector -> new($$config{dsn}, $$config{username}, $$config{password}, $attr) );
$self -> schema
(
Business::Cart::Generic::Schema -> connect(sub{return $self -> connector -> dbh})
);
if ($$config{dsn} =~ /SQLite/i)
{
$self -> connector -> dbh -> do('PRAGMA foreign_keys = ON');
}
# populate.tables.pl and place.orders.pl call us with online => 0.
$self -> set_up_session($config) if ($self -> online);
# Note: A database object is created before a session object, so
# we can't pass the session object to any other objects. Not that
# we want to. Just use $obj -> db -> session...
$self -> order
(
Business::Cart::Generic::Database::Order -> new
(
db => $self,
)
);
$self -> product
(
Business::Cart::Generic::Database::Product -> new
(
db => $self,
)
);
$self -> search
(
Business::Cart::Generic::Database::Search -> new
(
db => $self,
)
);
return $self;
( run in 0.741 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )