... | ... |
@@ -1,8 +1,8 @@ |
1 |
-0.1641 |
|
1 |
+0.1643 |
|
2 | 2 |
fix bug : filter can't overwirite undef value. |
3 | 3 |
add feature to apply_filter(). you can apply end filter. |
4 | 4 |
add feature to apply_filter(). TABLE__COLUMN is filterded now. |
5 |
-0.1640 |
|
5 |
+0.1642 |
|
6 | 6 |
removed experimental DBIx::Custom::Table base() method |
7 | 7 |
table created by tabled method can call base_$method correponding to base_table's one |
8 | 8 |
0.1641 |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
package DBIx::Custom; |
2 | 2 |
|
3 |
-our $VERSION = '0.1642'; |
|
3 |
+our $VERSION = '0.1643'; |
|
4 | 4 |
|
5 | 5 |
use 5.008001; |
6 | 6 |
use strict; |
... | ... |
@@ -209,6 +209,9 @@ sub create_query { |
209 | 209 |
# Set statement handle |
210 | 210 |
$query->sth($sth); |
211 | 211 |
|
212 |
+ # Set filters |
|
213 |
+ $query->filters($self->filters); |
|
214 |
+ |
|
212 | 215 |
return $query; |
213 | 216 |
} |
214 | 217 |
|
... | ... |
@@ -5,7 +5,37 @@ use warnings; |
5 | 5 |
|
6 | 6 |
use base 'Object::Simple'; |
7 | 7 |
|
8 |
-__PACKAGE__->attr([qw/columns filter sql sth/]); |
|
8 |
+use Carp 'croak'; |
|
9 |
+ |
|
10 |
+__PACKAGE__->attr([qw/columns sql sth filters/]); |
|
11 |
+ |
|
12 |
+sub filter { |
|
13 |
+ my $self = shift; |
|
14 |
+ |
|
15 |
+ if (@_) { |
|
16 |
+ my $filter = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
17 |
+ |
|
18 |
+ foreach my $column (keys %$filter) { |
|
19 |
+ my $fname = $filter->{$column}; |
|
20 |
+ |
|
21 |
+ if (exists $filter->{$column} |
|
22 |
+ && defined $fname |
|
23 |
+ && ref $fname ne 'CODE') |
|
24 |
+ { |
|
25 |
+ croak qq{Filter "$fname" is not registered"} |
|
26 |
+ unless exists $self->filters->{$fname}; |
|
27 |
+ |
|
28 |
+ $filter->{$column} = $self->filters->{$fname}; |
|
29 |
+ } |
|
30 |
+ } |
|
31 |
+ |
|
32 |
+ $self->{filter} = {%{$self->filter}, %$filter}; |
|
33 |
+ |
|
34 |
+ return $self; |
|
35 |
+ } |
|
36 |
+ |
|
37 |
+ return $self->{filter} ||= {}; |
|
38 |
+} |
|
9 | 39 |
|
10 | 40 |
# DEPRECATED! |
11 | 41 |
__PACKAGE__->attr('default_filter'); |
... | ... |
@@ -32,8 +62,8 @@ Column names. |
32 | 62 |
=head2 C<filter> |
33 | 63 |
|
34 | 64 |
my $filter = $query->filter; |
35 |
- $query = $query->filter({author => 'to_something', |
|
36 |
- title => 'to_something'}); |
|
65 |
+ $query = $query->filter(author => 'to_something', |
|
66 |
+ title => 'to_something'); |
|
37 | 67 |
|
38 | 68 |
Filters when parameter binding is executed. |
39 | 69 |
|