develooper Front page | perl.perl5.porters | Postings from July 2020

Re: try/catch and CLEANUP/FINALLY/&c.

Thread Previous | Thread Next
From:
Kent Fredric
Date:
July 17, 2020 04:15
Subject:
Re: try/catch and CLEANUP/FINALLY/&c.
Message ID:
CAATnKFAT7UKSQ-0V6RqJqLB5J6p3PvqWJQXSz11Yq70MZ_ULnw@mail.gmail.com
On Fri, 17 Jul 2020 at 00:48, Felipe Gasper <felipe@felipegasper.com> wrote:
>
> My understanding is that CLEANUP (“FINALLY”?) blocks essentially build into the language the functionality of modules like Scope::Guard, but without the Perl-level guard object.

>
> … more natural than the Scope::Guard pattern, where I can easily control both when the callback fires and whether to cancel it.
>

One of the advantages of the way Scope::Guard and friends do it is a)
its pure perl, and b) you have this flexibility.

But one of the disadvantages of the way they do it with a lexical
variable and destructor, is that the lexical variable can be
accidentally referenced and held, by closures, or other mechanisms.
Which can in turn, prevent collection.

There are other CPAN modules that provide the "anonymous" option,
which is not so prone to the close-over mechanism, but is of course,
less friendly if you want to "undo" some previous "cleanup"
declaration. ( and the ones that provide the anonymous option all seem
to be either XS, or depend on things that in turn, leverage XS )


-- 
Kent

KENTNL - https://metacpan.org/author/KENTNL

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About