Web::Util::ExtPaging - Paginate DBIx::Class::ResultSets for ExtJS consumption
version 0.001003
package MyApp::People; use Web::Simple; use JSON::MaybeXS; use Web::Util::ExtPaging; sub dispatch_request { my $people_rs = get_rs(); sub (/people) { [ 200, [ 'Content-type', 'application/json' ], [ encode_json(ext_paginate($rs->search(undef, { rows => 25 }))) ], ] }, sub (/people_lite) { [ 200, [ 'Content-type', 'application/json' ], [ encode_json(ext_paginate( $rs->search(undef, { rows => 25 }), sub { my $person = shift; return { first_name => $person->first_name, last_name => $person->last_name, } }, )) ], ] }, sub (/people_more_different) { [ 200, [ 'Content-type', 'application/json' ], [ # this will call the 'foo' method on each person and put the # returned value into the datastructure encode_json(ext_paginate( $rs->search(undef, { rows => 25 }), 'foo', )) ], ] }, sub (/programmers_do_it_by_hand) { [ 200, [ 'Content-type', 'application/json' ], [ encode_json(ext_parcel([qw( foo bar baz )], 10)) ], ] }, sub (/programmers_do_it_by_hand_partially) { [ 200, [ 'Content-type', 'application/json' ], # defaults total to amount of items passed in [ encode_json(ext_parcel([qw( foo bar baz )])) ], ] }, sub () { [ 404, [ 'Content-type', 'text/plain' ], [ 'not found' ] ] } }
This module is mostly for sending DBIx::Class paginated data to ExtJS based javascript code.
my $json = ext_paginate($resultset, { root => 'root' }); my $json_str = json_encode($json);
Returns a structure like the following from the ResultSet:
{ data => \@results, total => $count_before_pagination }
rs - paginated ResultSet to get the data from (optional) coderef - any valid scalar that can be called on the result object (optional) config - passed to ext_parcel
my $items = [qw{foo bar baz}]; my $total = 7; my $json = $self->ext_parcel($data, $total, { root => 'root' }); my $json_str = to_json($json);
Returns a structure like the following:
{ data => [@{$items}], total => $total || scalar @{$items} }
list - a list of anything you want to be in the data structure total - whatever you want to say the total is. Defaults to size of the list passed in. (optional) config - a hashref containing root or total_property. root is the key used to store the data under, total_property is the key used to store the total under
Catalyst::TraitFor::Controller::DoesExtPaging, which this module was factored out of.
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
This software is copyright (c) 2015 by Arthur Axel "fREW" Schmidt.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Web::Util::ExtPaging, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Web::Util::ExtPaging
CPAN shell
perl -MCPAN -e shell install Web::Util::ExtPaging
For more information on module installation, please visit the detailed CPAN module installation guide.