X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSource%2FRowParser.pm;h=83be406fcdb598e14b7b999d63490ab1d906e613;hb=bf718c435cea6f053657e4ba09edb07878695cd0;hp=1c84b3ce6fdd9fc9de3a3b60fa0a9a89b48c02a6;hpb=cef91eed52efd44af9f14b522a5f75978d1eec6c;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/ResultSource/RowParser.pm b/lib/DBIx/Class/ResultSource/RowParser.pm index 1c84b3c..83be406 100644 --- a/lib/DBIx/Class/ResultSource/RowParser.pm +++ b/lib/DBIx/Class/ResultSource/RowParser.pm @@ -14,32 +14,32 @@ use DBIx::Class::ResultSource::RowParser::Util qw( assemble_collapsing_parser ); +use DBIx::Class::Carp; + use namespace::clean; -# Accepts one or more relationships for the current source and returns an -# array of column names for each of those relationships. Column names are -# prefixed relative to the current source, in accordance with where they appear -# in the supplied relationships. -sub _resolve_prefetch { - my ($self, $pre, $alias, $alias_map, $order, $pref_path) = @_; +# Accepts a prefetch map (one or more relationships for the current source), +# returns a set of select/as pairs for each of those relationships. Columns +# are fully qualified inflation_slot names +sub _resolve_selection_from_prefetch { + my ($self, $pre, $alias_map, $pref_path) = @_; + + # internal recursion marker $pref_path ||= []; if (not defined $pre or not length $pre) { return (); } elsif( ref $pre eq 'ARRAY' ) { - return - map { $self->_resolve_prefetch( $_, $alias, $alias_map, $order, [ @$pref_path ] ) } - @$pre; + map { $self->_resolve_selection_from_prefetch( $_, $alias_map, [ @$pref_path ] ) } + @$pre; } elsif( ref $pre eq 'HASH' ) { - my @ret = map { - $self->_resolve_prefetch($_, $alias, $alias_map, $order, [ @$pref_path ] ), - $self->related_source($_)->_resolve_prefetch( - $pre->{$_}, "${alias}.$_", $alias_map, $order, [ @$pref_path, $_] ) + $self->_resolve_selection_from_prefetch($_, $alias_map, [ @$pref_path ] ), + $self->related_source($_)->_resolve_selection_from_prefetch( + $pre->{$_}, $alias_map, [ @$pref_path, $_] ) } keys %$pre; - return @ret; } elsif( ref $pre ) { $self->throw_exception( @@ -47,26 +47,40 @@ sub _resolve_prefetch { } else { my $p = $alias_map; - $p = $p->{$_} for (@$pref_path, $pre); + $p = $p->{$_} for @$pref_path, $pre; $self->throw_exception ( "Unable to resolve prefetch '$pre' - join alias map does not contain an entry for path: " . join (' -> ', @$pref_path, $pre) ) if (ref $p->{-join_aliases} ne 'ARRAY' or not @{$p->{-join_aliases}} ); - my $as = shift @{$p->{-join_aliases}}; - - my $rel_info = $self->relationship_info( $pre ); - $self->throw_exception( $self->source_name . " has no such relationship '$pre'" ) - unless $rel_info; + # this shift() is critical - it is what allows prefetch => [ (foo) x 2 ] to work + my $src_alias = shift @{$p->{-join_aliases}}; + + # ordered [select => as] pairs + map { [ + "${src_alias}.$_" => join ( '.', + @$pref_path, + $pre, + $_, + ) + ] } $self->related_source($pre)->columns; + } +} - my $as_prefix = ($alias =~ /^.*?\.(.+)$/ ? $1.'.' : ''); +sub _resolve_prefetch { + carp_unique( + 'There is no good reason to call this internal deprecated method - ' + . 'please open a ticket detailing your usage, so that a better plan can ' + . 'be devised for your case. In either case _resolve_prefetch() is ' + . 'deprecated in favor of _resolve_selection_from_prefetch(), which has ' + . 'a greatly simplified arglist.' + ); - return map { [ "${as}.$_", "${as_prefix}${pre}.$_", ] } - $self->related_source($pre)->columns; - } + $_[0]->_resolve_selection_from_prefetch( $_[1], $_[3] ); } + # Takes an arrayref of {as} dbic column aliases and the collapse and select # attributes from the same $rs (the selector requirement is a temporary # workaround... I hope), and returns a coderef capable of: @@ -136,6 +150,9 @@ sub _mk_row_parser { }); }; + utf8::upgrade($src) + if DBIx::Class::_ENV_::STRESSTEST_UTF8_UPGRADE_GENERATED_COLLAPSER_SOURCE; + return ( $args->{eval} ? ( eval "sub $src" || die $@ ) : $src, $check_null_columns, @@ -180,26 +197,12 @@ sub _resolve_collapse { is_single => ( $inf->{attrs}{accessor} && $inf->{attrs}{accessor} ne 'multi' ), is_inner => ( ( $inf->{attrs}{join_type} || '' ) !~ /^left/i), rsrc => $self->related_source($rel), + fk_map => $self->_resolve_relationship_condition( + rel_name => $rel, + self_alias => "\xFE", # irrelevant + foreign_alias => "\xFF", # irrelevant + )->{identity_map}, }; - - # FIME - need to use _resolve_cond here instead - my $cond = $inf->{cond}; - - if ( - ref $cond eq 'HASH' - and - keys %$cond - and - ! defined first { $_ !~ /^foreign\./ } (keys %$cond) - and - ! defined first { $_ !~ /^self\./ } (values %$cond) - ) { - for my $f (keys %$cond) { - my $s = $cond->{$f}; - $_ =~ s/^ (?: foreign | self ) \.//x for ($f, $s); - $relinfo->{$rel}{fk_map}{$s} = $f; - } - } } # inject non-left fk-bridges from *INNER-JOINED* children (if any)