8 use Moose::Util::TypeConstraints;
9 use MooseX::Types::Moose qw/ArrayRef Str Int HashRef CodeRef/;
10 use MooseX::AttributeHelpers;
11 use SQL::Abstract::Types qw/NameSeparator QuoteChars AST/;
12 use Devel::PartialDump qw/dump/;
14 our $VERSION = '2.000000';
16 our $AST_VERSION = '1';
18 # Operator precedence for bracketing
37 # LIKE is always "field LIKE <value>"
39 'not_like' => 'NOT LIKE',
42 has expr_dispatch_table => (
45 builder => '_build_expr_dispatch_table',
46 isa => HashRef[CodeRef],
47 metaclass => 'Collection::ImmutableHash',
49 get => 'lookup_expr_dispatch'
56 builder => '_build_binops',
58 metaclass => 'Collection::ImmutableHash',
60 exists => 'is_valid_binop',
61 get => 'binop_mapping',
62 keys => 'binary_operators'
66 # List of default binary operators (for in where clauses)
67 sub _build_binops { return {%BINOP_MAP} };
69 method _build_expr_dispatch_table {
70 my $binop = $self->can('_binop') or croak "InternalError: $self can't do _binop!";
72 map { $_ => $binop } $self->binary_operators
82 has ident_separator => (
89 has list_separator => (
99 predicate => 'is_quoting',
100 clearer => 'disable_quoting',
107 clearer => '_clear_binds',
109 default => sub { [ ] },
110 metaclass => 'Collection::Array',
116 # TODO: once MXMS supports %args, use that here
117 # TODO: improve this so you can pass other args
118 method create(ClassName $class: Int $ver) {
119 croak "AST version $ver is greater than supported version of $AST_VERSION"
120 if $ver > $AST_VERSION;
122 my $name = "${class}::AST::v$ver";
123 Class::MOP::load_class($name);
125 return $name->new(ast_version => $ver);
129 method generate(ClassName $class: AST $ast) {
130 my $ver = $ast->{-ast_version};
131 croak "SQL::Abstract AST version not specified"
134 # TODO: once MXMS supports %args, use that here
135 my $self = $class->create($ver);
137 return ($self->dispatch($ast), $self->binds);
141 $self->_clear_binds();
144 method dispatch (AST $ast) {
146 my $tag = "_" . $ast->{-type};
148 my $meth = $self->can($tag) || croak "Unknown tag '$tag'";
149 return $meth->($self, $ast);
158 SQL::Abstract - AST based re-implementation of SQL::Abstract
164 Ash Berlin C<< <ash@cpan.org> >>
168 This program is free software; you can redistribute it and/or modify it under
169 the same terms as Perl itself.