branching
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Collection / Role / Pager.pm
1 package Reaction::UI::ViewPort::Collection::Role::Pager;
2
3 use Reaction::Role;
4
5 use aliased 'Reaction::InterfaceModel::Collection';
6
7 # XX This needs to be consumed after Ordered
8 role Pager, which {
9
10   #has paged_collection => (isa => Collection, is => 'rw', lazy_build => 1);
11
12   has pager    => (isa => 'Data::Page', is => 'rw', lazy_build => 1);
13   has page     => (isa => 'Int', is => 'rw', lazy_build => 1, trigger_adopt('page'));
14   has per_page => (isa => 'Int', is => 'rw', lazy_build => 1, trigger_adopt('page'));
15   has per_page_max => (isa => 'Int', is => 'rw', lazy_build => 1);
16
17   implements _build_page     => as { 1  };
18   implements _build_per_page => as { 10 };
19   implements _build_per_page_max => as { 100 };
20
21   implements _build_pager => as { shift->current_collection->pager };
22
23   implements adopt_page => as {
24     my ($self) = @_;
25     #$self->clear_paged_collection;
26
27     $self->clear_pager;
28     $self->clear_current_collection;
29   };
30
31   around accept_events => sub { ('page','per_page', shift->(@_)); };
32
33   #implements build_paged_collection => as {
34   #  my ($self) = @_;
35   #  my $collection = $self->current_collection;
36   #  return $collection->where(undef, {rows => $self->per_page})->page($self->page);
37   #};
38
39   around _build_current_collection => sub {
40     my $orig = shift;
41     my ($self) = @_;
42     my $collection = $orig->(@_);
43     return $collection->where(undef, {rows => $self->per_page})->page($self->page);
44   };
45
46 };
47
48 1;