develooper Front page | perl.perl5.porters | Postings from September 2012

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

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
September 27, 2012 18:55
Subject:
[perl #21827] Carp::confess() reports wrong name for aliased subs
Message ID:
rt-3.6.HEAD-11172-1348797297-991.21827-15-0@perl.org
On Mon Apr 07 08:43:43 2003, alankila@Elma.Net wrote:
> On 7 Apr 2003, Rafael Garcia-Suarez wrote:
> 
> > > 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.
> 
> It depends. Since writing that initial complaint, I've discovered that
> perl
> seems to store the name of the subroutine along with the code
> reference itself.
> Perl's caller() apparently digs the name up there. So, in general as
> long as
> the code reference is the same, the name visible will always be the
> name of the
> original function, regardless of the name I used to call the function.
> 
> Originally this happened in the context of an OO program where I had
> this kind
> of situation:
> 
> package A;
> 
> sub foo { ... }
> 
> *bar = \&foo;
> 
> package A::B;
> use base 'A';
> 
> sub foo { ... }
> 
> 
> Now, notice I didn't overload bar(), but I was calling bar() anyway in
> style
> A::B->bar(). That was a bug in my program. Perl correctly called
> A::bar() in
> this case, and then the program died in a very obscure error message,
> with the
> stack trace attached that pointed out that I had actually called A-
> >foo().
> 
> Now, I lied a bit. That was my deduction. You know that the stack
> trace doesn't
> say "While calling A::B->foo", it says more like "while calling
> A::foo('A::B')", but my point being, I *had* overloaded foo() and I
> *thought* I
> was calling A::B->foo, because I thought the stack trace said so.
> 
> After I spent 15 minutes scratching my head, I discovered the nature
> of the
> error, and I still maintain it *is* a bug, because the stack trace
> should
> contain the name I called, not the name of the function inside class
> which
> just happens to implement the name I called. This is not big deal, in
> the scale
> of things, but it seems like one of the minor annoyances you keep on
> hitting
> with Perl. That is why I suggested that a cleaner way to rename a
> subroutine
> was given, one that would report the actual name for the aliased
> function.
> 
> But I agree that your point is solid. Perhaps, in order to get the
> best of both
> worlds, we should really see the both names in case of Exporting and
> typeglob
> aliasing...  Just my thoughts on the issue.
> 

Reviewing this ticket, which has been gathering dust for nine years, my
impression is that this is a "wontfix".  I proposed that we close it in
seven days unless someone has a good reason for keeping it open.  (A
patch would at least keep the ticket open.)

Thank you very much.
Jim Keenan

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=21827

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