From: Amiri Barksdale at Home Date: Sun, 6 Jun 2010 16:18:46 +0000 (-0700) Subject: Remove extraneous include in parser; replace loop with map in parser; add throws_ok... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c418c5cc5d3e8b3b456ea0daf7569f4ac3ef7cd4;p=dbsrgits%2FDBIx-Class-Historic.git Remove extraneous include in parser; replace loop with map in parser; add throws_ok test --- diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 93a39a0..bd3d3ba 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -17,7 +17,6 @@ use SQL::Translator::Utils qw(debug normalize_name); use Carp::Clan qw/^SQL::Translator|^DBIx::Class|^Try::Tiny/; use Scalar::Util 'weaken'; use Try::Tiny; -use Devel::Dwarn; use namespace::clean; use base qw(Exporter); @@ -301,21 +300,17 @@ EOW my %views; my @views = map { $dbicschema->source($_) } keys %view_monikers; - my $view_dependencies; - ### This is a loop instead of a map because - ### passing an object to the sub failed--gave - ### $view->name instead of the $view! - - for my $view (@views) { - $view_dependencies->{ $view->name } = - _resolve_view_deps ( { view => $view }, \%view_monikers ); - } + my $view_dependencies = { + map { + $_ => _resolve_view_deps( $dbicschema->source($_), \%view_monikers ) + } ( keys %view_monikers ) + }; my @view_sources = sort { - keys %{ $view_dependencies->{ $a->name } || {} } <=> - keys %{ $view_dependencies->{ $b->name } || {} } + keys %{ $view_dependencies->{ $a->source_name } || {} } <=> + keys %{ $view_dependencies->{ $b->source_name } || {} } || $a->source_name cmp $b->source_name } map { $dbicschema->source($_) } @@ -391,15 +386,14 @@ sub _resolve_deps { } sub _resolve_view_deps { - my ( $view0, $monikers, $seen ) = @_; - my $view = $view0->{view}; - my $ret = {}; + my ( $view, $monikers, $seen ) = @_; + + my $ret = {}; $seen ||= {}; # copy and bump all deps by one (so we can reconstruct the chain) my %seen = map { $_ => $seen->{$_} + 1 } ( keys %$seen ); $seen{ $view->source_name } = 1; - for my $dep ( keys %{ $view->{deploy_depends_on} } ) { if ( $seen->{$dep} ) { return {}; @@ -407,8 +401,8 @@ sub _resolve_view_deps { my ($new_source_name) = grep { $view->schema->source($_)->name eq $dep } @{ [ $view->schema->sources ] }; - my $subdeps = _resolve_view_deps( - { view => $view->schema->source($new_source_name) }, + my $subdeps = + _resolve_view_deps( $view->schema->source($new_source_name), $monikers, \%seen, ); $ret->{$_} += $subdeps->{$_} for ( keys %$subdeps ); diff --git a/t/105view_deps.t b/t/105view_deps.t index 66e409d..d53dc79 100644 --- a/t/105view_deps.t +++ b/t/105view_deps.t @@ -97,7 +97,13 @@ dies_ok( sub { $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next; }, - "Query on AbaNameArtistsAnd2010CDsWithManyTracks fails, because of incorrect deploy_depends_on in AbaNameArtists" + "Query on AbaNameArtistsAnd2010CDsWithManyTracks dies, because of incorrect deploy_depends_on in AbaNameArtists" ); +throws_ok { + $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next; +} +qr/no such table: aba_name_artists_and_2010_cds_with_many_tracks/, + "Query on AbaNameArtistsAnd2010CDsWithManyTracks throws, because the table does not exist"; + done_testing;