use namespace::autoclean
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator.pm
CommitLineData
c5051351 1package SQL::Translator;
a832857f 2use namespace::autoclean;
3use Moose;
4use MooseX::Types::Moose qw(Str);
5use SQL::Translator::Types qw(DBIHandle);
6
7has 'parser' => (
8 isa => Str,
9 is => 'ro',
10 init_arg => 'from',
11 required => 1,
12);
13
14has 'producer' => (
15 isa => Str,
16 is => 'ro',
17 init_arg => 'to',
18 required => 1,
19);
20
21has 'dbh' => (
22 isa => DBIHandle,
23 is => 'ro',
24 predicate => 'has_dbh',
25);
26
27has 'filename' => (
28 isa => Str,
29 is => 'ro',
30 predicate => 'has_ddl',
31);
32
33sub BUILD {}
34
35after BUILD => sub {
36 my $self = shift;
37
38 my $parser_class = 'SQL::Translator::Parser';
39 my $producer_class = 'SQL::Translator::Producer';
40 my $producer_role = $producer_class . '::' . $self->producer;
41
42 Class::MOP::load_class($parser_class);
43
44 my $parser = $parser_class->new({ dbh => $self->dbh });
45
46 Class::MOP::load_class($producer_class);
47 Class::MOP::load_class($producer_role);
48
49 my $producer = $producer_class->new({ schema => $parser->parse });
50 $producer_role->meta->apply($producer);
51 $producer->produce;
52};
53
54__PACKAGE__->meta->make_immutable;
c5051351 55
561;