use Try::Tiny;
use List::Util qw(first max);
-use B 'perlstring';
use DBIx::Class::ResultSource::RowParser::Util qw(
assemble_simple_parser
# any sort of adjustment/rewrite should be relatively easy (fsvo relatively)
#
sub _mk_row_parser {
- my ($self, $args) = @_;
+ # $args and $attrs are separated to delineate what is core collapser stuff and
+ # what is dbic $rs specific
+ my ($self, $args, $attrs) = @_;
- my $val_index = { map
- { $args->{inflate_map}[$_] => $_ }
- ( 0 .. $#{$args->{inflate_map}} )
- };
+ die "HRI without pruning makes zero sense"
+ if ( $args->{hri_style} && ! $args->{prune_null_branches} );
- my $src;
+ my %common = (
+ hri_style => $args->{hri_style},
+ prune_null_branches => $args->{prune_null_branches},
+ val_index => { map
+ { $args->{inflate_map}[$_] => $_ }
+ ( 0 .. $#{$args->{inflate_map}} )
+ },
+ );
- if (! $args->{collapse} ) {
- $src = assemble_simple_parser({
- val_index => $val_index,
- hri_style => $args->{hri_style},
- prune_null_branches => $args->{prune_null_branches},
- });
- }
- else {
+ my $check_null_columns;
+
+ my $src = (! $args->{collapse} ) ? assemble_simple_parser(\%common) : do {
my $collapse_map = $self->_resolve_collapse ({
- premultiplied => $args->{premultiplied},
# FIXME
# only consider real columns (not functions) during collapse resolution
# this check shouldn't really be here, as fucktards are not supposed to
# (it is now trivial as the attrs specify where things go out of sync
# needs MOAR tests)
as => { map
- { ref $args->{selection}[$val_index->{$_}] ? () : ( $_ => $val_index->{$_} ) }
- keys %$val_index
- }
+ { ref $attrs->{select}[$common{val_index}{$_}] ? () : ( $_ => $common{val_index}{$_} ) }
+ keys %{$common{val_index}}
+ },
+ premultiplied => $args->{premultiplied},
});
- $src = assemble_collapsing_parser({
- val_index => $val_index,
+ $check_null_columns = $collapse_map->{-identifying_columns}
+ if @{$collapse_map->{-identifying_columns}};
+
+ assemble_collapsing_parser({
+ %common,
collapse_map => $collapse_map,
- hri_style => $args->{hri_style},
- prune_null_branches => $args->{prune_null_branches},
});
- }
+ };
+
+ utf8::upgrade($src)
+ if DBIx::Class::_ENV_::STRESSTEST_UTF8_UPGRADE_GENERATED_COLLAPSER_SOURCE;
- return (! $args->{eval})
- ? $src
- : eval "sub { $src }" || die $@
- ;
+ return (
+ $args->{eval} ? ( eval "sub $src" || die $@ ) : $src,
+ $check_null_columns,
+ );
}
if $args->{_parent_info}{collapser_reusable};
}
- # Still dont know how to collapse - try to resolve based on our columns (plus already inserted FK bridges)
+ # Still don't know how to collapse - try to resolve based on our columns (plus already inserted FK bridges)
if (
! $collapse_map->{-identifying_columns}
and
# if we got here - we are good to go, but the construction is tricky
# since our children will want to include our collapse criteria - we
# don't give them anything (safe, since they are all collapsible on their own)
- # in addition we record the individual collapse posibilities
+ # in addition we record the individual collapse possibilities
# of all left children node collapsers, and merge them in the rowparser
# coderef later
$collapse_map->{-identifying_columns} = [];