X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract.pm;h=e95b8b84422b5ad2b52e94cd41ed12f843436599;hb=cbcfedc1e28bc756373605ec2854dc43c31be53b;hp=f077979edb1557774a55f4e173415f9eafd51f72;hpb=704c513833ed286daebbf137fa170fe29eb60ca5;p=dbsrgits%2FSQL-Abstract-2.0-ish.git diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index f077979..e95b8b8 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -10,16 +10,10 @@ class SQL::Abstract { use MooseX::Types -declare => [qw/NameSeparator/]; use MooseX::Types::Moose qw/ArrayRef Str Int HashRef CodeRef/; use MooseX::AttributeHelpers; + use SQL::Abstract::Types qw/NameSeparator AST ArrayAST/; clean; - subtype NameSeparator, - as ArrayRef[Str]; - #where { @$_ == 1 ||| @$_ == 2 }, - #message { "Name separator must be one or two elements" }; - - coerce NameSeparator, from Str, via { [ $_ ] }; - our $VERSION = '2.000000'; our $AST_VERSION = '1'; @@ -116,7 +110,7 @@ class SQL::Abstract { } # Main entry point - method generate(ClassName $class: ArrayRef $ast) { + method generate(ClassName $class: AST $ast) { croak "SQL::Abstract AST version not specified" unless ($ast->[0] eq '-ast_version'); @@ -132,12 +126,16 @@ class SQL::Abstract { $self->_clear_binds(); } - method dispatch (ArrayRef $ast) { - - local $_ = $ast->[0]; - s/^-/_/ or croak "Unknown type tag '$_'"; + method dispatch (AST $ast) { + # I want multi methods! + my $tag; + if (is_ArrayAST($ast)) { + ($tag = $ast->[0]) =~ s/^-/_/; + } else { + $tag = "_" . $ast->{-type}; + } - my $meth = $self->can($_) || croak "Unknown tag '$_'"; + my $meth = $self->can($tag) || croak "Unknown tag '$tag'"; return $meth->($self, $ast); }