#!/usr/bin/perl -w
#
# cpanfeed2html - Fetch a feed of new CPAN releases and generate HTML list
#
# Copyright (c) 2008 EPIPE Communications
#
# Permission to use, copy, modify, and/or distribute this software
# for any purpose with or without fee is hereby granted, provided
# that the above copyright notice and this permission notice appear
# in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
#
# Version: 1.0
#
# Version history:
#
# - 1.0: initial release (2008-11-19)
#
# Download location:
#
# http://dist.epipe.com/perl/
#
# Author contact information:
#
# info # epipe.com
# http://epipe.com/
#
# Usage:
#
# cpanfeed2html http://search.cpan.org/uploads.rdf cpan-feed.html
#
use strict;
use IO::File;
use XML::FeedPP;
use HTML::Entities;
#
sub processfeed ($$) {
my ($feedurl) = shift;
my ($outputfile) = shift;
my ($fh) = IO::File->new($outputfile . '.tmp', '>');
die "$outputfile.tmp: $!" unless defined($fh);
my ($feed) = XML::FeedPP->new($feedurl);
die "$feedurl: Can not fetch" unless defined($feed);
$feed->normalize();
$feed->limit_item(20);
my (@items) = $feed->get_item(undef);
# output list header
print $fh "
\n";
foreach (@items) {
my ($title) = $_->title();
my ($pubdate) = $_->pubDate();
my ($link) = $_->link();
my ($description) = $_->description();
my ($user, $userlink);
next unless defined($title) && defined($pubdate) && defined($link);
$title = encode_entities($title);
$description = '' unless defined($description);
$description = encode_entities($description);
$pubdate =~ s/T.*$//;
if ($link =~ m!^http://search\.cpan\.org/\~(\w+)/(.*)$!) {
$user = uc $1;
$userlink = "http://search.cpan.org/~$1/";
}
print $fh "- $pubdate: ";
print $fh "$title";
print $fh " by $user" if defined($user);
print $fh ":
$description";
print $fh " \n";
}
# output list footer
print $fh "
\n";
undef $fh;
# move new file in place
rename($outputfile . '.tmp', $outputfile);
}
# main()
if (@ARGV != 2) {
print STDERR "usage: $0 feed-URL output.html\n";
exit(2);
}
processfeed($ARGV[0], $ARGV[1]);
# eof