[OT] blessed sub-refs in the symbol table

Philippe Bruhat (BooK) philippe.bruhat at free.fr
Fri Feb 1 09:10:27 GMT 2013


On Thu, Jan 31, 2013 at 11:12:30AM +0000, David Cantrell wrote:
> I am most disappointed to find that if you put a blessed sub-ref in the
> symbol table and then replace it, its DESTROY method doesn't get called
> straight away:
> 
> package Immortal;
> 
> sub new { return bless sub { print "called the object\n" }, shift; }
> sub DESTROY { print "called DESTROY\n"; }
> 1;
> 
> $ perl -MImmortal -e '*Foo::bar = Immortal->new(); Foo::bar(); *Foo::bar = sub {print "blargh\n"}; Foo::bar();'
> called the object
> blargh
> called DESTROY
> 
> looks like the blessed sub continues to exist right to the end of the
> process, even though all references to it have gone away.  Is this a bug?

It looks worse here (system perl 5.14.2 on Debian):

    $ /usr/bin/perl -MImmortal -e '*Foo::bar = Immortal->new(); Foo::bar(); *Foo::bar = sub {print "blargh\n"}; Foo::bar();'
    called the object
    blargh

-- 
 Philippe Bruhat (BooK)

 The man who accuses others falsely only succeeds in condemning himself.
                                   (Moral from Groo The Wanderer #112 (Epic))


More information about the london.pm mailing list