Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Not a fan of this change. What's wrong with saying $foo->require or die $@; That's not too much to type. It breaks this kind of useful idiom: $this->require or $that->require or die "No alternatives found: $@"; and it breaks this kind of portability even more

    if ( $better->require )
    {
       $better->frobnicate;
    }
    else
    {
        $default->frobnicate;
    }

    It also makes it difficult to write a custom error message - I have to wrap the call in an eval, and so we're back where we starte

    • What's wrong with saying $foo->require or die $@; That's not too much to type.
      Its not about the amount of typing (well... part of it is). Its about the expectation that require() should die. Even *I'm* surprised to find out that $foo->require doesn't die and I WROTE THE MODULE!

      Error checking should be something you turn off, not something you turn on. Especially when it comes to dealing with the World Outside Your Program. Files, networks, etc... things not totally under your program's control and thus likely to do unexpected things.

      I will say using $@ to return the error is a lot better than $UNIVERSAL::require::ERROR, and it seems to work... which is an accident, but a happy one. It certainly makes me gag a lot less. However I'm not happy about the mixing of idioms, using $@ for an error even though there's no (visible) eval.
      It breaks this kind of useful idiom: $this->require or $that->require or die "No alternatives found: $@";
      I have no matching idiom for that and that bothers me. Though it bothers me less than thinking about having to append "or die $@" on the end of most of my require calls much in the same way it bugs me about open() or any other "outside world" call. I tend to use Fatal a lot.
      Might as well not return the true value if the failure mode will die anyway.
      That makes eval { $foo->require } or do_bleh a little difficult.

      Its a little known, and little used, fact that you can return pretty much any scalar from require including references.