1 package Reaction::UI::ViewPort::Collection::Role::Pager;
5 use aliased 'Reaction::InterfaceModel::Collection';
7 # XX This needs to be consumed after Ordered
8 use namespace::clean -except => [ qw(meta) ];
11 #has paged_collection => (isa => Collection, is => 'rw', lazy_build => 1);
13 has pager => (isa => 'Data::Page', is => 'rw', lazy_build => 1);
14 has page => (isa => 'Int', is => 'rw', lazy_build => 1, trigger_adopt('page'), clearer => 'clear_page');
15 has per_page => (isa => 'Int', is => 'rw', lazy_build => 1, trigger_adopt('page'));
16 has per_page_max => (isa => 'Int', is => 'rw', lazy_build => 1);
17 sub _build_page { 1 };
18 sub _build_per_page { 10 };
19 sub _build_per_page_max { 100 };
20 sub _build_pager { shift->current_collection->pager };
23 #$self->clear_paged_collection;
26 $self->clear_current_collection;
29 after clear_page => sub {
32 $self->clear_current_collection;
35 around accept_events => sub { ('page','per_page', shift->(@_)); };
37 #implements build_paged_collection => as {
39 # my $collection = $self->current_collection;
40 # return $collection->where(undef, {rows => $self->per_page})->page($self->page);
43 around _build_current_collection => sub {
46 my $collection = $orig->(@_);
47 return $collection->where(undef, {rows => $self->per_page})->page($self->page);