2 use MooseX::Method::Signatures;
10 use Moose::Util::TypeConstraints;
11 use MooseX::Types -declare => ['NameSeparator'];
12 use MooseX::Types::Moose qw/ArrayRef Str/;
13 use MooseX::AttributeHelpers;
15 use namespace::clean -except => ['meta'];
17 subtype NameSeparator,
19 #where { @$_ == 1 ||| @$_ == 2 },
20 #message { "Name separator must be one or two elements" };
22 coerce NameSeparator, from Str, via { [ $_ ] };
24 our $VERSION = '2.000000';
26 our $AST_VERSION = '1';
28 has name_separator => (
31 default => sub { ['.'] },
36 has list_separator => (
45 default => sub { [ ] },
46 metaclass => 'Collection::Array',
53 method generate (ArrayRef $ast) {
54 $self = new $self unless blessed($self);
57 s/^-/_/ or croak "Unknown type tag '$_'";
58 my $meth = $self->can($_) || \&_generic_func;
59 return $meth->($self, $ast);
62 method _select(ArrayRef $ast) {
66 method _name(ArrayRef $ast) {
67 my (undef, @names) = @$ast;
69 my $sep = $self->name_separator;
72 join( $sep->[1] . $sep->[0], @names ) .
76 return join($sep->[0], @names);
79 method _list(ArrayRef $ast) {
80 my (undef, @items) = @$ast;
83 $self->list_separator,
84 map { $self->generate($_) } @items);
87 method _alias(ArrayRef $ast) {
88 my (undef, $alias, $as) = @$ast;
90 return $self->generate($alias) . " AS $as";
94 method _value(ArrayRef $ast) {
95 my ($undef, $value) = @$ast;
97 $self->add_bind($value);
101 method _where(ArrayRef $ast) {
102 my (undef, @clauses) = @$ast;
109 unless (substr($op, 0, 1) eq '-') {
110 # A simple comparison op (==, >, etc.)
111 croak "Binary operator $op expects 2 children, got " . $#$_
114 push @output, $self->generate($_->[1]),
116 $self->generate($_->[2]);
120 return join(' ', 'WHERE', @output);
123 method _generic_func(ArrayRef $ast) {