Commit | Line | Data |
4f4fd192 |
1 | use MooseX::Declare; |
2 | class SQL::Translator::Parser { |
094c084f |
3 | use MooseX::Types::Moose qw(Maybe Str); |
4 | use SQL::Translator::Types qw(DBIHandle Translator); |
cc73c25e |
5 | |
4f4fd192 |
6 | has 'dbh' => ( |
7 | isa => DBIHandle, |
8 | is => 'ro', |
9 | predicate => 'has_dbh', |
4f4fd192 |
10 | ); |
d6201a5e |
11 | |
4f4fd192 |
12 | has 'filename' => ( |
13 | isa => Str, |
14 | is => 'ro', |
15 | predicate => 'has_ddl', |
4f4fd192 |
16 | ); |
d6201a5e |
17 | |
eba3827b |
18 | has 'type' => ( |
094c084f |
19 | isa => Maybe[Str], |
eba3827b |
20 | is => 'ro', |
f1bc36f4 |
21 | predicate => 'has_type', |
eba3827b |
22 | ); |
23 | |
094c084f |
24 | has 'translator' => ( |
25 | isa => Translator, |
26 | is => 'ro', |
27 | weak_ref => 1, |
28 | required => 1, |
29 | handles => [ qw(schema) ], |
30 | ); |
31 | |
f1bc36f4 |
32 | method BUILD(@) { |
33 | my $role = __PACKAGE__; |
34 | if ($self->has_dbh) { |
35 | $role .= '::DBI'; |
36 | } elsif ($self->has_type || $self->has_ddl) { |
37 | $role .= '::DDL'; |
38 | } |
39 | Class::MOP::load_class($role); |
40 | $role->meta->apply($self); |
41 | $self->_subclass(); |
42 | } |
bab65ec9 |
43 | } |