X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSCSite%2FPageSet.pm;fp=lib%2FSCSite%2FPageSet.pm;h=c5854fb825de76f625982c5c6c28dd46e3faf2de;hb=cbb06a720cd579a1754fc772ee4ce73cd99d921b;hp=60a2a62080ee1080adc1fa0c527b149babe9fae8;hpb=0fb543cdf1fbd8edf05c4020b853ee4ae73c72b6;p=scpubgit%2FSCS.git diff --git a/lib/SCSite/PageSet.pm b/lib/SCSite/PageSet.pm index 60a2a62..c5854fb 100644 --- a/lib/SCSite/PageSet.pm +++ b/lib/SCSite/PageSet.pm @@ -10,6 +10,8 @@ use Try::Tiny; use JSON; use Moo; +with 'SCSite::PageChildren'; + { my $j = JSON->new; sub _json { $j } @@ -28,6 +30,10 @@ sub _build_rel_path { ->catdir(File::Spec->abs2rel($self->base_dir->name, $self->top_dir->name)) } +sub _page_set_class { ref($_[0]) } +sub _top_dir { shift->top_dir } +sub _my_path { shift->base_dir } + sub get { my ($self, $spec) = @_; $spec->{path} or die "path is required to get"; @@ -83,10 +89,7 @@ sub _depth_under_base { sub flatten { my ($self) = @_; - return unless (my $base = $self->base_dir)->exists; - my %seen; my $slash = io->dir('/'); - my $min = $self->min_depth; map { my ($path, $type) = $_->name =~ /^(.*)${\$self->_types_re}$/; $self->_inflate( @@ -94,7 +97,24 @@ sub flatten { $slash->catdir(File::Spec->abs2rel($path, $self->top_dir->name)), $_ ); - } map { + } $self->_all_files; +} + +sub all_paths { + my ($self) = @_; + my $slash = io->dir('/'); + map { + my ($path, $type) = $_->name =~ /^(.*)${\$self->_types_re}$/; + $slash->catdir(File::Spec->abs2rel($path, $self->top_dir->name))->name, + } $self->_all_files; +} + +sub _all_files { + my ($self) = @_; + return unless (my $base = $self->base_dir)->exists; + my %seen; + my $min = $self->min_depth; + map { $_->filter(sub { $_->filename =~ /${\$self->_types_re}$/ }) ->all_files($self->max_depth - ($min-1)) } map