[Catalyst] new Catalyst::Plugin::HashParam
Christopher Heschong
chris at wiw.org
Mon Apr 10 03:31:17 CEST 2006
Hi, planning on uploading this module to CPAN and wanted to get any
feedback. Basically it allows input paramteters to be created with a
"hash[key]" format. Are there any standard actions around submitting
new modules? Do you guys usually provide svn space, or just for
catalyst developers?
From the POD:
=head1 SYNOPSIS
<input name="primary[name]" />
<input name="primary[address]" />
<input name="secondary[name]" />
<input name="secondary[address]" />
...
use Catalyst qw/HashParam/;
sub something : Local
{
my ($self, $c) = @_;
my $foo = $c->req->hashparam('primary');
my $bar = $c->req->hashparam('secondary');
$c->stash->{winner} = $foo->{name};
$c->stash->{loser} = $bar->{name};
}
=head1 DESCRIPTION
Stealing a handy feature from PHP, allow a set of form variables to
be returned
as a hashref. Also useful when you have multiple rows worth of fields,
such as a grid. For example:
<input name="name[1]" /> <input name="address[1]" /> <br />
<input name="name[2]" /> <input name="address[2]" /> <br />
<input name="name[3]" /> <input name="address[3]" /> <br />
...
for ( keys %{$c->req->hashparam(name)} )
{
$c->model('MyData')->create(
name => $c->req->hashparam('name')->{$_},
address => $c->req->hashparam('address')->{$_},
);
}
If multiple entries exist a listref is returned as the value.
<input name="animal[type]" />
<input name="animal[type]" />
<input name="animal[type]" />
...
my @types = @{ $c->req->hashparam('animal')->{type} }
$c->stash->{summary} = join (', ', @types);
$c->log->debug('No kittens!')
unless grep /(kitten|kitty|cat)/, @types;
--
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Catalyst-Plugin-HashParam-0.01.tar.gz
Type: application/x-gzip
Size: 9934 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060409/1f41afc7/attachment-0001.bin
More information about the Catalyst
mailing list