File Coverage

blib/lib/AnyEvent/KVStore.pm
Criterion Covered Total %
statement 31 31 100.0
branch 1 2 50.0
condition n/a
subroutine 10 10 100.0
pod n/a
total 42 43 97.6


line stmt bran cond sub pod time code
1             package AnyEvent::KVStore;
2              
3 2     2   235233 use 5.010;
  2         9  
4 2     2   35 use strict;
  2         5  
  2         110  
5 2     2   15 use warnings FATAL => 'all';
  2         6  
  2         171  
6              
7             =head1 NAME
8              
9             AnyEvent::KVStore - A pluggable key-value store API for AnyEvent
10              
11             =head1 VERSION
12              
13             Version 0.1.2
14              
15             =cut
16              
17 2     2   15 use strict;
  2         16  
  2         70  
18 2     2   16 use warnings;
  2         4  
  2         130  
19 2     2   1563 use Moo;
  2         22327  
  2         16  
20 2     2   6061 use Type::Tiny;
  2         79426  
  2         104  
21 2     2   1724 use Try::Tiny;
  2         3883  
  2         208  
22 2     2   1497 use Types::Standard qw(Str HashRef);
  2         267499  
  2         30  
23             our $VERSION = '0.1.2';
24              
25              
26             =head1 SYNOPSIS
27              
28             use AnyEvent::KVStore;
29              
30             my $foo = AnyEvent::KVStore->new(type => 'etcd', config => $config);
31             my $val = $foo->read($key);
32             $foo->write($key, $val2);
33              
34             $foo->watch($keyspace, \&process_vals);
35              
36             =head1 DESCRIPTION
37              
38             The AnyEventLLKVStore framework intends to be a simple, pluggable API for
39             abstracting away the details of key-value store integratoins in event loop for
40             the standard operations one is likely to experience in an event loop.
41              
42             The idea is to make key-value stores reasonably pluggable for variou skinds of
43             operations so that when one fails to scale in one scenario, another can be used
44             and alaternatively, the same app can support several different stores.
45              
46             The framework uses Moo (Minimalist Object Orientation) to procide the basic
47             interface specifications, and modules providing drivers here are expected to
48             use Moo for defining accessors, etc.
49              
50             =head1 ACCESSORS/PROPERTIES
51              
52             =head2 module
53              
54             The name of the driver used.
55              
56             =cut
57              
58             my $kvs_module = Type::Tiny->new(
59             name => 'Module',
60             constraint => sub { $_->does('AnyEvent::KVStore::Driver')},
61             message => sub { "Not a kvstore driver object: $_"},
62             );
63              
64             has _proxy => ( is => 'lazy', isa => $kvs_module, builder => \&_connect,
65             handles => 'AnyEvent::KVStore::Driver');
66              
67             sub _connect($){
68 1     1   271051 my ($self) = @_;
69 1         4 local $@ = undef;
70 1         9 my $modname = "AnyEvent::KVStore::" . ucfirst($self->module);
71 1 50       133 eval "require $modname" or die $@;
72 1         12 return $modname->new($self->config);
73             }
74              
75             has module => (is => => 'ro', isa => Str, required => 1);
76              
77             =head2 config
78              
79             This is the configuratoin to connect to the driver.
80              
81             =cut
82              
83             has config => (is => 'ro', isa => HashRef, required => 1);
84              
85             =head1 SUBROUTINES/METHODS
86              
87             =head2 new($args or %args)
88              
89             Returns a new kvstore object for use in your application. Note that the actual
90             connection is lazy, and therefore is not even made until use. This uses
91             standard Moo/Moose constructor syntax.
92              
93             =head2 list($prefix)
94              
95             List all keys starting with C<$prefix>
96              
97             Returns a list of strings.
98              
99             =head2 exists($key)
100              
101             Returns true if the key exists, false if it does not.
102              
103             =head2 read($key)
104              
105             Returns the value of the key.
106              
107             =head2 write($key, $value)
108              
109             Writes the key to the key value store.
110              
111             =head2 watch($prefix, $callback)
112              
113             Watch the keys starting with C<$prefix> and for each such key, execute
114             $callback with the arguments as ($key, $value)
115              
116             =head1 WRITING YOUR OWN DRIVER
117              
118             Your driver should consume the L role. It then
119             needs to implement the required interfaces. See the L
120             documentation for details.
121              
122             =head1 AUTHOR
123              
124             Chris Travers, C<< >>
125              
126             =head1 BUGS
127              
128             Please report any bugs or feature requests to C, or through
129             the web interface at L. I will be notified, and then you'll
130             automatically be notified of progress on your bug as I make changes.
131              
132              
133             =head1 MODULE VARIATION
134              
135             A few properties may vary from one module to another. For example, most
136             modules should support multiple watch runs concurrently, though it is possible
137             that some might not. Different modules may require different configuration
138             hash keys.
139              
140             =head1 SUPPORT
141              
142             You can find documentation for this module with the perldoc command.
143              
144             perldoc AnyEvent::KVStore
145              
146              
147             You can also look for information at:
148              
149             =over 4
150              
151             =item * RT: CPAN's request tracker (report bugs here)
152              
153             L
154              
155             =item * CPAN Ratings
156              
157             L
158              
159             =item * Search CPAN
160              
161             L
162              
163             =back
164              
165              
166             =head1 ACKNOWLEDGEMENTS
167              
168              
169             =head1 LICENSE AND COPYRIGHT
170              
171             This software is Copyright (c) 2023 by Chris Travers.
172              
173             This is free software, licensed under:
174              
175             The (three-clause) BSD License
176              
177              
178             =cut
179              
180             1; # End of AnyEvent::KVStore