line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ubic::Cmd::Results; |
2
|
|
|
|
|
|
|
$Ubic::Cmd::Results::VERSION = '1.59'; |
3
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
44
|
|
4
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
57
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
497
|
use Term::ANSIColor qw(:constants); |
|
2
|
|
|
|
|
4537
|
|
|
2
|
|
|
|
|
809
|
|
7
|
|
|
|
|
|
|
$Term::ANSIColor::AUTORESET = 1; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
11
|
use Params::Validate qw(:all); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
972
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: console results set |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
4
|
|
|
4
|
1
|
31
|
return bless { data => [] } => shift; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub print_bad { |
18
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
19
|
1
|
50
|
|
|
|
6
|
if (-t STDOUT) { |
20
|
0
|
|
|
|
|
0
|
print RED @_; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
else { |
23
|
1
|
|
|
|
|
5
|
print @_; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub print_good { |
28
|
3
|
|
|
3
|
1
|
9
|
my $self = shift; |
29
|
3
|
50
|
|
|
|
17
|
if (-t STDOUT) { |
30
|
0
|
|
|
|
|
0
|
print GREEN @_; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
3
|
|
|
|
|
26
|
print @_; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub print($$;$) { |
38
|
3
|
|
|
3
|
1
|
17
|
my $self = shift; |
39
|
3
|
|
|
|
|
86
|
my ($result, $color) = validate_pos(@_, { isa => 'Ubic::Result::Class' }, { optional => 1, regex => qr/^good|bad$/ }); |
40
|
|
|
|
|
|
|
|
41
|
3
|
|
100
|
|
|
36
|
$color ||= ''; |
42
|
3
|
100
|
66
|
|
|
9
|
if ($result->status eq 'broken' or $color eq 'bad') { |
43
|
1
|
|
|
|
|
2
|
my $str = "$result"; |
44
|
1
|
|
|
|
|
5
|
chomp $str; |
45
|
1
|
|
|
|
|
6
|
$self->print_bad("$str\n"); |
46
|
1
|
|
|
|
|
5
|
$self->add($result, 'bad'); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
2
|
|
|
|
|
4
|
$self->print_good("$result\n"); |
50
|
2
|
|
|
|
|
7
|
$self->add($result, 'good'); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub add { |
56
|
3
|
|
|
3
|
1
|
8
|
my ($self, $result, $type) = @_; |
57
|
3
|
|
50
|
|
|
6
|
$type ||= 'good'; # is this too optimistic? |
58
|
3
|
|
|
|
|
5
|
push @{$self->{data}}, [$result => $type]; |
|
3
|
|
|
|
|
33
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub results { |
62
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
63
|
0
|
|
|
|
|
0
|
return map { $_->[0] } @{ $self->{data} }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub exit_code { |
67
|
1
|
|
|
1
|
1
|
15
|
my ($self, $new_code) = validate_pos(@_, 1, 0); |
68
|
1
|
50
|
|
|
|
4
|
if (defined $new_code) { |
69
|
0
|
|
|
|
|
0
|
$self->{exit_code} = $new_code; |
70
|
0
|
|
|
|
|
0
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
1
|
50
|
|
|
|
4
|
if ($self->{exit_code}) { |
73
|
0
|
|
|
|
|
0
|
return $self->{exit_code}; |
74
|
|
|
|
|
|
|
} |
75
|
1
|
|
|
|
|
1
|
my $data = $self->{data}; |
76
|
1
|
|
|
|
|
4
|
my $bad = grep { $_->[1] eq 'bad' } @$data; |
|
1
|
|
|
|
|
3
|
|
77
|
1
|
50
|
|
|
|
9
|
return ($bad ? 1 : 0); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub finish($$) { |
82
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
83
|
0
|
|
|
|
|
|
my $data = $self->{data}; |
84
|
0
|
|
|
|
|
|
my $bad = grep { $_->[1] eq 'bad' } @$data; |
|
0
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
if (@$data > 1) { |
86
|
0
|
|
|
|
|
|
$self->print_bad("Failed: $bad service(s)\n"); |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
|
return $self->exit_code; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |