FreeIPA/Request.pm

filter: Statementstmt 100% 29 / 29 Branchbran 100% 4 / 4 Conditioncond 81.8% 9 / 11 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 93.6% 59 / 63 CC 8 SCAR 11.5
CC
8
Cov
95%
new
6.1
post_data
2.0
is_error
2.0
CRAP 3.2
« FreeIPA/API/Magic.pm ↑ Summary FreeIPA/Response.pm »
1 package Net::FreeIPA::Request;
2 9 $Net::FreeIPA::Request::VERSION = '3.0.3';
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 our @EXPORT = qw(mkrequest);
9  
10 9 ▶use overload bool => '_boolean';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 Net::FreeIPA::Request is an request class for Net::FreeIPA.
15  
16 Boolean logic is overloaded using C<_boolean> method (as inverse of C<is_error>).
17  
18 =head2 Public methods
19  
20 =over
21  
22 =item mkrequest
23  
24 A C<Net::FreeIPA::Request> factory
25  
26 =cut
27  
28 sub mkrequest
29 8 ▶{
Subroutine mkrequest: called CC=1 SCAR=0.0
Pod documented
30 8 return Net::FreeIPA::Request->new(@_);
31 }
32  
33  
34 =item new
35  
36 Create new request instance from options for command C<command>.
37  
38 Options
39  
40 =over
41  
42 =item args: positional arguments
43  
44 =item opts: optional arguments
45  
46 =item error: an error (no default)
47  
48 =item id: id (no default)
49  
50 =back
51  
52 =cut
53  
54 sub new
55 9 ▶{
Subroutine new: called CC=6 SCAR=18.0
Pod documented
56 9 my ($this, $command, %opts) = @_;
57 9 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
090
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
58 my $self = {
59 command => $command,
60  
61 args => $opts{args} || [],
62 opts => $opts{opts} || {},
63  
64 rpc => $opts{rpc} || {}, # options for rpc
65 post => $opts{post} || {}, # options for post
66  
67 error => $opts{error}, # no default
68 id => $opts{id}, # no default
69 9 ▶ };
Condition100%8/8
$opts{'args'} || []
l!l
27
$opts{'opts'} || {}
l!l
27
$opts{'rpc'} || {}
l!l
27
$opts{'post'} || {}
l!l
18
MC/DC100%1/1
$opts{'args'} || []
$opts{'args'}
MC/DC100%1/1
$opts{'opts'} || {}
$opts{'opts'}
MC/DC100%1/1
$opts{'rpc'} || {}
$opts{'rpc'}
MC/DC100%1/1
$opts{'post'} || {}
$opts{'post'}
Truth table100%2/2
A
A= $opts{'args'}
Aresult
11
00
Truth table100%2/2
A
A= $opts{'opts'}
Aresult
11
00
Truth table100%2/2
A
A= $opts{'rpc'}
Aresult
11
00
Truth table100%2/2
A
A= $opts{'post'}
Aresult
11
00
70  
71 9 bless $self, $class;
72  
73 9 return $self;
74 };
75  
76 =item post_data
77  
78 Return the RPC::POST hashref (no JSON encoding).
79  
80 Returns undef if the id is not defined.
81  
82 =cut
83  
84 sub post_data
85 2 ▶{
Subroutine post_data: called CC=2 SCAR=6.9
Pod documented
86 2 my $self = shift;
87  
88 2 ▶ return if (! defined($self->{id}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"id"} 1 1 2
89  
90 my $data = {
91 method => $self->{command},
92 params => [$self->{args}, $self->{opts}],
93 id => $self->{id},
94 1 };
95  
96 1 return $data;
97 }
98  
99 =item is_error
100  
101 Test if this is an error or not (based on error attribute).
102  
103 =cut
104  
105 sub is_error
106 11 ▶{
Subroutine is_error: called CC=2 SCAR=6.9
Pod documented
107 11 my $self = shift;
108 11 ▶ return $self->{error} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'error'} ? : 7 4 11
109 }
110  
111 # Overloaded boolean, inverse of is_error
112 sub _boolean
113 8 ▶{
Subroutine _boolean: called CC=1 SCAR=0.0
114 8 my $self = shift;
115 8 return ! $self->is_error();
116 }
117  
118 =pod
119  
120 =back
121  
122 =cut
123  
124 9 1;
« FreeIPA/API/Magic.pm ↑ Summary FreeIPA/Response.pm »