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

Re: [perl #21827] Carp::confess() reports wrong name for aliased subs

Thread Previous
From:
Rafael Garcia-Suarez
Date:
April 7, 2003 07:07
Subject:
Re: [perl #21827] Carp::confess() reports wrong name for aliased subs
Message ID:
20030407160753.02ef0b82.rgarciasuarez@free.fr
Antti Lankila (via RT) <perlbug-followup@perl.org> wrote:
> 
> I don't really care if this ever gets fixed or not, as I suspect people who
> make use of typeglob aliases deserve what they get. But nevertheless, I would
> like to have a clean way to alias functions to different names, as I sometimes
> need this feature. The less typing and runtime overhead to it, the better.
> 
> % perl -wle 'use Carp; *foo = \&bar; sub bar { confess("Should be foo") } foo()'
> Should be foo at -e line 1
>          main::bar() called at -e line 1

I think that's intended, or at least useful, behaviour.
Consider the following script:

#!perl
package Foo;
use Carp;
use Exporter;
BEGIN {
    our @ISA = 'Exporter';
    our @EXPORT = 'bar';
}
sub bar { confess("Mea culpa") }
package main;
BEGIN { Foo->import(); }
bar();
__END__

It outputs:

Mea culpa at /home/rafael/x line 9
	Foo::bar() called at /home/rafael/x line 12

with the full name (as opposed to the aliased name) of the offending
function. It looks more useful to the programmer.

-- 
Unending is not *NIX

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