File Coverage

blib/lib/Data/Hive/Store.pm
Criterion Covered Total %
statement 19 25 76.0
branch n/a
condition n/a
subroutine 6 9 66.6
pod 0 3 0.0
total 25 37 67.5


line stmt bran cond sub pod time code
1 4     4   1616 use strict;
  4         9  
  4         106  
2 4     4   18 use warnings;
  4         7  
  4         133  
3             package Data::Hive::Store 1.014;
4             # ABSTRACT: a backend storage driver for Data::Hive
5              
6 4     4   18 use Carp ();
  4         6  
  4         191  
7              
8             #pod =head1 DESCRIPTION
9             #pod
10             #pod Data::Hive::Store is a generic interface to a backend store
11             #pod for Data::Hive.
12             #pod
13             #pod =head1 METHODS
14             #pod
15             #pod All methods are passed at least a 'path' (arrayref of namespace pieces). Store
16             #pod classes exist to operate on the entities found at named paths.
17             #pod
18             #pod =head2 get
19             #pod
20             #pod print $store->get(\@path, \%opt);
21             #pod
22             #pod Return the resource represented by the given path.
23             #pod
24             #pod =head2 set
25             #pod
26             #pod $store->set(\@path, $value, \%opt);
27             #pod
28             #pod Analogous to C<< get >>.
29             #pod
30             #pod =head2 name
31             #pod
32             #pod print $store->name(\@path, \%opt);
33             #pod
34             #pod Return a store-specific name for the given path. This is primarily useful for
35             #pod stores that may be accessed independently of the hive.
36             #pod
37             #pod =head2 exists
38             #pod
39             #pod if ($store->exists(\@path, \%opt)) { ... }
40             #pod
41             #pod Returns true if the given path exists in the store.
42             #pod
43             #pod =head2 delete
44             #pod
45             #pod $store->delete(\@path, \%opt);
46             #pod
47             #pod Delete the given path from the store. Return the previous value, if any.
48             #pod
49             #pod Stores can also implement C to delete this path and all paths below
50             #pod it. If C is not provided, the generic one-by-one delete in this
51             #pod class will be used.
52             #pod
53             #pod =head2 keys
54             #pod
55             #pod my @keys = $store->keys(\@path, \%opt);
56             #pod
57             #pod This returns a list of next-level path elements that lead toward existing
58             #pod values. For more information on the expected behavior, see the L
59             #pod method|Data:Hive/keys> in Data::Hive.
60             #pod
61             #pod =cut
62              
63             BEGIN {
64 4     4   16 for my $meth (qw(get set name exists delete keys)) {
65 4     4   21 no strict 'refs';
  4         14  
  4         291  
66 24     0   769 *$meth = sub { Carp::croak("$_[0] does not implement $meth") };
  0         0  
67             }
68             }
69              
70       0 0   sub save {}
71              
72             sub save_all {
73 0     0 0 0 my ($self, $path) = @_;
74              
75 0         0 $self->save;
76 0         0 for my $key ($self->keys($path)) {
77 0         0 $self->save_all([ @$path, $key ]);
78             }
79              
80 0         0 return;
81             }
82              
83             sub delete_all {
84 9     9 0 20 my ($self, $path) = @_;
85              
86 9         29 $self->delete($path);
87 9         52 for my $key ($self->keys($path)) {
88 6         28 $self->delete_all([ @$path, $key ]);
89             }
90              
91 9         26 return;
92             }
93              
94             1;
95              
96             __END__