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