in reply to Perl OO Lint

I don't see do_the_other_thing could have been executed because of the typo. I get, as I should,
Can't locate object method "caught" via package "My::Excpetion::Thingy +" (perhaps you forgot to load "My::Excpetion::Thingy"?) at script.pl +line 8.

True, it's a runtime error, but that's necessary since functions can be loaded at any time (including through AUTOLOAD) and @ISA can change at any time. Perl has no way of knowing at compile-time whether My::Excpetion::Thingy->caught will be valid any or all times that statement will be executed.

For example, I sometimes do:

if ($@) { require Carp; Carp::croak(...); }

Carp::croak doesn't exist until the require is executed, which is only executed at run-time when the exception occurs. A compile-time check would think this is an error. However, I'll cede that it could be useful for lint to give an (overridable) *warning*.

Replies are listed 'Best First'.
Re^2: Perl OO Lint
by jffry (Hermit) on Mar 13, 2006 at 21:23 UTC
    Oopsie! Now I see why I wasn't getting the "Can't locate object method...via package..." error. Here is the actual code with names changed to protect the innocent (i.e. me).
    eval { $lock->create() }; if (my $exception = My::Execption::Lock::Exists->caught()) { while ($lock->query()) { sleep 180; } exit 0; } die $@ if $@;
    Because my if () was always false due to a mispelling, I was just dieing with the prior eval error message, thus supressing the "missing object method" error message. Egads!

    My shame for all Perl monks to see.

      What are you talking about? That code still gives the Can't locate object method "caught" via package "My::Execption::Lock::Exists" (perhaps you forgot to load "My::Execption::Lock::Exists"?) error message.

      The if is never false (as you say) or even true, since perl dies from the type before the if expression gets completely evaluated. Similarly, the die is never reached, since the if encountered a fatal error.

      I suspect the if was within eval's block.

        I see what you mean. Well, damn. I have modified the code so much now that I don't have time to break it and go back to find out exactly what was going on. However, in that same program, I used to have an END{} subroutine that dealt with the same object. Like this:
        eval { $lock->remove() }; if ($@) { if (my $exception = My::Exception::Lock::NotFound->caught()) { warn $exception; } else { die $@; } }
        Maybe that had something to do with why I wasn't getting the object-method-not-found error?