enable SSI
[scpubgit/App-SCS.git] / lib / App / SCS / LatestPageSet.pm
CommitLineData
f50b4a35 1package App::SCS::LatestPageSet;
2
3use Moo;
4
5has _parent => (is => 'ro', required => 1, init_arg => 'parent');
6has _max_entries => (is => 'ro', required => 1, init_arg => 'max_entries');
7
8sub 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
17sub map {
18 my ($self, $mapper) = @_;
19 [ map $mapper->($_), $self->flatten ]
20}
21
221;