File Coverage

blib/lib/Email/Pipemailer/DieHandler.pm
Criterion Covered Total %
statement 6 17 35.2
branch 0 6 0.0
condition 0 7 0.0
subroutine 2 5 40.0
pod n/a
total 8 35 22.8


line stmt bran cond sub pod time code
1 1     1   475 use strict;
  1         2  
  1         24  
2 1     1   4 use warnings;
  1         2  
  1         136  
3             package Email::Pipemailer::DieHandler 1.002;
4             # ABSTRACT: do not die embarassingly if you screw up your pipemailer
5              
6             #pod =head1 SYNOPSIS
7             #pod
8             #pod #!/usr/bin/perl
9             #pod use Email::Pipemailer::DieHandler -install;
10             #pod use strict;
11             #pod use warnings;
12             #pod
13             #pod # your code goes here
14             #pod
15             #pod Always put the DieHandler before B else. You want there to be
16             #pod B no condition that will cause a bounce, right? That includes
17             #pod failure to compile.
18             #pod
19             #pod This is also legal:
20             #pod
21             #pod use Email::Pipemailer::DieHandler -install => { logger => sub { ... } };
22             #pod
23             #pod The error will be passed to the sub.
24             #pod
25             #pod =cut
26              
27             sub import {
28 0     0     my ($self, $install, $arg) = @_;
29 0 0 0       return unless $install and $install eq '-install';
30              
31 0   0       $arg ||= {};
32 0   0 0     my $logger = $arg->{logger} || sub {};
33              
34             $SIG{__DIE__} = sub {
35 0 0   0     return if $^S; # don't interfere with evals
36 0           my ($e) = @_;
37 0 0         defined $^S and eval { $logger->($e); };
  0            
38 0           $! = 75;
39 0           die $e;
40 0           };
41             }
42              
43             1;
44              
45             __END__