| ... | ... |
@@ -234,8 +234,11 @@ sub _build_bind_values {
|
| 234 | 234 |
my $count = {};
|
| 235 | 235 |
foreach my $column (@{$query->columns}) {
|
| 236 | 236 |
|
| 237 |
+ croak "\"$column\" is not exists in params" |
|
| 238 |
+ unless exists $params->{$column};
|
|
| 239 |
+ |
|
| 237 | 240 |
# Value |
| 238 |
- my $value = ref $params->{$column}
|
|
| 241 |
+ my $value = ref $params->{$column} eq 'ARRAY'
|
|
| 239 | 242 |
? $params->{$column}->[$count->{$column} || 0]
|
| 240 | 243 |
: $params->{$column};
|
| 241 | 244 |
|
| ... | ... |
@@ -245,9 +248,21 @@ sub _build_bind_values {
|
| 245 | 248 |
# Filter name |
| 246 | 249 |
my $fname = $filter->{$column} || $self->default_query_filter || '';
|
| 247 | 250 |
|
| 248 |
- my $filters = $self->filters; |
|
| 249 |
- push @bind_values, $filters->{$fname}
|
|
| 250 |
- ? $filters->{$fname}->($value)
|
|
| 251 |
+ my $filter_func; |
|
| 252 |
+ if ($fname) {
|
|
| 253 |
+ |
|
| 254 |
+ if (ref $fname eq 'CODE') {
|
|
| 255 |
+ $filter_func = $fname; |
|
| 256 |
+ } |
|
| 257 |
+ else {
|
|
| 258 |
+ my $filters = $self->filters; |
|
| 259 |
+ croak "Not exists filter \"$fname\"" unless exists $filters->{$fname};
|
|
| 260 |
+ $filter_func = $filters->{$fname};
|
|
| 261 |
+ } |
|
| 262 |
+ } |
|
| 263 |
+ |
|
| 264 |
+ push @bind_values, $filter_func |
|
| 265 |
+ ? $filter_func->($value) |
|
| 251 | 266 |
: $value; |
| 252 | 267 |
|
| 253 | 268 |
# Count up |
| ... | ... |
@@ -67,6 +67,7 @@ sub fetch_hash {
|
| 67 | 67 |
# Filter |
| 68 | 68 |
my $row_hash = {};
|
| 69 | 69 |
for (my $i = 0; $i < @$columns; $i++) {
|
| 70 |
+ |
|
| 70 | 71 |
my $fname = $filter->{$columns->[$i]} || $self->{default_filter} || '';
|
| 71 | 72 |
|
| 72 | 73 |
if ($fname) {
|
| ... | ... |
@@ -9,29 +9,12 @@ use Carp 'croak'; |
| 9 | 9 |
use DBIx::Custom::Query; |
| 10 | 10 |
use DBIx::Custom::SQLTemplate::TagProcessor; |
| 11 | 11 |
|
| 12 |
-__PACKAGE__->dual_attr('tag_processors', default => sub { {} },
|
|
| 13 |
- inherit => 'hash_copy'); |
|
| 14 |
- |
|
| 15 |
-__PACKAGE__->dual_attr('tag_start', default => '{', inherit => 'scalar_copy');
|
|
| 16 |
-__PACKAGE__->dual_attr('tag_end', default => '}', inherit => 'scalar_copy');
|
|
| 17 |
- |
|
| 18 |
-__PACKAGE__->dual_attr('tag_syntax', inherit => 'scalar_copy');
|
|
| 19 |
- |
|
| 20 |
-__PACKAGE__->register_tag_processor( |
|
| 21 |
- '?' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_placeholder_tag, |
|
| 22 |
- '=' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 23 |
- '<>' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 24 |
- '>' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 25 |
- '<' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 26 |
- '>=' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 27 |
- '<=' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 28 |
- 'like' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 29 |
- 'in' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_in_tag, |
|
| 30 |
- 'insert' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_insert_tag, |
|
| 31 |
- 'update' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_update_tag |
|
| 32 |
-); |
|
| 33 |
- |
|
| 34 |
-__PACKAGE__->tag_syntax(<< 'EOS'); |
|
| 12 |
+__PACKAGE__->attr('tag_processors' => sub { {} });
|
|
| 13 |
+ |
|
| 14 |
+__PACKAGE__->attr(tag_start => '{');
|
|
| 15 |
+__PACKAGE__->attr(tag_end => '}'); |
|
| 16 |
+ |
|
| 17 |
+__PACKAGE__->attr('tag_syntax' => <<'EOS');
|
|
| 35 | 18 |
[tag] [expand] |
| 36 | 19 |
{? name} ?
|
| 37 | 20 |
{= name} name = ?
|
| ... | ... |
@@ -49,12 +32,31 @@ __PACKAGE__->tag_syntax(<< 'EOS'); |
| 49 | 32 |
{update key1 key2} set key1 = ?, key2 = ?
|
| 50 | 33 |
EOS |
| 51 | 34 |
|
| 35 |
+sub new {
|
|
| 36 |
+ my $self = shift->SUPER::new; |
|
| 37 |
+ |
|
| 38 |
+ $self->register_tag_processor( |
|
| 39 |
+ '?' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_placeholder_tag, |
|
| 40 |
+ '=' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 41 |
+ '<>' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 42 |
+ '>' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 43 |
+ '<' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 44 |
+ '>=' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 45 |
+ '<=' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 46 |
+ 'like' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag, |
|
| 47 |
+ 'in' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_in_tag, |
|
| 48 |
+ 'insert' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_insert_tag, |
|
| 49 |
+ 'update' => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_update_tag |
|
| 50 |
+ ); |
|
| 51 |
+ |
|
| 52 |
+ return $self; |
|
| 53 |
+} |
|
| 52 | 54 |
|
| 53 | 55 |
sub register_tag_processor {
|
| 54 |
- my $invocant = shift; |
|
| 56 |
+ my $self = shift; |
|
| 55 | 57 |
my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
|
| 56 |
- $invocant->tag_processors({%{$invocant->tag_processors}, %{$tag_processors}});
|
|
| 57 |
- return $invocant; |
|
| 58 |
+ $self->tag_processors({%{$self->tag_processors}, %{$tag_processors}});
|
|
| 59 |
+ return $self; |
|
| 58 | 60 |
} |
| 59 | 61 |
|
| 60 | 62 |
sub clone {
|
| ... | ... |
@@ -262,6 +264,8 @@ Default is '}' |
| 262 | 264 |
This class is L<Object::Simple> subclass. |
| 263 | 265 |
You can use all methods of L<Object::Simple> |
| 264 | 266 |
|
| 267 |
+=head2 new |
|
| 268 |
+ |
|
| 265 | 269 |
=head2 create_query |
| 266 | 270 |
|
| 267 | 271 |
Create L<DBIx::Custom::Query> object parsing SQL template |