/usr/share/perl5/KiokuDB/Backend.pm is in libkiokudb-perl 0.57-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | package KiokuDB::Backend;
BEGIN {
$KiokuDB::Backend::AUTHORITY = 'cpan:NUFFIN';
}
$KiokuDB::Backend::VERSION = '0.57';
use Moose::Role;
# ABSTRACT: Backend interface role
use Class::Load ();
use Moose::Util::TypeConstraints;
use Try::Tiny;
use namespace::clean -except => 'meta';
coerce ( __PACKAGE__,
from HashRef => via {
my %p = %$_;
my $class = delete $p{class} || die "Can't coerce backend from hash without a 'class' parameter";
try {
Class::Load::load_class("KiokuDB::Backend::$class");
"KiokuDB::Backend::$class"->new(%p);
} catch {
Class::Load::load_class($class);
$class->new(%p);
};
},
);
requires qw(
exists
insert
get
delete
);
sub new_from_dsn {
my ( $class, $params, @extra ) = @_;
if ( defined $params ) {
$class->new_from_dsn_params($class->parse_dsn_params($params), @extra);
} else {
return $class->new(@extra);
}
}
sub new_from_dsn_params {
my ( $class, @params ) = @_;
$class->new(@params);
}
sub parse_dsn_params {
my ( $self, $params ) = @_;
my @pairs = split ';', $params;
return map {
my ( $key, $value ) = /(\w+)(?:=(.*))/;
length($value) ? ( $key, $value ) : ( $key => 1 );
} @pairs;
}
__PACKAGE__
__END__
=pod
=encoding UTF-8
=head1 NAME
KiokuDB::Backend - Backend interface role
=head1 VERSION
version 0.57
=head1 SYNOPSIS
package KiokuDB::Backend::Foo;
use Moose;
# load the core api and additional interfaces based on backend capabilities
with qw(
KiokuDB::Backend
KiokuDB::Backend::Role::TXN
KiokuDB::Backend::Role::Clear
KiokuDB::Backend::Role::Scan
KiokuDB::Backend::Role::UnicodeSafe
KiokuDB::Backend::Role::BinarySafe
);
sub insert { ... }
sub get { ... }
sub delete { ... }
sub exists { ... }
# use the backend like this:
my $dir = KiokuDB->new(
backend => KiokuDB::Backend::Foo->new( );
);
=head1 DESCRIPTION
L<KiokuDB> is designed to be fairly backend agnostic.
This role defines the minimal API for writing new backends.
=head1 TRANSACTIONS
This role is supplemented by L<KiokuDB::Backend::Role::TXN>, a role for
first class transaction support that issues rollbacks using the
L<KiokuDB::Entry> objects.
=head1 QUERYING
This role is supplemented by L<KiokuDB::Backend::Role::Query>, a role for
backend specific queries.
L<KiokuDB::Backend::Role::Query::Simple> provides a universal query api for
backends that can perform property based lookup.
L<KiokuDB::Backend::Role::Query::GIN> is a role for using L<Search::GIN> based
indexing/querying with backends that do not natively support querying.
=head1 REQUIRED METHODS
=over 4
=item get @ids
Retrieve the L<KiokuDB::Entry> objects associated with the @ids.
If any other error is encountered, this method should die.
The backend may store private data in C<backend_data>, to be used in a subsequent update.
Returns a list of L<KiokuDB::Entry>, with the order corresponding to C<@ids>.
If an entry does not exist then C<undef> should be returned in place of it. The
backend may abort retrieval on the first non existent entry.
=item insert @entries
Insert entries to the store.
If the backend is transactional this operation should be atomic with respect to
the inserted/updated data.
The backend is required to store the data in the fields C<data>, C<class> using
the key in C<id>.
Entries which have an entry in C<prev> denote updates (either objects that have
been previously stored, or objects that were looked up). The previous entry may
be used to compare state for issuing a partial update, and will contain the
value of C<backend_data> for any other state tracking.
C<object> is a weak reference to the object this entry is representing, and may
be used for high level indexing. Do not use this field for storage.
If this backend implements some form of garbage collection, C<root> denotes
that the objects is part of the root set.
After all entries have been successfully written, C<backend_data> should be set
if necessary just as in C<get>.
Has no return value.
If C<insert> does not die the write is assumed to be successful.
=item delete @ids_or_entries
Delete the specified IDs or entries.
If the user provided objects then entries will be passed in. Any associated
state the entries may have (e.g. a revision) should be used in order to enforce
atomicity with respect to the time when the objects were loaded.
After all entries have been successfully deleted, C<deleted> should be set. The
entry passed in is the same one as was loaded by C<get> or last written by
C<insert>, so it is already up to date in the live objects.
Has no return value.
If C<delete> does not die the write is assumed to be successful.
=item exists @ids
Check for existence of the specified IDs, without retrieving their data.
Returns a list of true or false values.
=back
=head1 METHODS
These methods are provided by the L<KiokuDB::Backend> role, and may be overridden.
=over 4
=item new_from_dsn
Parses the second half of the DSN using C<parse_dsn_params> and instantiates a
new object using C<new_from_dsn>.
See L<KiokuDB::Util>.
=item new_from_dsn_params @args
Takes DSN parameters and converts them to arguments suitable for C<new>
=item parse_dsn_params $str
The string is split on C<;> to produce arguments. Arguments in the form
C<foo=bar> are split on C<=> into a key/value pair, and other arguments are
treated as a boolean key and returned as C<< $arg => 1 >>.
=back
=head1 ADDITIONAL INTERFACES
Your backend may include more roles, based on its capabilities.
=over 4
=item L<KiokuDB::Backend::Serialize>
=item L<KiokuDB::Backend::Serialize::Delegate>
For the actual serialization of entries, there are a number of serialization
roles.
=item L<KiokuDB::Backend::Role::Clear>
API for clearing all entries.
=item L<KiokuDB::Backend::Role::Scan>
API for enumerating entries.
=item L<KiokuDB::Backend::Role::BinarySafe>
=item L<KiokuDB::Backend::Role::UnicodeSafe>
If your serialization is able to store arbitrary binary data and/or unicode
strings, these informational roles should be included.
=item L<KiokuDB::Backend::Role::TXN>
If your storage supports nested transactions (C<txn_begin>, C<txn_commit> etc)
this role provides the api to expose that functionality to the high level
L<KiokuDB> api.
=item L<KiokuDB::Backend::Role::Query>
=item L<KiokuDB::Backend::Role::Query::GIN>
If your backend supports querying of some sort, these are the roles to include.
The querying API uses backend specific lookups to fetch entries, which
L<KiokuDB> will then relink into result objects.
=back
=head1 SHARED BACKENDS
A backend may be shared by several L<KiokuDB> instances, each with its own
distinct live object set. The backend may choose to share cached entry B<data>,
as that is not mutated by L<KiokuDB::Linker>, but not the L<KiokuDB::Entry>
instances themselves.
=head1 AUTHOR
Yuval Kogman <nothingmuch@woobling.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|