At work we're thriving to conform to the ITIL guidelines. This entails a detailed change management for our infrastructure. Change dates, authors and possible impact are tracked in our Technical Change Management System.
This is all nice and shiny, but how do you get this information to the individual administrator? To put it politely, the interface itself doesn't invite casual browsing. However that's a technical problem. And this time the solution was to write a simple Perl script using
Mojolicious. Mojolicous documentation is sparse at the moment, but the cheat sheet contains a note about simply calling
$self->render(format => 'rss');
during the render. I did just that, supplied a proper rss template and it just worked out of the box. The following code just dumps some test data into port 80.
use Mojolicious::Lite;
use strict;
use warnings;
my $data = [
{ author => 'Mark', title => 'Post to blog', description => 'Yadda.',
date => 'Wed, 02 Oct 2002 13:00:00 GMT'},
{ author => 'Mork', title => 'Scratch an itch', description => 'Yadda',
date => 'Wed, 02 Oct 2002 15:00:00 +0200'},
];
get '/changefeed' => sub {
my $self = shift;
$self->stash('items', $data);
$self->render(format => 'rss');
$self->render('changefeed');
};
app->start;
__DATA__
@@ changefeed.rss.ep
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>The Internation House of Mojo</title>
<link>http://houseofmojo.com</link>
<description>Current changes in our IT</description>
<copyright>The Witch</copyright>
% foreach my $item (@$items) {
<item>
<title><%= $item->{title} %></title>
<description><%= $item->{description} %></description>
<author><%= $item->{author} %></author>
<pubDate><%= $item->{date} %></pubDate>
</item>
% }
</channel>
</rss>
Testing is simple, save it to changefeed.pl and hit
perl changefeed.pl daemon
The above fragment is half code, half template. Even for someone who is dead set against using a framework for web development this is a good ratio. Of course Mojolicous tagline is to grow your application organically by introducing advanced concepts as you go.
If you want to generate the data from the database, the gotcha is to generate an RFC822 date. You can do this either by using DateTime::Format or you can format the date right in the database. I prefer the latter. In MS SQL Server this looks like the following.
left(datename( dw, your_date_column ), 3 ) + ', ' +
convert( varchar(20), your_date_column, 113 ) + ' GMT' as date