April 2009 Archives

Extending Catalyst::Response

| 1 Comment | No TrackBacks

This is how to extend the functionality of Catalyst::Response (and other components in a similar way). For example I would like better default response codes for redirect so I will extend Catalyst::Response into MyApp::Response and override ("around" to be more precise) the redirect method. In order to tell Catalyst to use this response class I will write this in MyApp :

# Override Catalyst::Response class
use MyApp::Response;
__PACKAGE__->response_class('MyApp::Response');

Here is the content of MyApp::Response file :

 package MyApp::Response;
use Moose;
extends 'Catalyst::Response';

around 'redirect' => sub {
my $orig = shift;
my $self = shift;
my ($location, $status) = @_;

# Behave as an accessor
return $self->$orig() unless @_;

my $method = $self->_context->request->method;

# Set better defaults for response codes
# http://sebastians-pamphlets.com/the-anatomy-of-http-redirects-301-302-307
unless ($status) {
if ($method eq 'GET' or $method eq 'HEAD') {
$status = 301; # Moved Permanently
}
elsif ($method eq 'POST') {
$status = 303; # See Other (POST-Redirect-GET pattern)
}
}

return $self->$orig($location, $status);
};

1
I've just read about the Enlightened Perl Organisation's initiative to make Perl more visible through blogging. I've also read Matt S. Trout's rant about this topic and it convinced me to revive me 2 year old Perl blog (containing only one post). So here I am, decided to start my blogger career for the sake of showing what Perl actually stands for.

The first step I had to take was moving the blog from blogger.com to a more flexible Perl based opensource solution hosted on my own server. I've looked and found only two options: Blosxom and MovableType. The first one is very lightweight and has lots of plugins, the second one has lots of functionality out of the box. If I where to go with Blosxom i knew for sure that while searching for the right plugins I would get lost and abandon the blogging project (again). So I chose MovableType.

What other Perl based blog software do you know ? Anything opensource based on Catalyst for example ?

About this Archive

This page is an archive of entries from April 2009 listed from newest to oldest.

October 2006 is the previous archive.

May 2009 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Categories

Pages

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.25