Slash Boxes
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.
More | Login | Reply
Loading... please wait.
  • Yes, C should be using A but I've read a lot of commercial code that just assumes other modules are loaded and its a horrible thing to debug.

    What a bogus argument. I would accept this if you had said "I have written a lot of commercial code that just assumes ...", but arguing a (unremovable, by now) misfeature of your code as something actually beneficial is quite a stretch. I hadn't looked at the source code of before people argued against it, but for my taste it is far too close to the code of UNIVERSAL::require which also silently gobbles up errors happening during requireing a file. The custom $SIG{__DIE__} handler also is an unneccessary complication that stems from the same idea that errors should not be visible upwards.

    Now, neither of these two points are what constitutes a "bug", but for some code that should basically be (less the error checking for recursive inheritance)

    package base;
    use strict;

    sub import {
        my ($class,$base) = @_;
        my $target = caller();
        (my $file = $base) =~ s!::|'!/!g;
        $file .= ".pm";
        require $file;
            no strict 'refs';
            push @{ "$target\::ISA" }, $base;

    1 has far too many lines and does far too many contortions that I do not want to track down just in case I have a weirdo error that chooses to suppress. Also, no bad action-at-a-distance occurs by messing with $VERSION and all errors point directly to the source like Can't locate in @INC (... instead of Base class package "Foo" is empty. - in 95% of the cases, that's exactly what's wanted, because somebody misspelled Foo.

    (Yes, I'm aware that my code forces every base class to be in a file with a name that matches that base class. If you don't want that, write your own @INC hook or fiddle with %INC.)

    Anyway - I started out liking, but after looking at the source code and having been bitten by UNIVERSAL::require gobbling my (syntax) errors far too many times, I don't want to become one of the people with anecdotal evidence that has bugs.

    • I think we're having a violent agreement. My example about the commercial code was illustrating the importance of inheriting at compile time vs setting @ISA at run time. All the other details of "use base" are orthogonal.

      Some people remember to put a BEGIN around setting @ISA (and @EXPORT) but most don't either because they forget or aren't aware.