When you say under Apache, do you mean with mod_perl?

If so then it is quite possible that the script you are running never actually loses the object (eg it is in a global variable), it survives because it is in a persistent processs, and DESTROY is never going to be called.

Try using Apache's register_cleanup function to register a function that does your cleanup. To do that you will need to keep track of the created objects, and then do the save in your cleanup function. I haven't done that myself, but recent versions of CGI.pm first check whether $ENV{GATEWAY_INTERFACE} exists, and if it does then does it match /^CGI-Perl\//. If it does then mod_perl is on, they require Apache, then later on:

if ($MOD_PERL && defined Apache->request) { Apache->request->register_cleanup(\&CGI::_reset_globals); undef $NPH; }
The $NPH doesn't concern you. The Apache->request bit does. You might do that by having in your constructor something like this:
if ($MOD_PERL && defined Apache::Request) { Apache->request->register_cleanup(\&saveall); push @OBJ_STORE, $self; }
and then in saveall save each method in @OBJ_STORE then discard them all. (Check in your DESTROY whether things have been saved.)

This is untested, but give it a shot and see if it doesn't work.


In reply to Re (tilly) 1: $obj-DESTROY isn't called upon by tilly
in thread $obj-DESTROY isn't called upon by Sinister

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.