From: Ash Berlin Date: Mon, 20 Jul 2009 20:22:52 +0000 (+0100) Subject: Updates to MX::Declare required changes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;p=dbsrgits%2FSQL-Abstract-2.0-ish.git Updates to MX::Declare required changes --- diff --git a/Makefile.PL b/Makefile.PL index 6a29649..7ae2f92 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -5,8 +5,7 @@ use inc::Module::Install 0.79; name 'SQL-Abstract'; requires 'Moose' => '0.71'; -requires 'MooseX::Method::Signatures' => '0.13_804d1448'; -requires 'MooseX::Declare' => '0.09'; +requires 'MooseX::Declare' => '0.22'; requires 'MooseX::Types::Structured' => '0.09'; requires 'Devel::PartialDump' => '0.07'; @@ -15,6 +14,7 @@ test_requires 'Test::Differences'; test_requires 'Sub::Exporter'; auto_provides_class(); +json_meta(); auto_install; tests_recursive 't'; diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index c855117..e21f4ca 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -11,8 +11,6 @@ class SQL::Abstract { use SQL::Abstract::Types qw/NameSeparator QuoteChars AST/; use Devel::PartialDump qw/dump/; - clean; - our $VERSION = '2.000000'; our $AST_VERSION = '1'; diff --git a/lib/SQL/Abstract/AST/v1.pm b/lib/SQL/Abstract/AST/v1.pm index 604c02a..b43d479 100644 --- a/lib/SQL/Abstract/AST/v1.pm +++ b/lib/SQL/Abstract/AST/v1.pm @@ -11,8 +11,6 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract { use SQL::Abstract::Types qw/AST/; use Devel::PartialDump qw/dump/; - clean; - # set things that are valid in where clauses override _build_expr_dispatch_table { return { diff --git a/lib/SQL/Abstract/Compat.pm b/lib/SQL/Abstract/Compat.pm index 5045664..0850164 100644 --- a/lib/SQL/Abstract/Compat.pm +++ b/lib/SQL/Abstract/Compat.pm @@ -12,7 +12,6 @@ class SQL::Abstract::Compat { use Carp qw/croak/; class_type 'SQL::Abstract'; - clean; has logic => ( is => 'rw', @@ -107,6 +106,9 @@ class SQL::Abstract::Compat { push @values, { -type => 'value', value => $fields->{$_} }; } + $ast->{where} = $self->recurse_where($where) + if defined $where; + return $ast; } @@ -177,14 +179,14 @@ class SQL::Abstract::Compat { }; } - method recurse_where(WhereType $ast, LogicEnum $logic?) returns (AST) { + method recurse_where(WhereType $ast, LogicEnum $logic?) { return $self->recurse_where_hash($logic || 'AND', $ast) if is_HashRef($ast); return $self->recurse_where_array($logic || 'OR', $ast) if is_ArrayRef($ast); croak "Unknown where clause type " . dump($ast); } # Deals with where({ .... }) case - method recurse_where_hash(LogicEnum $logic, HashRef $ast) returns (AST) { + method recurse_where_hash(LogicEnum $logic, HashRef $ast) { my @args; my $ret = { -type => 'expr', @@ -215,7 +217,7 @@ class SQL::Abstract::Compat { } # Deals with where([ .... ]) case - method recurse_where_array(LogicEnum $logic, ArrayRef $ast) returns (AST) { + method recurse_where_array(LogicEnum $logic, ArrayRef $ast) { my @args; my $ret = { -type => 'expr', @@ -248,7 +250,7 @@ class SQL::Abstract::Compat { } # { field => { .... } } case - method field_hash(Str $key, HashRef $value) returns (AST) { + method field_hash(Str $key, HashRef $value) { my ($op, @rest) = keys %$value; confess "Don't know how to handle " . dump($value) . " (too many keys)" @@ -313,7 +315,7 @@ class SQL::Abstract::Compat { }; } - method field(Str $key, $value) returns (AST) { + method field(Str $key, $value) { if (is_HashRef($value)) { return $self->field_hash($key, $value); @@ -334,7 +336,7 @@ class SQL::Abstract::Compat { return $ret; } - method value($value) returns (AST) { + method value($value) { return $self->apply_convert( { -type => 'value', value => $value }) if is_Str($value); diff --git a/lib/SQL/Abstract/Types.pm b/lib/SQL/Abstract/Types.pm index 51b834b..bafaa33 100644 --- a/lib/SQL/Abstract/Types.pm +++ b/lib/SQL/Abstract/Types.pm @@ -1,5 +1,5 @@ use MooseX::Declare; -class SQL::Abstract::Types { +class SQL::Abstract::Types is dirty { use Moose::Util::TypeConstraints; use MooseX::Types::Moose qw/ArrayRef Str Int Ref HashRef/; diff --git a/lib/SQL/Abstract/Types/Compat.pm b/lib/SQL/Abstract/Types/Compat.pm index fff3859..9b833da 100644 --- a/lib/SQL/Abstract/Types/Compat.pm +++ b/lib/SQL/Abstract/Types/Compat.pm @@ -1,6 +1,6 @@ use MooseX::Declare; -class SQL::Abstract::Types::Compat { +class SQL::Abstract::Types::Compat is dirty { use Moose::Util::TypeConstraints; use MooseX::Types::Moose qw/ArrayRef Str Int Ref HashRef ScalarRef/; diff --git a/t/compat/01generate.t b/t/compat/01generate.t index 5d4b418..0ff36b2 100644 --- a/t/compat/01generate.t +++ b/t/compat/01generate.t @@ -573,7 +573,7 @@ for (@tests) { } else { &$test; } - is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind}); + is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind}) or diag "On $_->{stmt}"; } } diff --git a/t/compat/ast/02update.t b/t/compat/ast/02update.t index 0b68b14..c82babf 100644 --- a/t/compat/ast/02update.t +++ b/t/compat/ast/02update.t @@ -6,25 +6,18 @@ use lib "$FindBin::Bin/../../lib"; use Test::SQL::Abstract::Util qw/ mk_name mk_value - mk_expr field_op_value :dumper_sort /; use SQL::Abstract::Compat; -use Test::More tests => 2; +use Test::More tests => 3; use Test::Differences; ok(my $visitor = SQL::Abstract::Compat->new); -my $foo_id = { -type => 'identifier', elements => [qw/foo/] }; -my $bar_id = { -type => 'identifier', elements => [qw/bar/] }; - -my $foo_eq_1 = field_op_value($foo_id, '==', 1); -my $bar_eq_str = field_op_value($bar_id, '==', 'some str'); - eq_or_diff $visitor->update_ast('test', { foo => 1 }), { -type => 'update', @@ -38,5 +31,21 @@ eq_or_diff }, "simple update"; +eq_or_diff + $visitor->update_ast('test', { foo => 1 }, { id => 2 }), + { -type => 'update', + tablespec => mk_name('test'), + columns => [ + mk_name('foo') + ], + values => [ + mk_value(1) + ], + where => field_op_value('id' => '==', 2) + }, + "simple update"; + + +