2 class SQL::Translator {
4 use MooseX::Types::Moose qw(Bool HashRef Str);
5 use SQL::Translator::Types qw(DBIHandle Parser Producer Schema);
6 use SQL::Translator::Object::Schema;
24 handles => [ qw(parse) ],
31 handles => [ qw(produce) ],
37 predicate => 'has_dbh',
44 default => sub { SQL::Translator::Object::Schema->new },
47 has 'parser_args' => (
50 predicate => 'has_parser_args',
53 has 'producer_args' => (
56 predicate => 'has_producer_args',
59 has 'add_drop_table' => (isa => Bool, is => 'rw', default => 0);
60 has 'no_comments' => (isa => Bool, is => 'rw', default => 0);
61 has 'show_warnings' => (isa => Bool, is => 'rw', default => 1);
62 has 'trace' => (isa => Bool, is => 'rw', default => 0);
63 has 'quote_table_names' => (isa => Bool, is => 'rw', default => 0);
64 has 'quote_field_names' => (isa => Bool, is => 'rw', default => 0);
65 has 'version' => (isa => Str, is => 'rw');
66 has 'filename' => (isa => Str, is => 'rw');
68 method _build__parser {
69 my $class = 'SQL::Translator::Parser';
71 Class::MOP::load_class($class);
75 $parser = $class->new({ translator => $self, dbh => $self->dbh });
77 $parser = $class->new({ translator => $self, type => $self->parser || '' });
83 method _build__producer {
84 my $class = 'SQL::Translator::Producer';
85 my $role = $class . '::' . $self->producer;
87 Class::MOP::load_class($class);
89 Class::MOP::load_class($role)
91 $role = $class . '::SQL::' . $self->producer;
92 Class::MOP::load_class($role)
95 my $producer = $class->new({ translator => $self });
96 $role->meta->apply($producer);
101 method translate(:$data, :$producer?, :$producer_args?, :$parser?, :$parser_args?) {
103 $self->_clear_parser;
104 $self->parser($parser);
107 } elsif ($producer) {
108 $self->_clear_producer;
109 $self->parse($data) if $data;
110 $self->producer($producer);
115 method parser_type { return $self->parser }
116 method producer_type { return $self->producer }