package SCSite::LatestPageSet;

use Moo;

has _parent => (is => 'ro', required => 1, init_arg => 'parent');
has _max_entries => (is => 'ro', required => 1, init_arg => 'max_entries');

sub flatten {
  my ($self) = @_;
  my @sorted = sort {
    $a->created cmp $b->created
  } $self->_parent->flatten;
  $self->_max_entries ? @sorted[0..$self->_max_entries-1] : @sorted;
}

sub map {
  my ($self, $mapper) = @_;
  [ map $mapper->($_), $self->flatten ]
}

1;
