11 April 2008
This post may be outdated due to it was written on 2008. The links may be broken. The code may be not working anymore. Leave comments if needed.
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.


blog comments powered by Disqus