From: Ash Berlin Date: Sat, 4 Apr 2009 21:35:29 +0000 (+0100) Subject: Chage {-type => 'name', args => [] } to {-type => 'identifier', elements => [] } X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=627dcb628879019141978e2211c56044fbd205c6;p=dbsrgits%2FSQL-Abstract-2.0-ish.git Chage {-type => 'name', args => [] } to {-type => 'identifier', elements => [] } --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index d987fd7..0379c16 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -75,7 +75,7 @@ class SQL::Abstract { required => 1 ); - has name_separator => ( + has ident_separator => ( is => 'rw', isa => NameSeparator, default => '.', diff --git a/lib/SQL/Abstract/AST/v1.pm b/lib/SQL/Abstract/AST/v1.pm index e27584b..a87fc5c 100644 --- a/lib/SQL/Abstract/AST/v1.pm +++ b/lib/SQL/Abstract/AST/v1.pm @@ -25,7 +25,7 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract { or => $self->can('_recurse_where'), map { +"$_" => $self->can("_$_") } qw/ value - name + identifier true false expr @@ -116,10 +116,10 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract { return $output; } - method _name(AST $ast) { - my @names = @{$ast->{args}}; + method _identifier(AST $ast) { + my @names = @{$ast->{elements}}; - my $sep = $self->name_separator; + my $sep = $self->ident_separator; my $quote = $self->is_quoting ? $self->quote_chars : [ '' ]; diff --git a/lib/SQL/Abstract/Compat.pm b/lib/SQL/Abstract/Compat.pm index ea74a1a..edde9e7 100644 --- a/lib/SQL/Abstract/Compat.pm +++ b/lib/SQL/Abstract/Compat.pm @@ -67,7 +67,7 @@ class SQL::Abstract::Compat { ); $args{quote_chars} = $self->quote_char if $self->has_quote_chars; - $args{name_sep} = $self->name_sep + $args{ident_separator} = $self->name_sep if $self->has_name_sep; # TODO: this needs improving along with SQL::A::create @@ -131,7 +131,7 @@ class SQL::Abstract::Compat { @names = split /\Q@{[$self->name_sep]}\E/, $names[0] if (@names == 1 && $self->has_name_sep); - my $ast = { -type => 'name', args => [ @names ] }; + my $ast = { -type => 'identifier', elements => [ @names ] }; return $ast unless $use_convert && $self->has_field_convertor; diff --git a/t/001_basic.t b/t/001_basic.t index 6eea38a..95c6022 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -10,22 +10,22 @@ use_ok('SQL::Abstract::AST::v1') or BAIL_OUT( "$@" ); my $sqla = SQL::Abstract->create(1); # TODO: once MXMS supports %args, use that here -is $sqla->dispatch( { -type => 'name', args => [qw/me id/] }), "me.id", - "Simple name generator"; +is $sqla->dispatch( { -type => 'identifier', elements => [qw/me id/] }), "me.id", + "Simple identifier generator"; -is $sqla->dispatch( { -type => 'name', args => ['*'] } ), +is $sqla->dispatch( { -type => 'identifier', elements => ['*'] } ), "*", - "* name generator"; + "* identifier generator"; -is $sqla->dispatch( { -type => 'name', args => [qw/me */]}), +is $sqla->dispatch( { -type => 'identifier', elements => [qw/me */]}), "me.*", - "Simple name generator"; + "Simple identifier generator"; $sqla->quote_chars(['`']); -is $sqla->dispatch( { -type => 'name', args => [qw/me */]}), +is $sqla->dispatch( { -type => 'identifier', elements => [qw/me */]}), "`me`.*", - "Simple name generator"; + "Simple identifier generator"; $sqla->disable_quoting; @@ -40,16 +40,16 @@ is $sqla->dispatch( is $sqla->dispatch( { -type => 'list', args => [ - { -type => name => args => [qw/me id/] }, - { -type => name => args => [qw/me foo bar/] }, - { -type => name => args => [qw/bar/] } + { -type => identifier => elements => [qw/me id/] }, + { -type => identifier => elements => [qw/me foo bar/] }, + { -type => identifier => elements => [qw/bar/] } ] } ), "me.id, me.foo.bar, bar", "List generator"; is $sqla->dispatch( - { -type => 'alias', ident => { -type => name => args => [qw/me id/]}, as => "foobar" } + { -type => 'alias', ident => { -type => identifier => elements => [qw/me id/]}, as => "foobar" } ), "me.id AS foobar", "Alias generator"; diff --git a/t/003_quote.t b/t/003_quote.t index 6f26fb6..a7a6b58 100644 --- a/t/003_quote.t +++ b/t/003_quote.t @@ -13,16 +13,16 @@ lives_ok { } "coercion of quote_chars from Str works"; -is $sqla->dispatch( { -type => 'name', args => [qw/me id/] }), +is $sqla->dispatch( { -type => 'identifier', elements => [qw/me id/] }), "[me].[id]", "me.id"; -is $sqla->dispatch( { -type => 'name', args => [qw/me */] }), +is $sqla->dispatch( { -type => 'identifier', elements => [qw/me */] }), "[me].*", "me.*"; -is $sqla->dispatch( { -type => 'name', args => [qw/*/] }), +is $sqla->dispatch( { -type => 'identifier', elements => [qw/*/] }), "*", "*"; diff --git a/t/100_expr_basic.t b/t/100_expr_basic.t index 9e1b014..7159413 100644 --- a/t/100_expr_basic.t +++ b/t/100_expr_basic.t @@ -12,7 +12,7 @@ is $sqla->dispatch( { -type => 'expr', op => '>', args => [ - {-type => name => args => [qw/me id/] }, + {-type => identifier => elements => [qw/me id/] }, { -type => 'value', value => 500 } ] } @@ -23,7 +23,7 @@ is $sqla->dispatch( { -type => 'expr', op => '>', args => [ - {-type => 'name', args => [qw/me id/]}, + {-type => 'identifier', elements => [qw/me id/]}, {-type => 'value', value => 500 } ] } @@ -34,14 +34,14 @@ my $cols = [ { -type => 'expr', op => '>', args => [ - {-type => 'name', args => [qw/me id/]}, + {-type => 'identifier', elements => [qw/me id/]}, {-type => 'value', value => 500 } ] }, { -type => 'expr', op => '==', args => [ - {-type => 'name', args => [qw/me name/]}, + {-type => 'identifier', elements => [qw/me name/]}, {-type => 'value', value => '200' } ] }, @@ -73,7 +73,7 @@ is $sqla->dispatch( { -type => 'expr', op => 'or', args => [ { -type => 'expr', op => '==', - args => [ {-type => 'name', args => [qw/me name/] }, {-type => 'value', value => 500 } ] + args => [ {-type => 'identifier', elements => [qw/me name/] }, {-type => 'value', value => 500 } ] }, { -type => 'expr', op => 'or', args => $cols } ] @@ -85,7 +85,7 @@ is $sqla->dispatch( { -type => 'expr', op => 'or', args => [ { -type => 'expr', op => '==', - args => [ {-type => 'name', args => [qw/me name/] }, {-type => 'value', value => 500 } ] + args => [ {-type => 'identifier', elements => [qw/me name/] }, {-type => 'value', value => 500 } ] }, { -type => 'expr', op => 'and', args => $cols } ] @@ -96,7 +96,7 @@ is $sqla->dispatch( is $sqla->dispatch( { -type => 'expr', op => 'and', args => [ { -type => 'expr', op => '==', args => [ - {-type => 'name', args => [qw/me id/] }, {-type => 'value', value => 200 } + {-type => 'identifier', elements => [qw/me id/] }, {-type => 'value', value => 200 } ], }, { -type => 'expr', op => 'and', args => $cols } @@ -109,7 +109,7 @@ is $sqla->dispatch( is $sqla->dispatch( { -type => 'expr', op => 'and', args => [ { -type => 'expr', op => '==', args => [ - {-type => 'name', args => [qw/me id/] }, {-type => 'value', value => 200 } + {-type => 'identifier', elements => [qw/me id/] }, {-type => 'value', value => 200 } ], }, { -type => 'expr', op => 'or', args => $cols } @@ -125,7 +125,7 @@ is $sqla->dispatch( is $sqla->dispatch( { -type => 'expr', op => 'in', - args => [ { -type => 'name', args => ['foo'] } ], + args => [ { -type => 'identifier', elements => ['foo'] } ], } ), "0 = 1", "emtpy -in"; @@ -138,7 +138,7 @@ eq_or_diff( { -type => 'expr', op => 'in', args => [ - {-type => 'name', args => [qw/me id/] }, + {-type => 'identifier', elements => [qw/me id/] }, {-type => 'value', value => 100 }, {-type => 'value', value => 200 }, {-type => 'value', value => 300 }, @@ -163,7 +163,7 @@ eq_or_diff( { -type => 'expr', op => 'not_in', args => [ - {-type => 'name', args => [qw/me id/] }, + {-type => 'identifier', elements => [qw/me id/] }, {-type => 'value', value => 100 }, {-type => 'value', value => 200 }, {-type => 'value', value => 300 }, @@ -184,7 +184,7 @@ is $sqla->dispatch( { -type => 'expr', op => 'like', args => [ - {-type => name => args => [qw/me id/] }, + {-type => identifier => elements => [qw/me id/] }, { -type => 'value', value => 500 } ] } @@ -196,7 +196,7 @@ is $sqla->dispatch( { -type => 'expr', op => '==', args => [ - {-type => name => args => [qw/me id/] }, + {-type => identifier => elements => [qw/me id/] }, { -type => 'value', value => undef } ] } @@ -208,7 +208,7 @@ is $sqla->dispatch( { -type => 'expr', op => '!=', args => [ - {-type => name => args => [qw/me id/] }, + {-type => identifier => elements => [qw/me id/] }, { -type => 'value', value => undef } ] } diff --git a/t/101_expr_funcitons.t b/t/101_expr_funcitons.t index 148f3cd..4f4944a 100644 --- a/t/101_expr_funcitons.t +++ b/t/101_expr_funcitons.t @@ -16,7 +16,7 @@ is $sqla->dispatch( { -type => 'expr', op => 'ROUND', args => [ - {-type => name => args => [qw/me id/] }, + {-type => identifier => elements => [qw/me id/] }, ] }, { -type => 'expr', @@ -41,7 +41,7 @@ is $sqla->dispatch( { -type => 'expr', op => 'between', args => [ - {-type => name => args => [qw/me id/] }, + {-type => identifier => elements => [qw/me id/] }, { -type => 'value', value => 500 }, { -type => 'value', value => 599 }, ], diff --git a/t/200_join.t b/t/200_join.t index 9ba74b6..24db838 100644 --- a/t/200_join.t +++ b/t/200_join.t @@ -8,12 +8,12 @@ use_ok('SQL::Abstract') or BAIL_OUT( "$@" ); my $sqla = SQL::Abstract->create(1); -my $foo = {-type => name => args => [qw/foo/]}; -my $bar = {-type => name => args => [qw/bar/]}, -my $fnord = {-type => name => args => [qw/fnord/]}; +my $foo = {-type => identifier => elements => [qw/foo/]}; +my $bar = {-type => identifier => elements => [qw/bar/]}, +my $fnord = {-type => identifier => elements => [qw/fnord/]}; -my $foo_id = { -type => 'name', args => [qw/foo id/] }; -my $me_foo_id = { -type => 'name', args => [qw/me foo_id/] }; +my $foo_id = { -type => 'identifier', elements => [qw/foo id/] }; +my $me_foo_id = { -type => 'identifier', elements => [qw/me foo_id/] }; is $sqla->dispatch( { -type => 'join', @@ -29,7 +29,7 @@ is $sqla->dispatch( "simple join clause"; -$foo_id = { -type => 'name', args => [qw/foo_id/] }; +$foo_id = { -type => 'identifier', elements => [qw/foo_id/] }; is $sqla->dispatch( { -type => 'join', diff --git a/t/201_select.t b/t/201_select.t index b20dc46..6745c07 100644 --- a/t/201_select.t +++ b/t/201_select.t @@ -10,16 +10,16 @@ my $sqla = SQL::Abstract->create(1); my $foo_as_me = { -type => 'alias', - ident => {-type => 'name', args => [qw/foo/]}, + ident => {-type => 'identifier', elements => [qw/foo/]}, as => 'me' }; -my $me_foo_id = { -type => 'name', args => [qw/me foo_id/] }; +my $me_foo_id = { -type => 'identifier', elements => [qw/me foo_id/] }; is $sqla->dispatch( { -type => 'select', tablespec => $foo_as_me, columns => [ - { -type => 'name', args => [qw/me id/] }, + { -type => 'identifier', elements => [qw/me id/] }, { -type => 'alias', ident => $me_foo_id, as => 'foo' }, ] } @@ -29,20 +29,20 @@ is $sqla->dispatch( is $sqla->dispatch( { -type => 'select', columns => [ - { -type => 'name', args => [qw/me id/] }, + { -type => 'identifier', elements => [qw/me id/] }, { -type => 'alias', ident => $me_foo_id, as => 'foo' }, - { -type => 'name', args => [qw/bar name/] }, + { -type => 'identifier', elements => [qw/bar name/] }, ], tablespec => { -type => 'join', lhs => $foo_as_me, - rhs => {-type => 'name', args => [qw/bar/] }, + rhs => {-type => 'identifier', elements => [qw/bar/] }, on => { -type => 'expr', op => '==', args => [ - {-type => 'name', args => [qw/bar id/]}, - {-type => 'name', args => [qw/me bar_id/]} + {-type => 'identifier', elements => [qw/bar id/]}, + {-type => 'identifier', elements => [qw/me bar_id/]} ], } }, @@ -56,14 +56,14 @@ is $sqla->dispatch( is $sqla->dispatch( { -type => 'select', columns => [ - { -type => 'name', args => [qw/me */] }, + { -type => 'identifier', elements => [qw/me */] }, ], tablespec => $foo_as_me, where => { -type => 'expr', op => '==', args => [ - {-type => 'name', args => [qw/me id/]}, + {-type => 'identifier', elements => [qw/me id/]}, {-type => 'value', value => 1 }, ] } @@ -78,11 +78,11 @@ is $sqla->dispatch( { -type => 'select', tablespec => $foo_as_me, columns => [ - { -type => 'name', args => [qw/me id/] }, + { -type => 'identifier', elements => [qw/me id/] }, { -type => 'alias', ident => $me_foo_id, as => 'foo' }, ], order_by => [ - { -type => 'ordering', expr => { -type => 'name', args => [qw/me name/] }, direction => 'desc' }, + { -type => 'ordering', expr => { -type => 'identifier', elements => [qw/me name/] }, direction => 'desc' }, $me_foo_id, ] } diff --git a/t/300_ordering.t b/t/300_ordering.t index cf5456a..1ec198f 100644 --- a/t/300_ordering.t +++ b/t/300_ordering.t @@ -10,13 +10,13 @@ my $sqla = SQL::Abstract->create(1); is $sqla->dispatch( - { -type => 'ordering', expr => { -type => name => args => [qw/me date/ ] } } + { -type => 'ordering', expr => { -type => identifier => elements => [qw/me date/ ] } } ), "me.date", "basic ordering"; is $sqla->dispatch( { -type => 'ordering', - expr => { -type => name => args => [qw/me date/] }, + expr => { -type => identifier => elements => [qw/me date/] }, direction => 'DESC' } ), "me.date DESC", @@ -25,7 +25,7 @@ is $sqla->dispatch( is $sqla->dispatch( { -type => 'ordering', - expr => { -type => name => args => [qw/me date/] }, + expr => { -type => identifier => elements => [qw/me date/] }, direction => 'asc' } ), "me.date ASC", diff --git a/t/900_errors.t b/t/900_errors.t index f5a6fef..f885a89 100644 --- a/t/900_errors.t +++ b/t/900_errors.t @@ -12,8 +12,8 @@ throws_ok { $sqla->dispatch( { -type => 'expr', op => '==', args => [ - { -type => 'name', args => [qw/me id/] }, - { -type => 'alias', ident => { -type => 'name', args => [qw/me id/] }, as => 'bar' } + { -type => 'identifier', elements => [qw/me id/] }, + { -type => 'alias', ident => { -type => 'identifier', elements => [qw/me id/] }, as => 'bar' } ] } ) @@ -35,7 +35,7 @@ throws_ok { throws_ok { $sqla->dispatch( - { -type => 'alias', iden => { -type => 'name', args => ['id'] }, as => 'foo' } # iden not ident + { -type => 'alias', iden => { -type => 'identifier', elements => ['id'] }, as => 'foo' } # iden not ident ) } qr/foobar/, "alias: iden instead of ident"; diff --git a/t/compat/ast/01.t b/t/compat/ast/01.t index 0fb36ee..e42e20e 100644 --- a/t/compat/ast/01.t +++ b/t/compat/ast/01.t @@ -13,8 +13,8 @@ use Test::Differences; ok(my $visitor = SQL::Abstract::Compat->new); -my $foo_id = { -type => 'name', args => [qw/foo/] }; -my $bar_id = { -type => 'name', args => [qw/bar/] }; +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'); @@ -133,7 +133,7 @@ my $worker_eq = sub { -type => 'expr', op => '==', args => [ - { -type => 'name', args => ['worker'] }, + { -type => 'identifier', elements => ['worker'] }, { -type => 'value', value => $_[0] }, ], } @@ -180,8 +180,8 @@ eq_or_diff 'test', '*', [ { ticket => [11, 12, 13] } ] ), { -type => 'select', - columns => [ { -type => 'name', args => ['*'] } ], - tablespec => { -type => 'name', args => ['test'] }, + columns => [ { -type => 'identifier', elements => ['*'] } ], + tablespec => { -type => 'identifier', elements => ['test'] }, where => $ticket_or_eq }, "Complex AST with convert('UPPER')"; @@ -207,8 +207,8 @@ eq_or_diff ] ), { -type => 'select', - columns => [ { -type => 'name', args => ['*'] } ], - tablespec => { -type => 'name', args => ['test'] }, + columns => [ { -type => 'identifier', elements => ['*'] } ], + tablespec => { -type => 'identifier', elements => ['test'] }, where => $hostname_and_ticket }, "Complex AST mixing arrays+hashes with convert('UPPER')"; @@ -232,8 +232,8 @@ eq_or_diff ] ), { -type => 'select', - columns => [ { -type => 'name', args => ['*'] } ], - tablespec => { -type => 'name', args => ['test'] }, + columns => [ { -type => 'identifier', elements => ['*'] } ], + tablespec => { -type => 'identifier', elements => ['test'] }, where => { -type => 'expr', op => 'or', @@ -273,8 +273,8 @@ eq_or_diff ] ), { -type => 'select', - columns => [ { -type => 'name', args => ['*'] } ], - tablespec => { -type => 'name', args => ['test'] }, + columns => [ { -type => 'identifier', elements => ['*'] } ], + tablespec => { -type => 'identifier', elements => ['test'] }, where => { -type => 'expr', op => 'or', @@ -300,8 +300,8 @@ eq_or_diff ] ), { -type => 'select', - columns => [ { -type => 'name', args => ['*'] } ], - tablespec => { -type => 'name', args => ['test'] }, + columns => [ { -type => 'identifier', elements => ['*'] } ], + tablespec => { -type => 'identifier', elements => ['test'] }, where => { -type => 'expr', op => 'or', @@ -330,8 +330,8 @@ sub field_op_value { $field = ref $field eq 'HASH' ? $field : ref $field eq 'ARRAY' - ? { -type => 'name', args => $field } - : { -type => 'name', args => [$field] }; + ? { -type => 'identifier', elements => $field } + : { -type => 'identifier', elements => [$field] }; my @value = ref $value eq 'HASH' ? $value @@ -366,8 +366,8 @@ sub mk_name { $field = ref $field eq 'HASH' ? $field : ref $field eq 'ARRAY' - ? { -type => 'name', args => $field } - : { -type => 'name', args => [$field] }; + ? { -type => 'identifier', elements => $field } + : { -type => 'identifier', elements => [$field] }; return $field; }