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