packaging one directory
|
1 |
package DBIx::Custom::Result; |
update document
|
2 | |
packaging one directory
|
3 |
use strict; |
4 |
use warnings; |
|
update document
|
5 | |
6 |
use base 'Object::Simple'; |
|
cleanup
|
7 | |
packaging one directory
|
8 |
use Carp 'croak'; |
9 | ||
many many changes
|
10 |
__PACKAGE__->attr([qw/sth filters default_filter filter/]); |
cleanup
|
11 | |
packaging one directory
|
12 |
sub fetch { |
changed argument of tag proc...
|
13 |
my $self = shift; |
14 |
|
|
15 |
$self->{filters} ||= {}; |
|
16 |
$self->{filter} ||= {}; |
|
packaging one directory
|
17 |
|
18 |
# Fetch |
|
changed argument of tag proc...
|
19 |
my @row = $self->{sth}->fetchrow_array; |
packaging one directory
|
20 |
|
21 |
# Cannot fetch |
|
update document
|
22 |
return unless @row; |
many many changes
|
23 | |
packaging one directory
|
24 |
# Filter |
changed argument of tag proc...
|
25 |
for (my $i = 0; $i < @{$self->{sth}->{NAME_lc}}; $i++) { |
update document
|
26 |
|
changed argument of tag proc...
|
27 |
# Filter name |
28 |
my $column = $self->{sth}->{NAME_lc}->[$i]; |
|
29 |
my $fname = exists $self->{filter}->{$column} |
|
30 |
? $self->{filter}->{$column} |
|
31 |
: $self->{default_filter}; |
|
some changed
|
32 |
|
changed argument of tag proc...
|
33 |
# Filter |
34 |
$row[$i] = $self->{filters}->{$fname}->($row[$i]) |
|
35 |
if $fname; |
|
packaging one directory
|
36 |
} |
many many changes
|
37 | |
removed reconnect method
|
38 |
return \@row; |
39 |
} |
|
40 | ||
41 |
sub fetch_first { |
|
42 |
my $self = shift; |
|
43 |
|
|
44 |
# Fetch |
|
45 |
my $row = $self->fetch; |
|
46 |
|
|
47 |
# Not exist |
|
48 |
return unless $row; |
|
49 |
|
|
50 |
# Finish statement handle |
|
51 |
$self->sth->finish; |
|
52 |
|
|
53 |
return $row; |
|
54 |
} |
|
55 | ||
56 |
sub fetch_multi { |
|
57 |
my ($self, $count) = @_; |
|
58 |
|
|
59 |
# Not specified Row count |
|
changed argument of tag proc...
|
60 |
croak 'Row count must be specified' |
removed reconnect method
|
61 |
unless $count; |
62 |
|
|
63 |
# Fetch multi rows |
|
64 |
my $rows = []; |
|
65 |
for (my $i = 0; $i < $count; $i++) { |
|
66 |
my $row = $self->fetch; |
|
67 |
|
|
68 |
last unless $row; |
|
69 |
|
|
70 |
push @$rows, $row; |
|
71 |
} |
|
72 |
|
|
73 |
return unless @$rows; |
|
74 |
return $rows; |
|
75 |
} |
|
76 | ||
77 |
sub fetch_all { |
|
78 |
my $self = shift; |
|
79 |
|
|
80 |
# Fetch all rows |
|
81 |
my $rows = []; |
|
82 |
while(my $row = $self->fetch) { |
|
83 |
push @$rows, $row; |
|
84 |
} |
|
85 |
return $rows; |
|
packaging one directory
|
86 |
} |
87 | ||
88 |
sub fetch_hash { |
|
changed argument of tag proc...
|
89 |
my $self = shift; |
90 |
|
|
91 |
$self->{filters} ||= {}; |
|
92 |
$self->{filter} ||= {}; |
|
packaging one directory
|
93 |
|
94 |
# Fetch |
|
changed argument of tag proc...
|
95 |
my $row = $self->{sth}->fetchrow_arrayref; |
packaging one directory
|
96 |
|
97 |
# Cannot fetch |
|
98 |
return unless $row; |
|
99 |
|
|
100 |
# Filter |
|
101 |
my $row_hash = {}; |
|
changed argument of tag proc...
|
102 |
for (my $i = 0; $i < @{$self->{sth}->{NAME_lc}}; $i++) { |
update document
|
103 |
|
changed argument of tag proc...
|
104 |
# Filter name |
105 |
my $column = $self->{sth}->{NAME_lc}->[$i]; |
|
106 |
my $fname = exists $self->{filter}->{$column} |
|
107 |
? $self->{filter}->{$column} |
|
108 |
: $self->{default_filter}; |
|
add query filter error check
|
109 |
|
changed argument of tag proc...
|
110 |
# Filter |
111 |
$row_hash->{$column} |
|
112 |
= $fname ? $self->{filters}->{$fname}->($row->[$i]) |
|
113 |
: $row->[$i]; |
|
packaging one directory
|
114 |
} |
115 |
|
|
removed reconnect method
|
116 |
return $row_hash; |
packaging one directory
|
117 |
} |
118 | ||
removed reconnect method
|
119 |
sub fetch_hash_first { |
packaging one directory
|
120 |
my $self = shift; |
121 |
|
|
122 |
# Fetch hash |
|
123 |
my $row = $self->fetch_hash; |
|
124 |
|
|
125 |
# Not exist |
|
126 |
return unless $row; |
|
127 |
|
|
128 |
# Finish statement handle |
|
some changed
|
129 |
$self->sth->finish; |
packaging one directory
|
130 |
|
removed reconnect method
|
131 |
return $row; |
packaging one directory
|
132 |
} |
133 | ||
renamed fetch_rows to fetch_...
|
134 |
sub fetch_hash_multi { |
packaging one directory
|
135 |
my ($self, $count) = @_; |
136 |
|
|
137 |
# Not specified Row count |
|
changed argument of tag proc...
|
138 |
croak 'Row count must be specified' |
packaging one directory
|
139 |
unless $count; |
140 |
|
|
141 |
# Fetch multi rows |
|
142 |
my $rows = []; |
|
143 |
for (my $i = 0; $i < $count; $i++) { |
|
removed reconnect method
|
144 |
my $row = $self->fetch_hash; |
packaging one directory
|
145 |
|
removed reconnect method
|
146 |
last unless $row; |
packaging one directory
|
147 |
|
removed reconnect method
|
148 |
push @$rows, $row; |
packaging one directory
|
149 |
} |
150 |
|
|
151 |
return unless @$rows; |
|
removed reconnect method
|
152 |
return $rows; |
packaging one directory
|
153 |
} |
154 | ||
155 |
sub fetch_hash_all { |
|
156 |
my $self = shift; |
|
157 |
|
|
update document
|
158 |
# Fetch all rows as hash |
packaging one directory
|
159 |
my $rows = []; |
removed reconnect method
|
160 |
while(my $row = $self->fetch_hash) { |
161 |
push @$rows, $row; |
|
packaging one directory
|
162 |
} |
changed argument of tag proc...
|
163 |
|
removed reconnect method
|
164 |
return $rows; |
packaging one directory
|
165 |
} |
166 | ||
update document
|
167 |
1; |
168 | ||
packaging one directory
|
169 |
=head1 NAME |
170 | ||
cleanup
|
171 |
DBIx::Custom::Result - Result of select |
packaging one directory
|
172 | |
update document
|
173 |
=head1 SYNOPSIS |
packaging one directory
|
174 |
|
removed reconnect method
|
175 |
# Result |
176 |
my $result = $dbi->select(table => 'books'); |
|
177 |
|
|
178 |
# Fetch a row into array |
|
179 |
while (my $row = $result->fetch) { |
|
180 |
my $value1 = $row->[0]; |
|
181 |
my $valuu2 = $row->[1]; |
|
182 |
|
|
183 |
# do something |
|
version 0.0901
|
184 |
} |
185 |
|
|
removed reconnect method
|
186 |
# Fetch only first row into array |
187 |
my $row = $result->fetch_first; |
|
188 |
|
|
189 |
# Fetch multiple rows into array of array |
|
190 |
while (my $rows = $result->fetch_multi(5)) { |
|
191 |
# do something |
|
192 |
} |
|
193 |
|
|
194 |
# Fetch all rows into array of array |
|
195 |
my $rows = $result->fetch_all; |
|
196 |
|
|
197 |
# Fetch hash into hash |
|
198 |
while (my $row = $result->fetch_hash) { |
|
199 |
my $value1 = $row->{title}; |
|
200 |
my $value2 = $row->{author}; |
|
201 |
|
|
202 |
# do something |
|
packaging one directory
|
203 |
} |
removed reconnect method
|
204 |
|
205 |
# Fetch only first row into hash |
|
206 |
my $row = $result->fetch_hash_first; |
|
207 |
|
|
208 |
# Fetch multiple rows into array of hash |
|
209 |
while (my $rows = $result->fetch_hash_multi) { |
|
210 |
# do something |
|
211 |
} |
|
212 |
|
|
213 |
# Fetch all rows into array of hash |
|
214 |
my $rows = $result->fetch_hash_all; |
|
packaging one directory
|
215 | |
update document
|
216 |
=head1 ATTRIBUTES |
packaging one directory
|
217 | |
removed DBIx::Custom commit ...
|
218 |
=head2 C<sth> |
packaging one directory
|
219 | |
cleanup
|
220 |
my $sth = $reuslt->sth |
version 0.0901
|
221 |
$result = $result->sth($sth); |
many many changes
|
222 | |
removed DESTROY method(not b...
|
223 |
Statement handle. |
224 | ||
225 |
=head2 C<default_filter> |
|
many many changes
|
226 | |
cleanup
|
227 |
my $default_filter = $result->default_filter; |
228 |
$result = $result->default_filter('decode_utf8'); |
|
many many changes
|
229 | |
removed DESTROY method(not b...
|
230 |
Default filter for fetching. |
packaging one directory
|
231 | |
removed DESTROY method(not b...
|
232 |
=head2 C<filter> |
update document
|
233 | |
cleanup
|
234 |
my $filter = $result->filter; |
removed reconnect method
|
235 |
$result = $result->filter({title => 'decode_utf8'}); |
packaging one directory
|
236 | |
removed DESTROY method(not b...
|
237 |
Filters for fetching. |
238 | ||
update document
|
239 |
=head1 METHODS |
240 | ||
241 |
This class is L<Object::Simple> subclass. |
|
242 |
You can use all methods of L<Object::Simple> |
|
packaging one directory
|
243 | |
removed DBIx::Custom commit ...
|
244 |
=head2 C<fetch> |
packaging one directory
|
245 | |
removed reconnect method
|
246 |
$row = $result->fetch; |
version 0.0901
|
247 | |
removed DESTROY method(not b...
|
248 |
Fetch a row into array |
packaging one directory
|
249 | |
250 |
while (my $row = $result->fetch) { |
|
251 |
# do something |
|
removed reconnect method
|
252 |
my $value1 = $row->[0]; |
253 |
my $value2 = $row->[1]; |
|
packaging one directory
|
254 |
} |
255 | ||
removed DBIx::Custom commit ...
|
256 |
=head2 C<fetch_first> |
update document
|
257 | |
removed reconnect method
|
258 |
$row = $result->fetch_first; |
packaging one directory
|
259 | |
removed DESTROY method(not b...
|
260 |
Fetch only first row into array and finish statment handle. |
packaging one directory
|
261 | |
removed DESTROY method(not b...
|
262 |
=head2 C<fetch_multi> |
update document
|
263 | |
removed reconnect method
|
264 |
$rows = $result->fetch_multi($count); |
packaging one directory
|
265 |
|
removed DESTROY method(not b...
|
266 |
Fetch multiple rows into array of array. |
version 0.0901
|
267 | |
renamed fetch_rows to fetch_...
|
268 |
while(my $rows = $result->fetch_multi(10)) { |
update document
|
269 |
# do someting |
270 |
} |
|
packaging one directory
|
271 | |
removed DBIx::Custom commit ...
|
272 |
=head2 C<fetch_all> |
packaging one directory
|
273 | |
removed reconnect method
|
274 |
$rows = $result->fetch_all; |
version 0.0901
|
275 | |
removed DESTROY method(not b...
|
276 |
Fetch all rows into array of array. |
packaging one directory
|
277 | |
removed DESTROY method(not b...
|
278 |
=head2 C<fetch_hash> |
packaging one directory
|
279 | |
removed reconnect method
|
280 |
$row = $result->fetch_hash; |
packaging one directory
|
281 | |
removed DESTROY method(not b...
|
282 |
Fetch a row into hash |
update document
|
283 | |
removed reconnect method
|
284 |
while (my $row = $result->fetch_hash) { |
285 |
my $val1 = $row->{title}; |
|
286 |
my $val2 = $row->{author}; |
|
287 |
|
|
288 |
# do something |
|
289 |
} |
|
version 0.0901
|
290 | |
removed DBIx::Custom commit ...
|
291 |
=head2 C<fetch_hash_first> |
removed reconnect method
|
292 |
|
293 |
$row = $result->fetch_hash_first; |
|
packaging one directory
|
294 | |
removed DESTROY method(not b...
|
295 |
Fetch only first row into hash and finish statment handle. |
packaging one directory
|
296 | |
removed DESTROY method(not b...
|
297 |
=head2 C<fetch_hash_multi> |
update document
|
298 | |
removed reconnect method
|
299 |
$rows = $result->fetch_hash_multi($count); |
update document
|
300 |
|
removed DESTROY method(not b...
|
301 |
Fetch multiple rows into array of hash |
packaging one directory
|
302 | |
removed reconnect method
|
303 |
while(my $rows = $result->fetch_hash_multi(10)) { |
304 |
# do someting |
|
305 |
} |
|
update document
|
306 | |
removed DBIx::Custom commit ...
|
307 |
=head2 C<fetch_hash_all> |
packaging one directory
|
308 | |
removed reconnect method
|
309 |
$rows = $result->fetch_hash_all; |
packaging one directory
|
310 | |
removed DESTROY method(not b...
|
311 |
Fetch all rows into array of hash. |
312 | ||
packaging one directory
|
313 |
=cut |