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 |
|
|
cleanup
|
15 |
# Filters |
changed argument of tag proc...
|
16 |
$self->{filters} ||= {}; |
17 |
$self->{filter} ||= {}; |
|
packaging one directory
|
18 |
|
19 |
# Fetch |
|
changed argument of tag proc...
|
20 |
my @row = $self->{sth}->fetchrow_array; |
packaging one directory
|
21 |
|
cleanup
|
22 |
# No row |
update document
|
23 |
return unless @row; |
many many changes
|
24 | |
cleanup
|
25 |
# Filtering |
26 |
my $columns = $self->{sth}->{NAME_lc}; |
|
27 |
for (my $i = 0; $i < @$columns; $i++) { |
|
update document
|
28 |
|
changed argument of tag proc...
|
29 |
# Filter name |
cleanup
|
30 |
my $column = $columns->[$i]; |
changed argument of tag proc...
|
31 |
my $fname = exists $self->{filter}->{$column} |
32 |
? $self->{filter}->{$column} |
|
33 |
: $self->{default_filter}; |
|
some changed
|
34 |
|
cleanup
|
35 |
# Filtering |
changed argument of tag proc...
|
36 |
$row[$i] = $self->{filters}->{$fname}->($row[$i]) |
37 |
if $fname; |
|
packaging one directory
|
38 |
} |
many many changes
|
39 | |
removed reconnect method
|
40 |
return \@row; |
41 |
} |
|
42 | ||
43 |
sub fetch_first { |
|
44 |
my $self = shift; |
|
45 |
|
|
46 |
# Fetch |
|
47 |
my $row = $self->fetch; |
|
48 |
|
|
cleanup
|
49 |
# No row |
removed reconnect method
|
50 |
return unless $row; |
51 |
|
|
52 |
# Finish statement handle |
|
53 |
$self->sth->finish; |
|
54 |
|
|
55 |
return $row; |
|
56 |
} |
|
57 | ||
58 |
sub fetch_multi { |
|
59 |
my ($self, $count) = @_; |
|
60 |
|
|
cleanup
|
61 |
# Row count not specifed |
changed argument of tag proc...
|
62 |
croak 'Row count must be specified' |
removed reconnect method
|
63 |
unless $count; |
64 |
|
|
65 |
# Fetch multi rows |
|
66 |
my $rows = []; |
|
67 |
for (my $i = 0; $i < $count; $i++) { |
|
68 |
my $row = $self->fetch; |
|
69 |
last unless $row; |
|
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 |
|
|
cleanup
|
91 |
# Filters |
changed argument of tag proc...
|
92 |
$self->{filters} ||= {}; |
93 |
$self->{filter} ||= {}; |
|
packaging one directory
|
94 |
|
95 |
# Fetch |
|
changed argument of tag proc...
|
96 |
my $row = $self->{sth}->fetchrow_arrayref; |
packaging one directory
|
97 |
|
98 |
# Cannot fetch |
|
99 |
return unless $row; |
|
100 |
|
|
101 |
# Filter |
|
102 |
my $row_hash = {}; |
|
cleanup
|
103 |
my $columns = $self->{sth}->{NAME_lc}; |
104 |
for (my $i = 0; $i < @$columns; $i++) { |
|
update document
|
105 |
|
changed argument of tag proc...
|
106 |
# Filter name |
cleanup
|
107 |
my $column = $columns->[$i]; |
changed argument of tag proc...
|
108 |
my $fname = exists $self->{filter}->{$column} |
109 |
? $self->{filter}->{$column} |
|
110 |
: $self->{default_filter}; |
|
add query filter error check
|
111 |
|
cleanup
|
112 |
# Filtering |
changed argument of tag proc...
|
113 |
$row_hash->{$column} |
114 |
= $fname ? $self->{filters}->{$fname}->($row->[$i]) |
|
115 |
: $row->[$i]; |
|
packaging one directory
|
116 |
} |
117 |
|
|
removed reconnect method
|
118 |
return $row_hash; |
packaging one directory
|
119 |
} |
120 | ||
removed reconnect method
|
121 |
sub fetch_hash_first { |
packaging one directory
|
122 |
my $self = shift; |
123 |
|
|
124 |
# Fetch hash |
|
125 |
my $row = $self->fetch_hash; |
|
126 |
|
|
cleanup
|
127 |
# No row |
packaging one directory
|
128 |
return unless $row; |
129 |
|
|
130 |
# Finish statement handle |
|
some changed
|
131 |
$self->sth->finish; |
packaging one directory
|
132 |
|
removed reconnect method
|
133 |
return $row; |
packaging one directory
|
134 |
} |
135 | ||
renamed fetch_rows to fetch_...
|
136 |
sub fetch_hash_multi { |
packaging one directory
|
137 |
my ($self, $count) = @_; |
138 |
|
|
cleanup
|
139 |
# Row count not specified |
changed argument of tag proc...
|
140 |
croak 'Row count must be specified' |
packaging one directory
|
141 |
unless $count; |
142 |
|
|
143 |
# Fetch multi rows |
|
144 |
my $rows = []; |
|
145 |
for (my $i = 0; $i < $count; $i++) { |
|
removed reconnect method
|
146 |
my $row = $self->fetch_hash; |
147 |
last unless $row; |
|
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 statement |
packaging one directory
|
172 | |
update document
|
173 |
=head1 SYNOPSIS |
cleanup
|
174 | |
175 |
Get the result of select statement. |
|
176 | ||
removed reconnect method
|
177 |
# Result |
178 |
my $result = $dbi->select(table => 'books'); |
|
cleanup
|
179 | |
180 |
Fetch row into array. |
|
removed reconnect method
|
181 |
|
182 |
# Fetch a row into array |
|
183 |
while (my $row = $result->fetch) { |
|
cleanup
|
184 |
my $author = $row->[0]; |
185 |
my $title = $row->[1]; |
|
removed reconnect method
|
186 |
|
version 0.0901
|
187 |
} |
188 |
|
|
cleanup
|
189 |
# Fetch only a first row into array |
removed reconnect method
|
190 |
my $row = $result->fetch_first; |
191 |
|
|
192 |
# Fetch multiple rows into array of array |
|
193 |
while (my $rows = $result->fetch_multi(5)) { |
|
cleanup
|
194 |
my $first_author = $rows->[0][0]; |
195 |
my $first_title = $rows->[0][1]; |
|
196 |
my $second_author = $rows->[1][0]; |
|
197 |
my $second_value = $rows->[1][1]; |
|
198 |
|
|
removed reconnect method
|
199 |
} |
200 |
|
|
201 |
# Fetch all rows into array of array |
|
202 |
my $rows = $result->fetch_all; |
|
cleanup
|
203 | |
204 |
Fetch row into hash. |
|
205 | ||
206 |
# Fetch a row into hash |
|
removed reconnect method
|
207 |
while (my $row = $result->fetch_hash) { |
cleanup
|
208 |
my $title = $row->{title}; |
209 |
my $author = $row->{author}; |
|
removed reconnect method
|
210 |
|
packaging one directory
|
211 |
} |
removed reconnect method
|
212 |
|
cleanup
|
213 |
# Fetch only a first row into hash |
removed reconnect method
|
214 |
my $row = $result->fetch_hash_first; |
215 |
|
|
216 |
# Fetch multiple rows into array of hash |
|
cleanup
|
217 |
while (my $rows = $result->fetch_hash_multi(5)) { |
218 |
my $first_title = $rows->[0]{title}; |
|
219 |
my $first_author = $rows->[0]{author}; |
|
220 |
my $second_title = $rows->[1]{title}; |
|
221 |
my $second_author = $rows->[1]{author}; |
|
222 |
|
|
removed reconnect method
|
223 |
} |
224 |
|
|
225 |
# Fetch all rows into array of hash |
|
226 |
my $rows = $result->fetch_hash_all; |
|
packaging one directory
|
227 | |
update document
|
228 |
=head1 ATTRIBUTES |
packaging one directory
|
229 | |
removed DBIx::Custom commit ...
|
230 |
=head2 C<sth> |
packaging one directory
|
231 | |
cleanup
|
232 |
my $sth = $reuslt->sth |
version 0.0901
|
233 |
$result = $result->sth($sth); |
many many changes
|
234 | |
cleanup
|
235 |
Statement handle of L<DBI>. |
removed DESTROY method(not b...
|
236 | |
237 |
=head2 C<default_filter> |
|
many many changes
|
238 | |
cleanup
|
239 |
my $default_filter = $result->default_filter; |
240 |
$result = $result->default_filter('decode_utf8'); |
|
many many changes
|
241 | |
cleanup
|
242 |
Default filter when a row is fetched. |
packaging one directory
|
243 | |
removed DESTROY method(not b...
|
244 |
=head2 C<filter> |
update document
|
245 | |
cleanup
|
246 |
my $filter = $result->filter; |
cleanup
|
247 |
$result = $result->filter({title => 'decode_utf8', |
248 |
author => 'decode_utf8'}); |
|
packaging one directory
|
249 | |
cleanup
|
250 |
Filters when a row is fetched. |
251 |
This overwrites C<default_filter>. |
|
removed DESTROY method(not b...
|
252 | |
update document
|
253 |
=head1 METHODS |
254 | ||
cleanup
|
255 |
L<DBIx::Custom::Resutl> inherits all methods from L<Object::Simple> |
256 |
and implements the following new ones. |
|
packaging one directory
|
257 | |
removed DBIx::Custom commit ...
|
258 |
=head2 C<fetch> |
packaging one directory
|
259 | |
cleanup
|
260 |
my $row = $result->fetch; |
version 0.0901
|
261 | |
cleanup
|
262 |
Fetch a row into array. |
packaging one directory
|
263 | |
removed DBIx::Custom commit ...
|
264 |
=head2 C<fetch_first> |
update document
|
265 | |
cleanup
|
266 |
my $row = $result->fetch_first; |
packaging one directory
|
267 | |
cleanup
|
268 |
Fetch only a first row into array and finish statment handle. |
packaging one directory
|
269 | |
removed DESTROY method(not b...
|
270 |
=head2 C<fetch_multi> |
update document
|
271 | |
cleanup
|
272 |
my $rows = $result->fetch_multi(5); |
packaging one directory
|
273 |
|
removed DESTROY method(not b...
|
274 |
Fetch multiple rows into array of array. |
cleanup
|
275 |
Row count must be specified. |
packaging one directory
|
276 | |
removed DBIx::Custom commit ...
|
277 |
=head2 C<fetch_all> |
packaging one directory
|
278 | |
cleanup
|
279 |
my $rows = $result->fetch_all; |
version 0.0901
|
280 | |
removed DESTROY method(not b...
|
281 |
Fetch all rows into array of array. |
packaging one directory
|
282 | |
removed DESTROY method(not b...
|
283 |
=head2 C<fetch_hash> |
packaging one directory
|
284 | |
cleanup
|
285 |
my $row = $result->fetch_hash; |
packaging one directory
|
286 | |
removed DESTROY method(not b...
|
287 |
Fetch a row into hash |
update document
|
288 | |
removed DBIx::Custom commit ...
|
289 |
=head2 C<fetch_hash_first> |
removed reconnect method
|
290 |
|
cleanup
|
291 |
my $row = $result->fetch_hash_first; |
packaging one directory
|
292 | |
removed DESTROY method(not b...
|
293 |
Fetch only first row into hash and finish statment handle. |
packaging one directory
|
294 | |
removed DESTROY method(not b...
|
295 |
=head2 C<fetch_hash_multi> |
update document
|
296 | |
cleanup
|
297 |
my $rows = $result->fetch_hash_multi(5); |
update document
|
298 |
|
removed DESTROY method(not b...
|
299 |
Fetch multiple rows into array of hash |
cleanup
|
300 |
Row count must be specified. |
update document
|
301 | |
removed DBIx::Custom commit ...
|
302 |
=head2 C<fetch_hash_all> |
packaging one directory
|
303 | |
cleanup
|
304 |
my $rows = $result->fetch_hash_all; |
packaging one directory
|
305 | |
removed DESTROY method(not b...
|
306 |
Fetch all rows into array of hash. |
307 | ||
packaging one directory
|
308 |
=cut |