line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perinci::Sub::Property::dies_on_error; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
57033
|
use 5.010001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
48
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
6
|
|
|
|
|
|
|
#use Log::Any '$log'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
941
|
use Perinci::Sub::PropertyUtil qw(declare_property); |
|
1
|
|
|
|
|
995
|
|
|
1
|
|
|
|
|
452
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.05'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
declare_property( |
13
|
|
|
|
|
|
|
name => 'dies_on_error', |
14
|
|
|
|
|
|
|
type => 'function', |
15
|
|
|
|
|
|
|
schema => ['any*' => {of=>[ |
16
|
|
|
|
|
|
|
['bool' => {default=>0}], |
17
|
|
|
|
|
|
|
['hash*' => {keys=>{ |
18
|
|
|
|
|
|
|
'success_statuses' => ['regex' => {default=>'^(2..|304)$'}], |
19
|
|
|
|
|
|
|
}}], |
20
|
|
|
|
|
|
|
]}], |
21
|
|
|
|
|
|
|
wrapper => { |
22
|
|
|
|
|
|
|
meta => { |
23
|
|
|
|
|
|
|
v => 2, |
24
|
|
|
|
|
|
|
prio => 99, # very low, the last to do stuff to $_w_res |
25
|
|
|
|
|
|
|
convert => 1, |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
handler => sub { |
28
|
10
|
|
|
10
|
|
70898
|
my ($self, %args) = @_; |
29
|
10
|
|
33
|
|
|
242
|
my $v = $args{new} // $args{value} // 0; |
|
|
|
50
|
|
|
|
|
30
|
10
|
|
|
|
|
20
|
my $meta = $args{meta}; |
31
|
|
|
|
|
|
|
|
32
|
10
|
50
|
|
|
|
34
|
return unless $v; |
33
|
|
|
|
|
|
|
|
34
|
10
|
100
|
|
|
|
83
|
die "Cannot use dies_on_error if result_naked is 1" |
35
|
|
|
|
|
|
|
if $self->{_meta}{result_naked}; |
36
|
|
|
|
|
|
|
|
37
|
8
|
100
|
|
|
|
30
|
$v = {} if ref($v) ne 'HASH'; |
38
|
|
|
|
|
|
|
|
39
|
8
|
|
66
|
|
|
50
|
$v->{success_statuses} //= qr/^(2..|304)$/; |
40
|
|
|
|
|
|
|
|
41
|
8
|
|
|
|
|
15
|
for my $k (qw/success_statuses/) { |
42
|
8
|
50
|
33
|
|
|
68
|
if (defined($v->{$k}) && ref($v->{$k}) ne 'Regexp') { |
43
|
0
|
|
|
|
|
0
|
$v->{$k} = qr/$v->{$k}/; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
8
|
|
|
|
|
33
|
$self->select_section('after_eval'); |
48
|
|
|
|
|
|
|
|
49
|
8
|
|
|
|
|
123
|
$self->push_lines('if ($_w_eval_err) { die $_w_eval_err }'); |
50
|
|
|
|
|
|
|
|
51
|
8
|
|
|
|
|
434
|
$self->push_lines('if ($_w_res->[0] !~ /'.$v->{success_statuses}.'/) {'); |
52
|
8
|
|
|
|
|
126
|
$self->indent; |
53
|
8
|
50
|
|
|
|
105
|
$self->push_lines(join( |
54
|
|
|
|
|
|
|
"", |
55
|
|
|
|
|
|
|
"die 'Call to ", |
56
|
|
|
|
|
|
|
($self->{_args}{sub_name} ? "$self->{_args}{sub_name}()" : "function"), |
57
|
|
|
|
|
|
|
q[ returned non-success status '. "$_w_res->[0]: $_w_res->[1]";])); |
58
|
8
|
|
|
|
|
161
|
$self->unindent; |
59
|
8
|
|
|
|
|
65
|
$self->push_lines('}'); |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
# ABSTRACT: Die on non-success result |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |