File Coverage

lib/Class/StorageFactory/YAML.pm
Criterion Covered Total %
statement 31 31 100.0
branch 6 6 100.0
condition n/a
subroutine 8 8 100.0
pod 2 2 100.0
total 47 47 100.0


line stmt bran cond sub pod time code
1             package Class::StorageFactory::YAML;
2              
3 2     2   23791 use strict;
  2         6  
  2         92  
4 2     2   11 use warnings;
  2         4  
  2         79  
5              
6 2     2   11 use base 'Class::StorageFactory';
  2         3  
  2         432  
7              
8 2     2   12 use Carp ();
  2         4  
  2         53  
9 2     2   846 use YAML qw( LoadFile DumpFile );
  2         9273  
  2         153  
10 2     2   1105 use File::Spec::Functions 'catfile';
  2         985  
  2         536  
11              
12             sub fetch
13             {
14 3     3 1 3034 my ($self, $id) = @_;
15 3         15 my $storage = $self->storage();
16 3         15 my $type = $self->type();
17              
18 3 100       17 Carp::croak( 'No id specified for fetch()' ) unless $id;
19              
20 2         13 my $file = catfile( $storage, $id . '.yml' );
21              
22 2 100       83 Carp::croak( "No file found for id '$id'" ) unless -e $file;
23              
24 1         7 my $data = LoadFile( $file );
25 1         12520 $type->new( $data );
26             }
27              
28             sub store
29             {
30 2     2 1 1533 my ($self, $id, $object) = @_;
31 2         12 my $storage = $self->storage();
32              
33 2 100       42 Carp::croak( 'No id specified for store()' ) unless $id;
34              
35 1         5 my $path = catfile( $storage, $id . '.yml' );
36 1         4 DumpFile( $path, $object->data() );
37             }
38              
39             1;
40             __END__