From: Justin Hunter Date: Sun, 21 Feb 2010 02:50:41 +0000 (-0800) Subject: add MooseX::Aliases (to allow for to/from and producer/parser) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FSQL-Translator-2.0-ish.git;a=commitdiff_plain;h=c6b7881f57801746440fa4e1362f92cdf152e843 add MooseX::Aliases (to allow for to/from and producer/parser) change how $parser and $producer are determined in a ->translate only use the ones from ->new if they haven't been run through already --- diff --git a/Makefile.PL b/Makefile.PL index 3ba2a16..30dd4ab 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -12,6 +12,7 @@ tests 't/*.t'; requires 'aliased', '0.30'; requires 'FindBin'; requires 'Moose', '0.90'; +requires 'MooseX::Aliases', '0.08'; requires 'MooseX::Declare', '0.31'; requires 'MooseX::Types', '0.20'; requires 'MooseX::Method::Signatures', '0.29'; diff --git a/lib/SQL/Translator.pm b/lib/SQL/Translator.pm index 61bfadc..3fbb0e7 100644 --- a/lib/SQL/Translator.pm +++ b/lib/SQL/Translator.pm @@ -2,6 +2,7 @@ use MooseX::Declare; class SQL::Translator { use TryCatch; use MooseX::Types::Moose qw(Bool HashRef Int Str Undef); + use MooseX::Aliases; use SQL::Translator::Types qw(DBIHandle Parser Producer Schema); use SQL::Translator::Object::Schema; @@ -10,13 +11,13 @@ class SQL::Translator { has 'parser' => ( isa => Str, is => 'rw', - init_arg => 'from', + alias => 'from', ); has 'producer' => ( isa => Str, is => 'rw', - init_arg => 'to', + alias => 'to', ); has '_parser' => ( @@ -24,6 +25,7 @@ class SQL::Translator { is => 'rw', lazy_build => 1, handles => [ qw(parse) ], + predicate => 'has_parser', ); has '_producer' => ( @@ -31,6 +33,7 @@ class SQL::Translator { is => 'rw', lazy_build => 1, handles => [ qw(produce) ], + predicate => 'has_producer', ); has 'dbh' => ( @@ -107,7 +110,9 @@ class SQL::Translator { method translate(:$data, :$producer?, :$producer_args?, :$parser?, :$parser_args?) { my $return; - $parser ||= $self->parser; + $self->_clear_schema if defined $parser; + + $parser ||= $self->parser unless $self->has_parser; if (defined $parser) { $self->_clear_parser; $self->parser($parser); @@ -115,7 +120,7 @@ class SQL::Translator { $return = $self->schema; } - $producer ||= $self->producer; + $producer ||= $self->producer unless $self->has_producer; if (defined $producer) { $self->_clear_producer; $self->producer($producer);