File Coverage

blib/lib/Project/Easy/Config/File.pm
Criterion Covered Total %
statement 25 25 100.0
branch 1 2 50.0
condition 4 6 66.6
subroutine 6 6 100.0
pod 0 3 0.0
total 36 42 85.7


line stmt bran cond sub pod time code
1             package Project::Easy::Config::File;
2              
3 3     3   1280 use Class::Easy;
  3         5  
  3         17  
4              
5 3     3   458 use base qw(IO::Easy::File);
  3         5  
  3         1369  
6              
7 3     3   66534 use Project::Easy::Config;
  3         5  
  3         835  
8              
9             sub deserialize {
10 4     4 0 1671 my $self = shift;
11 4         7 my $expansion = shift;
12            
13 4         12 my $contents = $self->contents;
14 4 50 66     381 if ($expansion and ref $expansion and ref $expansion eq 'HASH') {
      66        
15 2         8 $contents = Project::Easy::Config::string_from_template (
16             $contents,
17             $expansion
18             );
19             }
20            
21 4         14 my $serializer = Project::Easy::Config->serializer ($self->extension);
22            
23 4         13 return $serializer->parse_string ($contents);
24             }
25              
26             sub patch {
27 2     2 0 1369 my $self = shift;
28 2         3 my $patch = shift;
29            
30 2         6 my $structure = $self->deserialize;
31 2         8 Project::Easy::Config::patch ($structure, $patch);
32            
33 2         6 $self->serialize ($structure);
34             }
35              
36             sub serialize {
37 4     4 0 761 my $self = shift;
38 4         6 my $struct = shift;
39            
40 4         19 my $serializer = Project::Easy::Config->serializer ($self->extension);
41            
42 4         14 $self->store ($serializer->dump_struct ($struct));
43             }
44              
45             1;