Validator/Utils.pm

filter: Statementstmt 100% 38 / 38 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 97.9% 47 / 48 CC 5 SCAR 10.4
CC
5
Cov
98%
obj_to_json
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.8
« Validator.pm ↑ Summary
1 package App::MARC::Validator::Utils;
2  
3 6 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use Cpanel::JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Cpanel::JSON::XS::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 Readonly::Array our @EXPORT_OK => qw(obj_to_json);
12  
13 6 our $VERSION = 0.09;
14  
15 1 ▶sub obj_to_json {
Subroutine obj_to_json: called CC=5 SCAR=16.1
Pod documented
16 1 my ($self, $report) = @_;
17  
18 1 my $struct_hr = {};
19 1 foreach my $plugin (@{$report->plugins}) {
20 $struct_hr->{$plugin->name} = {
21 'checks' => {
22 'not_valid' => {},
23 },
24 'datetime' => $report->datetime->iso8601,
25 'module_name' => $plugin->module_name,
26 'module_version' => $plugin->version,
27 'name' => $plugin->name,
28 },
29 1 my $not_valid_hr = $struct_hr->{$plugin->name}->{'checks'}->{'not_valid'};
30 1 foreach my $plugin_errors (@{$plugin->plugin_errors}) {
31 1 $not_valid_hr->{$plugin_errors->record_id} = [];
32 1 foreach my $error (@{$plugin_errors->errors}) {
33 1 push @{$not_valid_hr->{$plugin_errors->record_id}}, {
34 'error' => $error->error,
35 'params' => $error->params,
36 };
37 }
38 }
39 }
40  
41 # JSON output.
42 1 my $j = Cpanel::JSON::XS->new;
43 1 ▶ if ($self->{'_opts'}->{'p'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_opts"}{"p"}) 1 0 1
44 1 $j = $j->pretty;
45 }
46 1 my $json = $j->canonical(1)->encode($struct_hr);
47  
48 1 return $json;
49 }
50  
51 6 1;
52  
53 __END__
« Validator.pm ↑ Summary