NAME
Evo::Guard - A guard
VERSION
version 0.0161
SYNOPSIS
use Evo::Base -strict;
use Evo::Guard;
eval {
my $guard
= Evo::Guard->new(sub($err=undef) { say $err ? "$err" : "alive" });
die "Error";
};
eval {
my $guard
= Evo::Guard->new(sub($err=undef) { say $err ? "$err" : "alive" });
};
DESCRIPTION
Executes a code when no refs are pointed to this object. The behavoiur is similar to "guard" in Guard, but this module is pure perl (and about 70-80% slower) and covers more cases.
It can be used to do some cleanups no matter was exception thrown or not. Or it can do something usefull only on exceptions Or it can do both
METHODS
new
Creates a guard object. It will raise an exception if you forget to save it in somewhere.
The first argument will be executed when guard is out of scope.
If there was an exception in scope, the first argument will be passed to the cb. If all is ok, no arguments will be passed. So you can check the first argument to do some job on errors only
AUTHOR
alexbyk.com
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by alexbyk.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.