+++ /dev/null
-use strictures 1;
-use Data::Query::ExprBuilder::Identifier;
-use Data::Query::ExprHelpers;
-use Data::Query::Constants;
-
-sub expr (&) {
- _run_expr($_[0])->{expr};
-}
-
-sub _run_expr {
- local $_ = Data::Query::ExprBuilder::Identifier->new({
- expr => Identifier(),
- });
- $_[0]->();
-}
-
-sub AS {
- my $as = shift;
- (bless(\$as, 'LIES::AS'), @_);
-}
-
-sub SELECT (&;@) {
- my @select = map +(
- ref()
- ? $_
- : { expr => perl_scalar_value($_) }
- ), _run_expr(shift);
- my @final;
- while (@select) {
- my $e = shift @select;
- push @final,
- (ref($select[0]) eq 'LIES::AS'
- ? Alias(${shift(@select)}, $e->{expr})
- : $e->{expr}
- );
- }
-
- return +{
- expr => Select(\@final, ($_[0]||{})->{expr})
- };
-}
-
-sub BY (&;@) { @_ }
-
-sub FROM (&;@) {
- my @from = _run_expr(shift);
- if (@from == 2 and ref($from[1]) eq 'LIES::AS') {
- return +{
- expr => Alias(${$from[1]}, $from[0])
- };
- } elsif (@from == 1) {
- return { expr => $from[0] };
- }
- die "Huh?"
-}
-
-1;
use Test::More qw(no_plan);
use Test::Exception;
-BEGIN { require 't/expr.include' }
+use Data::Query::ExprDeclare;
+use Data::Query::Constants;
sub expr_is (&;@) {
my $sub = shift;
- is_deeply(_run_expr($sub)->{expr}, @_);
+ is_deeply(Data::Query::ExprDeclare::_run_expr($sub)->{expr}, @_);
}
expr_is { $_->foo }
use Devel::Dwarn;
use Data::Query::Renderer::Perl;
use Data::Query::ExprHelpers qw(perl_scalar_value);
-
-BEGIN { require 't/expr.include' }
+use Data::Query::ExprDeclare;
+use Scalar::Util qw(blessed);
my $rend = Data::Query::Renderer::Perl->new;
sub expr_perl_is (&;@) {
my $sub = shift;
- @_
- ? is_deeply($rend->render(_run_expr($sub)->{expr}), @_)
- : ::Dwarn($rend->render(_run_expr($sub)->{expr}));
+ my $e = Data::Query::ExprDeclare::_run_expr($sub);
+ $e = blessed($e) ? $e->{expr} : $e;
+ @_
+ ? is_deeply($rend->render($e), @_)
+ : ::Dwarn($rend->render($e));
}
expr_perl_is { $_->foo }
use strictures 1;
use Test::More qw(no_plan);
+use Scalar::Util qw(blessed);
use Devel::Dwarn;
use Data::Query::Renderer::SQL::Naive;
use Data::Query::ExprHelpers qw(perl_scalar_value);
-
-BEGIN { require 't/expr.include' }
+use Data::Query::ExprDeclare qw(SELECT AS expr);
my $rend = Data::Query::Renderer::SQL::Naive->new({ quote_chars => [ "'" ] });
sub expr_sql_is (&;@) {
my $sub = shift;
+ my $e = Data::Query::ExprDeclare::_run_expr($sub);
+ $e = blessed($e) ? $e->{expr} : $e;
@_
- ? is_deeply($rend->render(_run_expr($sub)->{expr}), @_)
- : ::Dwarn($rend->render(_run_expr($sub)->{expr}));
+ ? is_deeply($rend->render($e), @_)
+ : ::Dwarn($rend->render($e));
}
expr_sql_is { $_->foo }