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