API/Template.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 64 CC 4 SCAR 13.1
CC
4
Cov
0%
id
6.0
prefix
6.0
items
6.0
CRAP 3.7
1 package Zabbix::API::Template;
2  
3 use strict;
4 use warnings;
5 use 5.010;
6 use Carp;
7  
8 use parent qw/Zabbix::API::CRUDE/;
9  
10 sub id {
11  
12 ## mutator for id
13  
14 my ($self, $value) = @_;
15  
16 if (defined $value) {
17  
18 $self->data->{templateid} = $value;
19 return $self->data->{templateid};
20  
21 } else {
22  
23 return $self->data->{templateid};
24  
25 }
26  
27 }
28  
29 sub prefix {
30  
31 my (undef, $suffix) = @_;
32  
33 if ($suffix) {
34  
35 return 'template'.$suffix;
36  
37 } else {
38  
39 return 'template';
40  
41 }
42  
43 }
44  
45 sub extension {
46  
47 return ( output => 'extend' );
48  
49 }
50  
51 sub collides {
52  
53 my $self = shift;
54  
55 return @{$self->{root}->query(method => $self->prefix('.get'),
56 params => { filter => { host => $self->data->{host} },
57 $self->extension })};
58  
59 }
60  
61 sub name {
62  
63 my $self = shift;
64  
65 return $self->data->{host} || '';
66  
67 }
68  
69 sub items {
70  
71 ## accessor for items
72  
73 my ($self, $value) = @_;
74  
75 if (defined $value) {
76  
77 die 'Accessor items called as mutator';
78  
79 } else {
80  
81 my $items = $self->{root}->fetch('Item', params => { templateids => [ $self->data->{templateid} ] });
82  
83 $self->{items} = $items;
84  
85 return $self->{items};
86  
87 }
88  
89 }
90  
91 1;
92 __END__