REST/Config.pm

filter: Statementstmt 91.4% 32 / 35 Branchbran 75.0% 15 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 85.0% 51 / 60 CC 11 SCAR 22.6
CC
11
Cov
85%
BUILDARGS
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 9.6
« REST/Exception.pm ↑ Summary REST/APICaller.pm »
1 package Opsview::REST::Config;
2 {
3 9 $Opsview::REST::Config::VERSION = '0.013';
4 }
5  
6 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 has base => (
10 is => 'ro',
11 122 ▶ default => sub { '/config/' },
Subroutine __ANON__: called CC=1 SCAR=0.0
12 9 init_arg => undef,
13 );
14  
15 9 with 'Opsview::REST::QueryBuilder';
16  
17 9 has '+path' => (
18 required => 1,
19 );
20  
21 9 my @valid_types = qw/
22 contact host role servicecheck hosttemplate attribute timeperiod hostgroup
23 servicegroup notificationmethod hostcheckcommand keyword monitoringserver
24 /;
25  
26 125 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=11 SCAR=24.8
Pod undocumented
27 125 my ($class, $obj_type, @args) = @_;
28  
29 125 ▶ croak "object type required" unless $obj_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $obj_type 1 124 125
30  
31 124 my $id;
32 124 ▶ $id = shift @args if (scalar @args & 1 == 1);
Branch: 1 branch
BranchTrueFalseTotal
if 4 120 124
33 124 ▶ croak "odd number of elements" if (scalar @args & 1 == 1);
Branch: 1 branch
BranchTrueFalseTotal
if 0 124 124
34  
35 124 ▶ if (defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 4 120 124
36 4 ▶ if ($id !~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id =~ /^\d+$/) 2 2 4
37 2 croak 'id must be numeric';
38 }
39 }
40  
41 122 ▶ if (defined $obj_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj_type) { } 122 0 122
42 122 ▶ unless (scalar grep { $obj_type eq $_ } @valid_types) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar grep({$obj_type eq $_;} @valid_types)) 0 122 122
43 0 croak 'object type must be one of: ' . join ' ', @valid_types;
44 }
45 } else {
46 0 $obj_type = '';
47 }
48  
49 122 ▶ if (@args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1) { } 0 122 122
50 0 return {};
51 } else {
52 122 my $path = '';
53 122 ▶ if ($obj_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj_type) 122 0 122
54 122 $path = $obj_type;
55 122 ▶ $path .= "/$id" if $id;
Branch: 1 branch
BranchTrueFalseTotal
if $id 2 120 122
56 }
57  
58 return {
59 122 path => $path,
60 args => { @args },
61 };
62 }
63 }
64  
65 9 __PACKAGE__->meta->make_immutable;
66  
67 9 1;
68 __END__
« REST/Exception.pm ↑ Summary REST/APICaller.pm »