A long time ago i read some material here at the Monastery that disuaded using "indirect object syntax" (thanks Corion). After reading your question, which is a good one ... i did a Google Search Gone Wrong (notice the first hit) and found the result so funny that i just had to share it in the CB. This led to both bart and Corion correcting my search parameters, and bart went searching for material. From one of runrig's journal entries, bart posted this link in the CB. I invite you to copy that code and run it on your own.
Done so yet? Good. :) The only difference in the two versions is that the second declares package X::Y before it is used in package X. Had the code not used indirect object syntax, it would not have mattered which package was declared first. That is, new X::Y (@_); should have been X::Y->new(@_);. Using direct object syntax, in essence, is just a Good Habit™ to get into. For your example, it doesn't really matter. But the day may come when you, like Simon Cozens, will get bitten in the butt from using indirect object syntax (or notation).
To add some more insight to your original question (and yes, your understanding is correct) i only instantiate a CGI object (via my $cgi = CGI->new;) if i have to reuse that CGI object. Otherwise i just import the functions into my namespace for ease of typing. Check this out:
perl -MCGI=foo -le'print foo{bar=>baz}=>qux'
Thanks to bart (who should get all the credit for this node), Corion, and of course, yourself and Zaxo. :)
|