In your constructor, you bless a hash into the current class, storing it in $this. Then, you tie the dereferenced hash into the current class.

I think that's double-blessing. Good for the pious, but tricky for programs. Here's my suggestion:

sub new { my $proto = shift; my $class = ref ($proto) || $proto; my %this; return tie(%this, $class); }
Let's make things a little more explicit by tieing a hash blessed into a different class. Here's the new class and a slightly different constructor:
package FunClass; sub new { my $class = shift; my $self = {}; bless($self, $class); } sub DESTROY { my $self = shift; print "Destroying $self!\n"; } sub new { my $proto = shift; my $class = ref ($proto) || $proto; my $this = FunClass->new(); tie %{$this}, $class; return $this; }
And the results?
Destroying FunClass=HASH(0x80f173c)! Calling DESTROY by SillyClass=HASH(0x80f600c)

In reply to Re: DESTROY for tied classes by chromatic
in thread DESTROY for tied classes by MeowChow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.