From: Amiri Barksdale at Home Date: Thu, 8 Jul 2010 03:00:53 +0000 (-0700) Subject: Unified _resolve_deps from two branches to one. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a8cbaf3895156fb728da9877970be5f5c80b7d95;p=dbsrgits%2FDBIx-Class-Historic.git Unified _resolve_deps from two branches to one. --- diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index b2ba72c..280f7fe 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -303,7 +303,7 @@ EOW my $view_dependencies = { map { - $_ => _resolve_view_deps( $dbicschema->source($_), \%view_monikers ) + $_ => _resolve_deps( $dbicschema->source($_), \%view_monikers ) } ( keys %view_monikers ) }; @@ -354,58 +354,39 @@ EOW # Quick and dirty dependency graph calculator # sub _resolve_deps { - my ($table, $tables, $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{$table} = 1; - - for my $dep (keys %{$tables->{$table}{foreign_table_deps}} ) { - - if ($seen->{$dep}) { - - # warn and remove the circular constraint so we don't get flooded with the same warning over and over - #carp sprintf ("Circular dependency detected, schema may not be deployable:\n%s\n", - # join (' -> ', (sort { $seen->{$b} <=> $seen->{$a} } (keys %$seen) ), $table, $dep ) - #); - #delete $tables->{$table}{foreign_table_deps}{$dep}; - - return {}; - } - - my $subdeps = _resolve_deps ($dep, $tables, \%seen); - $ret->{$_} += $subdeps->{$_} for ( keys %$subdeps ); - - ++$ret->{$dep}; - } - - return $ret; -} - -sub _resolve_view_deps { - my ( $view, $monikers, $seen ) = @_; - + my ( $question, $answers, $seen ) = @_; my $ret = {}; $seen ||= {}; + my @deps; # copy and bump all deps by one (so we can reconstruct the chain) my %seen = map { $_ => $seen->{$_} + 1 } ( keys %$seen ); - $seen{ $view->result_class } = 1; - for my $dep ( keys %{ $view->{deploy_depends_on} } ) { + if ( ref($question) =~ /View/ ) { + $seen{ $question->result_class } = 1; + @deps = keys %{ $question->{deploy_depends_on} }; + } + else { + $seen{$question} = 1; + @deps = keys %{ $answers->{$question}{foreign_table_deps} }; + } + + for my $dep (@deps) { if ( $seen->{$dep} ) { return {}; } - my ($new_source_name) = - grep { $view->schema->source($_)->result_class eq $dep } - @{ [ $view->schema->sources ] }; - my $subdeps = - _resolve_view_deps( $view->schema->source($new_source_name), - $monikers, \%seen, ); - $ret->{$_} += $subdeps->{$_} for ( keys %$subdeps ); + my $next_dep; + if ( ref($question) =~ /View/ ) { + my ($next_dep_source_name) = + grep { $question->schema->source($_)->result_class eq $dep } + @{ [ $question->schema->sources ] }; + $next_dep = $question->schema->source($next_dep_source_name); + } + else { + $next_dep = $dep; + } + my $subdeps = _resolve_deps( $next_dep, $answers, \%seen ); + $ret->{$_} += $subdeps->{$_} for ( keys %$subdeps ); ++$ret->{$dep}; } return $ret;