factor out child code into PageChildren and add an all_paths method to PageSet
[scpubgit/SCS.git] / lib / SCSite / Page.pm
index 7d09627..028483e 100644 (file)
@@ -4,6 +4,8 @@ use IO::All;
 use Time::Local qw(timelocal);
 use Moo;
 
+with 'SCSite::PageChildren';
+
 has $_ => (is => 'ro') for qw(
   title subtitle description keywords body created path
 );
@@ -18,18 +20,8 @@ sub published_at {
 
 has "_$_" => (is => 'ro', init_arg => $_) for qw(page_set);
 
-sub children {
-  my ($self, %args) = @_;
-  if (my $at = delete $args{at_depth}) {
-    @args{qw(min_depth max_depth)} = ($at, $at);
-  }
-  my $ps = $self->_page_set;
-  (ref $ps)->new(
-    top_dir => $ps->base_dir,
-    base_dir => io->dir($ps->base_dir)->catdir($self->path),
-    max_depth => 1,
-    %args,
-  );
-}
+sub _page_set_class { ref($_[0]->_page_set) }
+sub _top_dir { $_[0]->_page_set->top_dir }
+sub _my_path { io->dir($_[0]->_top_dir)->catdir($_[0]->path) }
 
 1;