API/User.pm

filter: Statementstmt 28.9% 20 / 69 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 37.5% 6 / 16 Podpod 100% 9 / 9 totaltotal 29.6% 35 / 118 CC 11 SCAR 22.0
CC
11
Cov
22%
_usergroup_or_name_to_usergroup
30.0
id
6.0
prefix
6.0
CRAP 9.0
« API/Map.pm ↑ Summary API/Trigger.pm »
1 package Zabbix::API::User;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use parent qw/Exporter Zabbix::API::CRUDE/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 USER_TYPE_USER => 1,
12 USER_TYPE_ADMIN => 2,
13 USER_TYPE_SUPERADMIN => 3,
14 1 };
15  
16 1 our @EXPORT_OK = qw/
17 USER_TYPE_USER
18 USER_TYPE_ADMIN
19 USER_TYPE_SUPERADMIN/;
20  
21 1 our %EXPORT_TAGS = (
22 user_types => [
23 qw/USER_TYPE_USER
24 USER_TYPE_ADMIN
25 USER_TYPE_SUPERADMIN/
26 ],
27 );
28  
29 0 ▶sub id {
Subroutine id: not called CC=2 SCAR=17.9
Pod documented
30  
31 ## mutator for id
32  
33 0 my ($self, $value) = @_;
34  
35 0 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 0 0 0
36  
37 0 $self->data->{userid} = $value;
38 0 return $self->data->{userid};
39  
40 } else {
41  
42 0 return $self->data->{userid};
43  
44 }
45  
46 }
47  
48 0 ▶sub prefix {
Subroutine prefix: not called CC=2 SCAR=17.9
Pod documented
49  
50 0 my (undef, $suffix) = @_;
51  
52 0 ▶ if ($suffix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suffix) { } 0 0 0
53  
54 0 return 'user'.$suffix;
55  
56 } else {
57  
58 0 return 'user';
59  
60 }
61  
62 }
63  
64 0 ▶sub extension {
Subroutine extension: not called CC=1 SCAR=6.9
Pod documented
65  
66 0 return ( output => 'extend',
67 select_usrgrps => 'refer' );
68  
69 }
70  
71 0 ▶sub collides {
Subroutine collides: not called CC=1 SCAR=6.9
Pod documented
72  
73 0 my $self = shift;
74  
75 0 return @{$self->{root}->query(method => $self->prefix('.get'),
76 params => { filter => { alias => $self->data->{alias} },
77 0 $self->extension })};
78  
79 }
80  
81 0 ▶sub name {
Subroutine name: not called CC=2 SCAR=17.9
Pod documented
82  
83 0 my $self = shift;
84  
85 0 ▶ return $self->data->{alias} || '[no username?]';
Condition0%0/2
$self->data->{'alias'} || '[no username?]'
l!l
00
MC/DC0%0/1
$self->data->{'alias'} || '[no username?]'
$self->data->{'alias'}
Truth table0%0/2
A
A= $self->data->{'alias'}
Aresult
11
00
86  
87 }
88  
89 0 ▶sub usergroups {
Subroutine usergroups: not called CC=2 SCAR=17.9
Pod documented
90  
91 ## accessor for usergroups
92  
93 0 my ($self, $value) = @_;
94  
95 0 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 0 0 0
96  
97 0 die 'Accessor usergroups called as mutator';
98  
99 } else {
100  
101 0 my $usergroups = $self->{root}->fetch('UserGroup', params => { usrgrpids => [ map { $_->{usrgrpid} } @{$self->data->{usrgrps}} ] });
102 0 $self->{usergroups} = $usergroups;
103  
104 0 return $self->{usergroups};
105  
106 }
107  
108 }
109  
110 0 ▶sub _usergroup_or_name_to_usergroup {
Subroutine _usergroup_or_name_to_usergroup: not called CC=5 SCAR=34.0
111  
112 0 my $zabbix = shift;
113 0 my $usergroup_or_name = shift;
114 0 my $usergroup;
115  
116 0 ▶ if (ref $usergroup_or_name and eval { $usergroup_or_name->isa('Zabbix::API::UserGroup') }) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $usergroup_or_name and eval { do { $usergroup_or_name->isa('Zabbix::API::UserGroup') } }) { } 0 0 0
elsif (not ref $usergroup_or_name) { } 0 0 0
Condition0%0/3
ref $usergroup_or_name and eval { do { $usergroup_or_name->isa("Zabbix::API::UserGroup") } }
!ll&&!rl&&r
000
MC/DC0%0/2
ref $usergroup_or_name and eval { do { $usergroup_or_name->isa("Zabbix::API::UserGroup") } }
ref $usergroup_or_name eval { do { $usergroup_or_name->isa("Zabbix::API::UserGroup") } }
Truth table0%0/3
A and B
A= ref $usergroup_or_nameB= eval { do { $usergroup_or_name->isa("Zabbix::API::UserGroup") } }
ABresult
0X0
100
111
117  
118 # it's a UserGroup object, keep it
119 0 $usergroup = $usergroup_or_name;
120  
121 } elsif (not ref $usergroup_or_name) {
122  
123 0 $usergroup = $zabbix->fetch('UserGroup', params => { filter => { name => $usergroup_or_name } })->[0];
124  
125 0 ▶ unless ($usergroup) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($usergroup) 0 0 0
126  
127 0 die 'Parameter to add_to_usergroup or set_usergroups must be a Zabbix::API::UserGroup object or an existing usergroup name';
128  
129 }
130  
131 } else {
132  
133 0 die 'Parameter to add_to_usergroup or set_usergroups must be a Zabbix::API::UserGroup object or an existing usergroup name';
134  
135 }
136  
137 0 return $usergroup;
138  
139 }
140  
141 0 ▶sub add_to_usergroup {
Subroutine add_to_usergroup: not called CC=2 SCAR=17.9
Pod documented
142  
143 0 my ($self, $usergroup_or_name) = @_;
144 0 my $usergroup = _usergroup_or_name_to_usergroup($self->{root}, $usergroup_or_name);
145  
146 0 ▶ die 'User does not exist (yet?) on server'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->created 0 0 0
147 unless $self->created;
148  
149 0 $self->{root}->query(method => 'usergroup.massAdd',
150 params => { usrgrpids => [ $usergroup->id ],
151 userids => [ $self->id ] });
152  
153 0 return $self;
154  
155 }
156  
157 0 ▶sub set_usergroups {
Subroutine set_usergroups: not called CC=2 SCAR=17.9
Pod documented
158  
159 0 my ($self, @list_of_usergroups_or_names) = @_;
160  
161 0 ▶ die 'User does not exist (yet?) on server'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->created 0 0 0
162 unless $self->created;
163  
164 0 my @list_of_usergroups = map { _usergroup_or_name_to_usergroup($self->{root}, $_) } @list_of_usergroups_or_names;
165  
166 $self->{root}->query(method => 'user.update',
167 params => { userid => $self->id,
168 0 usrgrps => [ map { $_->id } @list_of_usergroups ] });
169  
170 0 return $self;
171  
172 }
173  
174 0 ▶sub set_password {
Subroutine set_password: not called CC=1 SCAR=6.9
Pod documented
175  
176 0 my ($self, $password) = @_;
177 0 $self->data->{passwd} = $password;
178 0 return $self;
179  
180 }
181  
182 1 1;
183 __END__
« API/Map.pm ↑ Summary API/Trigger.pm »