File Coverage

blib/lib/QualysGuard/Response/MapReportList.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package QualysGuard::Response::MapReportList;
2              
3 1     1   10288 use warnings;
  1         4  
  1         48  
4 1     1   8 use strict;
  1         2  
  1         53  
5              
6 1     1   7 use base qw( QualysGuard::Response );
  1         2  
  1         120  
7             use Scalar::Util qw( reftype );
8              
9             our $VERSION = '0.02';
10              
11              
12             # =============================================================
13             # - new
14             # =============================================================
15             sub new {
16             my ( $class, $xml ) = @_;
17              
18             my $self = __PACKAGE__->SUPER::new( $xml );
19              
20             bless $self, $class;
21              
22             # -- check for QualysGuard function error
23              
24             if ( $self->exists('/MAP_REPORT_LIST/ERROR') ) {
25             $self->{error_code} = $self->findvalue('/MAP_REPORT_LIST/ERROR/@number');
26             $self->{error_text} = $self->getNodeText('/MAP_REPORT_LIST/ERROR');
27             $self->{error_text} =~ s/^\s+(.*)\s+$/$1/m;
28             }
29              
30             return $self;
31             }
32              
33              
34              
35             # =============================================================
36             # - get_map_refs
37             # =============================================================
38             sub get_map_refs {
39             my $self = shift;
40             my @nodes = $self->findnodes('/MAP_REPORT_LIST/MAP_REPORT');
41             my $rv = {};
42              
43             foreach my $node ( @nodes ) {
44             my $key = $node->getAttribute( 'domain' );
45             my $val = $node->getAttribute( 'ref' );
46              
47             if ( exists $rv->{$key} ) {
48              
49             if ( reftype( \$rv->{$key} ) eq 'SCALAR' ) {
50             $rv->{$key} = [ $rv->{$key} ];
51             push( @{$rv->{$key}}, $val );
52             }
53              
54             elsif ( reftype( $rv->{$key} ) eq 'ARRAY' ) {
55             push( @{$rv->{$key}}, $val );
56             }
57             }
58              
59             else {
60             $rv->{$key} = $val;
61             }
62             }
63              
64             return $rv;
65             }
66              
67              
68              
69             1;
70              
71             __END__