File Coverage

blib/lib/Connector/Proxy/YAML.pm
Criterion Covered Total %
statement 30 36 83.3
branch 2 4 50.0
condition 1 3 33.3
subroutine 8 9 88.8
pod 1 1 100.0
total 42 53 79.2


line stmt bran cond sub pod time code
1             # Connector::Proxy::YAML
2             #
3             # Proxy class for reading YAML configuration
4             #
5             # Written by Scott Hardin and Martin Bartosch for the OpenXPKI project 2012
6             #
7              
8             use strict;
9 4     4   89144 use warnings;
  4         13  
  4         110  
10 4     4   63 use English;
  4         9  
  4         101  
11 4     4   17 use YAML;
  4         5  
  4         23  
12 4     4   2483 use Data::Dumper;
  4         19369  
  4         172  
13 4     4   531  
  4         5643  
  4         164  
14             use Moose;
15 4     4   455  
  4         374190  
  4         23  
16             extends 'Connector::Builtin::Memory';
17              
18             # set Location required (unset by parent class)
19             has '+LOCATION' => ( required => 1 );
20              
21             my $self = shift;
22              
23 6     6   19 # File not exist or not readable
24             my $config;
25             my $file = $self->LOCATION();
26 6         13 if ( ( -e $file ) && ( -r $file ) ) {
27 6         143 eval {
28 6 50 33     221 $config = YAML::LoadFile( $file );
29 6         19 };
30 6         58 if ($@) {
31             $self->log()->error('Proxy::Yaml error parsing file '.$file);
32 6 50       56615 $self->log()->debug( Dumper( $@ ) );
33 0         0 return $self->_node_not_exists( $file );
34 0         0 }
35 0         0 $self->log()->debug('Proxy::Yaml loading configuration from file '.$file);
36             } else {
37 6         203 $self->log()->warn('Proxy::Yaml configuration file '.$file.' not found or not readable');
38             }
39 0         0 $self->_config($config);
40             }
41 6         177  
42              
43             no Moose;
44 0     0 1   __PACKAGE__->meta->make_immutable;
  0            
45              
46 4     4   23363 1;
  4         11  
  4         21  
47              
48             =head1 Name
49              
50             Connector::Proxy::YAML
51              
52             =head1 Description
53              
54             Reads a yaml file from the path given as LOCATION and makes its structure
55             available via the accessor methods.
56              
57             If the file could not be loaded this connector returns undef for all requests.
58              
59             B<Note>: Changes made to the YAML file after the connector was first
60             initialized will not be visible as the file is read once on startup and
61             persited into memory.
62              
63             =head1 Parameters
64              
65             =over
66              
67             =item LOCATION
68              
69             The location of the yaml file.
70              
71             =back