line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perinci::Object::EnvResultMulti; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2021-01-02'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'Perinci-Object'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.311'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
20
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
9
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
10
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
459
|
use parent qw(Perinci::Object::EnvResult); |
|
1
|
|
|
|
|
306
|
|
|
1
|
|
|
|
|
5
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
6
|
|
|
6
|
1
|
19
|
my ($class, $res) = @_; |
16
|
6
|
|
50
|
|
|
37
|
$res //= [200, "Success/no items"]; |
17
|
6
|
|
|
|
|
12
|
my $obj = \$res; |
18
|
6
|
|
|
|
|
18
|
bless $obj, $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub add_result { |
22
|
12
|
|
|
12
|
1
|
2752
|
my ($self, $status, $message, $extra) = @_; |
23
|
12
|
|
50
|
|
|
28
|
$extra //= {}; |
24
|
12
|
|
|
|
|
16
|
my $num_ok = 0; |
25
|
12
|
|
|
|
|
18
|
my $num_nok = 0; |
26
|
|
|
|
|
|
|
|
27
|
12
|
|
|
|
|
17
|
push @{ ${$self}->[3]{results} }, |
|
12
|
|
|
|
|
17
|
|
|
12
|
|
|
|
|
89
|
|
28
|
|
|
|
|
|
|
{status=>$status, message=>$message, %$extra}; |
29
|
12
|
100
|
|
|
|
36
|
if (exists $extra->{payload}) { |
30
|
2
|
|
100
|
|
|
5
|
${$self}->[2] //= []; |
|
2
|
|
|
|
|
8
|
|
31
|
2
|
|
|
|
|
4
|
push @{ ${$self}->[2] }, $extra->{payload}; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
5
|
|
32
|
|
|
|
|
|
|
} |
33
|
12
|
|
50
|
|
|
19
|
for (@{ ${$self}->[3]{results} // [] }) { |
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
39
|
|
34
|
21
|
100
|
|
|
|
73
|
if ($_->{status} =~ /\A(2|304)/) { |
35
|
15
|
|
|
|
|
29
|
$num_ok++; |
36
|
|
|
|
|
|
|
} else { |
37
|
6
|
|
|
|
|
11
|
$num_nok++; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
12
|
100
|
|
|
|
23
|
if ($num_ok) { |
41
|
9
|
100
|
|
|
|
18
|
if ($num_nok) { |
42
|
2
|
|
|
|
|
4
|
${$self}->[0] = 207; |
|
2
|
|
|
|
|
5
|
|
43
|
2
|
|
|
|
|
5
|
${$self}->[1] = "Partial success"; |
|
2
|
|
|
|
|
6
|
|
44
|
|
|
|
|
|
|
} else { |
45
|
7
|
|
|
|
|
10
|
my $overall_status = 200; |
46
|
7
|
|
|
|
|
10
|
my %statuses; |
47
|
7
|
|
50
|
|
|
10
|
for (@{ ${$self}->[3]{results} // []}) { |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
20
|
|
48
|
13
|
|
|
|
|
27
|
$statuses{ $_->{status} }++; |
49
|
|
|
|
|
|
|
} |
50
|
7
|
100
|
|
|
|
20
|
if (keys %statuses == 1) { |
51
|
3
|
|
|
|
|
7
|
my @tmp = keys %statuses; |
52
|
3
|
|
|
|
|
7
|
$overall_status = $tmp[0]; |
53
|
|
|
|
|
|
|
} |
54
|
7
|
|
|
|
|
8
|
${$self}->[0] = $overall_status; |
|
7
|
|
|
|
|
13
|
|
55
|
7
|
|
|
|
|
11
|
${$self}->[1] = "All success"; |
|
7
|
|
|
|
|
35
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} else { |
58
|
3
|
|
|
|
|
6
|
${$self}->[0] = $status; |
|
3
|
|
|
|
|
6
|
|
59
|
3
|
|
|
|
|
5
|
${$self}->[1] = $message; |
|
3
|
|
|
|
|
8
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
# ABSTRACT: Represent enveloped result (multistatus) |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |