Skip to content

Instantly share code, notes, and snippets.

@hatyuki
Created January 18, 2010 02:52
Show Gist options
  • Save hatyuki/279746 to your computer and use it in GitHub Desktop.
Save hatyuki/279746 to your computer and use it in GitHub Desktop.
package MyApp::Model;
use DBIx::Skinny;
use MyApp::Model::Iterator;
{
no warnigns 'redefine';
*_get_sth_iterator = sub {
my ($class, $sql, $sth, $opt_table_info) = @_;
return MyApp::Model::Iterator->new(
skinny => $class,
sth => $sth,
row_class => $class->_mk_row_class($sql, $opt_table_info),
opt_table_info => $opt_table_info
);
};
}
1;
package MyApp::Model::Iterator;
use base qw/ DBIx::Skinny::Iterator /;
use strict;
use warnings;
sub to_json
{
my $self = shift;
my $data;
while (my $row = $self->next) {
push @$data, $row->get_columns;
}
return $data
? JSON::XS->new->pretty(1)->utf8->encode($data)
: undef;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment