The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Evo::Guard - A guard

VERSION

version 0.0159

SYNOPSIS

  use Evo::Base -strict;
  use Evo::Guard;

  eval {
    my $guard = Evo::Guard->new(
      error  => sub { say "ERROR cleanups" },
      always => sub { say "Always cleanups" }
    );
    die "Error";
  };

Arguments

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.

If an error callback will cause an exception (but this is surely a bug in your code), always callback will be executed too

error

A callback that will be executed only if an unhandled exception was trown in the same scope

always

This callback will be executed no matter was exception thrown or not

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.