From: Guillermo Roditi Date: Mon, 25 Aug 2008 20:17:49 +0000 (+0000) Subject: is_virtual support X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9774f48b59d8b131a8b628d0988f5c3775b95624;p=dbsrgits%2FDBIx-Class-Historic.git is_virtual support --- diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index a026339..1734d52 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -71,6 +71,18 @@ and don't actually accomplish anything on their own: "_engine" => 'InnoDB', }); +=cut + +sub is_virtual { 0 } + +=pod + +=head2 is_virtual + +Returns true if the resultsource is a virtual result source. This stub +method returns false by default, see L +for more information. + =head2 add_columns $table->add_columns(qw/col1 col2 col3/); diff --git a/lib/DBIx/Class/ResultSource/View.pm b/lib/DBIx/Class/ResultSource/View.pm index 61c22b9..ffe719e 100644 --- a/lib/DBIx/Class/ResultSource/View.pm +++ b/lib/DBIx/Class/ResultSource/View.pm @@ -7,6 +7,7 @@ use DBIx::Class::ResultSet; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/ResultSource/); +__PACKAGE__->mk_group_accessors('simple' => ' is_virtual'); =head1 NAME @@ -20,13 +21,22 @@ Table object that inherits from L =head1 METHODS +=head2 is_virtual + +Attribute to declare a view as virtual. + =head2 from Returns the FROM entry for the table (i.e. the view name) +or the definition if this is a virtual view. =cut -sub from { shift->name; } +sub from { + my $self = shift; + return \"(${\$self->view_definition})" if $self->is_virtual; + return $self->name; +} 1; diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 66367f8..ae14d0b 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -68,6 +68,7 @@ sub parse { my(@table_monikers, @view_monikers); for my $moniker (@monikers){ my $source = $dbicschema->source($moniker); + next if $source->is_virtual; if ( $source->isa('DBIx::Class::ResultSource::Table') || $source->isa('DBIx::Class::ResultSourceProxy::Table') ) { push(@table_monikers, $moniker);