From: Matt S Trout Date: Mon, 7 Oct 2013 13:42:55 +0000 (+0000) Subject: add scan_dq_nodes helper X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=790d0b64b870ec4332977f1ace915d45c3eb2fd3;p=dbsrgits%2FData-Query.git add scan_dq_nodes helper --- diff --git a/lib/Data/Query/ExprHelpers.pm b/lib/Data/Query/ExprHelpers.pm index 809948e..399a8e2 100644 --- a/lib/Data/Query/ExprHelpers.pm +++ b/lib/Data/Query/ExprHelpers.pm @@ -7,6 +7,7 @@ use base qw(Exporter); our @EXPORT = qw( perl_scalar_value perl_operator Literal Identifier compose intersperse + scan_dq_nodes ); sub intersperse { my $i = shift; my @i = map +($_, $i), @_; pop @i; @i } @@ -127,5 +128,17 @@ sub compose (&@) { $a; } +sub scan_dq_nodes { + my ($cb_map, @queue) = @_; + while (my $node = shift @queue) { + if ($node->{type} and my $cb = $cb_map->{$node->{type}}) { + $cb->($node); + } + push @queue, + grep ref($_) eq 'HASH', + map +(ref($_) eq 'ARRAY' ? @$_ : $_), + @{$node}{grep !/\./, keys %$node}; + } +} 1;