implement 'use aliased'
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Parser / DBI.pm
index f81aebc..6937049 100644 (file)
@@ -5,41 +5,41 @@ use MooseX::Types::Moose qw(Maybe Str);
 use DBI::Const::GetInfoType;
 use DBI::Const::GetInfo::ANSI;
 use DBI::Const::GetInfoReturn;
-use SQL::Translator::Object::Column;
-use SQL::Translator::Object::Index;
-use SQL::Translator::Object::Table;
-use SQL::Translator::Object::View;
+use aliased 'SQL::Translator::Object::Column';
+use aliased 'SQL::Translator::Object::Index';
+use aliased 'SQL::Translator::Object::Table';
+use aliased 'SQL::Translator::Object::View';
 
 has 'quoter' => (
-  is => 'rw',
-  isa => Str,
-  requried => 1,
-  lazy => 1,
-  default => sub { shift->dbh->get_info(29) || q{"} }
+    is => 'rw',
+    isa => Str,
+    requried => 1,
+    lazy => 1,
+    default => sub { shift->dbh->get_info(29) || q{"} }
 );
 
 has 'namesep' => (
-  is => 'rw',
-  isa => Str,
-  required => 1,
-  lazy => 1,
-  default => sub { shift->dbh->get_info(41) || '.' }
+    is => 'rw',
+    isa => Str,
+    required => 1,
+    lazy => 1,
+    default => sub { shift->dbh->get_info(41) || '.' }
 );
 
 has 'schema_name' => (
-  is => 'rw',
-  isa => Maybe[Str],
-  required => 0,
-  lazy => 1,
-  default => undef
+    is => 'rw',
+    isa => Maybe[Str],
+    required => 0,
+    lazy => 1,
+    default => undef
 );
 
 has 'catalog_name' => (
-  is => 'rw',
-  isa => Maybe[Str],
-  required => 0,
-  lazy => 1,
-  default => undef
+    is => 'rw',
+    isa => Maybe[Str],
+    required => 0,
+    lazy => 1,
+    default => undef
 );
 
 sub _subclass {
@@ -59,14 +59,16 @@ sub _add_tables {
     my $sth = $self->dbh->table_info($self->catalog_name, $self->schema_name, '%', 'TABLE,VIEW');
     while (my $table_info = $sth->fetchrow_hashref) {
         if ($table_info->{TABLE_TYPE} eq 'TABLE') {
-            my $table = SQL::Translator::Object::Table->new({ name => $table_info->{TABLE_NAME} });
+            my $table = Table->new({ name => $table_info->{TABLE_NAME} });
             $schema->add_table($table);
             $self->_add_columns($table);
             $self->_add_primary_key($table);
         }
         elsif ($table_info->{TABLE_TYPE} eq 'VIEW') {
             my $sql = $self->_get_view_sql($table_info->{TABLE_NAME});
-            $schema->add_view(SQL::Translator::Object::View->new({ name => $table_info->{TABLE_NAME}, sql => $sql }));
+            my $view = View->new({ name => $table_info->{TABLE_NAME}, sql => $sql });
+            $schema->add_view($view);
+            $self->_add_columns($view);
         }
     }
 }
@@ -77,11 +79,11 @@ sub _add_columns {
 
     my $sth = $self->dbh->column_info($self->catalog_name, $self->schema_name, $table->name, '%');
     while (my $col_info = $sth->fetchrow_hashref) {
-        my $column = SQL::Translator::Object::Column->new({ name => $col_info->{COLUMN_NAME},
-                                                            data_type => $col_info->{TYPE_NAME},
-                                                            size => $col_info->{COLUMN_SIZE},
-                                                            default_value => $col_info->{COLUMN_DEF},
-                                                            is_nullable => $col_info->{NULLABLE}, });
+        my $column = Column->new({ name => $col_info->{COLUMN_NAME},
+                                   data_type => $col_info->{TYPE_NAME},
+                                   size => $col_info->{COLUMN_SIZE},
+                                   default_value => $col_info->{COLUMN_DEF},
+                                   is_nullable => $col_info->{NULLABLE}, });
         $table->add_column($column);
     }
 }
@@ -96,7 +98,7 @@ sub _add_primary_key {
         $pk_name = $pk_col->{PK_NAME};
         push @pk_cols, $pk_col->{COLUMN_NAME};
     }
-    my $index = SQL::Translator::Object::Index->new({ name => $pk_name, type => 'PRIMARY_KEY' });
+    my $index = Index->new({ name => $pk_name, type => 'PRIMARY_KEY' });
     $index->add_column($table->get_column($_)) for @pk_cols;
     $table->add_index($index);
 }