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

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

Thread Previous
From:
Nick Ing-Simmons
Date:
October 30, 2003 05:29
Subject:
Re: [perl #24350] package base produces incorrect error messages
Message ID:
20031030132912.3077.6@llama.elixent.com
Paul Kremer <pkremer@spurious.biz> 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 / && 
>%{"$base\::"});
>
>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 base.pm 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;
                Carp::croak(<<ERROR);
Base class package "$base" is empty.
    (Perhaps you need to 'use' the module which defines that package first.)
ERROR

            }

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.




>
>hand,
>paul


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About