using value/related_object for related objects
[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 use namespace::clean -except => [ qw(meta) ];
9
10
11 #has paged_collection => (isa => Collection, is => 'rw', lazy_build => 1);
12
13 has pager    => (isa => 'Data::Page', is => 'rw', lazy_build => 1);
14 has page     => (isa => 'Int', is => 'rw', lazy_build => 1, trigger_adopt('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 };
21 sub adopt_page {
22   my ($self) = @_;
23   #$self->clear_paged_collection;
24
25   $self->clear_pager;
26   $self->clear_current_collection;
27 };
28
29 around accept_events => sub { ('page','per_page', shift->(@_)); };
30
31 #implements build_paged_collection => as {
32 #  my ($self) = @_;
33 #  my $collection = $self->current_collection;
34 #  return $collection->where(undef, {rows => $self->per_page})->page($self->page);
35 #};
36
37 around _build_current_collection => sub {
38   my $orig = shift;
39   my ($self) = @_;
40   my $collection = $orig->(@_);
41   return $collection->where(undef, {rows => $self->per_page})->page($self->page);
42 };
43
44
45
46 1;