---
layout: post
title: A simple feed aggregator with modern Perl - part 4
summary: In which we reach the conclusion on how to write a feed aggregator.
---
We have the model, the aggregator (and some tests), now we can do a basic frontend to read our feed. For this I will create a webapp using [Catalyst](http://www.catalystframework.org).
[Catalyst::Devel](http://search.cpan.org/perldoc?Catalyst::Devel) is required for developping catalyst application, so we will install it first:
{% highlight perl %}
% cpan Catalyst::Devel
{% endhighlight %}
Now we can create our catalyst application using the helper:
{% highlight perl %}
% catalyst.pl MyFeedReader
{% endhighlight %}
This command initialise the framework for our application **MyFeedReader**. A number of files are created, like the structure of the MVC directory, some tests, helpers, ...
We start by creating a view, using [TTSite](http://search.cpan.org/perldoc?Catalyst::View::TT). TTSite generate some templates for us, and the configuration for this template. We will also have a basic CSS, a header, footer, etc.
{% highlight bash %}
cd MyFeedReader
perl script/myfeedreader_create.pl view TT TTSite
{% endhighlight %}
TTSite files are under **root/src** and **root/lib**. A **MyAggregator/View/TT.pm** file is also created. We edit it to make it look like this:
{% highlight perl %}
__PACKAGE__->config({
INCLUDE_PATH => [
MyFeedReader->path_to( 'root', 'src' ),
MyFeedReader->path_to( 'root', 'lib' )
],
PRE_PROCESS => 'config/main',
WRAPPER => 'site/wrapper',
ERROR => 'error.tt2',
TIMER => 0,
TEMPLATE_EXTENSION => '.tt2',
});
{% endhighlight %}
Now we create our first template, in **root/src/index.tt2**
{% highlight html %}
to your feeds
{% endhighlight %}
If you start the application (using `perl script/myfeedreader_server.pl`) and point your browser on http://localhost:3000/, this template will be rendered.
We need two models, one for KiokuDB and another one for MyModel:
**lib/MyFeedReader/Model/KiokuDB.pm**
{% highlight perl %}
package MyFeedReader::Model::KiokuDB;
use Moose;
BEGIN { extends qw(Catalyst::Model::KiokuDB) }
1;
{% endhighlight %}
we edit the configuration file (**myfeedreader.conf**), and set the dsn for our kiokudb backend
{% highlight xml %}
Now the controller for displaying the entries:
{% highlight perl %}
package MyFeedReader::Controller::Entry;
use strict;
use warnings;
use MyAggregator::Entry;
use parent 'Catalyst::Controller';
__PACKAGE__->config->{namespace} = 'entry';
sub view : Chained('/') : PathPart('entry') : Args(1) {
my ( $self, $c, $id ) = @_;
$c->stash->{entry} = $c->model('KiokuDB')->lookup($id);
}
1;
{% endhighlight %}
The function **view** fetch an entry from the kiokudb backend, and store it in the stash, so we can use it in our template.
**root/src/entry/view.tt2**
{% highlight html %}
Et voila, we are done with a really basic feed reader. You can add methods to add or delete feed, mark an entry as read, ...
[The code is available on my git server](http://git.lumberjaph.net/p5-ironman-myfeedreader.git/).