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

caller() not useful during sub DESTROY

Thread Next
From:
Paul LeoNerd Evans
Date:
August 16, 2012 13:13
Subject:
caller() not useful during sub DESTROY
Message ID:
20120816201330.GK19185@cel.leo
Consider the following program:

  #!/usr/bin/perl

  use strict;
  use warnings;

  package WhereDidIGo;

  sub DESTROY {
     print STDERR "DESTROYed at ", join(", ", (caller)[0,1,2] ), "\n";
  }

  {
     my $thing = bless [], "WhereDidIGo";
     undef $thing;                                  #### this is line 14
  }

When run this outputs:

  $ perl destroyed-at.pl 
  DESTROYed at main, destroyed-at.pl, 0

I had been expecting the output:

  DESTROYed at WhereDidIGo, destroyed-at.pl, 14


I have an object (CPS::Future) that represents a task-in-progress. I was
hoping to be able to print a warning message for debugging purposes, if
such an object is dropped before it completes.

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/

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