locked_user sundialsvc4 has asked for the wisdom of the Perl Monks concerning the following question:
Edit: I fixed it.
I have, as you know, a legacy app that used mod_perl and therefore a Apache2::RequestRec and a Apache2::Request.
Exactly what did that module return for my $scalar = $request->param('foo'); if 'foo' did not exist? Was it undef, or was it an empty string? The reason I ask, is that the original code apparently assumed empty-string.
(Large amounts of whining deleted...)The problem here is that param is a very complicated function. It can be called with zero parameters or one, and in an array context or a scalar context. The existing code simply did this:
has 'plack_request' ...... and it Just Works.™
handles param => 'param',
...
(More whimpering deleted ...)
Thanks to the clue given in post 853728, I solved the problem, I think:
around 'param' => sub { my $orig = shift; my $self = shift; my @result = $self->$orig(@_); if (wantarray) { return @result; } else { return defined($result[0]) ? $result[0] : ''; } };
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [SOLVED] Subtle Q: what does 'Apache2::RequestRec' return for missing "param()"?
by ikegami (Patriarch) on Jun 08, 2011 at 18:15 UTC | |
|
Re: [SOLVED] Subtle Q: what does 'Apache2::RequestRec' return for missing "param()"?
by locked_user sundialsvc4 (Abbot) on Jun 08, 2011 at 21:48 UTC |