[Catalyst] RFC: Catalyst::Plugin::EnhancedParams

Nilson Santos Figueiredo Junior acid06 at gmail.com
Sat Apr 1 20:33:51 CEST 2006

This is, admittedly, a personal taste but there's one simple thing
present in Rails that I missed in Catalyst.

Consider the situation where you've got a signup form. The usual
Catalyst way of doing it would be something like:

  <input type="text" name="name" />
  <input type="text" name="email" />

sub action : Local {
    my $c = shift;
    my $obj = $c->model('Person')->create({
        name => $c->req->param('name'),
        email => $c->req->param('email'),

Of course, you could use maybe DBIx::Class::Webform or something like that.
But I find this much more elegant:

  <input type="text" name="person[name]" />
  <input type="text" name="person[email]" />

sub action : Local {
    my $c = shift;
    my $obj = $c->model('Person')->create($c->param('person'));

So, basically, that's how Catalyst::Plugin::EnhancedParams enhances
the parameters. It allows processing of hashes (currently, only one
level deep). This can greatly simplify some things and make the code
more elegant (IMHO).

The only issue is that it might not be 100% CGI.pm compatible (for
those who care). But it somewhat tries to be by not deleting the
original "param[name]" parameters. So $c->param('param[name]') is
still valid.

By the way, it also aliases param(), params() and parameters() as
methods of the context object. Some purists might argue that this is
not good, but I find it pretty handy (I also usually use
Catalyst::Plugin::Redirect for this same reason).

So... Any comments?

I really think this enhanced parameter processing behaviour should be
added to the Catalyst core, since it's a really neat feature IMO. But,
well, that's just me.

For anyone who wants to take a look at it, it's available at:

I've already uploaded it to the CPAN, but PAUSE apparently hates me.
However, sooner or later it will end up appearing at your favorite
CPAN mirror.

-Nilson Santos F. Jr.

More information about the Catalyst mailing list