... | ... |
@@ -15,6 +15,7 @@ use DBIx::Custom::Query; |
15 | 15 |
use DBIx::Custom::QueryBuilder; |
16 | 16 |
use DBIx::Custom::Where; |
17 | 17 |
use DBIx::Custom::Table; |
18 |
+use DBIx::Custom::Tag; |
|
18 | 19 |
use Encode qw/encode_utf8 decode_utf8/; |
19 | 20 |
|
20 | 21 |
__PACKAGE__->attr( |
... | ... |
@@ -156,7 +157,7 @@ sub method { |
156 | 157 |
} |
157 | 158 |
|
158 | 159 |
sub connect { |
159 |
- my $self = ref $_[0] ? shift : shift->SUPER::new(@_);; |
|
160 |
+ my $self = ref $_[0] ? shift : shift->new(@_);; |
|
160 | 161 |
|
161 | 162 |
# Attributes |
162 | 163 |
my $data_source = $self->data_source; |
... | ... |
@@ -451,6 +452,20 @@ sub new { |
451 | 452 |
croak qq{"$attr" is invalid attribute name} |
452 | 453 |
unless $self->can($attr); |
453 | 454 |
} |
455 |
+ |
|
456 |
+ $self->register_tag( |
|
457 |
+ '?' => \&DBIx::Custom::Tag::placeholder, |
|
458 |
+ '=' => \&DBIx::Custom::Tag::equal, |
|
459 |
+ '<>' => \&DBIx::Custom::Tag::not_equal, |
|
460 |
+ '>' => \&DBIx::Custom::Tag::greater_than, |
|
461 |
+ '<' => \&DBIx::Custom::Tag::lower_than, |
|
462 |
+ '>=' => \&DBIx::Custom::Tag::greater_than_equal, |
|
463 |
+ '<=' => \&DBIx::Custom::Tag::lower_than_equal, |
|
464 |
+ 'like' => \&DBIx::Custom::Tag::like, |
|
465 |
+ 'in' => \&DBIx::Custom::Tag::in, |
|
466 |
+ 'insert_param' => \&DBIx::Custom::Tag::insert_param, |
|
467 |
+ 'update_param' => \&DBIx::Custom::Tag::update_param |
|
468 |
+ ); |
|
454 | 469 |
|
455 | 470 |
return $self; |
456 | 471 |
} |
... | ... |
@@ -676,8 +691,9 @@ sub update { |
676 | 691 |
|
677 | 692 |
sub update_all { shift->update(allow_update_all => 1, @_) }; |
678 | 693 |
|
679 |
-sub where { DBIx::Custom::Where->new( |
|
680 |
- query_builder => shift->query_builder) } |
|
694 |
+sub where { |
|
695 |
+ return DBIx::Custom::Where->new(query_builder => shift->query_builder) |
|
696 |
+} |
|
681 | 697 |
|
682 | 698 |
sub _build_binds { |
683 | 699 |
my ($self, $params, $columns, $filter) = @_; |
... | ... |
@@ -725,12 +741,13 @@ sub _croak { |
725 | 741 |
} |
726 | 742 |
} |
727 | 743 |
|
728 |
-# Following methos are DEPRECATED! |
|
744 |
+# DEPRECATED! |
|
729 | 745 |
__PACKAGE__->attr( |
730 | 746 |
dbi_options => sub { {} }, |
731 | 747 |
filter_check => 1 |
732 | 748 |
); |
733 | 749 |
|
750 |
+# DEPRECATED! |
|
734 | 751 |
sub default_bind_filter { |
735 | 752 |
my $self = shift; |
736 | 753 |
|
... | ... |
@@ -752,6 +769,7 @@ sub default_bind_filter { |
752 | 769 |
return $self->{default_out_filter}; |
753 | 770 |
} |
754 | 771 |
|
772 |
+# DEPRECATED! |
|
755 | 773 |
sub default_fetch_filter { |
756 | 774 |
my $self = shift; |
757 | 775 |
|
... | ... |
@@ -774,6 +792,7 @@ sub default_fetch_filter { |
774 | 792 |
return $self->{default_in_filter}; |
775 | 793 |
} |
776 | 794 |
|
795 |
+# DEPRECATED! |
|
777 | 796 |
sub register_tag_processor { |
778 | 797 |
return shift->query_builder->register_tag_processor(@_); |
779 | 798 |
} |
... | ... |
@@ -924,14 +943,6 @@ Default filter when row is fetched. |
924 | 943 |
my $filters = $dbi->filters; |
925 | 944 |
$dbi = $dbi->filters(\%filters); |
926 | 945 |
|
927 |
-=head2 C<filter_check> |
|
928 |
- |
|
929 |
- my $filter_check = $dbi->filter_check; |
|
930 |
- $dbi = $dbi->filter_check(0); |
|
931 |
- |
|
932 |
-B<this attribute is now deprecated and has no mean |
|
933 |
-because check is always done>. |
|
934 |
- |
|
935 | 946 |
=head2 C<password> |
936 | 947 |
|
937 | 948 |
my $password = $dbi->password; |
... | ... |
@@ -970,7 +981,7 @@ C<connect()> method use this value to connect the database. |
970 | 981 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
971 | 982 |
and implements the following new ones. |
972 | 983 |
|
973 |
-=head2 C<(experimental) apply_filter > |
|
984 |
+=head2 C<(experimental) apply_filter> |
|
974 | 985 |
|
975 | 986 |
$dbi->apply_filter( |
976 | 987 |
$table, |
... | ... |
@@ -1056,8 +1067,6 @@ is expanded to |
1056 | 1067 |
|
1057 | 1068 |
This is used in C<select()> |
1058 | 1069 |
|
1059 |
- |
|
1060 |
- |
|
1061 | 1070 |
=head2 C<delete> |
1062 | 1071 |
|
1063 | 1072 |
$dbi->delete(table => $table, |
... | ... |
@@ -1187,7 +1196,7 @@ C<default_filter> and C<filter> of C<DBIx::Custom::Result> |
1187 | 1196 |
} |
1188 | 1197 |
); |
1189 | 1198 |
|
1190 |
-Register tag processor. |
|
1199 |
+Register tag. |
|
1191 | 1200 |
|
1192 | 1201 |
=head2 C<rollback> |
1193 | 1202 |
|
... | ... |
@@ -1282,16 +1291,87 @@ Return value of C<update_all()> is the count of affected rows. |
1282 | 1291 |
|
1283 | 1292 |
Create a new L<DBIx::Custom::Where> object. |
1284 | 1293 |
|
1285 |
-=head2 C<(deprecated) cache_method> |
|
1294 |
+=head2 C<cache_method> |
|
1286 | 1295 |
|
1287 | 1296 |
$dbi = $dbi->cache_method(\&cache_method); |
1288 | 1297 |
$cache_method = $dbi->cache_method |
1289 | 1298 |
|
1290 | 1299 |
Method to set and get caches. |
1291 | 1300 |
|
1301 |
+=head1 Tags |
|
1302 |
+ |
|
1303 |
+The following tags is available. |
|
1304 |
+ |
|
1305 |
+=head2 C<?> |
|
1306 |
+ |
|
1307 |
+Placeholder tag. |
|
1308 |
+ |
|
1309 |
+ {? NAME} -> ? |
|
1310 |
+ |
|
1311 |
+=head2 C<=> |
|
1312 |
+ |
|
1313 |
+Equal tag. |
|
1314 |
+ |
|
1315 |
+ {= NAME} -> NAME = ? |
|
1316 |
+ |
|
1317 |
+=head2 C<E<lt>E<gt>> |
|
1318 |
+ |
|
1319 |
+Not equal tag. |
|
1320 |
+ |
|
1321 |
+ {<> NAME} -> NAME <> ? |
|
1322 |
+ |
|
1323 |
+=head2 C<E<lt>> |
|
1324 |
+ |
|
1325 |
+Lower than tag |
|
1326 |
+ |
|
1327 |
+ {< NAME} -> NAME < ? |
|
1328 |
+ |
|
1329 |
+=head2 C<E<gt>> |
|
1330 |
+ |
|
1331 |
+Greater than tag |
|
1332 |
+ |
|
1333 |
+ {> NAME} -> NAME > ? |
|
1334 |
+ |
|
1335 |
+=head2 C<E<gt>=> |
|
1336 |
+ |
|
1337 |
+Greater than or equal tag |
|
1338 |
+ |
|
1339 |
+ {>= NAME} -> NAME >= ? |
|
1340 |
+ |
|
1341 |
+=head2 C<E<lt>=> |
|
1342 |
+ |
|
1343 |
+Lower than or equal tag |
|
1344 |
+ |
|
1345 |
+ {<= NAME} -> NAME <= ? |
|
1346 |
+ |
|
1347 |
+=head2 C<like> |
|
1348 |
+ |
|
1349 |
+Like tag |
|
1350 |
+ |
|
1351 |
+ {like NAME} -> NAME like ? |
|
1352 |
+ |
|
1353 |
+=head2 C<in> |
|
1354 |
+ |
|
1355 |
+In tag. |
|
1356 |
+ |
|
1357 |
+ {in NAME COUNT} -> NAME in [?, ?, ..] |
|
1358 |
+ |
|
1359 |
+=head2 C<insert_param> |
|
1360 |
+ |
|
1361 |
+Insert parameter tag. |
|
1362 |
+ |
|
1363 |
+ {insert_param NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
|
1364 |
+ |
|
1365 |
+=head2 C<update_param> |
|
1366 |
+ |
|
1367 |
+Updata parameter tag. |
|
1368 |
+ |
|
1369 |
+ {update_param NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
|
1370 |
+ |
|
1292 | 1371 |
=head1 STABILITY |
1293 | 1372 |
|
1294 |
-L<DBIx::Custom> is now stable. APIs keep backword compatible in the feature. |
|
1373 |
+L<DBIx::Custom> is stable. APIs keep backword compatible |
|
1374 |
+except experimental one in the feature. |
|
1295 | 1375 |
|
1296 | 1376 |
=head1 BUGS |
1297 | 1377 |
|
... | ... |
@@ -1307,7 +1387,7 @@ Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
1307 | 1387 |
|
1308 | 1388 |
=head1 COPYRIGHT & LICENSE |
1309 | 1389 |
|
1310 |
-Copyright 2009 Yuki Kimoto, all rights reserved. |
|
1390 |
+Copyright 2009-2011 Yuki Kimoto, all rights reserved. |
|
1311 | 1391 |
|
1312 | 1392 |
This program is free software; you can redistribute it and/or modify it |
1313 | 1393 |
under the same terms as Perl itself. |
... | ... |
@@ -7,28 +7,13 @@ use base 'Object::Simple'; |
7 | 7 |
|
8 | 8 |
use Carp 'croak'; |
9 | 9 |
use DBIx::Custom::Query; |
10 |
-use DBIx::Custom::Tag; |
|
11 | 10 |
|
12 | 11 |
# Carp trust relationship |
13 | 12 |
push @DBIx::Custom::CARP_NOT, __PACKAGE__; |
14 | 13 |
push @DBIx::Custom::Where::CARP_NOT, __PACKAGE__; |
15 | 14 |
|
16 | 15 |
# Attributes |
17 |
-__PACKAGE__->attr('tags' => sub { |
|
18 |
- { |
|
19 |
- '?' => \&DBIx::Custom::Tag::placeholder, |
|
20 |
- '=' => \&DBIx::Custom::Tag::equal, |
|
21 |
- '<>' => \&DBIx::Custom::Tag::not_equal, |
|
22 |
- '>' => \&DBIx::Custom::Tag::greater_than, |
|
23 |
- '<' => \&DBIx::Custom::Tag::lower_than, |
|
24 |
- '>=' => \&DBIx::Custom::Tag::greater_than_equal, |
|
25 |
- '<=' => \&DBIx::Custom::Tag::lower_than_equal, |
|
26 |
- 'like' => \&DBIx::Custom::Tag::like, |
|
27 |
- 'in' => \&DBIx::Custom::Tag::in, |
|
28 |
- 'insert_param' => \&DBIx::Custom::Tag::insert_param, |
|
29 |
- 'update_param' => \&DBIx::Custom::Tag::update_param |
|
30 |
- } |
|
31 |
-}); |
|
16 |
+__PACKAGE__->attr('tags' => sub { {} }); |
|
32 | 17 |
|
33 | 18 |
sub build_query { |
34 | 19 |
my ($self, $source) = @_; |
... | ... |
@@ -45,7 +30,7 @@ sub build_query { |
45 | 30 |
sub register_tag { |
46 | 31 |
my $self = shift; |
47 | 32 |
|
48 |
- # Merge tag processor |
|
33 |
+ # Merge tag |
|
49 | 34 |
my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
50 | 35 |
$self->tags({%{$self->tags}, %$tags}); |
51 | 36 |
|
... | ... |
@@ -76,23 +61,23 @@ sub _build_query { |
76 | 61 |
# Tag arguments |
77 | 62 |
my $tag_args = $node->{tag_args}; |
78 | 63 |
|
79 |
- # Get tag processor |
|
80 |
- my $tag_processor = $self->tag_processors->{$tag_name} |
|
64 |
+ # Get tag |
|
65 |
+ my $tag = $self->tag_processors->{$tag_name} |
|
81 | 66 |
|| $self->tags->{$tag_name}; |
82 | 67 |
|
83 |
- # Tag processor is not registered |
|
68 |
+ # Tag is not registered |
|
84 | 69 |
croak qq{Tag "$tag_name" in "{a }" is not registered} |
85 |
- unless $tag_processor; |
|
70 |
+ unless $tag; |
|
86 | 71 |
|
87 |
- # Tag processor not sub reference |
|
88 |
- croak qq{Tag processor "$tag_name" must be sub reference} |
|
89 |
- unless ref $tag_processor eq 'CODE'; |
|
72 |
+ # Tag not sub reference |
|
73 |
+ croak qq{Tag "$tag_name" must be sub reference} |
|
74 |
+ unless ref $tag eq 'CODE'; |
|
90 | 75 |
|
91 |
- # Execute tag processor |
|
92 |
- my $r = $tag_processor->(@$tag_args); |
|
76 |
+ # Execute tag |
|
77 |
+ my $r = $tag->(@$tag_args); |
|
93 | 78 |
|
94 |
- # Check tag processor return value |
|
95 |
- croak qq{Tag processor "$tag_name" must return [STRING, ARRAY_REFERENCE]} |
|
79 |
+ # Check tag return value |
|
80 |
+ croak qq{Tag "$tag_name" must return [STRING, ARRAY_REFERENCE]} |
|
96 | 81 |
unless ref $r eq 'ARRAY' && defined $r->[0] && ref $r->[1] eq 'ARRAY'; |
97 | 82 |
|
98 | 83 |
# Part of SQL statement and colum names |
... | ... |
@@ -275,13 +260,14 @@ sub _placeholder_count { |
275 | 260 |
return $count; |
276 | 261 |
} |
277 | 262 |
|
278 |
-# Follwoing methods are DEPRECATED! |
|
263 |
+# DEPRECATED! |
|
279 | 264 |
__PACKAGE__->attr('tag_processors' => sub { {} }); |
280 | 265 |
|
266 |
+# DEPRECATED! |
|
281 | 267 |
sub register_tag_processor { |
282 | 268 |
my $self = shift; |
283 | 269 |
|
284 |
- # Merge tag processor |
|
270 |
+ # Merge tag |
|
285 | 271 |
my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
286 | 272 |
$self->tag_processors({%{$self->tag_processors}, %{$tag_processors}}); |
287 | 273 |
|
... | ... |
@@ -306,9 +292,9 @@ DBIx::Custom::QueryBuilder - Query builder |
306 | 292 |
=head2 C<tags> |
307 | 293 |
|
308 | 294 |
my $tags = $builder->tags; |
309 |
- $builder = $builder->tags(\%tags); |
|
295 |
+ $builder = $builder->tags(\%tags); |
|
310 | 296 |
|
311 |
-Tag processors. |
|
297 |
+Tags. |
|
312 | 298 |
|
313 | 299 |
=head1 METHODS |
314 | 300 |
|
... | ... |
@@ -346,11 +332,11 @@ Query |
346 | 332 |
$builder->register_tag(\%tags); |
347 | 333 |
$builder->register_tag(%tags); |
348 | 334 |
|
349 |
-Register tag processor. |
|
335 |
+Register tag. |
|
350 | 336 |
|
351 | 337 |
B<Example:> |
352 | 338 |
|
353 |
- $builder->register_tag_processor( |
|
339 |
+ $builder->register_tag( |
|
354 | 340 |
'?' => sub { |
355 | 341 |
my $column = shift; |
356 | 342 |
|
... | ... |
@@ -358,74 +344,5 @@ B<Example:> |
358 | 344 |
} |
359 | 345 |
); |
360 | 346 |
|
361 |
-See also L<DBIx::Custom::QueryBuilder::TagProcessors> to know tag processor. |
|
362 |
- |
|
363 |
-=head1 Tags |
|
364 |
- |
|
365 |
-The following tags is available. |
|
366 |
- |
|
367 |
-=head2 C<?> |
|
368 |
- |
|
369 |
-Placeholder tag. |
|
370 |
- |
|
371 |
- {? NAME} -> ? |
|
372 |
- |
|
373 |
-=head2 C<=> |
|
374 |
- |
|
375 |
-Equal tag. |
|
376 |
- |
|
377 |
- {= NAME} -> NAME = ? |
|
378 |
- |
|
379 |
-=head2 C<E<lt>E<gt>> |
|
380 |
- |
|
381 |
-Not equal tag. |
|
382 |
- |
|
383 |
- {<> NAME} -> NAME <> ? |
|
384 |
- |
|
385 |
-=head2 C<E<lt>> |
|
386 |
- |
|
387 |
-Lower than tag |
|
388 |
- |
|
389 |
- {< NAME} -> NAME < ? |
|
390 |
- |
|
391 |
-=head2 C<E<gt>> |
|
392 |
- |
|
393 |
-Greater than tag |
|
394 |
- |
|
395 |
- {> NAME} -> NAME > ? |
|
396 |
- |
|
397 |
-=head2 C<E<gt>=> |
|
398 |
- |
|
399 |
-Greater than or equal tag |
|
400 |
- |
|
401 |
- {>= NAME} -> NAME >= ? |
|
402 |
- |
|
403 |
-=head2 C<E<lt>=> |
|
404 |
- |
|
405 |
-Lower than or equal tag |
|
406 |
- |
|
407 |
- {<= NAME} -> NAME <= ? |
|
408 |
- |
|
409 |
-=head2 C<like> |
|
410 |
- |
|
411 |
-Like tag |
|
412 |
- |
|
413 |
- {like NAME} -> NAME like ? |
|
414 |
- |
|
415 |
-=head2 C<in> |
|
416 |
- |
|
417 |
-In tag. |
|
418 |
- |
|
419 |
- {in NAME COUNT} -> NAME in [?, ?, ..] |
|
420 |
- |
|
421 |
-=head2 C<insert_param> |
|
422 |
- |
|
423 |
-Insert parameter tag. |
|
424 |
- |
|
425 |
- {insert_param NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
|
426 |
- |
|
427 |
-=head2 C<update_param> |
|
428 |
- |
|
429 |
-Updata parameter tag. |
|
347 |
+See also L<DBIx::Custom::Tag> to know tag. |
|
430 | 348 |
|
431 |
- {update_param NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
... | ... |
@@ -14,8 +14,8 @@ use Carp 'croak'; |
14 | 14 |
push @DBIx::Custom::CARP_NOT, __PACKAGE__; |
15 | 15 |
|
16 | 16 |
__PACKAGE__->attr( |
17 |
- [qw/param query_builder/], |
|
18 |
- clause => sub { [] }, |
|
17 |
+ [qw/param query_builder/], |
|
18 |
+ clause => sub { [] }, |
|
19 | 19 |
); |
20 | 20 |
|
21 | 21 |
sub to_string { |
... | ... |
@@ -37,7 +37,6 @@ sub to_string { |
37 | 37 |
} |
38 | 38 |
|
39 | 39 |
our %VALID_OPERATIONS = map { $_ => 1 } qw/and or/; |
40 |
- |
|
41 | 40 |
sub _parse { |
42 | 41 |
my ($self, $clause, $where, $count, $op) = @_; |
43 | 42 |
|
... | ... |
@@ -764,7 +764,7 @@ test 'connect super'; |
764 | 764 |
} |
765 | 765 |
|
766 | 766 |
sub new { |
767 |
- my $self = shift->SUPER::connect(@_); |
|
767 |
+ my $self = shift->SUPER::new(@_); |
|
768 | 768 |
|
769 | 769 |
return $self; |
770 | 770 |
} |
... | ... |
@@ -776,10 +776,27 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
776 | 776 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
777 | 777 |
|
778 | 778 |
$dbi = MyDBI->new($NEW_ARGS->{0}); |
779 |
+$dbi->connect; |
|
779 | 780 |
$dbi->execute($CREATE_TABLE->{0}); |
780 | 781 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
781 | 782 |
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
782 | 783 |
|
784 |
+{ |
|
785 |
+ package MyDBI2; |
|
786 |
+ |
|
787 |
+ use base 'DBIx::Custom'; |
|
788 |
+ sub connect { |
|
789 |
+ my $self = shift->SUPER::new(@_); |
|
790 |
+ $self->connect; |
|
791 |
+ |
|
792 |
+ return $self; |
|
793 |
+ } |
|
794 |
+} |
|
795 |
+ |
|
796 |
+$dbi = MyDBI->connect($NEW_ARGS->{0}); |
|
797 |
+$dbi->execute($CREATE_TABLE->{0}); |
|
798 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
799 |
+is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1); |
|
783 | 800 |
|
784 | 801 |
test 'end_filter'; |
785 | 802 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
... | ... |
@@ -3,7 +3,7 @@ use warnings; |
3 | 3 |
|
4 | 4 |
use Test::More 'no_plan'; |
5 | 5 |
|
6 |
-use DBIx::Custom::QueryBuilder; |
|
6 |
+use DBIx::Custom; |
|
7 | 7 |
|
8 | 8 |
# Function for test name |
9 | 9 |
sub test{ print "# $_[0]\n" } |
... | ... |
@@ -54,17 +54,17 @@ $datas = [ |
54 | 54 |
|
55 | 55 |
for (my $i = 0; $i < @$datas; $i++) { |
56 | 56 |
my $data = $datas->[$i]; |
57 |
- my $builder = DBIx::Custom::QueryBuilder->new; |
|
57 |
+ my $builder = DBIx::Custom->new->query_builder; |
|
58 | 58 |
my $query = $builder->build_query($data->{source}); |
59 | 59 |
is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql"); |
60 | 60 |
is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns"); |
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
|
64 |
-test 'Original tag processor'; |
|
65 |
-$builder = DBIx::Custom::QueryBuilder->new; |
|
64 |
+test 'Original tag'; |
|
65 |
+$builder = DBIx::Custom->new->query_builder; |
|
66 | 66 |
|
67 |
-$ret_val = $builder->register_tag_processor( |
|
67 |
+$ret_val = $builder->register_tag( |
|
68 | 68 |
p => sub { |
69 | 69 |
my @args = @_; |
70 | 70 |
|
... | ... |
@@ -75,49 +75,49 @@ $ret_val = $builder->register_tag_processor( |
75 | 75 |
); |
76 | 76 |
|
77 | 77 |
$query = $builder->build_query("{p a b}"); |
78 |
-is($query->{sql}, "? a b;", "register_tag_processor sql"); |
|
79 |
-is_deeply($query->{columns}, [2], "register_tag_processor columns"); |
|
78 |
+is($query->{sql}, "? a b;", "register_tag sql"); |
|
79 |
+is_deeply($query->{columns}, [2], "register_tag columns"); |
|
80 | 80 |
isa_ok($ret_val, 'DBIx::Custom::QueryBuilder'); |
81 | 81 |
|
82 | 82 |
|
83 |
-test "Tag processor error case"; |
|
84 |
-$builder = DBIx::Custom::QueryBuilder->new; |
|
83 |
+test "Tag error case"; |
|
84 |
+$builder = DBIx::Custom->new->query_builder; |
|
85 | 85 |
|
86 | 86 |
eval{$builder->build_query('{? }')}; |
87 | 87 |
like($@, qr/\QColumn name must be specified in tag "{? }"/, "? not arguments"); |
88 | 88 |
|
89 | 89 |
eval{$builder->build_query("{a }")}; |
90 |
-like($@, qr/\QTag "a" in "{a }" is not registered/, "tag_processor not exist"); |
|
90 |
+like($@, qr/\QTag "a" in "{a }" is not registered/, "tag not exist"); |
|
91 | 91 |
|
92 |
-$builder->register_tag_processor({ |
|
92 |
+$builder->register_tag({ |
|
93 | 93 |
q => 'string' |
94 | 94 |
}); |
95 | 95 |
|
96 | 96 |
eval{$builder->build_query("{q}", {})}; |
97 |
-like($@, qr/Tag processor "q" must be sub reference/, "tag_processor not code ref"); |
|
97 |
+like($@, qr/Tag "q" must be sub reference/, "tag not code ref"); |
|
98 | 98 |
|
99 |
-$builder->register_tag_processor({ |
|
99 |
+$builder->register_tag({ |
|
100 | 100 |
r => sub {} |
101 | 101 |
}); |
102 | 102 |
|
103 | 103 |
eval{$builder->build_query("{r}")}; |
104 |
-like($@, qr/\QTag processor "r" must return [STRING, ARRAY_REFERENCE]/, "tag processor return noting"); |
|
104 |
+like($@, qr/\QTag "r" must return [STRING, ARRAY_REFERENCE]/, "tag return noting"); |
|
105 | 105 |
|
106 |
-$builder->register_tag_processor({ |
|
106 |
+$builder->register_tag({ |
|
107 | 107 |
s => sub { return ["a", ""]} |
108 | 108 |
}); |
109 | 109 |
|
110 | 110 |
eval{$builder->build_query("{s}")}; |
111 |
-like($@, qr/\QTag processor "s" must return [STRING, ARRAY_REFERENCE]/, "tag processor return not array columns"); |
|
111 |
+like($@, qr/\QTag "s" must return [STRING, ARRAY_REFERENCE]/, "tag return not array columns"); |
|
112 | 112 |
|
113 |
-$builder->register_tag_processor( |
|
113 |
+$builder->register_tag( |
|
114 | 114 |
t => sub {return ["a", []]} |
115 | 115 |
); |
116 | 116 |
|
117 | 117 |
|
118 | 118 |
test 'General error case'; |
119 |
-$builder = DBIx::Custom::QueryBuilder->new; |
|
120 |
-$builder->register_tag_processor( |
|
119 |
+$builder = DBIx::Custom->new->query_builder; |
|
120 |
+$builder->register_tag( |
|
121 | 121 |
a => sub { |
122 | 122 |
return ["? ? ?", ['']]; |
123 | 123 |
} |
... | ... |
@@ -126,7 +126,7 @@ eval{$builder->build_query("{a}")}; |
126 | 126 |
like($@, qr/\QPlaceholder count in "? ? ?" must be same as column count 1/, "placeholder count is invalid"); |
127 | 127 |
|
128 | 128 |
|
129 |
-test 'Default tag processor Error case'; |
|
129 |
+test 'Default tag Error case'; |
|
130 | 130 |
eval{$builder->build_query("{= }")}; |
131 | 131 |
like($@, qr/Column name must be specified in tag "{= }"/, "basic '=' : key not exist"); |
132 | 132 |
|