File Coverage

blib/lib/Data/Remember/YAML.pm
Criterion Covered Total %
statement 28 30 93.3
branch 2 4 50.0
condition 4 6 66.6
subroutine 8 8 100.0
pod 3 3 100.0
total 45 51 88.2


line stmt bran cond sub pod time code
1 5     5   8138 use strict;
  5         11  
  5         155  
2 5     5   23 use warnings;
  5         6  
  5         243  
3              
4             package Data::Remember::YAML;
5             {
6             $Data::Remember::YAML::VERSION = '0.140490';
7             }
8 5     5   25 use base qw/ Data::Remember::Memory /;
  5         7  
  5         8413  
9             # ABSTRACT: a frozen memory brain plugin for Data::Remember
10              
11 5     5   30 use Carp;
  5         12  
  5         279  
12 5     5   1749 use YAML::Syck ();
  5         4160  
  5         973  
13              
14              
15             sub new {
16 5     5 1 9 my $class = shift;
17 5         19 my %args = @_;
18              
19 5 50       20 croak 'You must specify a "file" to load the data from.'
20             unless $args{file};
21              
22 5         7 my $brain;
23 5 50       109 if (-f $args{file}) {
24 5         24 $brain = YAML::Syck::LoadFile($args{file});
25             }
26             else {
27 0         0 carp qq{Empty brain, "$args{file}" is not a file.};
28 0         0 $brain = {};
29             }
30              
31 5         1058 bless {
32             brain => $brain,
33             file => $args{file},
34             }, $class;
35             }
36              
37              
38             sub load {
39 2     2 1 4 my $self = shift;
40 2   66     9 my $file = shift || $self->{file};
41              
42 2         7 $self->{brain} = YAML::Syck::LoadFile($file);
43             }
44              
45              
46             sub dump {
47 2     2 1 4 my $self = shift;
48 2   66     13 my $file = shift || $self->{file};
49              
50 2         10 YAML::Syck::DumpFile($file, $self->{brain});
51             }
52              
53              
54             1;
55              
56             __END__