[Catalyst] parameter validation
Matt S Trout
dbix-class at trout.me.uk
Sun Jul 20 01:39:39 BST 2008
On Wed, Jul 02, 2008 at 11:08:46PM +0100, Caroline Johnston wrote:
> Hi,
>
> This isn't strictly a catalyst question, but it arose from a previous
> thread,
> http://lists.scsys.co.uk/pipermail/catalyst/2007-December/016329.html, on
> parameter validation and the problems of code like
>
> my $user = $rs->create({
> is_admin => 0,
> username => $c->req->param('username'),
> });
>
>
> I'm using Data::FormValidator. If I have a DFV constraint on fields that
> shouldn't be multi-valued, something like:
>
> sub is_single{
> my $c = shift;
> return sub{
> my $dfv = shift;
> $dfv->name_this('is_single');
> my $field = $dfv->get_current_constraint_field;
> my $data = $dfv->get_filtered_data;
> my $test = $data->{$field};
> return ref $test ? 0:1;
> }
> }
>
> should that allow me to use validated parameters in hashes with impunity
> or am I missing the point of the problem?
The point of that message was that $c->req->param('foo') is list context
aware whereas $c->req->params->{foo} isn't.
But once you've done the validating, you're going to be ok either way.
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
More information about the Catalyst
mailing list