File Coverage

blib/lib/Catmandu/Store/CHI.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Catmandu::Store::CHI - a CHI backed caching store
4              
5             =head1 SYNOPSIS
6              
7             # From the command line
8             $ catmandu export CHI --driver File --root_dir /data to YAML
9             $ catmandu import JSON to CHI --driver File --root_dir /data < data.json
10              
11             # From perl
12             use Catmandu;
13              
14             my $store = Catmandu->store('CHI', driver => 'File' , root_dir => '/data');
15              
16             $store->bag->each(sub {
17             my $item = shift;
18             ...
19             });
20              
21             $store->bag->add({ test => 123 });
22              
23             =head1 METHODS
24              
25             =head2 new()
26              
27             =head2 new(driver => $chi_driver, [OPT => VAL, OPT2 => VAL])
28              
29             Create a new Catmandu::Store::CHI with a $chi_driver and optional parameters. When no driver is given
30             then by default the 'Memory' driver will be used. See L<CHI> for more documentation on possible drivers.
31              
32             =head2 bag($name)
33            
34             Create or retieve a bag with name $name. Returns a L<Catmandu::Bag>.
35              
36             =head1 SEE ALSO
37              
38             L<CHI>, L<Catmandu> , L<Catmandu::Store> , L<Catmandu::Bag>
39              
40             =head1 AUTHOR
41            
42             Patrick Hochstenbach, C<< <patrick.hochstenbach at ugent.be> >>
43            
44             =head1 LICENSE AND COPYRIGHT
45            
46             This program is free software; you can redistribute it and/or modify it
47             under the terms of either: the GNU General Public License as published
48             by the Free Software Foundation; or the Artistic License.
49            
50             See http://dev.perl.org/licenses/ for more information.
51            
52             =cut
53             package Catmandu::Store::CHI;
54              
55             {
56             $Catmandu::Store::CHI::VERSION = '0.02';
57             }
58              
59 2     2   44273 use Moo;
  2         25281  
  2         10  
60 2     2   3035 use CHI;
  0            
  0            
61             use Catmandu::Store::CHI::Bag;
62              
63             with 'Catmandu::Store';
64              
65             has 'driver' => (is => 'ro' , required => 1 , default => sub { 'Memory' });
66             has 'opts' => (is => 'rw');
67              
68             sub BUILD {
69             my ($self,$opts) = @_;
70              
71             if (keys %$opts == 0) {
72             $opts->{global} = 1;
73             }
74              
75             delete $opts->{driver};
76              
77             $self->opts($opts);
78             }
79              
80             1;