line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Try::Tiny::Warnings; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
# ABSTRACT: extension to Try::Tiny to also catch warnings |
4
|
|
|
|
|
|
|
$Try::Tiny::Warnings::VERSION = '0.1.0'; |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
39582
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
58
|
|
7
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
81
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
7
|
use Exporter; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
118
|
|
10
|
2
|
|
|
2
|
|
483
|
use Try::Tiny; |
|
2
|
|
|
|
|
1129
|
|
|
2
|
|
|
|
|
106
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
930
|
use parent 'Exporter'; |
|
2
|
|
|
|
|
801
|
|
|
2
|
|
|
|
|
10
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ try catch finally /; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT = qw/ |
17
|
|
|
|
|
|
|
try_warnings |
18
|
|
|
|
|
|
|
try_fatal_warnings |
19
|
|
|
|
|
|
|
catch_warnings |
20
|
|
|
|
|
|
|
/; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
23
|
|
|
|
|
|
|
'all' => [ @EXPORT, @EXPORT_OK ], |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub try_fatal_warnings(&;@) { |
27
|
4
|
|
|
4
|
0
|
19882
|
my $sub = shift; |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
4
|
|
45
|
local $SIG{__WARN__} = sub { die @_ }; |
|
4
|
|
|
|
|
92
|
|
30
|
|
|
|
|
|
|
|
31
|
4
|
|
|
4
|
|
22
|
try { $sub->() } @_; |
|
4
|
|
|
|
|
123
|
|
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub try_warnings(&;@) { |
35
|
2
|
|
|
2
|
0
|
14
|
my $sub = shift; |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
4
|
my @warnings; |
38
|
2
|
|
|
4
|
|
9
|
local $SIG{__WARN__} = sub { push @warnings, @_ }; |
|
4
|
|
|
|
|
47
|
|
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
2
|
|
71
|
try { $sub->() } map { |
41
|
2
|
|
|
|
|
9
|
my $x = $_; |
|
4
|
|
|
|
|
6
|
|
42
|
|
|
|
|
|
|
ref $_ eq 'Try::Tiny::Warnings::Catch' |
43
|
2
|
|
|
2
|
|
59
|
? finally { $x->(@warnings) } |
44
|
4
|
100
|
|
|
|
43
|
: $_ |
45
|
|
|
|
|
|
|
} @_; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub catch_warnings(&;@) { |
50
|
2
|
|
|
2
|
0
|
890
|
my $sub = shift; |
51
|
2
|
|
|
|
|
29
|
return bless( $sub, 'Try::Tiny::Warnings::Catch' ), @_ |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |