| 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
Condition33%1/3
-e $file and -r $file
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$@ or not $config or not ref $config
$@ or not $config
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||