http://qs321.pair.com?node_id=11149644


in reply to Re: Modules return value
in thread Modules return value

No, I can't think of any reason why you'd want to return a false value.

I can. Say you write a Parser to handle XML files. You might check during a BEGIN() if there is any functioning backend you can use. Yes, your module probably did some kind of test during install time, but that doesn't mean that those external libraries are still available and still functioning.

Now, why would you not want to just crash-and-burn or die()? Maybe your library is used from another module that's also dynamically searching for usable XML backends. There are many ways to load a ".pm" file (require, eval, probably Inline::Perl, ...), not just "use", and the easiest way to check if the operation worked is if you get a true value back. TIMTOWTDI, and yes that probably includes all the stuff that source code filters could do for (or "to") you ;-)

PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP