From: Amiri Barksdale Date: Mon, 24 May 2010 15:31:31 +0000 (+0000) Subject: In the middle of making deploy_depends_on smarter. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e55d9d8946103bc78bb7550fee64aa6f15cc1e56;p=dbsrgits%2FDBIx-Class-Historic.git In the middle of making deploy_depends_on smarter. --- diff --git a/lib/DBIx/Class/ResultSource/View.pm b/lib/DBIx/Class/ResultSource/View.pm index e14bc7f..2229be4 100644 --- a/lib/DBIx/Class/ResultSource/View.pm +++ b/lib/DBIx/Class/ResultSource/View.pm @@ -4,12 +4,11 @@ use strict; use warnings; use DBIx::Class::ResultSet; - +use SQL::Translator::Parser::DBIx::Class; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/ResultSource/); __PACKAGE__->mk_group_accessors( - 'simple' => qw(is_virtual view_definition depends_on) -); + 'simple' => qw(is_virtual view_definition deploy_depends_on) ); =head1 NAME @@ -130,19 +129,32 @@ database-based view. An SQL query for your view. Will not be translated across database syntaxes. +=head2 deploy_depends_on + + __PACKAGE__->result_source_instance->deploy_depends_on( + "MyDB::Schema::Result::Year","MyDB::Schema::Result::CD" + ); + +Specify the result classes that comprise this view. Pass this +method a list. + =head1 OVERRIDDEN METHODS =head2 new The constructor. This is a private method, as only other DBIC modules -should call this. See L. +should call this. =cut sub new { - my $new = shift->next::method(@_); - $new->{depends_on} = { %{$new->{depends_on}||{}} }; - return $new; + my ( $self, @args ) = @_; + my $new = $self->next::method(@args); + $new->{deploy_depends_on} + = { map { $_ => 1 } @{ ($new->{deploy_depends_on} || []) } }; + use Data::Dumper; + print STDERR Dumper $new; + return $new; } =head2 from @@ -153,20 +165,18 @@ or the SQL as a subselect if this is a virtual view. =cut sub from { - my $self = shift; - return \"(${\$self->view_definition})" if $self->is_virtual; - return $self->name; + my $self = shift; + return \"(${\$self->view_definition})" if $self->is_virtual; + return $self->name; } =head1 PRIVATE METHODS -=head2 depends_on +=head2 deploy_depends_on An internal method for the construction of a hashref of the view's superclasses, e.g., the sources that comprise it. -See L. - =cut 1; @@ -183,6 +193,8 @@ Jess Robinson Wallace Reis +Amiri Barksdale + =head1 LICENSE You may distribute this code under the same terms as Perl itself. diff --git a/t/105view_deps.t b/t/105view_deps.t index 8c8bb9a..d0895cf 100644 --- a/t/105view_deps.t +++ b/t/105view_deps.t @@ -7,6 +7,7 @@ use Test::More; use Test::Exception; use lib qw(t/lib); use ViewDeps; +use Devel::Dwarn; BEGIN { use_ok('DBIx::Class::ResultSource::View'); @@ -19,16 +20,18 @@ my $view = DBIx::Class::ResultSource::View->new( { name => 'Quux' } ); isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view'); isa_ok( $view, 'DBIx::Class', 'A new view also'); -can_ok( $view, $_ ) for qw/new from depends_on/; +can_ok( $view, $_ ) for qw/new from deploy_depends_on/; ### DEPS my $schema = ViewDeps->connect; ok( $schema, 'Connected to ViewDeps schema OK' ); +my $bar_rs = $schema->resultset('Bar'); +#diag(DwarnS $bar_rs->result_source); -my @bar_deps = keys %{ $schema->resultset('Bar')->result_source->depends_on }; +my @bar_deps = keys %{ $schema->resultset('Bar')->result_source->deploy_depends_on }; -my @foo_deps = keys %{ $schema->resultset('Foo')->result_source->depends_on }; +my @foo_deps = keys %{ $schema->resultset('Foo')->result_source->deploy_depends_on }; isa_ok( $schema->resultset('Bar')->result_source, 'DBIx::Class::ResultSource::View', 'Bar' ); @@ -47,9 +50,9 @@ isa_ok( "Baz on the other hand" ); dies_ok { - ViewDeps::Result::Baz->result_source_instance->depends_on( + ViewDeps::Result::Baz->result_source_instance->deploy_depends_on( { ViewDeps::Result::Mixin->result_source_instance->name => 1 } ); } -"...and you cannot use depends_on with that"; +"...and you cannot use deploy_depends_on with that"; done_testing; diff --git a/t/lib/ViewDeps/Result/Bar.pm b/t/lib/ViewDeps/Result/Bar.pm index 3660c44..acc0eb0 100644 --- a/t/lib/ViewDeps/Result/Bar.pm +++ b/t/lib/ViewDeps/Result/Bar.pm @@ -3,14 +3,15 @@ package # hide from PAUSE use strict; use warnings; -use parent qw(ViewDeps::Result::Foo); +use base qw(ViewDeps::Result::Foo); use ViewDeps::Result::Mixin; +use ViewDeps::Result::Baz; __PACKAGE__->table('bar'); -__PACKAGE__->result_source_instance->depends_on( - { ViewDeps::Result::Mixin->result_source_instance->name => 1 } +__PACKAGE__->result_source_instance->deploy_depends_on( + "ViewDeps::Result::Baz", "ViewDeps::Result::Mixin" ); __PACKAGE__->add_columns( diff --git a/t/lib/ViewDeps/Result/Baz.pm b/t/lib/ViewDeps/Result/Baz.pm index 63ee336..13078ec 100644 --- a/t/lib/ViewDeps/Result/Baz.pm +++ b/t/lib/ViewDeps/Result/Baz.pm @@ -4,7 +4,7 @@ package # hide from PAUSE use strict; use warnings; -use parent qw(DBIx::Class::Core); +use base qw(DBIx::Class::Core); __PACKAGE__->table('bar'); diff --git a/t/lib/ViewDeps/Result/Foo.pm b/t/lib/ViewDeps/Result/Foo.pm index f259001..512af94 100644 --- a/t/lib/ViewDeps/Result/Foo.pm +++ b/t/lib/ViewDeps/Result/Foo.pm @@ -3,7 +3,7 @@ package # hide from PAUSE use strict; use warnings; -use parent qw(DBIx::Class::Core); +use base qw(DBIx::Class::Core); use aliased 'DBIx::Class::ResultSource::View'; __PACKAGE__->table_class(View); diff --git a/t/lib/ViewDeps/Result/Mixin.pm b/t/lib/ViewDeps/Result/Mixin.pm index 4cfb2c7..b45dd94 100644 --- a/t/lib/ViewDeps/Result/Mixin.pm +++ b/t/lib/ViewDeps/Result/Mixin.pm @@ -4,7 +4,7 @@ package # hide from PAUSE use strict; use warnings; -use parent qw(DBIx::Class::Core); +use base qw(DBIx::Class::Core); __PACKAGE__->table('mixin');