Port more of the back-compat tests
[dbsrgits/SQL-Abstract-2.0-ish.git] / lib / SQL / Abstract / Compat.pm
CommitLineData
0bcf772f 1use MooseX::Declare;
2
3class SQL::Abstract::Compat {
7c300b3a 4
5 use Moose::Util::TypeConstraints;
bad761ba 6 use MooseX::Types::Moose qw/Str ScalarRef ArrayRef HashRef/;
0a18aa4f 7 use SQL::Abstract::Types::Compat ':all';
8 use SQL::Abstract::AST::Compat;
9 use SQL::Abstract::AST::v1;
10 use Data::Dump qw/pp/;
bad761ba 11
0a18aa4f 12 class_type 'SQL::Abstract';
7c300b3a 13 clean;
14
15 has logic => (
16 is => 'rw',
17 isa => LogicEnum,
aa0f2366 18 default => 'AND',
19 coerce => 1
7c300b3a 20 );
21
0a18aa4f 22 has visitor => (
23 is => 'rw',
24 isa => 'SQL::Abstract',
25 clearer => 'clear_visitor',
26 lazy => 1,
27 builder => '_build_visitor',
28 );
bad761ba 29
30
7c300b3a 31 method select(Str|ArrayRef|ScalarRef $from, ArrayRef|Str $fields,
0a18aa4f 32 WhereType $where?,
33 WhereType $order?)
34 {
35
36 my $ast = $self->_new_compat_ast->select($from,$fields,$where,$order);
7c300b3a 37
0a18aa4f 38 return ($self->visitor->dispatch($ast), $self->visitor->binds);
39 }
bad761ba 40
0a18aa4f 41 method where(WhereType $where,
42 WhereType $order?)
43 {
44 my $ret = "";
45
46 if ($where) {
47 my $ast = $self->_new_compat_ast->generate($where);
48 $ret .= "WHERE " . $self->visitor->_expr($ast);
49 }
50
51 return $ret;
7c300b3a 52 }
bad761ba 53
0a18aa4f 54 #TODO: Handle logic and similar args later
55 method _new_compat_ast() {
56 return SQL::Abstract::AST::Compat->new;
bad761ba 57 }
58
0a18aa4f 59 method _build_visitor() {
60 return SQL::Abstract->create(1);
61 }
62
0bcf772f 63}
64
65=head1 NAME
66
67SQL::Abstract::Compant - compatibility layer for SQL::Abstrct v 1.xx
68
69=head1 DESCRIPTION
70
71This class attempts to maintain the original behaviour of version 1 of
72SQL::Abstract. It does this by internally converting to an AST and then using
73the standard AST visitor.
74
75If so desired, you can get hold of this transformed AST somehow. This is aimed
76at libraries such as L<DBIx::Class> that use SQL::Abstract-style arrays or
77hashes as part of their public interface.
78
79=head1 AUTHOR
80
81Ash Berlin C<< <ash@cpan.org> >>
82
83=cut
84
851;