NAME
Catalyst::Plugin::EnhancedParams - Enhances Catalyst parameter processing behaviour
VERSION
Version 0.01
SYNOPSIS
This module enhances Catalyst parameter processing support by adding hash (could also be viewed as object) parameters. It integrates well with Catalyst providing these hash parameters through the already used param()
method of the request object but doesn't destroy the original parameter data so it's still somewhat CGI-compatible.
It further provides helper methods param()
, parameters()
and its alias params()
on the Catalyst context namespace so that you can be even lazier and just use $c-
param('field_name')> instead of $c-
req->param('field_name')>.
In MyApp.pm:
use Catalyst qw/
....
EnhancedParams
/;
In your template file (or whatever you use as your view):
<form>
<input type="text" name="person[name]" />
<input type="text" name="person[age]" />
</form>
Inside the corresponding controller action:
# using the alias at the context object
my $person = $c->param('person');
$c->log->debug("Person name: $person->{name}");
$c->log->debug("Person age: $person->{age}");
# assuming these are the only required fields
my $obj = $c->model('Person')->create($person);
METHODS
$c->param(...)
Alias to $c-
request->param(...)>.
$c->params
$c->parameters
Alias to $c-
request->parameters>.
prepare_body
Catalyst pluggable action. Described below.
INTERACTION WITH CATALYST
Catalyst::Plugin::EnhancedParams
plugs into this handler and post-processes its output, translating parameters which would be accessed as param('param_name[key]')
to param('param_name')-
{key}>.
Having the parameters in this form is really useful if you want to do stuff such as directly passing them to the model (e.g. the create()
method of DBIx::Class).
The original param('name[key]')
still works.
IMPORTANT NOTE: If there was already a parameter named "param_name" in the above example it would be overriden.
LIMITATIONS
Currently, only one "hash level" is supported, i.e., you can't use field_name[key1][key2]
and expect it to work. It won't do anything. This feature may be added in future versions.
AUTHOR
Nilson Santos Figueiredo Júnior, <nilsonsfj at cpan.org>
BUGS
Please report any bugs and feature requests directly to the author. If you ask nicely it will probably be implemented.
SEE ALSO
COPYRIGHT & LICENSE
Copyright 2006 Nilson Santos Figueiredo Júnior, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 123:
Non-ASCII character seen before =encoding in 'Júnior,'. Assuming CP1252