From: Justin Hunter Date: Tue, 11 Aug 2009 04:49:11 +0000 (-0700) Subject: use method BUILD instead of triggers X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f1bc36f4088d6970281db6bf22786cfb2e3e4602;p=dbsrgits%2FSQL-Translator-2.0-ish.git use method BUILD instead of triggers --- diff --git a/lib/SQL/Translator/Parser.pm b/lib/SQL/Translator/Parser.pm index 7346c3b..bce6f86 100644 --- a/lib/SQL/Translator/Parser.pm +++ b/lib/SQL/Translator/Parser.pm @@ -4,41 +4,36 @@ class SQL::Translator::Parser { use SQL::Translator::Types qw(DBIHandle); use aliased 'SQL::Translator::Object::Schema'; - my $apply_role_dbi = sub { - my $self = shift; - my $role = __PACKAGE__ . '::DBI'; - Class::MOP::load_class($role); - $role->meta->apply($self); - $self->_subclass(); - }; - - my $apply_role_ddl = sub { - my $self = shift; - my $role = __PACKAGE__ . '::DDL'; - Class::MOP::load_class($role); - $role->meta->apply($self); - $self->_subclass(); - }; - has 'dbh' => ( isa => DBIHandle, is => 'ro', predicate => 'has_dbh', - trigger => $apply_role_dbi, ); has 'filename' => ( isa => Str, is => 'ro', predicate => 'has_ddl', - trigger => $apply_role_ddl, ); has 'type' => ( isa => Str, is => 'ro', + predicate => 'has_type', ); + method BUILD(@) { + my $role = __PACKAGE__; + if ($self->has_dbh) { + $role .= '::DBI'; + } elsif ($self->has_type || $self->has_ddl) { + $role .= '::DDL'; + } + Class::MOP::load_class($role); + $role->meta->apply($self); + $self->_subclass(); + } + method parse { my $schema = Schema->new({ name => $self->schema_name }); $self->_add_tables($schema);