factor out child code into PageChildren and add an all_paths method to PageSet
[scpubgit/SCS.git] / lib / SCSite / PageChildren.pm
diff --git a/lib/SCSite/PageChildren.pm b/lib/SCSite/PageChildren.pm
new file mode 100644 (file)
index 0000000..42590f9
--- /dev/null
@@ -0,0 +1,22 @@
+package SCSite::PageChildren;
+
+use Moo::Role;
+
+requires '_page_set_class';
+requires '_top_dir';
+requires '_my_path';
+
+sub children {
+  my ($self, %args) = @_;
+  if (my $at = delete $args{at_depth}) {
+    @args{qw(min_depth max_depth)} = ($at, $at);
+  }
+  $self->_page_set_class->new(
+    top_dir => $self->_top_dir,
+    base_dir => $self->_my_path,
+    max_depth => 1,
+    %args,
+  );
+}
+
+1;