From: Matt Phillips Date: Mon, 18 Mar 2013 13:31:28 +0000 (-0400) Subject: allow optional hashref as final arg to helpers X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=abb46fd094b311cee59cde2134c6f207de99c632;p=dbsrgits%2FData-Query.git allow optional hashref as final arg to helpers --- diff --git a/lib/Data/Query/ExprHelpers.pm b/lib/Data/Query/ExprHelpers.pm index 674bacc..809948e 100644 --- a/lib/Data/Query/ExprHelpers.pm +++ b/lib/Data/Query/ExprHelpers.pm @@ -75,13 +75,21 @@ foreach my $name (values %Data::Query::Constants::CONST) { $dq->{type} and $dq->{type} eq $name }; push @EXPORT, $sub; - if ($map{$name}) { - my @map = @{$map{$name}}; + if (my @map = @{$map{$name}||[]}) { *$name = sub { my $dq = { type => $name }; - foreach (0..$#_) { + foreach (0..$#map) { $dq->{$map[$_]} = $_[$_] if defined $_[$_]; } + + if (my $optional = $_[$#map+1]) { + unless(ref $optional eq 'HASH') { + require Carp; + Carp::croak("Not a hashreference"); + } + @{$dq}{keys %$optional} = values %$optional; + } + return $dq; }; push @EXPORT, $name;