enable SSI
[scpubgit/App-SCS.git] / lib / App / SCS / LatestPageSet.pm
1 package App::SCS::LatestPageSet;
2
3 use Moo;
4
5 has _parent => (is => 'ro', required => 1, init_arg => 'parent');
6 has _max_entries => (is => 'ro', required => 1, init_arg => 'max_entries');
7
8 sub flatten {
9   my ($self) = @_;
10   my @sorted = sort {
11     $b->created cmp $a->created
12   } $self->_parent->flatten;
13   my $max = $self->_max_entries||0;
14   $max && @sorted > $max ? @sorted[0..$max-1] : @sorted;
15 }
16
17 sub map {
18   my ($self, $mapper) = @_;
19   [ map $mapper->($_), $self->flatten ]
20 }
21
22 1;