From: Amiri Barksdale Date: Thu, 27 May 2010 14:40:20 +0000 (+0000) Subject: view_sources sorter done? --AKB X-Git-Tag: v0.08124~114^2~23 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bf5c3a3f1c0f706106d762e52a0b7092bee1932a;p=dbsrgits%2FDBIx-Class.git view_sources sorter done? --AKB --- diff --git a/lib/DBIx/Class/ResultSource/View.pm b/lib/DBIx/Class/ResultSource/View.pm index 2229be4..6693060 100644 --- a/lib/DBIx/Class/ResultSource/View.pm +++ b/lib/DBIx/Class/ResultSource/View.pm @@ -5,6 +5,8 @@ use warnings; use DBIx::Class::ResultSet; use SQL::Translator::Parser::DBIx::Class; +use Data::Dumper::Concise; + use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/ResultSource/); __PACKAGE__->mk_group_accessors( @@ -151,9 +153,8 @@ sub 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; + = { map { $_->result_source_instance->name => 1 } @{ $new->{deploy_depends_on}||[] } } + unless ref $new->{deploy_depends_on} eq 'HASH'; return $new; } diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index b838260..20a2d64 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -11,12 +11,11 @@ use warnings; use vars qw($DEBUG $VERSION @EXPORT_OK); $VERSION = '1.10'; $DEBUG = 0 unless defined $DEBUG; - +use Data::Dumper; use Exporter; use SQL::Translator::Utils qw(debug normalize_name); use Carp::Clan qw/^SQL::Translator|^DBIx::Class/; use Scalar::Util (); - use base qw(Exporter); @EXPORT_OK = qw(parse); @@ -264,6 +263,7 @@ sub parse { my $dependencies = { map { $_ => _resolve_deps ($_, \%tables) } (keys %tables) }; + for my $table (sort { keys %{$dependencies->{$a} || {} } <=> keys %{ $dependencies->{$b} || {} } @@ -292,13 +292,39 @@ EOW } my %views; + #my @view_sources = + #sort { + #(exists $a->deploy_depends_on->{$b->source_name} ? 1 : 0) + #<=> + #(exists $b->deploy_depends_on->{$a->source_name} ? 1 : 0) + #} + #map { $dbicschema->source($_) } (sort keys %view_monikers); + + #my @view_sources = + #grep { $_->can('view_definition') } # make sure it's a view + #map { $dbicschema->source($_) } # have to get a source + #map { $tables{$_}{source}{source_name} } # have to get a sourcename + #sort { + #keys %{ $dependencies->{$a} || {} } + #<=> + #keys %{ $dependencies->{$b} || {} } + #|| + #$a cmp $b + #} + #keys %$dependencies; + my @view_sources = - sort { - (exists $a->depends_on->{$b->source_name} ? 1 : 0) - <=> - (exists $b->depends_on->{$a->source_name} ? 1 : 0) - } - map { $dbicschema->source($_) } (sort keys %view_monikers); + sort { + keys %{ $dependencies->{$a} || {} } + <=> + keys %{ $dependencies->{$b} || {} } + || + $a cmp $b + } + map { $dbicschema->source($_) } (sort keys %view_monikers); + + print STDERR Dumper @view_sources; + print STDERR Dumper "Dependencies: ", $dependencies; foreach my $source (@view_sources) { diff --git a/t/105view_deps.t b/t/105view_deps.t index d0895cf..d3aaf58 100644 --- a/t/105view_deps.t +++ b/t/105view_deps.t @@ -36,7 +36,8 @@ my @foo_deps = keys %{ $schema->resultset('Foo')->result_source->deploy_depends_ isa_ok( $schema->resultset('Bar')->result_source, 'DBIx::Class::ResultSource::View', 'Bar' ); -is( $bar_deps[0], 'mixin', 'which is reported to depend on mixin.' ); +is( $bar_deps[0], 'baz', 'which is reported to depend on baz...' ); +is( $bar_deps[1], 'mixin', 'and on mixin.' ); is( $foo_deps[0], undef, 'Foo has no dependencies...' ); isa_ok( @@ -55,4 +56,10 @@ dies_ok { } "...and you cannot use deploy_depends_on with that"; +diag("ViewDeps::Foo view definition: ", ViewDeps->source('Foo')->view_definition); +diag("schema->rs(Bar) view definition: ", $schema->resultset('Bar')->result_source->view_definition); + +my $dir = "t/sql"; # tempdir(CLEANUP => 0); +$schema->create_ddl_dir([ 'PostgreSQL' ], 0.1, $dir); + done_testing; diff --git a/t/lib/ViewDeps/Result/Bar.pm b/t/lib/ViewDeps/Result/Bar.pm index acc0eb0..e0243df 100644 --- a/t/lib/ViewDeps/Result/Bar.pm +++ b/t/lib/ViewDeps/Result/Bar.pm @@ -11,7 +11,7 @@ use ViewDeps::Result::Baz; __PACKAGE__->table('bar'); __PACKAGE__->result_source_instance->deploy_depends_on( - "ViewDeps::Result::Baz", "ViewDeps::Result::Mixin" +["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 13078ec..db80ab2 100644 --- a/t/lib/ViewDeps/Result/Baz.pm +++ b/t/lib/ViewDeps/Result/Baz.pm @@ -6,7 +6,7 @@ use strict; use warnings; use base qw(DBIx::Class::Core); -__PACKAGE__->table('bar'); +__PACKAGE__->table('baz'); __PACKAGE__->add_columns( id => { data_type => 'integer' } ); diff --git a/t/lib/ViewDeps/Result/Foo.pm b/t/lib/ViewDeps/Result/Foo.pm index 512af94..8950489 100644 --- a/t/lib/ViewDeps/Result/Foo.pm +++ b/t/lib/ViewDeps/Result/Foo.pm @@ -8,6 +8,9 @@ use aliased 'DBIx::Class::ResultSource::View'; __PACKAGE__->table_class(View); __PACKAGE__->table('foo'); + +__PACKAGE__->result_source_instance->view_definition("select * from just_a_table"); + __PACKAGE__->add_columns( id => { data_type => 'integer', is_auto_increment => 1 }, a => { data_type => 'integer', is_nullable => 1 } @@ -18,4 +21,6 @@ __PACKAGE__->set_primary_key('id'); __PACKAGE__->belongs_to( 'bar', 'ViewDeps::Result::Bar', { 'foreign.id' => 'self.a' } ); + + 1;