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.021003';
3 8     8   29174 use Carp;
  8         11  
  8         453  
4 8     8   33 use strictures 2;
  8         938  
  8         384  
5              
6 8     8   1398 use Try::Tiny;
  8         11  
  8         385  
7              
8 8     8   29 use Bot::Cobalt::Common -types;
  8         42  
  8         58  
9 8     8   386 use Bot::Cobalt::Serializer;
  8         12  
  8         157  
10              
11 8     8   73 use Moo::Role;
  8         11  
  8         54  
12              
13             has _serializer => (
14             is => 'ro',
15             isa => InstanceOf['Bot::Cobalt::Serializer'],
16 52     52   55053 builder => sub { Bot::Cobalt::Serializer->new },
17             );
18              
19             sub readfile {
20 12     12 0 20 my ($self, $path) = @_;
21              
22 12 50       35 confess "readfile() needs a path to read"
23             unless defined $path;
24              
25 12         12 my $err;
26             my $thawed_cf = try {
27 12     12   540 $self->_serializer->readfile( $path )
28             } catch {
29 0     0   0 $err = $_
30 12         105 };
31              
32 12 50       372 confess "Serializer readfile() failed for $path; $err"
33             if defined $err;
34              
35 12         37 $thawed_cf
36             }
37              
38              
39             1;
40             __END__