Apache-Blog

 view release on metacpan or  search on metacpan

Blog.pm  view on Meta::CPAN


	# second line is the date
	my $date = <$fh>;

	# the rest is the entry
	my $entry;
	{ local $/=undef;
	  $entry = <$fh>;
	};

	# get the unixtime of the entry too (%s is the Date::Manip way
	# of saying "seconds since the epoch")
	my $unixtime = Date::Manip::UnixDate($date ,'%s');

	# and fix up the date
	$date = POSIX::strftime( '%a %d %b %y %H:%M', localtime $unixtime );

	# see if we can get any comments
	my $comments_ref = [];
	if (-d "$filename-comment") {
		my @comments = Apache::Blog::Entry->get_all( "$filename-comment" );
		$comments_ref = \@comments;
	} # end comment if


	# store those results (wonder if there's a better way to count
	# words than scalar( @{[split /\s+/, $entry]} )
	my %self = (  date => $date,
		      unixtime => $unixtime,
		      entry => $entry,
		      short_name => $short_name,
		      filepath => $filename,
		      filename => basename( $filename ),
	              wc => scalar( @{[split /\s+/, $entry]} ), 
		      comments => $comments_ref,
		   );

	return bless(\%self, $class);
} # end new

sub date { return shift->{date} };
sub unixtime { return shift->{unixtime} };
sub short_name { return shift->{short_name} };
sub filename { return shift->{filename} };
sub filepath { return shift->{filepath} };
sub wc { return shift->{wc} };
sub comments { return @{ shift->{comments} } };

# does simple html-formatting of the plain text
sub entry {
	my $self = shift;

Blog.pm  view on Meta::CPAN

	my ($class, $dir) = @_;

	# get all of the details of all of the entries
	opendir DIR, $dir;
	my @entries = map { Apache::Blog::Entry->new( $dir."/".$_ ) }
	              grep !/\.html$/ && !/^\./ && !(-d $dir."/".$_), readdir DIR;
	closedir DIR;

	# now sort those
	my @out_entries;
	foreach my $entry (sort { $b->unixtime <=> $a->unixtime } @entries) {
		push @out_entries, $entry;
	} # end foreach

	return @out_entries;
} # end get_all



package Apache::Blog;



( run in 0.609 second using v1.01-cache-2.11-cpan-39bf76dae61 )