Business-AU-Ledger

 view release on metacpan or  search on metacpan

lib/Business/AU/Ledger/Util/Create.pm  view on Meta::CPAN

package Business::AU::Ledger::Util::Create;

# Documentation:
#	POD-style documentation is at the end. Extract it with pod2html.*.
#
# Note:
#	o tab = 4 spaces || die
#
# Author:
#	Ron Savage <ron@savage.net.au>

use Business::AU::Ledger::Util::Config;

use Carp;

use DBIx::Admin::CreateTable;
use DBIx::Simple;

use Encode;

use FindBin::Real;

use Log::Dispatch;
use Log::Dispatch::DBI;

use Moose;

has config         => (is => 'rw', isa => 'HashRef');
has creator        => (is => 'rw', isa => 'DBIx::Admin::CreateTable');
has edit_types     => (is => 'rw', isa => 'HashRef');
has last_insert_id => (is => 'rw', isa => 'Int');
has logger         => (is => 'rw', isa => 'Log::Dispatch');
has simple         => (is => 'rw', isa => 'DBIx::Simple');
has table_names    => (is => 'rw', isa => 'HashRef');
has time_option    => (is => 'rw', isa => 'Str');
has verbose        => (is => 'rw', isa => 'Int');

use namespace::autoclean;

our $VERSION = '0.88';

# -----------------------------------------------

sub BUILD
{
	my($self) = @_;

	$self -> config(Business::AU::Ledger::Util::Config -> new -> config);

	my($config) = $self -> config;
	my($attr)   =
	{
		AutoCommit => $$config{'AutoCommit'},
		RaiseError => $$config{'RaiseError'},
	};

	$self -> simple(DBIx::Simple -> connect($$config{'dsn'}, $$config{'username'}, $$config{'password'}, $attr) );
	$self -> creator(DBIx::Admin::CreateTable -> new(dbh => $self -> simple -> dbh, verbose => $self -> verbose) );
	$self -> time_option($self -> creator -> db_vendor =~ /(?:MySQL|Postgres)/i ? '(0) without time zone' : '');
	$self -> logger(Log::Dispatch -> new);
	$self -> logger -> add
	(
		Log::Dispatch::DBI -> new
		(
		 dbh       => $self -> simple -> dbh,
		 min_level => 'info',
		 name      => 'Ledger',
		)
	);

	$self;

}	# End of BUILD.

# -----------------------------------------------

sub create_all_tables
{
	my($self) = @_;

	# Warning: The order is important.

	my($method);
	my($table_name);

	for $table_name (qw/
log
sessions
tx_details
tx_types
category_codes
gst_codes
months
reconciliations
payment_methods
payments
receipts
/)



( run in 3.094 seconds using v1.01-cache-2.11-cpan-a49fcb8fa48 )