Following on from a comment on a previous post, this post will demonstrate how to use XML::Feed and Template::Toolkit to format your recent Stackoverflow activity, suitable for including on your own web page. Aptly, this was aided by a stackoverflow question!
This time we can use XML::Feed both to get and parse the feed:
use XML::Feed;
my $feed = XML::Feed->parse(URI->new('http://stackoverflow.com/feeds/user/1691146'));
We need to adapt the template to account for XML::Feed’s differences:
my $template = <<"TEMPLATE";
[% feed.title %]
Activity:
[% FOREACH item = feed.items %]
[% item.issued.dmy %] [% item.issued.hms %]t[% item.title %]
[% END %]
TEMPLATE
And the template toolkit invocation:
$tt->process( $template, { 'feed' => $feed } )
or die $tt->error();
Full example:
#!/usr/bin/perl
use strict;
use warnings;
use XML::Feed;
use Template;
my $stackoverflow_id = 1691146;
my $stackoverflow_url = "http://stackoverflow.com/feeds/user/$stackoverflow_id";
my $template = <<"TEMPLATE";
[% feed.title %]
Activity:
[% FOREACH item = feed.items %]
[% item.issued.dmy %] [% item.issued.hms %]t[% item.title %]
[% END %]
TEMPLATE
my $tt = Template->new( 'STRICT' => 1 )
or die "Failed to load template: $Template::ERRORn";
my $feed = XML::Feed->parse(URI->new($stackoverflow_url));
$tt->process( $template, { 'feed' => $feed } )
or die $tt->error();
This is still a really simple script with added support for Atom feeds.