use Try::Tiny instead of TryCatch
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator.pm
index 2eee7b5..833c91c 100644 (file)
@@ -1,22 +1,24 @@
 use MooseX::Declare;
 class SQL::Translator {
-    use TryCatch;
+    use Try::Tiny;
     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;
 
     our $VERSION = '0.001';
+    $VERSION = eval $VERSION;
 
     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 +26,7 @@ class SQL::Translator {
         is => 'rw',
         lazy_build => 1,
         handles => [ qw(parse) ],
+        predicate => 'has_parser',
     );
     
     has '_producer' => (
@@ -31,6 +34,7 @@ class SQL::Translator {
         is => 'rw',
         lazy_build => 1,
         handles => [ qw(produce) ],
+        predicate => 'has_producer',
     );
     
     has 'dbh' => (
@@ -58,14 +62,19 @@ class SQL::Translator {
         is => 'rw',
         predicate => 'has_producer_args',
     );
+
+    has 'data' => (
+        isa => Str,
+        is => 'rw',
+    );
     
+    has 'version' => (isa => Str, is => 'ro', default => $VERSION);
     has 'add_drop_table' => (isa => Bool, is => 'rw', default => 0);
     has 'no_comments' => (isa => Bool, is => 'rw', default => 0);
-    has 'show_warnings' => (isa => Bool, is => 'rw', default => 1);
+    has 'show_warnings' => (isa => Bool, is => 'rw', default => 0);
     has 'trace' => (isa => Bool, is => 'rw', default => 0);
     has 'quote_table_names' => (isa => Bool, is => 'rw', default => 0);
     has 'quote_field_names' => (isa => Bool, is => 'rw', default => 0);
-    has 'version' => (isa => Str, is => 'rw');
     has 'filename' => (isa => Str, is => 'rw');
 
     has '_producer_mapping' => (
@@ -74,6 +83,11 @@ class SQL::Translator {
         default => sub { { MySQL => 'SQL::MySQL', SQLite => 'SQL::SQLite', PostgreSQL => 'SQL::PostgreSQL', XML => 'XML', YAML => 'YAML' } }
     );
 
+    has 'error' => (
+        is => 'rw',
+        isa => Str,
+    );
+
     method _build__parser {
         my $class = 'SQL::Translator::Parser';
     
@@ -107,16 +121,18 @@ class SQL::Translator {
     method translate(:$data, :$producer?, :$producer_args?, :$parser?, :$parser_args?) {
         my $return;
 
-        $parser ||= $self->parser;
+        $self->_clear_schema if defined $parser;
+        $data ||= $self->data;
+
+        $parser ||= $self->parser unless $self->has_parser;
         if (defined $parser) {
             $self->_clear_parser;
-            $self->_clear_schema;
             $self->parser($parser);
             $self->parse($data);
             $return = $self->schema;
         }
 
-        $producer ||= $self->producer;
+        $producer ||= $self->producer unless $self->has_producer;
         if (defined $producer) {
             $self->_clear_producer;
             $self->producer($producer);