File Coverage

blib/lib/Bot/Cobalt/Conf/File.pm
Criterion Covered Total %
statement 44 46 95.6
branch 3 4 75.0
condition n/a
subroutine 16 17 94.1
pod 1 3 33.3
total 64 70 91.4


line stmt bran cond sub pod time code
1             package Bot::Cobalt::Conf::File;
2             $Bot::Cobalt::Conf::File::VERSION = '0.021001';
3 8     8   15343 use v5.10;
  8         17  
4 8     8   381 use strictures 2;
  8         1082  
  8         214  
5 8     8   1089 use Carp;
  8         8  
  8         354  
6              
7 8     8   354 use Bot::Cobalt::Common ':types';
  8         9  
  8         32  
8 8     8   2163 use Bot::Cobalt::Serializer;
  8         55  
  8         199  
9              
10 8     8   53 use Try::Tiny;
  8         7  
  8         365  
11              
12 8     8   2811 use Types::Path::Tiny -types;
  8         109443  
  8         55  
13              
14 8     8   4645 use List::Objects::WithUtils;
  8         12  
  8         53  
15 8     8   8079 use List::Objects::Types -types;
  8         10  
  8         44  
16              
17 8     8   5927 use Moo;
  8         10  
  8         38  
18             with 'Bot::Cobalt::Conf::Role::Reader';
19              
20              
21             has cfg_path => (
22             required => 1,
23             is => 'rwp',
24             isa => Path,
25             coerce => 1,
26             );
27              
28             has cfg_as_hash => (
29             lazy => 1,
30             is => 'rwp',
31             isa => HashObj,
32             coerce => 1,
33             builder => '_build_cfg_hash',
34             );
35              
36             has debug => (
37             is => 'rw',
38             isa => Bool,
39 3     3   2395 builder => sub { 0 },
40             );
41              
42             sub BUILD {
43 10     10 0 1595 my ($self) = @_;
44 10         97 $self->cfg_as_hash
45             }
46              
47             sub _build_cfg_hash {
48 11     11   3521 my ($self) = @_;
49              
50 11 100       107 if ($self->debug) {
51 1         442 warn
52             ref $self, " (debug) reading cfg_as_hash from ", $self->cfg_path, "\n"
53             }
54            
55 11         2322 my $cfg = $self->readfile( $self->cfg_path );
56              
57 11         15 my $err; try {
58 11     11   576 $self->validate($cfg)
59             } catch {
60 0     0   0 $err = $_;
61             undef
62 11 50       63 } or croak "Conf validation failed for ". $self->cfg_path .": $err";
  0         0  
63              
64 11         142 $cfg
65             }
66              
67             sub rehash {
68 1     1 1 1241 my ($self) = @_;
69            
70 1         3 $self->_set_cfg_as_hash( $self->_build_cfg_hash )
71             }
72              
73             sub validate {
74 2     2 0 4 my ($self, $cfg) = @_;
75            
76 2         5 1
77             }
78              
79             1;
80             __END__