lib/Ubic/Result/Class.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 90.0% 18 / 20 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 92.3% 12 / 13 Podpod 100% 4 / 4 totaltotal 93.6% 88 / 94 SCAR 24.9
CC
12
Cov
95%
status
6.0
as_string
4.0
action
3.0
CRAP 12.0
« lib/Ubic/Multiservice.pm ↑ Summary blib/lib/Ubic/AccessGuard.pm »
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"
l!l
3620
MC/DC0%0/1
$self->{"type"} ||= "unknown"
$self->{"type"}
Truth table50%1/2
A
A= $self->{"type"}
Aresult
11
00
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
BranchTrueFalseTotal
if @_ 0 526 526
38 526 ▶ if (grep { $_ eq $self->{type} } ('running', 'already running', 'started', 'already started', 'restarted', 'reloaded', 'stopping')) {
Branch: 4 branches
BranchTrueFalseTotal
if (grep {$_ eq $self->{'type'};} 'running', 'already running', 'started', 'already started', 'restarted', 'reloaded', 'stopping') { } 204 322 526
elsif (grep {$_ eq $self->{'type'};} 'not running', 'stopped', 'starting') { } 288 34 322
elsif (grep {$_ eq $self->{'type'};} 'down') { } 10 24 34
elsif (grep {$_ eq $self->{'type'};} 'autostarting') { } 1 23 24
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
BranchTrueFalseTotal
if @_ 0 14 14
58 14 ▶ if (grep { $_ eq $self->{type} } ('started', 'stopped', 'reloaded')) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $self->{"type"};} "started", "stopped", "reloaded") 7 7 14
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
BranchTrueFalseTotal
$self->{'cached'} ? : 3 786 789
67 789 ▶ if (defined $self->{msg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'msg'}) { } 310 479 789
68 310 ▶ if ($self->{type} eq 'unknown') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'type'} eq 'unknown') { } 2 308 310
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__
« lib/Ubic/Multiservice.pm ↑ Summary blib/lib/Ubic/AccessGuard.pm »