[Catalyst] Alternatives to Catalyst ?

Charlie Garrison garrison at zeta.org.au
Tue Apr 27 15:12:32 GMT 2010


Good morning,

On 27/04/10 at 1:22 PM +0100, Dermot <paikkos at googlemail.com> wrote:

>That comment was obviously tongue in cheek but there was an
>underlining point that access via sub-routine reference is slower than
>access via a hash. Toby was quick to point out that as far as he knew
>$req->param->{} was the referred method.  Now that doesn't break
>encapsulation and I'm assuming that it will be faster access method
>than $req->params(). I could be wrong. I haven't benchmarked. I am
>simply following the logic that subroutine references are slower that
>hash lookups. Is it really so wrong to want to use params->{} over
>params()?  You may call it premature optimisation (as if is a dirty
>word) but to me it's just a good habit that has the benefits of being
>a bit faster.
>
>So just in case you missed it, when I said:
>
>...but if I'm breaking the encapsulation in some ways that's going to
>bite me later, I'd steer
>clear.
>
>I meant, "I'd don't want break encapsulation".
>
>I hope that clear things up and you can stop talking about me as if
>I'm not here :)

That didn't clear things up for me, and I thought I had some 
clarity already. So I guess one of us is (still) confused.

I thought it was an issue of:

     $req->param(...)

vs:

     $req->params->{...}

Note, one is plural, the other is not. The param method is for 
legacy CGI.pm compatibility, and as such, is slower. The params 
method returns a hash, and of course one then does direct hash lookups.

The params method is an alias for parameters. And since it 
simply returns a hash it is relatively speedy and encapsulates 
the internal parameters access (hash or whatever) within C::Request.

And for those who like juggling with sharp knives with one hand, 
they could skip both param and params methods and use:

     $req->{parameters}->{...}


So as long as one doesn't need CGI.pm compat, use 
$req->params->{...} as the 'best practices' approach. It's not 
slower like $req->param(...) is, but still offers the desired encapsulation.

Have I got that right or am I still confused?

My mental clue sheet looks like this:

     $req->param(...) will return one value (scalar or array), 
the way I'm used to with CGI.pm.
     $req->params->{...} returns multiple values in a hash, 
which I can then reference by key.

One thing this discussion did help me with was some confusion 
that HTML::FormFu threw in there for me. In my mind, I kept 
confusing its $form->param(...) (& related) methods with 
$req->params->{...}. This discussion has resulted in me 
reviewing my usage of all various param(s) methods and I've 
found a few things to fix (or improve).

I hope I've got it right now.  :-)


Charlie

-- 
    Ꮚ Charlie Garrison ♊ <garrison at zeta.org.au>

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
〠  http://www.ietf.org/rfc/rfc1855.txt



More information about the Catalyst mailing list