summaryrefslogtreecommitdiff
path: root/posts/2009-05-18-a-simple-feed-aggregator-with-modern-perl-part-4.1.md
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--posts/2009-05-18-a-simple-feed-aggregator-with-modern-perl-part-4.1.md (renamed from posts/2009-05-18-a-simple-feed-aggregator-with-modern-perl-part-4.1.org)74
1 files changed, 28 insertions, 46 deletions
diff --git a/posts/2009-05-18-a-simple-feed-aggregator-with-modern-perl-part-4.1.org b/posts/2009-05-18-a-simple-feed-aggregator-with-modern-perl-part-4.1.md
index 41c5526..baeba5c 100644
--- a/posts/2009-05-18-a-simple-feed-aggregator-with-modern-perl-part-4.1.org
+++ b/posts/2009-05-18-a-simple-feed-aggregator-with-modern-perl-part-4.1.md
@@ -1,11 +1,8 @@
-You can thanks [[http://github.com/bobtfish][bobtfish]] for being such a
-pedantic guy, 'cause now you will have a better chained examples. He
-forked my repository from GitHub and fix some code that I'll explain
-here.
+You can thanks [bobtfish](http://github.com/bobtfish) for being such a pedantic guy, 'cause now you will have a better chained examples. He forked my repository from GitHub and fix some code that I'll explain here.
-*** lib/MyFeedReader.pm
+### lib/MyFeedReader.pm
-#+BEGIN_SRC perl
+``` perl
package MyFeedReader;
+use Moose;
+use namespace::autoclean;
@@ -18,38 +15,32 @@ here.
-use parent qw/Catalyst/;
+extends 'Catalyst';
-#+END_SRC
+```
-You can see that he use [[http://search.cpan.org/perldoc?Moose][Moose]],
-so we can remove
+You can see that he use [Moose](http://search.cpan.org/perldoc?Moose), so we can remove
-#+BEGIN_SRC perl
+``` perl
use strict;
use warnings;
-#+END_SRC
+```
-and have a more elegant way to inherit from
-[[http://search.cpan.org/perldoc?Catalyst][Catalyst]] with
+and have a more elegant way to inherit from [Catalyst](http://search.cpan.org/perldoc?Catalyst) with
-#+BEGIN_SRC perl
+``` perl
extends 'Catalyst';
-#+END_SRC
+```
instead of
-#+BEGIN_SRC perl
+``` perl
use parent qw/Catalyst/;
-#+END_SRC
+```
-He also have updated the *Catalyst::Runtime* version, and added
-*namespace::autoclean*. The purpose of this module is to keep imported
-methods out of you namespace. Take a look at the
-"documentation":http://search.cpan.org/perldoc?namespace::autoclean,
-it's easy to understand how and why it's usefull.
+He also have updated the **Catalyst::Runtime** version, and added **namespace::autoclean**. The purpose of this module is to keep imported methods out of you namespace. Take a look at the "documentation":<http://search.cpan.org/perldoc?namespace>::autoclean, it's easy to understand how and why it's usefull.
-*** lib/MyFeedReader/Controller/Root.pm
+### lib/MyFeedReader/Controller/Root.pm
-#+BEGIN_SRC perl
+``` perl
-use strict;
-use warnings;
-use parent 'Catalyst::Controller';
@@ -72,16 +63,13 @@ it's easy to understand how and why it's usefull.
my ( $self, $c ) = @_;
$c->response->body( 'Page not found' );
$c->response->status(404);
-#+END_SRC
+```
-A new method, =root=, that will be the root path for our application.
-All our methods will be chained from this action. If start you catalyst
-server and go to *http://localhost:3000/* you will be served with the
-Catalyst's welcome message as before.
+A new method, `root`, that will be the root path for our application. All our methods will be chained from this action. If start you catalyst server and go to \*<http://localhost:3000/*> you will be served with the Catalyst's welcome message as before.
-*** lib/MyFeedReader/Controller/Entry.pm
+### lib/MyFeedReader/Controller/Entry.pm
-#+BEGIN_SRC perl
+``` perl
-use warnings;
+use Moose;
use MyAggregator::Entry;
@@ -101,15 +89,13 @@ Catalyst's welcome message as before.
-1;
-
+__PACKAGE__->meta->make_immutable;
-#+END_SRC
+```
-We extends the *Catalyst::Controller* in a Moose way, and the
-=make_immutable= instruction is a Moose recommanded best practice (you
-can alsa add =no Moose= after the make\_immutable).
+We extends the **Catalyst::Controller** in a Moose way, and the `make_immutable` instruction is a Moose recommanded best practice (you can alsa add `no Moose` after the make\_immutable).
-*** lib/MyFeedreader/Controller/Feed.pm
+### lib/MyFeedreader/Controller/Feed.pm
-#+BEGIN_SRC perl
+``` perl
+use Moose;
+use namespace::autoclean;
+BEGIN { extends 'Catalyst::Controller' }
@@ -139,16 +125,13 @@ can alsa add =no Moose= after the make\_immutable).
-1;
+__PACKAGE__->meta->make_immutable;
-#+END_SRC
+```
-We got =feed= which is chained to root. =index= is chained to feed, and
-take no arguments. This method display the list of our feeds. And we got
-the =view= method, chained to feed too, but with one argument, that
-display the content of an entry.
+We got `feed` which is chained to root. `index` is chained to feed, and take no arguments. This method display the list of our feeds. And we got the `view` method, chained to feed too, but with one argument, that display the content of an entry.
If you start the application, you will see the following routes:
-#+BEGIN_EXAMPLE
+``` example
.-------------------------------------+--------------------------------------.
| Path Spec | Private |
+-------------------------------------+--------------------------------------+
@@ -163,7 +146,6 @@ If you start the application, you will see the following routes:
| /root | /root (0) |
| | => /index |
'-------------------------------------+--------------------------------------'
-#+END_EXAMPLE
+```
-I hope you got a better idea about chained action in catalyst now. And
-again, thanks to bobtfish for the code.
+I hope you got a better idea about chained action in catalyst now. And again, thanks to bobtfish for the code.