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

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

Thread Previous | Thread Next
Kent Fredric
July 17, 2020 04:15
Re: try/catch and CLEANUP/FINALLY/&c.
Message ID:
On Fri, 17 Jul 2020 at 00:48, Felipe Gasper <> 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 )



Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About