Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: The 'eval "require $module; 1"' idiom

by Anonymous Monk
on Apr 19, 2014 at 12:45 UTC ( [id://1082893]=note: print w/replies, xml ) Need Help??


in reply to The 'eval "require $module; 1"' idiom

Use UNIVERSAL::require to encapsulate much needed voodoo.
  • Comment on Re: The 'eval "require $module; 1"' idiom

Replies are listed 'Best First'.
Re^2: The 'eval "require $module; 1"' idiom (UNIVERSAL--)
by tye (Sage) on Apr 19, 2014 at 19:12 UTC

    Yes, polluting the UNIVERSAL namespace by adding a method that can impact every single other class used is so much better than writing one simple, well-understood line of Perl code.

    So, when I run across a line of code like:

    if( $module->require() ) {

    in some Perl code, I'll likely suspect what it might be doing. But, especially the first time, I likely won't be completely sure, especially not on all of the details. So I'm likely to want to go read the documentation for this routine. And it is so easy to imagine having no idea where to find that documentation. Especially if the loading of UNIVERSAL::require was done from some other code file (yay for action at a distance).

    A much less cute interface for this functionality would have been a much better idea. Running into code like:

    use Module::Require qw< could_require >; # ... if( could_require( $module ) ) {

    would make the breadcrumbs from the mystery code to the module that documents it obvious in the typical manner of Perl modules.

    Such an interface would also prevent weird surprises when you misremember a similar method name on some other class and get silent behavior very much different from what you expected and then waste a ton of time trying to figure out what is going on. Because the silent behavior was made possible by the loading of some module by some code that has almost nothing to do with the code you are working on. Action at a distance at its finest.

    - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1082893]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found