|There's more than one way to do things|
Re^2: The 'eval "require $module; 1"' idiom (intended)by tye (Cardinal)
|on Apr 19, 2014 at 18:54 UTC||Need Help??|
I generally consider it to be cargo cult.
I intentionally put the "; 1" into this exact construct not out of some worship of practices that I have observed and not understood.
I put the "; 1" to show that I am explicitly checking for whether or not the code inside of the eval dies.
To a lesser extent, I also do it just to short-circuit the reader having to contemplate if there are any ways where require could not die but also not return a true value. I believe that the 'die' behavior of require is quite well understood.
However, the return value from require is almost never used. It isn't even really documented. You can infer likely return value behavior from Perl code included in the require documentation but that code is marked "Has semantics similar to the following subroutine:" (emphasis added), so such conclusions seem wise to treat with a certain level of skepticism.
The primary interface for require is that it loads the module or it dies. So it makes sense to use a construct that tests for whether or not the require died. That is what the "; 1" does. Leaving off the "; 1" requires the reader to try to find and understand information about a bit of behavior that is nearly useless and is poorly documented. That is not an improvement.