TedYoung has asked for the wisdom of the Perl Monks concerning the following question:

Good Day,

I was reading Z-Rated Code and Reinventing the Wheel which made reference to a few alternatives to the CGI module. One in particular was CGI::Simple. The CGI::Simple perldocs say the following with regards to the import_names method:

This method was silly, non OO and has been deleted.

Now, CGI::Simple's goal is to provide an OO interface, so naturally this method doesn't make much sense here.

But the statement that it was silly made me think a bit. What do other's think about using import_names?

I write web apps for a living. For most of my apps, I break out the controller into packages of event handlers (each package representing related functionality). import_names allows me to import all of my params into a namespace (I normally use in::) so I don't have to pass an object or hash between packages. It even supports multi-values as arrays (i.e. @in::foo).

I remember that PHP had a similar feature that was ultimately frowned upon because of security concerns, but I thought those were moot here because we specify a namespace, into which to dump the data.

Now, I am not debating the advantages of an OO framework by any means. I am just curious if there are any major pitfals with import_names that I am not seeing.

Thanks,

Ted Young

($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)

Replies are listed 'Best First'.
Re: $CGI->import_names
by derby (Abbot) on Apr 17, 2006 at 16:16 UTC

    If you're the sole developer/maintainer and your modules are not overly huge, than there aren't many pitfalls ... but ... once that module hits a certain size or you start having multiple devs, namespace clashing becomes a real issue (and a real PITA to track down).

    -derby
Re: $CGI->import_names
by doc_faustroll (Scribe) on Apr 18, 2006 at 04:47 UTC
    Perhaps Ovid will chime in with why he dislikes it but I suspect it is a general best practices tendency to avoid globals wherever possible.

    The old global filehandle, sans sigil, as in FH, is now considered bad form, for example.

    Lexical scoping in the smallest scope possible is the preferred best practice.