my $guard = guard { ... }; # or my $guard = scope_guard \&handler; # or my $guard = Scope::Guard->new(sub { ... }); $guard->dismiss(); # disable the handler
For more information, see: <http://www.drdobbs.com/cpp/184403758>
my $guard = Scope::Guard->new(sub { ... }); # or my $guard = Scope::Guard->new(\&handler);
The "new" method creates a new "Scope::Guard" object which calls the supplied handler when its "DESTROY" method is called, typically at the end of the scope.
$guard->dismiss(); # or $guard->dismiss(1);
"dismiss" detaches the handler from the "Scope::Guard" object. This revokes the ``promise'' to call the handler when the object is destroyed.
The handler can be re-enabled by calling:
$guard->dismiss(0);
Scope::Guard->new(...)
e.g.
my $guard = guard { ... };
Note: calling "guard" anonymously, i.e. in void context, will raise an exception. This is because anonymous guards are destroyed immediately (rather than at the end of the scope), which is unlikely to be the desired behaviour.
my $guard = scope_guard \&handler;
or:
my $guard = scope_guard sub { ... };
or:
my $guard = scope_guard $handler;
As with "guard", calling "scope_guard" in void context will raise an exception.
This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.