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             package Connector::Proxy::YAML;
8              
9 4     4   98305 use strict;
  4         17  
  4         139  
10 4     4   33 use warnings;
  4         5  
  4         107  
11 4     4   20 use English;
  4         8  
  4         28  
12 4     4   2939 use YAML;
  4         20682  
  4         223  
13 4     4   638 use Data::Dumper;
  4         5839  
  4         169  
14              
15 4     4   486 use Moose;
  4         393758  
  4         26  
16              
17             extends 'Connector::Builtin::Memory';
18              
19             # set Location required (unset by parent class)
20             has '+LOCATION' => ( required => 1 );
21              
22             sub _build_config {
23 6     6   14 my $self = shift;
24              
25             # File not exist or not readable
26 6         8 my $config;
27 6         152 my $file = $self->LOCATION();
28 6 50 33     230 if ( ( -e $file ) && ( -r $file ) ) {
29 6         22 eval {
30 6         58 $config = YAML::LoadFile( $file );
31             };
32 6 50       61531 if ($@) {
33 0         0 $self->log()->error('Proxy::Yaml error parsing file '.$file);
34 0         0 $self->log()->debug( Dumper( $@ ) );
35 0         0 return $self->_node_not_exists( $file );
36             }
37 6         188 $self->log()->debug('Proxy::Yaml loading configuration from file '.$file);
38             } else {
39 0         0 $self->log()->warn('Proxy::Yaml configuration file '.$file.' not found or not readable');
40             }
41 6         186 $self->_config($config);
42             }
43              
44 0     0 1   sub set { shift; die "No set() method defined"; };
  0            
45              
46 4     4   25989 no Moose;
  4         10  
  4         27  
47             __PACKAGE__->meta->make_immutable;
48              
49             1;
50             __END__
51              
52             =head1 Name
53              
54             Connector::Proxy::YAML
55              
56             =head1 Description
57              
58             Reads a yaml file from the path given as LOCATION and makes its structure
59             available via the accessor methods.
60              
61             If the file could not be loaded this connector returns undef for all requests.
62              
63             B<Note>: Changes made to the YAML file after the connector was first
64             initialized will not be visible as the file is read once on startup and
65             persited into memory.
66              
67             =head1 Parameters
68              
69             =over
70              
71             =item LOCATION
72              
73             The location of the yaml file.
74              
75             =back