| 1 | package Ubic::Result::Class; | ||||||||||||||||||||||
| 2 | 174 | $Ubic::Result::Class::VERSION = '1.59'; | |||||||||||||||||||||
| 3 | 174 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 174 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | # ABSTRACT: ubic result object | ||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | use overload '""' => sub { | ||||||||||||||||||||||
| 10 | 789 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | 789 | return $self->as_string; | |||||||||||||||||||||
| 12 | }, 'eq' => sub { | ||||||||||||||||||||||
| 13 | 38 | ▶ | return ("$_[0]" eq "$_[1]") | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | }, 'ne' => sub { | ||||||||||||||||||||||
| 15 | 0 | ▶ | return ("$_[0]" ne "$_[1]") | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 16 | 174 | ▶ | }; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | 174 | ▶ | use Params::Validate qw(:all); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 19 | 174 | ▶ | use Carp; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 20 | 174 | ▶ | use parent qw(Class::Accessor::Fast); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | 174 | __PACKAGE__->mk_accessors(qw/ type msg /); | |||||||||||||||||||||
| 23 | |||||||||||||||||||||||
| 24 | sub new { | ||||||||||||||||||||||
| 25 | 362 | ▶ | my $class = shift; | ||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||
| 26 | 362 | my $self = validate(@_, { | |||||||||||||||||||||
| 27 | type => { type => SCALAR, optional => 1 }, | ||||||||||||||||||||||
| 28 | msg => { optional => 1 }, | ||||||||||||||||||||||
| 29 | cached => { optional => 1 }, | ||||||||||||||||||||||
| 30 | }); | ||||||||||||||||||||||
| 31 | 362 | ▶ | $self->{type} ||= 'unknown'; | ||||||||||||||||||||
|
Condition50%1/2
$self->{"type"} ||= "unknown"
MC/DC0%0/1
$self->{"type"} ||= "unknown"
$self->{"type"}
Truth table50%1/2
A
A= $self->{"type"}
| |||||||||||||||||||||||
| 32 | 362 | return bless $self => $class; | |||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | sub status { | ||||||||||||||||||||||
| 36 | 526 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
status: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||
| 37 | 526 | ▶ | croak 'status() is read-only method' if @_; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 38 | 526 | ▶ | if (grep { $_ eq $self->{type} } ('running', 'already running', 'started', 'already started', 'restarted', 'reloaded', 'stopping')) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 39 | 204 | return 'running'; | |||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||
| 41 | 966 | elsif (grep { $_ eq $self->{type} } ('not running', 'stopped', 'starting')) { | |||||||||||||||||||||
| 42 | 288 | return 'not running'; | |||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||
| 44 | 34 | elsif (grep { $_ eq $self->{type} } ('down')) { | |||||||||||||||||||||
| 45 | 10 | return 'down'; | |||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||
| 47 | 24 | elsif (grep { $_ eq $self->{type} } ('autostarting')) { | |||||||||||||||||||||
| 48 | 1 | return 'autostarting'; | |||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||
| 51 | 23 | return 'broken'; | |||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | sub action { | ||||||||||||||||||||||
| 56 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
action: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||
| 57 | 14 | ▶ | croak 'action() is read-only method' if @_; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 58 | 14 | ▶ | if (grep { $_ eq $self->{type} } ('started', 'stopped', 'reloaded')) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 59 | 7 | return $self->{type}; | |||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||
| 61 | 7 | return 'none'; | |||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | sub as_string { | ||||||||||||||||||||||
| 65 | 789 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
as_string: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||
| 66 | 789 | ▶ | my $cached_str = ($self->{cached} ? ' [cached]' : ''); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 67 | 789 | ▶ | if (defined $self->{msg}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 68 | 310 | ▶ | if ($self->{type} eq 'unknown') { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 69 | 2 | return "$self->{msg}\n"; | |||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||||
| 72 | 308 | return "$self->{type} ($self->{msg})".$cached_str; | |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||
| 75 | else { | ||||||||||||||||||||||
| 76 | 479 | return $self->type.$cached_str; | |||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||
| 79 | |||||||||||||||||||||||
| 80 | |||||||||||||||||||||||
| 81 | 174 | 1; | |||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||