File: CaptureException.pm

package info (click to toggle)
libmoo-perl 2.005005-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 840 kB
  • sloc: perl: 2,506; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 488 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package CaptureException;
use strict;
use warnings;
use lib 't/lib';

use Exporter (); BEGIN { *import = \&Exporter::import }
use Carp ();

our @EXPORT = qw(exception);

sub exception (&) {
  my $cb = shift;
  eval {
    local $Test::Builder::Level = $Test::Builder::Level + 3;
    $cb->();
    1;
  } or do {
    return $@
      if $@;
    Carp::confess(
      (defined $@ ? 'false' : 'undef')
      . " exception caught by CaptureException::exception"
    );
  };
  return undef;
}

1;