Connector/Proxy/JSON.pm

filter: Statementstmt 86.3% 38 / 44 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 88.8% 8 / 9 Podpod 100% 1 / 1 totaltotal 72.2% 52 / 72 CC 6 SCAR 14.4
CC
6
Cov
75%
_build_config
8.3
set
2.0
BEGIN
1.0
CRAP 4.2
« Connector/Tee.pm ↑ Summary Connector/Proxy/Config/Std.pm »
1 # Connector::Proxy::JSON
2 #
3 # Proxy class for reading a JSON file
4  
5 package Connector::Proxy::JSON;
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 extends 'Connector::Builtin::Memory';
16  
17 # set Location required (unset by parent class)
18 1 has '+LOCATION' => ( required => 1 );
19  
20 1 ▶sub _build_config {
Subroutine _build_config: called CC=6 SCAR=21.2
21 1 my $self = shift;
22  
23 # File not exist or not readable
24 1 my $config;
25 1 my $file = $self->LOCATION();
26 1 ▶ if ( ( -e $file ) && ( -r $file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file and -r $file) { } 1 0 1
Condition33%1/3
-e $file and -r $file
!ll&&!rl&&r
001
MC/DC0%0/2
-e $file and -r $file
-e $file -r $file
Truth table33%1/3
A and B
A= -e $fileB= -r $file
ABresult
0X0
100
111
27  
28 1 my $content = do {
29 1 local $INPUT_RECORD_SEPARATOR;
30 1 open my $fh, '<', $file;
31 1 <$fh>;
32 };
33 1 eval {
34 1 $config = decode_json($content);
35 };
36 1 ▶ if ($@ || !$config || !ref $config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $config or not ref $config) 0 1 1
Condition33%2/6
$@ or not $config or not ref $config
l!l&&r!l&&!r
001
$@ or not $config
l!l&&r!l&&!r
001
MC/DC0%0/3
$@ or not $config or not ref $config
$@ not $config not ref $config
Truth table25%1/4
A or not(B) or not(C)
A= $@B= not $configC= not ref $config
ABCresult
1XX1
01X1
0011
0000
37 0 $self->log()->error('Proxy::JSON error parsing content from file '.$file);
38 0 $self->log()->debug( Dumper( $@ ) );
39 0 return $self->_node_not_exists( $file );
40 }
41 1 $self->log()->debug('Proxy::JSON loading configuration from file '.$file);
42 } else {
43 0 $self->log()->warn('Proxy::JSON configuration file '.$file.' not found ');
44 }
45 1 $self->_config($config);
46 }
47  
48 0 ▶sub set { shift; die "No set() method defined"; };
Subroutine set: not called CC=1 SCAR=6.9
Pod documented
49  
50 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 __PACKAGE__->meta->make_immutable;
52  
53 1 1;
54  
55 __END__
« Connector/Tee.pm ↑ Summary Connector/Proxy/Config/Std.pm »