File Coverage

blib/lib/Property/Lookup/File.pm
Criterion Covered Total %
statement 29 29 100.0
branch 4 8 50.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 41 45 91.1


line stmt bran cond sub pod time code
1 1     1   70498 use 5.008;
  1         5  
  1         55  
2 1     1   8 use strict;
  1         20  
  1         41  
3 1     1   6 use warnings;
  1         3  
  1         75  
4              
5             package Property::Lookup::File;
6             BEGIN {
7 1     1   26 $Property::Lookup::File::VERSION = '1.101400';
8             }
9             # ABSTRACT: File-based property lookup layer
10 1     1   7 use File::Basename;
  1         2  
  1         85  
11 1     1   1061 use parent 'Property::Lookup::Hash';
  1         390  
  1         8  
12             __PACKAGE__->mk_scalar_accessors(qw(filename));
13              
14             sub init {
15 1     1 1 68 my $self = shift;
16 1         33 $self->SUPER::init(@_);
17 1 50       22 if (my $conf_file = $self->filename) {
18              
19             # replace dollar-variables with their environment equivalent; also
20             # some special definitions
21 1 50       77 open my $fh, '<', $conf_file or die "can't open $conf_file: $!\n";
22 1         3 my $yaml = do { local $/; <$fh> };
  1         31  
  1         12698  
23 1 50       35 close $fh or die "can't close $conf_file: $!\n";
24 1         15 $ENV{SELF} = dirname($self->filename);
25 1 50       145 $yaml =~ s/\$(\w+)/$ENV{$1} || "\$$1"/ge;
  1         11  
26 1         1089 require YAML;
27 1         9229 $self->hash(YAML::Load($yaml));
28             }
29             }
30             1;
31              
32              
33             __END__