File Coverage

blib/lib/Bot/Cobalt/Conf/Role/Reader.pm
Criterion Covered Total %
statement 26 27 96.3
branch 2 4 50.0
condition n/a
subroutine 9 10 90.0
pod 0 1 0.0
total 37 42 88.1


line stmt bran cond sub pod time code
1             package Bot::Cobalt::Conf::Role::Reader;
2             $Bot::Cobalt::Conf::Role::Reader::VERSION = '0.021001';
3 8     8   24779 use Carp;
  8         10  
  8         399  
4 8     8   30 use strictures 2;
  8         787  
  8         289  
5              
6 8     8   1249 use Try::Tiny;
  8         11  
  8         381  
7              
8 8     8   33 use Bot::Cobalt::Common -types;
  8         37  
  8         67  
9 8     8   359 use Bot::Cobalt::Serializer;
  8         10  
  8         132  
10              
11 8     8   49 use Moo::Role;
  8         9  
  8         33  
12              
13             has _serializer => (
14             is => 'ro',
15             isa => InstanceOf['Bot::Cobalt::Serializer'],
16 52     52   49287 builder => sub { Bot::Cobalt::Serializer->new },
17             );
18              
19             sub readfile {
20 12     12 0 19 my ($self, $path) = @_;
21              
22 12 50       28 confess "readfile() needs a path to read"
23             unless defined $path;
24              
25 12         14 my $err;
26             my $thawed_cf = try {
27 12     12   492 $self->_serializer->readfile( $path )
28             } catch {
29 0     0   0 $err = $_
30 12         76 };
31              
32 12 50       335 confess "Serializer readfile() failed for $path; $err"
33             if defined $err;
34              
35 12         31 $thawed_cf
36             }
37              
38              
39             1;
40             __END__