... | ... |
@@ -1,4 +1,6 @@ |
1 | 1 |
0.1692 |
2 |
+ - removed EXPERIMENTAL DBIx::Model result_filter |
|
3 |
+ - DBIx::Custom::Result filter override type_rule |
|
2 | 4 |
- added EXPERIMENTAL DBIx::Custom::Result type_rule |
3 | 5 |
- added EXPERIMENTAL available_type_name method |
4 | 6 |
- EXPERIMENTAL type_rule_off is not passed form execute method |
... | ... |
@@ -68,10 +68,6 @@ sub fetch { |
68 | 68 |
my $type_rule = $self->type_rule || {}; |
69 | 69 |
|
70 | 70 |
for (my $i = 0; $i < @$columns; $i++) { |
71 |
- if (!$self->type_rule_off && (my $rule = $type_rule->{lc($types->[$i])})) |
|
72 |
- { |
|
73 |
- $row[$i] = $rule->($row[$i]); |
|
74 |
- } |
|
75 | 71 |
|
76 | 72 |
# Filter name |
77 | 73 |
my $column = $columns->[$i]; |
... | ... |
@@ -81,7 +77,14 @@ sub fetch { |
81 | 77 |
my $ef = $end_filter->{$column}; |
82 | 78 |
|
83 | 79 |
# Filtering |
84 |
- $row[$i] = $f->($row[$i]) if $f && !$self->filter_off; |
|
80 |
+ if ($f && !$self->filter_off) { |
|
81 |
+ $row[$i] = $f->($row[$i]); |
|
82 |
+ } |
|
83 |
+ elsif (!$self->type_rule_off && (my $rule = $type_rule->{lc($types->[$i])})) |
|
84 |
+ { |
|
85 |
+ $row[$i] = $rule->($row[$i]); |
|
86 |
+ } |
|
87 |
+ |
|
85 | 88 |
$row[$i] = $ef->($row[$i]) if $ef && !$self->filter_off; |
86 | 89 |
} |
87 | 90 |
|
... | ... |
@@ -136,12 +139,6 @@ sub fetch_hash { |
136 | 139 |
my $type_rule = $self->type_rule || {}; |
137 | 140 |
for (my $i = 0; $i < @$columns; $i++) { |
138 | 141 |
|
139 |
- # Type rule |
|
140 |
- if (!$self->type_rule_off && (my $rule = $type_rule->{lc($types->[$i])})) |
|
141 |
- { |
|
142 |
- $row->[$i] = $rule->($row->[$i]); |
|
143 |
- } |
|
144 |
- |
|
145 | 142 |
# Filter name |
146 | 143 |
my $column = $columns->[$i]; |
147 | 144 |
my $f = exists $filter->{$column} |
... | ... |
@@ -150,8 +147,14 @@ sub fetch_hash { |
150 | 147 |
my $ef = $end_filter->{$column}; |
151 | 148 |
|
152 | 149 |
# Filtering |
153 |
- $row_hash->{$column} = $f && !$self->filter_off ? $f->($row->[$i]) |
|
154 |
- : $row->[$i]; |
|
150 |
+ if ($f && !$self->filter_off) { |
|
151 |
+ $row_hash->{$column} = $f->($row->[$i]); |
|
152 |
+ } |
|
153 |
+ elsif (!$self->type_rule_off && (my $rule = $type_rule->{lc($types->[$i])})) |
|
154 |
+ { |
|
155 |
+ $row_hash->{$column} = $rule->($row->[$i]); |
|
156 |
+ } |
|
157 |
+ else { $row_hash->{$column} = $row->[$i] } |
|
155 | 158 |
$row_hash->{$column} = $ef->($row_hash->{$column}) |
156 | 159 |
if $ef && !$self->filter_off; |
157 | 160 |
} |
... | ... |
@@ -2854,6 +2854,20 @@ $row = $result->one; |
2854 | 2854 |
is($row->{key1}, 2); |
2855 | 2855 |
is($row->{key2}, 8); |
2856 | 2856 |
|
2857 |
+$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:'); |
|
2858 |
+$dbi->execute("create table table1 (key1 Date, key2 datetime)"); |
|
2859 |
+$dbi->type_rule( |
|
2860 |
+ from => { |
|
2861 |
+ date => sub { $_[0] * 2 }, |
|
2862 |
+ }, |
|
2863 |
+); |
|
2864 |
+$dbi->insert({key1 => 2}, table => 'table1'); |
|
2865 |
+$result = $dbi->select(table => 'table1'); |
|
2866 |
+$result->filter(key1 => sub { $_[0] * 3}); |
|
2867 |
+is($result->one->{key1}, 6); |
|
2868 |
+$result = $dbi->select(table => 'table1'); |
|
2869 |
+$result->filter(key1 => sub { $_[0] * 3}); |
|
2870 |
+is($result->fetch->[0], 6); |
|
2857 | 2871 |
|
2858 | 2872 |
test 'result_filter'; |
2859 | 2873 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |