Friday, April 11, 2008

Catalyst trap: param and params

well, if we write code as follows:
sub test : Local {
my ($self, $c) = @_;
my $test = {
a => $c->req->param('a'),
b => $c->req->param('b'),
c => $c->req->param('c'),
};
$c->res->body(Dumper(\$test));
}
then try to visit test?b=1, guess what we get? that's not what we expected.
$VAR1 = \{
'1' => 'c',
'a' => 'b'
};
a weird result!

please use follows, that's much better.
sub test : Local {
my ($self, $c) = @_;

my $test = {
a => $c->req->params->{'a'},
b => $c->req->params->{'b'},
c => $c->req->params->{'c'},
};
$c->res->body(Dumper(\$test));
}
and get what we want:
$VAR1 = \{
'a' => undef,
'b' => '1',
'c' => undef
};

so do remember that. and don't write dbix insert/update code like that.

Labels:

0 Comments:

Post a Comment

<< Home