develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24350] package base produces incorrect error messages

Nick Ing-Simmons
October 30, 2003 05:29
Re: [perl #24350] package base produces incorrect error messages
Message ID:
Paul Kremer <> writes:
>> No - you do not need to have a .pm file for package to exist.
>> Consider
>> package Base;
>> sub method { ... }
>> ...
>> package Derived;
>> use base 'Base';
>> ...
>> The class 'Base' is already defined in same file as derived class.
>> It does not have a .pm file of its own.
>> Base was originaly intended (as I recall) as a BEGIN time way to
>> set ISA. Lots of classes use it that way. The handy do the
>> require for you code came later.
>> The existing code reflects this usage pattern buy changing the error
>> message so point out that base class is empty, rather than that its
>> .pm file could not be found.
>> ...
>what about changing the problematic line to:
>    die if $@ && ! ( $@ =~ /^Can't locate .*? at \(eval / && 
>instead of the original line:
>    die if $@ && $@ !~ /^Can't locate .*? at \(eval /;
>the first patch was crap, I apologize for the waste of your time.

The current un-patched 5.8.1 has:

            eval "require $base";
            # Only ignore "Can't locate" errors from our eval require.
            # Other fatal errors (syntax etc) must be reported.
            die if $@ && $@ !~ /^Can't locate .*? at \(eval /;
            unless (%{"$base\::"}) {
                require Carp;
Base class package "$base" is empty.
    (Perhaps you need to 'use' the module which defines that package first.)


So if there was an error and it was NOT 'Can't locate' you get a die.
If get beyond that point either there was no error (so we don't want to die)
or it was the "Can't locate..." case which is explictly allowed, as the 
class may not have a .pm file of its own.

However if you get past that point and there is still nothing in the base 
class stash we croak with a re-worded message. That croak happens regardless
of whether .pm file was found - it is an error either way, but we don't 
know if .pm file was supposed to exist, just that there should be 
something in base class - hence the re-worded message.

>paul Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About