OpenVAS/OMP/Response.pm

filter: Statementstmt 75.0% 51 / 68 Branchbran 16.6% 3 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 65.2% 15 / 23 Podpod 100% 15 / 15 totaltotal 67.7% 84 / 124 CC 10 SCAR 11.6
CC
10
Cov
63%
is_created
6.0
is_accepted
6.0
is_forbidden
6.0
CRAP 3.2
« OpenVAS/OMP.pm ↑ Summary OpenVAS/Error.pm »
1 package Net::OpenVAS::OMP::Response;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Net::OpenVAS::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use XML::Hash::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use overload q|""| => 'raw', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 our $VERSION = '0.200';
16  
17 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
Pod documented
18  
19 1 my ( $class, %args ) = @_;
20  
21 1 my $request = $args{'request'};
22 1 my $response = $args{'response'};
23 1 my $command = $request->command;
24  
25 1 ▶ croak q/Net::OpenVAS::OMP::Response ( 'request' => ... ) must be "Net::OpenVAS::OMP::Request" instance/
Branch: 1 branch
BranchTrueFalseTotal
if !ref($request) eq "Net::OpenVAS::OMP::Request" 0 1 1
26 if ( !ref $request eq 'Net::OpenVAS::OMP::Request' );
27  
28 1 $response =~ s/<\?xml.*?\?>//; # Remove XML version and encoding from the response for XML report
29  
30 1 my $status = ( $response =~ /(status)="([^"]*)"/ )[1];
31 1 my $status_text = ( $response =~ /(status_text)="([^"]*)"/ )[1];
32 1 my $error = undef;
33  
34 1 ▶ if ( $status >= 400 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status >= 400) 0 1 1
35 0 $error = Net::OpenVAS::Error->new( $status_text, $status );
36 }
37  
38 my $self = {
39 status => $status + 0,
40 raw => $response,
41 request => $request,
42 status_text => $status_text,
43 error => $error,
44 1 result => eval { xml2hash $response },
45 };
46  
47 1 return bless $self, $class;
48  
49 }
50  
51 0 ▶sub result {
Subroutine result: not called CC=1 SCAR=6.9
Pod documented
52 0 my ($self) = @_;
53 0 return $self->{result};
54 }
55  
56 1 ▶sub error {
Subroutine error: called CC=1 SCAR=0.0
Pod documented
57 1 my ($self) = @_;
58 1 return $self->{error};
59 }
60  
61 2 ▶sub status {
Subroutine status: called CC=1 SCAR=0.0
Pod documented
62 2 my ($self) = @_;
63 2 return $self->{status};
64 }
65  
66 1 ▶sub is_ok {
Subroutine is_ok: called CC=2 SCAR=7.2
Pod documented
67 1 my ($self) = @_;
68 1 ▶ return ( $self->status == 200 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->status == 200 ? : 1 0 1
69 }
70  
71 0 ▶sub is_created {
Subroutine is_created: not called CC=2 SCAR=17.9
Pod documented
72 0 my ($self) = @_;
73 0 ▶ return ( $self->status == 201 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->status == 201 ? : 0 0 0
74 }
75  
76 0 ▶sub is_accepted {
Subroutine is_accepted: not called CC=2 SCAR=17.9
Pod documented
77 0 my ($self) = @_;
78 0 ▶ return ( $self->status == 202 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->status == 202 ? : 0 0 0
79 }
80  
81 0 ▶sub is_forbidden {
Subroutine is_forbidden: not called CC=2 SCAR=17.9
Pod documented
82 0 my ($self) = @_;
83 0 ▶ return ( $self->status == 403 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->status == 403 ? : 0 0 0
84 }
85  
86 0 ▶sub is_not_found {
Subroutine is_not_found: not called CC=2 SCAR=17.9
Pod documented
87 0 my ($self) = @_;
88 0 ▶ return ( $self->status == 404 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->status == 404 ? : 0 0 0
89 }
90  
91 0 ▶sub is_busy {
Subroutine is_busy: not called CC=2 SCAR=17.9
Pod documented
92 0 my ($self) = @_;
93 0 ▶ return ( $self->status == 409 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->status == 409 ? : 0 0 0
94 }
95  
96 0 ▶sub is_server_error {
Subroutine is_server_error: not called CC=2 SCAR=17.9
Pod documented
97 0 my ($self) = @_;
98 0 ▶ return ( $self->status >= 500 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->status >= 500 ? : 0 0 0
99 }
100  
101 1 ▶sub status_text {
Subroutine status_text: called CC=1 SCAR=0.0
Pod documented
102 1 my ($self) = @_;
103 1 return $self->{status_text};
104 }
105  
106 1 ▶sub raw {
Subroutine raw: called CC=1 SCAR=0.0
Pod documented
107 1 my ($self) = @_;
108 1 return $self->{raw};
109 }
110  
111 1 ▶sub command {
Subroutine command: called CC=1 SCAR=0.0
Pod documented
112 1 my ($self) = @_;
113 1 return $self->{request}->command;
114 }
115  
116 0 ▶sub request {
Subroutine request: not called CC=1 SCAR=6.9
Pod documented
117 0 my ($self) = @_;
118 0 return $self->{request};
119 }
120  
121 2 1;
122 __END__
« OpenVAS/OMP.pm ↑ Summary OpenVAS/Error.pm »