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:

my shell history

-bash-3.00$ history|awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}' |sort -rn|head
290 perl
235 svn
67 ls
60 screen
46 vim
27 mysql
25 cp
23 rm
22 ps
22 exit
Thursday, April 10, 2008

please support Perl in Google App Engine

http://code.google.com/p/googleappengine/issues/detail?id=34

star it please. so that we will have a free Perl host by Google!
Monday, April 07, 2008

I have a son

My son (nickname: diudiu 丢丢, formal name: 林锦喆) was born a week ago on April Fool's Day (4.1) and weight was 3kg. I'm pretty happy with that. I'll upload some photos later. :)