IPA/Response.pm

filter: Statementstmt 24.3% 10 / 41 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 30.0% 3 / 10 Podpod 0.0% 0 / 6 totaltotal 11.3% 13 / 115 CC 20 SCAR 28.5
CC
20
Cov
12%
is_error
30.0
error_code
20.0
error_name
20.0
CRAP 17.3
↑ Summary IPA.pm »
1 # Net::IPA.pm -- Perl 5 interface of the (Free)IPA JSON-RPC API
2 #
3 # for more information about this api see: https://vda.li/en/posts/2015/05/28/talking-to-freeipa-api-with-sessions/
4 #
5 # written by Nicolas Cisco (https://github.com/nickcis)
6 # https://github.com/nickcis/perl-Net-IPA
7 #
8 # Copyright (c) 2016 Nicolas Cisco. All rights reserved.
9 # Licensed under the GPLv2, see LICENSE file for more information.
10  
11 package Net::IPA::Response;
12  
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use vars qw($AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 OptionError => 3005,
18 RequirementError => 3007,
19 NotFound => 4001,
20 DuplicateEntry => 4002,
21 EmptyModlist => 4202, # e.g: user_mod with no modifications to the db
22 1 };
23  
24 sub new
25 0 ▶{
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
26 0 my ($proto, $result) = @_;
27 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
28 0 ▶ my $self = $result || {};
Condition0%0/2
$result || {}
l!l
00
MC/DC0%0/1
$result || {}
$result
Truth table0%0/2
A
A= $result
Aresult
11
00
29 0 bless $self, $class;
30 0 return $self;
31 }
32  
33 #** Returns a string explaining the error.
34 # If it's not an error, it returns an empty string
35 # @return String explaining the error
36 #*
37 sub error_string
38 0 ▶{
Subroutine error_string: not called CC=3 SCAR=24.8
Pod undocumented
39 0 my ($self) = @_;
40 0 ▶ return "" unless($self->is_error());
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_error 0 0 0
41 0 ▶ return "undef" unless(%$self);
Branch: 1 branch
BranchTrueFalseTotal
unless %$self 0 0 0
42 0 return "code: " . $self->error_code() ." (" . $self->error_name() .") " . $self->error_message();
43 }
44  
45 sub error_code
46 0 ▶{
Subroutine error_code: not called CC=4 SCAR=30.0
Pod undocumented
47 0 my ($self) = @_;
48 0 ▶ return $self->{error_code} if($self->{error_code});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"error_code"} 0 0 0
49 0 ▶ return $self->{error}->{code} if(ref($self->{error}) eq 'HASH' and $self->{error}->{code});
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"error"} eq "HASH" and $self->{"error"}{"code"} 0 0 0
Condition0%0/3
ref $self->{"error"} eq "HASH" and $self->{"error"}{"code"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self->{"error"} eq "HASH" and $self->{"error"}{"code"}
ref $self->{"error"} eq "HASH" $self->{"error"}{"code"}
Truth table0%0/3
A and B
A= ref $self->{"error"} eq "HASH"B= $self->{"error"}{"code"}
ABresult
0X0
100
111
50 0 return 0;
51 }
52  
53 sub error_name
54 0 ▶{
Subroutine error_name: not called CC=4 SCAR=30.0
Pod undocumented
55 0 my ($self) = @_;
56 0 ▶ return $self->{error_name} if($self->{error_name});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"error_name"} 0 0 0
57 0 ▶ return $self->{error}->{name} if(ref($self->{error}) eq 'HASH' and $self->{error}->{name});
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"error"} eq "HASH" and $self->{"error"}{"name"} 0 0 0
Condition0%0/3
ref $self->{"error"} eq "HASH" and $self->{"error"}{"name"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self->{"error"} eq "HASH" and $self->{"error"}{"name"}
ref $self->{"error"} eq "HASH" $self->{"error"}{"name"}
Truth table0%0/3
A and B
A= ref $self->{"error"} eq "HASH"B= $self->{"error"}{"name"}
ABresult
0X0
100
111
58 0 return '';
59 }
60  
61 sub error_message
62 0 ▶{
Subroutine error_message: not called CC=4 SCAR=30.0
Pod undocumented
63 0 my ($self) = @_;
64 0 ▶ return $self->{error}->{message} if(ref($self->{error}) eq 'HASH' and $self->{error}->{message});
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"error"} eq "HASH" and $self->{"error"}{"message"} 0 0 0
Condition0%0/3
ref $self->{"error"} eq "HASH" and $self->{"error"}{"message"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self->{"error"} eq "HASH" and $self->{"error"}{"message"}
ref $self->{"error"} eq "HASH" $self->{"error"}{"message"}
Truth table0%0/3
A and B
A= ref $self->{"error"} eq "HASH"B= $self->{"error"}{"message"}
ABresult
0X0
100
111
65 0 ▶ return $self->{error} if($self->{error});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"error"} 0 0 0
66 0 return '';
67 }
68  
69 #** Checks if the response is an error.
70 # @returns 1: If error, 0: if not error
71 #*
72 sub is_error
73 0 ▶{
Subroutine is_error: not called CC=5 SCAR=34.0
Pod undocumented
74 0 my ($self) = @_;
75 0 ▶ return 1 if(
Branch: 1 branch
BranchTrueFalseTotal
if not %$self or $self->error_code or $self->error_name or $self->error_message 0 0 0
Condition0%0/9
not %$self or $self->error_code or $self->error_name or $self->error_message
l!l&&r!l&&!r
000
not %$self or $self->error_code or $self->error_name
l!l&&r!l&&!r
000
not %$self or $self->error_code
l!l&&r!l&&!r
000
MC/DC0%0/4
not %$self or $self->error_code or $self->error_name or $self->error_message
not %$self $self->error_code $self->error_name $self->error_message
Truth table0%0/5
not(A) or B or C or D
A= not %$selfB= $self->error_codeC= $self->error_nameD= $self->error_message
ABCDresult
1XXX1
01XX1
001X1
00011
00000
76 not(%$self) ||
77 $self->error_code() ||
78 $self->error_name() ||
79 $self->error_message()
80 );
81 0 return 0;
82 }
83  
84 sub AUTOLOAD
85 0 ▶{
Subroutine AUTOLOAD: not called CC=3 SCAR=24.8
86 0 my ($self) = @_;
87  
88 0 my $sub = $AUTOLOAD;
89 0 (my $name = $sub) =~ s/.*:://;
90  
91 0 ▶ if(ref($self->{result}) eq 'HASH'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"result"} eq "HASH") 0 0 0
92 0 my $value = $self->{result}->{$name};
93 0 ▶ return ref($value) eq 'ARRAY' ? $value->[0] : $value;
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 0 0 0
94 };
95  
96  
97 0 return undef;
98 }
99  
100 1 1;
↑ Summary IPA.pm »