From: Matt S Trout Date: Sun, 3 Nov 2013 23:33:35 +0000 (+0000) Subject: make map_descending available as map_dq_tree via ExprHelpers X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fd6e1f4c94fdfd83ea55b28e9289d5fb14fdb149;p=dbsrgits%2FData-Query.git make map_descending available as map_dq_tree via ExprHelpers --- diff --git a/lib/Data/Query/ExprHelpers.pm b/lib/Data/Query/ExprHelpers.pm index b6df568..a48f687 100644 --- a/lib/Data/Query/ExprHelpers.pm +++ b/lib/Data/Query/ExprHelpers.pm @@ -7,7 +7,7 @@ use base qw(Exporter); our @EXPORT = qw( perl_scalar_value perl_operator Literal Identifier compose intersperse - scan_dq_nodes + scan_dq_nodes map_dq_tree ); sub intersperse { my $i = shift; my @i = map +($_, $i), @_; pop @i; @i } @@ -141,4 +141,21 @@ sub scan_dq_nodes { } } +sub map_dq_tree (&;@) { + my ($block, $in) = @_; + local $_ = $in; + $_ = $block->($_) if ref($_) eq 'HASH'; + if (ref($_) eq 'REF' and ref($$_) eq 'HASH') { + $$_; + } elsif (ref($_) eq 'HASH') { + my $mapped = $_; + local $_; + +{ map +($_ => &map_dq_tree($block, $mapped->{$_})), keys %$mapped }; + } elsif (ref($_) eq 'ARRAY') { + [ map &map_dq_tree($block, $_), @$_ ] + } else { + $_ + } +} + 1; diff --git a/lib/Data/Query/Renderer/SQL/MySQL.pm b/lib/Data/Query/Renderer/SQL/MySQL.pm index 116bbb2..25a4929 100644 --- a/lib/Data/Query/Renderer/SQL/MySQL.pm +++ b/lib/Data/Query/Renderer/SQL/MySQL.pm @@ -1,22 +1,5 @@ package Data::Query::Renderer::SQL::MySQL; -sub map_descending (&;@) { - my ($block, $in) = @_; - local $_ = $in; - $_ = $block->($_) if ref($_) eq 'HASH'; - if (ref($_) eq 'REF' and ref($$_) eq 'HASH') { - $$_; - } elsif (ref($_) eq 'HASH') { - my $mapped = $_; - local $_; - +{ map +($_ => &map_descending($block, $mapped->{$_})), keys %$mapped }; - } elsif (ref($_) eq 'ARRAY') { - [ map &map_descending($block, $_), @$_ ] - } else { - $_ - } -} - use Data::Query::Constants; use Data::Query::ExprHelpers; use Moo; @@ -43,7 +26,7 @@ sub _maybe_double_subquery { my $new = { %$dq }; foreach my $key (qw(set where)) { next unless $dq->{$key}; - $new->{$key} = map_descending { + $new->{$key} = map_dq_tree { if (is_Select) { my $found; scan_dq_nodes(do {