in reply to Per-object DESTROY

Well, why do you use the name on_cleanup() since it's pretty obvious you know about DESTROY?

In other words, you should use the sub/method name DESTROY for per-object destroys.

Replies are listed 'Best First'.
Re^2: Per-object DESTROY
by diotalevi (Canon) on Jul 08, 2007 at 00:53 UTC

    It's not my object. I'd need to either install a DESTROY method into the Archive::Extract object violating its implementation or write an object which I could hang my DESTROY-time code off of. tilly's ReleaseAction handles this case nicely. I just pass in my destroy code and make sure the ReleaseAction object is destroyed at the same time as the object.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      ReleaseAction would require you to synchronize the out-of-scope moment between the two objects.

      Wouldn't the classy way be to subclass Archive::Extract just inheriting its methods, and to implement your own DESTROY method in the subclass that invokes SUPER::DESTROY as its last action?

        In this case, the destruction moment isn't really identical. It would have been cheap and easy to join the two and it was my first thought. A better idea is to discard the archive object as soon as I've used it up and then retain the cleanup handle until I'm finished working with its extracted contents.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊