implement 'use aliased'
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator.pm
1 package SQL::Translator;
2 use namespace::autoclean;
3 use Moose;
4 use MooseX::Types::Moose qw(Str);
5 use SQL::Translator::Types qw(DBIHandle);
6
7 has 'parser' => (
8     isa => Str,
9     is => 'ro',
10     init_arg => 'from',
11     required => 1,
12 );
13
14 has 'producer' => (
15     isa => Str,
16     is => 'ro',
17     init_arg => 'to',
18     required => 1,
19 );
20
21 has 'dbh' => (
22     isa => DBIHandle,
23     is => 'ro',
24     predicate => 'has_dbh',
25 );
26
27 has 'filename' => (
28     isa => Str,
29     is => 'ro',
30     predicate => 'has_ddl',
31 );
32
33 sub BUILD {}
34
35 after 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;
55
56 1;