Introspect view definitions
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / Base.pm
index 1ad8474..923209c 100644 (file)
@@ -30,7 +30,7 @@ use List::Util qw/all any none/;
 use File::Temp 'tempfile';
 use namespace::clean;
 
-our $VERSION = '0.07043';
+our $VERSION = '0.07045';
 
 __PACKAGE__->mk_group_ro_accessors('simple', qw/
                                 schema
@@ -565,7 +565,7 @@ Only load matching tables.
 
 Exclude matching tables.
 
-These can be specified either as a regex (preferrably on the C<qr//>
+These can be specified either as a regex (preferably on the C<qr//>
 form), or as an arrayref of arrayrefs.  Regexes are matched against
 the (unqualified) table name, while arrayrefs are matched according to
 L</moniker_parts>.
@@ -675,7 +675,7 @@ passed, the code is called with arguments of
     }
     coderef ref that can be called with a hashref map
 
-The L<column|DBIx::Class::Schema::Loader::Table> and
+The L<column|DBIx::Class::Schema::Loader::Column> and
 L<table|DBIx::Class::Schema::Loader::Table> objects stringify to their
 unqualified names.
 
@@ -2570,6 +2570,8 @@ sub _table_is_view {
     return 0;
 }
 
+sub _view_definition { undef }
+
 # Set up metadata (cols, pks, etc)
 sub _setup_src_meta {
     my ($self, $table) = @_;
@@ -2580,11 +2582,17 @@ sub _setup_src_meta {
     my $table_class   = $self->classes->{$table->sql_name};
     my $table_moniker = $self->monikers->{$table->sql_name};
 
+    # Must come before ->table
     $self->_dbic_stmt($table_class, 'table_class', 'DBIx::Class::ResultSource::View')
-        if $self->_table_is_view($table);
+        if my $is_view = $self->_table_is_view($table);
 
     $self->_dbic_stmt($table_class, 'table', $table->dbic_name);
 
+    # Must come after ->table
+    if ($is_view and my $view_def = $self->_view_definition($table)) {
+        $self->_dbic_stmt($table_class, 'result_source_instance->view_definition', $view_def);
+    }
+
     my $cols     = $self->_table_columns($table);
     my $col_info = $self->__columns_info_for($table);