b1df31720c6a3690eeb44d5761063ad8982bc497
[dbsrgits/Data-Query.git] / lib / Data / Query / ExprBuilder.pm
1 package Data::Query::ExprBuilder;
2
3 use strictures 1;
4 use Data::Query::Constants qw(DQ_OPERATOR DQ_VALUE);
5 use Scalar::Util ();
6
7 use overload (
8   (map {
9     my $op = $_;
10     $op => sub {
11       Data::Query::ExprBuilder->new({
12         expr => {
13           type => DQ_OPERATOR,
14           operator => { perl => $op },
15           args => [
16            map {
17              (Scalar::Util::blessed($_)
18              && $_->isa('Data::Query::ExprBuilder'))
19                ? $_->{expr}
20                : {
21                    type => DQ_VALUE,
22                    subtype => { perl => 'Scalar' },
23                    value => $_
24                  }
25             } $_[2] ? @_[1,0] : @_[0,1]
26           ]
27         },
28       });
29     }
30   } qw(==))
31 ); 
32
33 sub new {
34   bless({ %{$_[1]} }, (ref($_[0])||$_[0]));
35 }
36
37 1;