Net/SecurityCenter/API/Report.pm

filter: Statementstmt 71.4% 35 / 49 Branchbran 27.7% 5 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 64.1% 50 / 78 CC 10 SCAR 20.2
CC
10
Cov
60%
download
20.0
list
6.9
get
3.0
CRAP 7.6
« Net/SecurityCenter/API/Feed.pm ↑ Summary Net/SecurityCenter/API/File.pm »
1 package Net::SecurityCenter::API::Report;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use parent 'Net::SecurityCenter::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Net::SecurityCenter::Utils qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our $VERSION = '0.311';
13  
14 2 my $common_template = {
15  
16 id => {
17 required => 1,
18 allow => qr/^\d+$/,
19 messages => {
20 required => 'Report ID is required',
21 allow => 'Invalid Report ID',
22 },
23 },
24  
25 filter => {
26 allow => [ 'running', 'completed', 'usable', 'manageable' ],
27 },
28  
29 fields => {
30 filter => \&sc_filter_array_to_string,
31 }
32  
33 };
34  
35 #-------------------------------------------------------------------------------
36 # METHODS
37 #-------------------------------------------------------------------------------
38  
39 1 ▶sub list {
Subroutine list: called CC=5 SCAR=19.3
Pod documented
40  
41 1 my ( $self, %args ) = @_;
42  
43 my $tmpl = {
44 fields => $common_template->{'fields'},
45 1 filter => $common_template->{'filter'},
46 raw => {},
47 };
48  
49 1 my $params = sc_check_params( $tmpl, \%args );
50 1 my $raw = delete( $params->{'raw'} );
51 1 my $reports = $self->client->get( '/report', $params );
52  
53 1 ▶ return if ( !$reports );
Branch: 1 branch
BranchTrueFalseTotal
unless $reports 0 1 1
54  
55 1 ▶ if ($raw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw) 0 1 1
56 0 ▶ return wantarray ? @{$reports} : $reports;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
57 }
58  
59 0 ▶ return wantarray ? @{ sc_merge($reports) } : sc_merge($reports);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
60  
61 }
62  
63 #-------------------------------------------------------------------------------
64  
65 1 ▶sub get {
Subroutine get: called CC=3 SCAR=11.1
Pod documented
66  
67 1 my ( $self, %args ) = @_;
68  
69 my $tmpl = {
70 fields => $common_template->{'fields'},
71 1 id => $common_template->{'id'},
72 raw => {},
73 };
74  
75 1 my $params = sc_check_params( $tmpl, \%args );
76  
77 1 my $report_id = delete( $params->{'id'} );
78 1 my $raw = delete( $params->{'raw'} );
79  
80 1 my $report = $self->client->get( "/report/$report_id", $params );
81  
82 1 ▶ return if ( !$report );
Branch: 1 branch
BranchTrueFalseTotal
unless $report 0 1 1
83 1 ▶ return $report if ($raw);
Branch: 1 branch
BranchTrueFalseTotal
if $raw 0 1 1
84 1 return sc_normalize_hash($report);
85  
86 }
87  
88 #-------------------------------------------------------------------------------
89  
90 0 ▶sub download {
Subroutine download: not called CC=4 SCAR=30.0
Pod documented
91  
92 0 my ( $self, %args ) = @_;
93  
94 my $tmpl = {
95 filename => {},
96 0 id => $common_template->{'id'},
97 };
98  
99 0 my $params = sc_check_params( $tmpl, \%args );
100  
101 0 my $report_id = delete( $params->{'id'} );
102 0 my $filename = delete( $params->{'filename'} );
103  
104 0 my $report_data = $self->client->post("/report/$report_id/download");
105  
106 0 ▶ return $report_data if ( !$filename );
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 0 0 0
107  
108 0 ▶ open my $fh, '>', $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $filename or croak("Could not open file '${filename}': $!") 0 0 0
109 or croak("Could not open file '$filename': $!");
110  
111 0 print $fh $report_data;
112  
113 0 ▶ close $fh
Branch: 1 branch
BranchTrueFalseTotal
close $fh or carp("Failed to close file '${filename}': $!") 0 0 0
114 or carp("Failed to close file '$filename': $!");
115  
116 0 return 1;
117  
118 }
119  
120 #-------------------------------------------------------------------------------
121  
122 2 1;
123  
124 __END__
« Net/SecurityCenter/API/Feed.pm ↑ Summary Net/SecurityCenter/API/File.pm »