File Coverage

blib/lib/DBIx/Tree/Persist/Config.pm
Criterion Covered Total %
statement 12 38 31.5
branch 0 6 0.0
condition 0 2 0.0
subroutine 4 6 66.6
pod 0 2 0.0
total 16 54 29.6


line stmt bran cond sub pod time code
1             package DBIx::Tree::Persist::Config;
2              
3 1     1   6 use strict;
  1         3  
  1         44  
4 1     1   5 use warnings;
  1         2  
  1         32  
5              
6 1     1   1106 use Config::Tiny;
  1         1220  
  1         30  
7              
8 1     1   856 use Hash::FieldHash ':all';
  1         1966  
  1         700  
9              
10             fieldhash my %config => 'config';
11             fieldhash my %config_file_path => 'config_file_path';
12             fieldhash my %section => 'section';
13             fieldhash my %verbose => 'verbose';
14              
15             our $VERSION = '1.04';
16              
17             # -----------------------------------------------
18              
19             sub init
20             {
21 0     0 0   my($self, $path) = @_;
22              
23 0           $self -> config_file_path($path);
24              
25             # Check [global].
26              
27 0           $self -> config(Config::Tiny -> read($path) );
28 0           $self -> section('global');
29              
30 0 0         if (! ${$self -> config}{$self -> section})
  0            
31             {
32 0           die "Config file '$path' does not contain the section [@{[$self -> section]}]";
  0            
33             }
34              
35             # Check [x] where x is host=x within [global].
36              
37 0           $self -> section(${$self -> config}{$self -> section}{'host'});
  0            
38              
39 0 0         if (! ${$self -> config}{$self -> section})
  0            
40             {
41 0           die "Config file '$path' does not contain the section [@{[$self -> section]}]";
  0            
42             }
43              
44             # Move desired section into config, so caller can just use $self -> config to get a hashref.
45              
46 0           $self -> config(${$self -> config}{$self -> section});
  0            
47              
48             } # End of init.
49              
50             # -----------------------------------------------
51              
52             sub new
53             {
54 0     0 0   my($class, %arg) = @_;
55 0   0       $arg{verbose} ||= 0;
56 0           my($self) = from_hash(bless({}, $class), \%arg);
57 0           my($name) = '.htdbix.tree.persist.conf';
58              
59 0           my($path);
60              
61 0           for (keys %INC)
62             {
63 0 0         next if ($_ !~ m|DBIx/Tree/Persist/Config.pm|);
64              
65 0           ($path = $INC{$_}) =~ s|Config.pm|$name|;
66             }
67              
68 0           $self -> init($path);
69              
70 0           return $self;
71              
72             } # End of new.
73              
74             # --------------------------------------------------
75              
76             1;