X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSource%2FRowParser%2FUtil.pm;h=d1c1e3b71ea02802cb56fd47ca391a7fb46894df;hb=d71502b;hp=f80fd7dc8ff85bc85b522cf4f0d6497a1cc7373d;hpb=79adc44f8b50de05a1d31f9b3d4a64b137c7d0d8;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSource/RowParser/Util.pm b/lib/DBIx/Class/ResultSource/RowParser/Util.pm index f80fd7d..d1c1e3b 100644 --- a/lib/DBIx/Class/ResultSource/RowParser/Util.pm +++ b/lib/DBIx/Class/ResultSource/RowParser/Util.pm @@ -7,6 +7,8 @@ use warnings; use List::Util 'first'; use B 'perlstring'; +use constant HAS_DOR => ( $] < 5.010 ? 0 : 1 ); + use base 'Exporter'; our @EXPORT_OK = qw( assemble_simple_parser @@ -151,9 +153,12 @@ sub assemble_collapsing_parser { my @idcol_args = $no_rowid_container ? ('', '') : ( ', %cur_row_ids', # only declare the variable if we'll use it - join ("\n", map { - qq(\$cur_row_ids{$_} = defined(\$cur_row_data->[$_]) ? \$cur_row_data->[$_] : "\0NULL\xFF\$rows_pos\xFF$_\0";) - } sort { $a <=> $b } keys %{ $stats->{idcols_seen} } ) + join ("\n", map { qq(\$cur_row_ids{$_} = ) . ( + # in case we prune - we will never hit these undefs + $args->{prune_null_branches} ? qq(\$cur_row_data->[$_];) + : HAS_DOR ? qq(\$cur_row_data->[$_] // "\0NULL\xFF\$rows_pos\xFF$_\0";) + : qq(defined(\$cur_row_data->[$_]) ? \$cur_row_data->[$_] : "\0NULL\xFF\$rows_pos\xFF$_\0";) + ) } sort { $a <=> $b } keys %{ $stats->{idcols_seen} } ), ); my $parser_src = sprintf (<<'EOS', @idcol_args, $top_node_key_assembler||'', $top_node_key, join( "\n", @{$data_assemblers||[]} ) ); @@ -173,7 +178,9 @@ sub assemble_collapsing_parser { ( $_[1] and $rows_pos = -1 and $_[1]->() ) ) ) { - # this code exists only when we are *not* assembling direct to HRI + # this code exists only when we are using a cur_row_ids + # furthermore the undef checks may or may not be there + # depending on whether we prune or not # # due to left joins some of the ids may be NULL/undef, and # won't play well when used as hash lookups @@ -250,8 +257,9 @@ sub __visit_infmap_collapse { my @src; if ($cur_node_idx == 0) { - push @src, sprintf( '%s ||= $_[0][$result_pos++] = %s;', + push @src, sprintf( '%s %s $_[0][$result_pos++] = %s;', $node_idx_slot, + (HAS_DOR ? '//=' : '||='), $me_struct || '{}', ); } @@ -263,8 +271,9 @@ sub __visit_infmap_collapse { ); if ($args->{collapse_map}->{-is_single}) { - push @src, sprintf ( '%s ||= %s%s;', + push @src, sprintf ( '%s %s %s%s;', $parent_attach_slot, + (HAS_DOR ? '//=' : '||='), $node_idx_slot, $me_struct ? " = $me_struct" : '', );