#!/usr/bin/perl
use warnings;
use URI;
use File::stat;
use XML::Atom::SimpleFeed;
use POSIX qw( strftime );
use XML::Tidy;
my $appdir="/Users/phil/atom/app/";
my $urlbase = "http://foo.bar";
my $urldir = "appcast";
my $appurl="$urlbase/$urldir";
my $dirbase = "/Users/phil/atom";
my $feed = XML::Atom::SimpleFeed->new(
title => 'Example Feed',
link => 'http://example.org/',
link => { rel => 'self', href => 'http://example.org/atom', },
updated => '2003-12-13T18:30:02Z',
author => 'John Doe',
);
opendir(D, "$appdir") || die "Can't open directory $appdir: $!\n";
my @files = readdir(D);
closedir(D) || die "Can't close dir $appdir\n";
if ( $sort ) {
@files = reverse(sort(@files));
}
foreach my $file ( @files ) {
next if $file !~ /\.[Zz][Ii][Pp]$/i;
my $filePath="$appdir/$file";
my @stat = stat($filePath);
my $filesize = stat($filePath)->size;
my ($zipname) = ( $file =~ /^(.+?)\.zip/i );
my $date = strftime '%Y-%m-%dT%H:%M:%SZ', gmtime;
$feed->add_entry(
title => $zipname,
link => $appurl,
id => 'urn:uuid:1234-56-78910',
summary => 'Some text.',
updated => $date,
category => 'Atom',
category => 'Miscellaneous',
);
}
my $text_section = $feed->as_string();
my $tidied_section = XML::Tidy->new('xml', $text_section); # or do it in one line
$tidied_section->tidy;
$tidied_section->write;
$feed->print