Front page | perl.perl5.porters |
Postings from October 2003
[perl #24182] Objects loosing overload magic during DESTROY
From:
Jos Boumans
Date:
October 10, 2003 23:47
Subject:
[perl #24182] Objects loosing overload magic during DESTROY
Message ID:
rt-24182-65923.8.51844289320937@rt.perl.org
# New Ticket Created by Jos Boumans
# Please include the string: [perl #24182]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24182 >
Hi,
when playing with overloaded stringification of objects, i noted the
overload magic has disappeared in the DESTROY, but only if it's
actually going out of scope.
Here's the relevant code, and the output.. note especially the last
Dump;
[kane@coke ~/Documents/Perl]$ cat stringify_in_destroy
#!/usr/bin/perl -w
use strict;
{
my $x = new Axe 'hack';
$x->printme;
print "X = $x\n";
$x->DESTROY;
}
print "After block\n";
package Axe;
use Devel::Peek;
use overload q{""} => \&_stringify;
sub new {
my $class = shift;
my $str = shift;
bless \$str, $class;
}
sub printme {
my $self = shift;
print "Printing $self\n";
Dump $self;
}
sub _stringify {
my $self = shift;
return "I'm $$self";
}
sub DESTROY {
my $self = shift;
print "Destroying $self\n";
Dump $self;
}
[kane@coke ~/Documents/Perl]$ perlc stringify_in_destroy
Printing I'm hack
SV = RV(0x5d07c) at 0x80d4c
REFCNT = 1
FLAGS = (PADBUSY,PADMY,ROK,OVERLOAD)
RV = 0x80dc4
SV = PVMG(0x72c40) at 0x80dc4
REFCNT = 2
FLAGS = (PADBUSY,PADMY,OBJECT,POK,pPOK)
IV = 0
NV = 0
PV = 0x58180 "hack"\0
CUR = 4
LEN = 5
STASH = 0x513f4 "Axe"
X = I'm hack
Destroying I'm hack
SV = RV(0x5d098) at 0x55aec
REFCNT = 1
FLAGS = (PADBUSY,PADMY,ROK,OVERLOAD)
RV = 0x80dc4
SV = PVMG(0x72c40) at 0x80dc4
REFCNT = 2
FLAGS = (PADBUSY,PADMY,OBJECT,POK,pPOK)
IV = 0
NV = 0
PV = 0x58180 "hack"\0
CUR = 4
LEN = 5
STASH = 0x513f4 "Axe"
Destroying Axe=SCALAR(0x80dc4)
SV = RV(0x5d098) at 0x55aec
REFCNT = 1
FLAGS = (PADBUSY,PADMY,ROK)
RV = 0x80dc4
SV = PVMG(0x72c40) at 0x80dc4
REFCNT = 2
FLAGS = (PADBUSY,PADMY,OBJECT,POK,pPOK)
IV = 0
NV = 0
PV = 0x58180 "hack"\0
CUR = 4
LEN = 5
STASH = 0x513f4 "Axe"
After block
--
Jos Boumans
How do I prove I am not crazy to people who are?
CPANPLUS http://cpanplus.sf.net
-
[perl #24182] Objects loosing overload magic during DESTROY
by Jos Boumans