Cmd/Host.pm

filter: Statementstmt 43.8% 25 / 57 Branchbran 22.7% 5 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 4 / 4 totaltotal 43.4% 40 / 92 CC 13 SCAR 31.0
CC
13
Cov
38%
list
56.0
del
12.0
add
6.1
CRAP 22.1
« Cmd/Init.pm ↑ Summary Cmd/Cobbler.pm »
1 package Tapper::Cmd::Host;
2 2 our $AUTHORITY = 'cpan:TAPPER';
3 2 $Tapper::Cmd::Host::VERSION = '5.0.14';
4 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Tapper::Model 'model';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use YAML::Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use parent 'Tapper::Cmd';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13  
14 sub add
15 2 ▶{
Subroutine add: called CC=5 SCAR=18.0
Pod documented
16 2 my ($self, $data) = @_;
17 2 ▶ if (not ref($data) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data eq "HASH") 0 2 2
18 0 die "Wrong data format, expected hash ref, got ",ref $data;
19 }
20 2 ▶ if ($data->{pool_count}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"pool_count"}) 1 1 2
21 1 ▶ die "pool_count can not go together with pool_free" if $data->{pool_free};
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"pool_free"} 1 0 1
22 0 $data->{pool_free} = $data->{pool_count};
23 }
24 1 my $host_r = Tapper::Model::model()->resultset('Host')->search({name => $data->{name}}, {rows => 1})->first;
25 1 ▶ if ($host_r) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host_r) { } 0 1 1
26 0 $host_r->is_deleted(0);
27 0 $host_r->update;
28 } else {
29 1 $host_r = model('TestrunDB')->resultset('Host')->new($data)->insert;
30 }
31 1 return $host_r->id;
32  
33 }
34  
35  
36  
37 sub del
38 0 ▶{
Subroutine del: not called CC=3 SCAR=24.8
Pod documented
39 0 my ($self, $id) = @_;
40 0 my $host;
41 0 ▶ if ($id =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /^\d+$/) { } 0 0 0
42 0 $host = model('TestrunDB')->resultset('Host')->find($id);
43 } else {
44 0 $host = model('TestrunDB')->resultset('Host')->find({name => $id});
45 }
46 0 ▶ die qq(Host "$id" not found) if not $host;;
Branch: 1 branch
BranchTrueFalseTotal
unless $host 0 0 0
47 0 $host->is_deleted(1);
48 0 $host->active(0);
49 0 $host->free(0);
50 0 $host->update;
51 0 return 0;
52 }
53  
54  
55 sub update
56 0 ▶{
Subroutine update: not called CC=1 SCAR=0.0
Pod documented
57 }
58  
59  
60 sub list
61 0 ▶{
Subroutine list: not called CC=7 SCAR=40.3
Pod documented
62 0 my ($self, $filter, $order) = @_;
63 0 my %options= (order_by => 'name');
64 0 my %search;
65  
66 0 for my $key ('free', 'active') {
67 0 ▶ $search{$key} = $filter->{$key} if defined $filter->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $filter->{$key} 0 0 0
68 }
69 0 ▶ $search{is_deleted} = {-in => [ 0, undef ] } unless $filter->{deleted};
Branch: 1 branch
BranchTrueFalseTotal
unless $filter->{"deleted"} 0 0 0
70 0 ▶ $search{is_pool} = { not => undef } if $filter->{pool};
Branch: 1 branch
BranchTrueFalseTotal
if $filter->{"pool"} 0 0 0
71  
72 # ignore all filterions if host is requested by name
73 0 ▶ %search = (name => $filter->{name}) if $filter->{name};
Branch: 1 branch
BranchTrueFalseTotal
if $filter->{"name"} 0 0 0
74  
75 0 ▶ if ($filter->{queue}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter->{"queue"}) 0 0 0
76 0 my @queue_ids = map {$_->id} model('TestrunDB')->resultset('Queue')->search({name => {-in => $filter->{queue}}});
77 0 $search{queue_id} = { -in => [ @queue_ids ]};
78 0 $options{join} = 'queuehosts';
79 0 $options{'+select'} = 'queuehosts.queue_id';
80 0 $options{'+as'} = 'queue_id';
81 }
82 0 my $hosts = model('TestrunDB')->resultset('Host')->search(\%search, \%options);
83 0 return $hosts;
84 }
85  
86 2 1; # End of Tapper::Cmd::Testrun
87  
88 __END__
« Cmd/Init.pm ↑ Summary Cmd/Cobbler.pm »