Showing 1 changed files with 49 additions and 46 deletions
+49 -46
lib/DBI/Custom.pm
... ...
@@ -182,7 +182,10 @@ sub query {
182 182
     # Select
183 183
     if ($sth->{NUM_OF_FIELDS}) {
184 184
         my $result_class = $self->result_class;
185
-        my $result = $result_class->new({sth => $sth});
185
+        my $result = $result_class->new({
186
+            sth => $sth,
187
+            fetch_filter => $self->fetch_filter
188
+        });
186 189
         return $result;
187 190
     }
188 191
     return $ret_val;
... ...
@@ -192,7 +195,7 @@ sub query {
192 195
 sub query_raw_sql {
193 196
     my ($self, $sql, @bind) = @_;
194 197
     
195
-    $sefl->connect unless $self->connected;
198
+    $self->connect unless $self->connected;
196 199
     my $sth = $self->dbh->prepare($sql);
197 200
     $sth->execute(@bind);
198 201
     return $sth;
... ...
@@ -205,17 +208,54 @@ Object::Simple->build_class;
205 208
 package DBI::Custom::Result;
206 209
 use Object::Simple;
207 210
 
208
-sub sth : Attr {};
211
+sub sth : Attr {}
212
+sub fetch_filter {}
209 213
 
210 214
 sub fetchrow_arrayref {
211 215
     my $self = shift;
212
-    $self->sth;
216
+    my $sth = $self->{sth};
217
+    
218
+    my $array = $sth->fetchrow_arrayref;
219
+    
220
+    return $array unless $array;
213 221
     
222
+    my $keys = $sth->{NAME_lc};
214 223
     
224
+    for (my $i = 0; $i < @$keys; $i++) {
225
+        $array->[$i] = $self->fetch_filter($keys->[$i], $array->[$i]);
226
+    }
227
+    return $array;
215 228
 }
216 229
 
230
+sub fetchrow_array {
231
+    my $self = shift;
232
+    my $sth = $self->{sth};
233
+    
234
+    my @array = $sth->fetchrow_array;
235
+    
236
+    return unless @array;
237
+    
238
+    my $keys = $sth->{NAME_lc};
239
+    
240
+    for (my $i = 0; $i < @$keys; $i++) {
241
+        $array[$i] = $self->fetch_filter($keys->[$i], $array[$i]);
242
+    }
243
+    return @array;
244
+}
217 245
 
218
-*fetch = \&fetchrow_arrayref;
246
+sub fetchrow_hashref {
247
+    my $self = shift;
248
+    my $sth = $self->{sth};
249
+    
250
+    my $hash = $sth->fetchrow_hashref;
251
+    
252
+    return unless $hash;
253
+    
254
+    foreach my $key (keys %$hash) {
255
+        $hash->{$key} = $self->fetch_filter($key, $hash->{$key});
256
+    }
257
+    return $hash;
258
+}
219 259
 
220 260
 sub err    { shift->sth->err }
221 261
 sub errstr { shift->sth->errstr }
... ...
@@ -460,51 +500,14 @@ Version 0.0101
460 500
 
461 501
 =head2 result_class
462 502
 
463
-=head1 AUTHOR
464
-
465
-Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
466
-
467
-=head1 BUGS
503
+=head2 commit
468 504
 
469
-Please report any bugs or feature requests to C<bug-dbi-custom at rt.cpan.org>, or through
470
-the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBI-Custom>.  I will be notified, and then you'll
471
-automatically be notified of progress on your bug as I make changes.
505
+=head2 rollback
472 506
 
473 507
 
508
+=head1 AUTHOR
474 509
 
475
-
476
-=head1 SUPPORT
477
-
478
-You can find documentation for this module with the perldoc command.
479
-
480
-    perldoc DBI::Custom
481
-
482
-
483
-You can also look for information at:
484
-
485
-=over 4
486
-
487
-=item * RT: CPAN's request tracker
488
-
489
-L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBI-Custom>
490
-
491
-=item * AnnoCPAN: Annotated CPAN documentation
492
-
493
-L<http://annocpan.org/dist/DBI-Custom>
494
-
495
-=item * CPAN Ratings
496
-
497
-L<http://cpanratings.perl.org/d/DBI-Custom>
498
-
499
-=item * Search CPAN
500
-
501
-L<http://search.cpan.org/dist/DBI-Custom/>
502
-
503
-=back
504
-
505
-
506
-=head1 ACKNOWLEDGEMENTS
507
-
510
+Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
508 511
 
509 512
 =head1 COPYRIGHT & LICENSE
510 513