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.0.2'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
22443
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
10
|
1
|
|
|
1
|
|
4
|
use Try::Tiny; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
725
|
use parent 'Exporter'; |
|
1
|
|
|
|
|
275
|
|
|
1
|
|
|
|
|
5
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT = qw/ try_warnings try_fatal_warnings catch_warnings /; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub try_fatal_warnings(&;@) { |
17
|
2
|
|
|
2
|
0
|
12805
|
my($sub,@rest) = @_; |
18
|
2
|
|
|
2
|
|
12
|
local $SIG{__WARN__} = sub { die @_ }; |
|
2
|
|
|
|
|
47
|
|
19
|
2
|
|
|
2
|
|
14
|
try { $sub->() } @rest; |
|
2
|
|
|
|
|
51
|
|
20
|
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub try_warnings(&;@) { |
23
|
1
|
|
|
1
|
0
|
7
|
my($sub,@rest) = @_; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
2
|
my @warnings; |
26
|
1
|
|
|
2
|
|
4
|
local $SIG{__WARN__} = sub { push @warnings, @_ }; |
|
2
|
|
|
|
|
23
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
@rest = map { |
29
|
1
|
|
|
|
|
3
|
my $x = $_; |
|
2
|
|
|
|
|
5
|
|
30
|
|
|
|
|
|
|
ref $_ eq 'Try::Tiny::Warnings::Catch' |
31
|
1
|
|
|
1
|
|
27
|
? finally { $x->(@warnings) } |
32
|
2
|
100
|
|
|
|
9
|
: $_ |
33
|
|
|
|
|
|
|
} @rest; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
1
|
|
14
|
try { $sub->() } @rest; |
|
1
|
|
|
|
|
28
|
|
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub catch_warnings(&;@) { |
39
|
1
|
|
|
1
|
0
|
761
|
my( $sub, @rest ) = @_; |
40
|
1
|
|
|
|
|
6
|
$sub = bless $sub, 'Try::Tiny::Warnings::Catch'; |
41
|
1
|
|
|
|
|
3
|
return( $sub, @rest ); |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |