Venerable fellow monks,

I have a strange thing happening that I would like to understand.

Here is the code in it's essentials:

package X; use strict; use Y; my $y = Y->new; 1;
So here we have a package that keeps an instance of a class Y in a "static" variable.

Here now the implementation of Y:

package Y; use Moose; sub DEMOLISH {} 1;
As you can see it's just an (empty) Moose-based class that provides an (in this case even empty) destructor.

Now I have a little driver script:

use strict; use X; print "done\n";
All this trivial stuff now results in this warning when the script exits:

(in cleanup) Can't call method "default" on an undefined value at (eval 36) line 7 during global destruction.

So evidently during the global destruction phase (that I have never fully understood) something gets cleaned up in a way that seems to confuse Moose or what is happening here?

The problem is not just this warning but the fact that the destructor (code in DEMOLISH) then never gets run so this means that I cannot rely on destructors to clean up resources when the Moose-instance is held in a static variable and gets garbage collected only during global destruction...

Regardless of whether or not using destructors in such a way is good or bad style - could someone explain what exactly is causing this problem?

Many thanks!

PS: I am running 5.10 on Linux with Moose 0.62


In reply to global destruction and Moose by morgon

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.