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

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

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
October 30, 2003 01:00
Subject:
Re: [perl #24350] package base produces incorrect error messages
Message ID:
20031030085955.2537.3@llama.elixent.com
Pkremer@Spurious.Biz <perl5-porters@perl.org> writes:
># New Ticket Created by  pkremer@spurious.biz 
># Please include the string:  [perl #24350]
># in the subject line of all future correspondence about this issue. 
># <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24350 >
>
>
>To: perlbug@perl.org
>Subject: package base produces incorrect error messages
>Reply-To: pkremer@spurious.biz
>
>This is a bug report for perl from pkremer@spurious.biz,
>generated with the help of perlbug 1.34 running under perl v5.8.1.
>
>
>-----------------------------------------------------------------
>[Please enter your report here]
>
>When trying to use a module as base package which does not exist,
>package base will bail out with the message:
>
>  Base class package "MODULE::DOES::NOT::EXIST" is empty.
>  (Perhaps you need to 'use' the module which defines that package first.)
>
>Code which leads to this error:
>
>  use base 'MODULE::DOES::NOT::EXIST';
>
>The error message should state:
>
>   Can't locate MODULE/DOES/NOT/EXIST.pm in @INC ....

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.



>
>Here is the "offending" code (from base.pm):
>
>            local $SIG{__DIE__} = 'IGNORE';
>            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
>
>Here is the replacement code:
>
>            if (my $e = $@) {
>                die $e if ($e =~ /^Can't locate .*? at \(eval /);

Not acceptable.




Thread Previous | Thread Next


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