... | ... |
@@ -250,7 +250,7 @@ sub _build_bind_values { |
250 | 250 |
my ($self, $query, $params) = @_; |
251 | 251 |
my $key_infos = $query->key_infos; |
252 | 252 |
my $bind_filter = $query->bind_filter; |
253 |
- my $no_bind_filters_map = $query->_no_bind_filters_map || {}; |
|
253 |
+ my $no_bind_filters = $query->_no_bind_filters || {}; |
|
254 | 254 |
|
255 | 255 |
# binding values |
256 | 256 |
my @bind_values; |
... | ... |
@@ -284,7 +284,7 @@ sub _build_bind_values { |
284 | 284 |
if (ref $current_key eq 'ARRAY') { |
285 | 285 |
# Filtering |
286 | 286 |
if ($bind_filter && |
287 |
- !$no_bind_filters_map->{$original_key}) |
|
287 |
+ !$no_bind_filters->{$original_key}) |
|
288 | 288 |
{ |
289 | 289 |
push @bind_values, |
290 | 290 |
$bind_filter->($root_params->[$current_key->[0]], |
... | ... |
@@ -305,7 +305,7 @@ sub _build_bind_values { |
305 | 305 |
|
306 | 306 |
# Filtering |
307 | 307 |
if ($bind_filter && |
308 |
- !$no_bind_filters_map->{$original_key}) |
|
308 |
+ !$no_bind_filters->{$original_key}) |
|
309 | 309 |
{ |
310 | 310 |
push @bind_values, |
311 | 311 |
$bind_filter->($root_params->{$current_key}, |
... | ... |
@@ -5,24 +5,34 @@ use strict; |
5 | 5 |
use warnings; |
6 | 6 |
|
7 | 7 |
__PACKAGE__->attr([qw/sql key_infos bind_filter fetch_filter sth/]); |
8 |
-__PACKAGE__->attr(_no_bind_filters_map => sub { {} }); |
|
8 |
+__PACKAGE__->attr(_no_bind_filters => sub { {} }); |
|
9 | 9 |
__PACKAGE__->attr(no_fetch_filters => sub { [] }); |
10 | 10 |
|
11 |
-__PACKAGE__->attr('no_bind_filters', trigger => sub { |
|
12 |
- my $self = shift; |
|
13 |
- my $no_bind_filters = $self->no_bind_filters || []; |
|
14 |
- my %no_bind_filters_map = map {$_ => 1} @{$no_bind_filters}; |
|
15 |
- $self->_no_bind_filters_map(\%no_bind_filters_map); |
|
16 |
-}); |
|
17 |
- |
|
18 | 11 |
sub new { |
19 | 12 |
my $self = shift->SUPER::new(@_); |
20 | 13 |
|
21 |
- Object::Simple::Util->init_attrs($self, 'no_bind_filters'); |
|
14 |
+ $self->no_bind_filters($self->{no_bind_filters}) |
|
15 |
+ if $self->{no_bind_filters}; |
|
22 | 16 |
|
23 | 17 |
return $self; |
24 | 18 |
} |
25 | 19 |
|
20 |
+sub no_bind_filters { |
|
21 |
+ my $self = shift; |
|
22 |
+ |
|
23 |
+ if (@_) { |
|
24 |
+ $self->{no_bind_filters} = $_[0]; |
|
25 |
+ |
|
26 |
+ my %no_bind_filters = map { $_ => 1 } @{$self->{no_bind_filters}}; |
|
27 |
+ |
|
28 |
+ $self->_no_bind_filters(\%no_bind_filters); |
|
29 |
+ |
|
30 |
+ return $self; |
|
31 |
+ } |
|
32 |
+ |
|
33 |
+ return $self->{no_bind_filters}; |
|
34 |
+} |
|
35 |
+ |
|
26 | 36 |
=head1 NAME |
27 | 37 |
|
28 | 38 |
DBIx::Custom::Query - DBIx::Custom query |
... | ... |
@@ -5,27 +5,35 @@ use strict; |
5 | 5 |
use warnings; |
6 | 6 |
use Carp 'croak'; |
7 | 7 |
|
8 |
-use Object::Simple::Util; |
|
9 |
- |
|
10 | 8 |
__PACKAGE__->attr([qw/_dbi sth fetch_filter/]); |
11 |
-__PACKAGE__->attr(_no_fetch_filters_map => sub { {} }); |
|
12 |
- |
|
13 |
-__PACKAGE__->attr('no_fetch_filters', trigger => sub { |
|
14 |
- my $self = shift; |
|
15 |
- my $no_fetch_filters = $self->no_fetch_filters || []; |
|
16 |
- my %no_fetch_filters_map = map {$_ => 1} @{$no_fetch_filters}; |
|
17 |
- $self->_no_fetch_filters_map(\%no_fetch_filters_map); |
|
18 |
-}); |
|
9 |
+__PACKAGE__->attr(_no_fetch_filters => sub { {} }); |
|
19 | 10 |
|
20 | 11 |
sub new { |
21 | 12 |
my $self = shift->SUPER::new(@_); |
22 | 13 |
|
23 |
- Object::Simple::Util->init_attrs($self, 'no_fetch_filters'); |
|
14 |
+ $self->no_fetch_filters($self->{no_fetch_filters}) |
|
15 |
+ if exists $self->{no_fetch_filters}; |
|
24 | 16 |
|
25 | 17 |
return $self; |
26 | 18 |
} |
27 | 19 |
|
28 |
-# Fetch (array) |
|
20 |
+sub no_fetch_filters { |
|
21 |
+ my $self = shift; |
|
22 |
+ |
|
23 |
+ if (@_) { |
|
24 |
+ |
|
25 |
+ $self->{no_fetch_filters} = $_[0]; |
|
26 |
+ |
|
27 |
+ my %no_fetch_filters = map {$_ => 1} @{$self->{no_fetch_filters}}; |
|
28 |
+ |
|
29 |
+ $self->_no_fetch_filters(\%no_fetch_filters); |
|
30 |
+ |
|
31 |
+ return $self; |
|
32 |
+ } |
|
33 |
+ |
|
34 |
+ return $self->{no_fetch_filters}; |
|
35 |
+} |
|
36 |
+ |
|
29 | 37 |
sub fetch { |
30 | 38 |
my ($self, $type) = @_; |
31 | 39 |
my $sth = $self->sth; |
... | ... |
@@ -42,7 +50,7 @@ sub fetch { |
42 | 50 |
my $keys = $sth->{NAME_lc}; |
43 | 51 |
my $types = $sth->{TYPE}; |
44 | 52 |
for (my $i = 0; $i < @$keys; $i++) { |
45 |
- next if $self->_no_fetch_filters_map->{$keys->[$i]}; |
|
53 |
+ next if $self->_no_fetch_filters->{$keys->[$i]}; |
|
46 | 54 |
$row->[$i]= $fetch_filter->($row->[$i], $keys->[$i], $self->_dbi, |
47 | 55 |
{type => $types->[$i], sth => $sth, index => $i}); |
48 | 56 |
} |
... | ... |
@@ -50,7 +58,6 @@ sub fetch { |
50 | 58 |
return wantarray ? @$row : $row; |
51 | 59 |
} |
52 | 60 |
|
53 |
-# Fetch (hash) |
|
54 | 61 |
sub fetch_hash { |
55 | 62 |
my $self = shift; |
56 | 63 |
my $sth = $self->sth; |
... | ... |
@@ -70,7 +77,7 @@ sub fetch_hash { |
70 | 77 |
if ($fetch_filter) { |
71 | 78 |
my $types = $sth->{TYPE}; |
72 | 79 |
for (my $i = 0; $i < @$keys; $i++) { |
73 |
- if ($self->_no_fetch_filters_map->{$keys->[$i]}) { |
|
80 |
+ if ($self->_no_fetch_filters->{$keys->[$i]}) { |
|
74 | 81 |
$row_hash->{$keys->[$i]} = $row->[$i]; |
75 | 82 |
} |
76 | 83 |
else { |
... | ... |
@@ -90,7 +97,6 @@ sub fetch_hash { |
90 | 97 |
return wantarray ? %$row_hash : $row_hash; |
91 | 98 |
} |
92 | 99 |
|
93 |
-# Fetch only first (array) |
|
94 | 100 |
sub fetch_first { |
95 | 101 |
my $self = shift; |
96 | 102 |
|
... | ... |
@@ -106,7 +112,6 @@ sub fetch_first { |
106 | 112 |
return wantarray ? @$row : $row; |
107 | 113 |
} |
108 | 114 |
|
109 |
-# Fetch only first (hash) |
|
110 | 115 |
sub fetch_hash_first { |
111 | 116 |
my $self = shift; |
112 | 117 |
|
... | ... |
@@ -122,7 +127,6 @@ sub fetch_hash_first { |
122 | 127 |
return wantarray ? %$row : $row; |
123 | 128 |
} |
124 | 129 |
|
125 |
-# Fetch multi rows (array) |
|
126 | 130 |
sub fetch_rows { |
127 | 131 |
my ($self, $count) = @_; |
128 | 132 |
|
... | ... |
@@ -144,7 +148,6 @@ sub fetch_rows { |
144 | 148 |
return wantarray ? @$rows : $rows; |
145 | 149 |
} |
146 | 150 |
|
147 |
-# Fetch multi rows (hash) |
|
148 | 151 |
sub fetch_hash_rows { |
149 | 152 |
my ($self, $count) = @_; |
150 | 153 |
|
... | ... |
@@ -166,8 +169,6 @@ sub fetch_hash_rows { |
166 | 169 |
return wantarray ? @$rows : $rows; |
167 | 170 |
} |
168 | 171 |
|
169 |
- |
|
170 |
-# Fetch all (array) |
|
171 | 172 |
sub fetch_all { |
172 | 173 |
my $self = shift; |
173 | 174 |
|
... | ... |
@@ -178,7 +179,6 @@ sub fetch_all { |
178 | 179 |
return wantarray ? @$rows : $rows; |
179 | 180 |
} |
180 | 181 |
|
181 |
-# Fetch all (hash) |
|
182 | 182 |
sub fetch_hash_all { |
183 | 183 |
my $self = shift; |
184 | 184 |
|
... | ... |
@@ -189,10 +189,8 @@ sub fetch_hash_all { |
189 | 189 |
return wantarray ? @$rows : $rows; |
190 | 190 |
} |
191 | 191 |
|
192 |
-# Finish |
|
193 | 192 |
sub finish { shift->sth->finish } |
194 | 193 |
|
195 |
-# Error |
|
196 | 194 |
sub error { |
197 | 195 |
my $self = shift; |
198 | 196 |
my $sth = $self->sth; |
... | ... |
@@ -27,11 +27,11 @@ $query = DBIx::Custom::Query->new( |
27 | 27 |
is($query->sql, 'a', "$test : sql"); |
28 | 28 |
is($query->key_infos, 'b', "$test : key_infos "); |
29 | 29 |
is($query->bind_filter, 'c', "$test : bind_filter"); |
30 |
-is_deeply(scalar $query->no_bind_filters, [qw/d e/], "$test : no_bind_filters"); |
|
31 |
-is_deeply(scalar $query->_no_bind_filters_map, {d => 1, e => 1}, "$test : _no_bind_filters_map"); |
|
32 |
-is_deeply(scalar $query->no_fetch_filters, [qw/g h/], "$test : no_fetch_filters"); |
|
30 |
+is_deeply($query->no_bind_filters, [qw/d e/], "$test : no_bind_filters"); |
|
31 |
+is_deeply($query->_no_bind_filters, {d => 1, e => 1}, "$test : _no_bind_filters"); |
|
32 |
+is_deeply($query->no_fetch_filters, [qw/g h/], "$test : no_fetch_filters"); |
|
33 | 33 |
is($query->sth, 'e', "$test : sth"); |
34 | 34 |
|
35 | 35 |
$query->no_bind_filters(undef); |
36 |
-is_deeply(scalar $query->_no_bind_filters_map, {}, "$test _no_bind_filters_map undef value"); |
|
36 |
+is_deeply(scalar $query->_no_bind_filters, {}, "$test _no_bind_filters undef value"); |
|
37 | 37 |
|