cache sidebar structure to avoid directory scans every request
[scpubgit/SCS.git] / lib / SCSite / Page.pm
1 package SCSite::Page;
2
3 use IO::All;
4 use Time::Local qw(timelocal);
5 use Moo;
6
7 has $_ => (is => 'ro') for qw(
8   title subtitle description keywords body created path
9 );
10
11 sub published_at {
12   $_[0]->created
13     ? scalar localtime timelocal
14         map +(@{$_}[0..3], $_->[4]-1, $_->[5]-1900),
15           [ reverse split '\D+', $_[0]->created ]
16     : ''
17 }
18
19 has "_$_" => (is => 'ro', init_arg => $_) for qw(page_set);
20
21 sub children {
22   my ($self, %args) = @_;
23   if (my $at = delete $args{at_depth}) {
24     @args{qw(min_depth max_depth)} = ($at, $at);
25   }
26   my $ps = $self->_page_set;
27   (ref $ps)->new(
28     top_dir => $ps->base_dir,
29     base_dir => io->dir($ps->base_dir)->catdir($self->path),
30     max_depth => 1,
31     %args,
32   );
33 }
34
35 1;