GuardSafe cleanup blocks | |
Download |
Guard Ranking & Summary
Advertisement
- License:
- Perl Artistic License
- Price:
- FREE
- Publisher Name:
- Marc Lehmann
- Publisher web site:
- http://www.goof.com/pcg/marc/
Guard Tags
Guard Description
Safe cleanup blocks Guard is a Perl module that implements so-called "guards". A guard is something (usually an object) that "guards" a resource, ensuring that it is cleaned up when expected.Specifically, this module supports two different types of guards: guard objects, which execute a given code block when destroyed, and scoped guards, which are tied to the scope exit.SYNOPSIS use Guard; # temporarily chdir to "/etc" directory, but make sure # to go back to "/" no matter how myfun exits: sub myfun { scope_guard { chdir "/" }; chdir "/etc"; code_that_might_die_or_does_other_fun_stuff; } # create an object that, when the last reference to it is gone, # invokes the given codeblock: my $guard = guard { print "destroyed! " }; undef $guard; # probably destroyed here Requirements: · Perl
Guard Related Software