my $view_dependencies = {
map {
- $_ => _resolve_view_deps( $dbicschema->source($_), \%view_monikers )
+ $_ => _resolve_deps( $dbicschema->source($_), \%view_monikers )
} ( keys %view_monikers )
};
# 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;