in reply to Re^4: is there a way to ensure some code is the last thing that is run? (SUPEREND)
in thread is there a way to ensure some code is the last thing that is run?

I think in the general case you cannot have a SUPEREND or something like that.

The reason is that this SUPEREND could again create an object and the destructor of that would again run later.

  • Comment on Re^5: is there a way to ensure some code is the last thing that is run? (SUPEREND)

Replies are listed 'Best First'.
Re^6: is there a way to ensure some code is the last thing that is run? (SUPEREND)
by LanX (Saint) on Feb 04, 2017 at 13:34 UTC
    > The reason is that this SUPEREND could again create an object and the destructor of that would again run later.

    I'm still wondering what you mean.

    This package is guaranteed to run the last possible (Perl coded) DESTROY, because the ref counter of $persist will only turn 0 after all wrapper ran. (see proof of concept)

    And you can put your desired code in that DESTROY.

    Furthermore you have full control of "SUPEREND" and all "created objects" (which would be handled by the same DESTROY() anyway)

    Of course there is still destruction happening afterwards, namely subs and package variables, but these are hard coded.

    And I wonder how you possibly want to run any code after destruction of subs???

    You stated you need to run the code to fix issues with misbehaving foreign modules.

    If this doesn't help, then it's most probably an XY Problem on your side

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Re^6: is there a way to ensure some code is the last thing that is run? (SUPEREND)
by LanX (Saint) on Feb 03, 2017 at 15:45 UTC
    > and the destructor of that would again run later.

    ? That is how it works!

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      But it only works because you know up-front that it's the destructor of a particular class that you need to handle.

      A true SUPEREND-feature should work without such knowledge and that is I believe not possible.

        > A true SUPEREND-feature should work without such knowledge and that is I believe not possible.

        It is, you can introspect all available packages (look into %main:: ) so far in a loop, check if DESTROY exists and install a wrapper.

        Do you need it?

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!