Blog-Blosxom
view release on metacpan or search on metacpan
lib/Blog/Blosxom.pm view on Meta::CPAN
my $curdepth = File::Spec->splitdir($rel_path);
my $fex = $self->{file_extension};
# not specifying a file extension is a bit silly.
if (!$fex || /\.$fex$/) {
no warnings "once"; # File::Find::name causes a warning.
my $rel_file = File::Spec->catfile( $rel_path, $_ );
$rel_file = File::Spec->canonpath($rel_file); # This removes any artefacts like ./
my $date = $self->date_of_post($File::Find::name);
my $file_info = { date => $date };
push @entries, [$rel_file, $file_info ];
}
$File::Find::prune = ($self->{depth} && $curdepth > $self->{depth});
};
File::Find::find( $find, $abs_path );
}
else {
# We use date stuff on a fake path.
# TODO: see whether we can split the path into a date section and a real section.
my @ymd = File::Spec->splitdir( $path );
my @all_entries = $self->entries_for_path( "" );
my @entries = grep {
my $post_date = localtime( $_->[1]{date} );
# requested year
($ymd[0] == ($post_date->year+1900))
and
# matches month, or moth not requested
(!$ymd[1] || $ymd[1] == ($post_date->mon+1))
and
# matches day, or day not rquested
(!$ymd[2] || $ymd[2] == $post_date->mday)
? $_ : ()
} @all_entries;
}
return @entries;
}
=head2 date_of_post ($fn)
Return a unix timestamp defining the date of the post. The filename provided to
the method is an absolute filename.
=cut
sub date_of_post {
my ($self, $fn) = @_;
my $dop;
return $dop if $dop = $self->_check_plugins("date_of_post", @_);
return stat($fn)->mtime;
}
=head2 filter (@entries)
This function returns only the desired entries from the array passed in. By
default it just returns the array back, so is just a place to check for plugins.
This can be overridden by plugins in order to alter the way the module filters
the files. See L<PLUGINS> for more details.
=cut
sub filter {
my ($self, @entries) = @_;
my @remaining_files = $self->_check_plugins("filter", @_);
return @remaining_files || @entries;
}
=head2 sort (@entries)
Sort @entries and return the new list.
Default behaviour is to sort by date.
=cut
sub sort {
my ($self, @entries) = @_;
my @sorted_entries;
return @sorted_entries if @sorted_entries = $self->_check_plugins("sort", @_);
@sorted_entries = sort { $a->[1]->{date} <=> $b->[1]->{date} } @entries;
return @sorted_entries;
}
=head2 static_mode($password, $on)
Sets static mode. Pass in the password to turn it on. Turns it off if it is already on.
=cut
sub static_mode {
my ($self, $password, $on) = @_;
die "No static dir defined" unless $self->{static_dir};
die "No static publishing password defined" unless $self->{static_password};
# Set it to toggle if we don't specify.
$on = !$self->{static_mode} if !defined $on;
if ($self->{static_mode} && !$on) {
$self->{static_mode} = 0;
$blosxom::static_or_dynamic = 'dynamic';
return;
}
if ($on && $password eq $self->{static_password}) {
( run in 1.346 second using v1.01-cache-2.11-cpan-39bf76dae61 )