line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Riak::Bucket; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Net::Riak::Bucket::VERSION = '0.1702'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
181685
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Net::Riak::Object; |
7
|
|
|
|
|
|
|
use Net::Riak::Types Client => {-as => 'Client_T'}; |
8
|
|
|
|
|
|
|
with 'Net::Riak::Role::Replica' => {keys => [qw/r w dw/]}; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has client => ( |
11
|
|
|
|
|
|
|
is => 'rw', |
12
|
|
|
|
|
|
|
isa => Client_T, |
13
|
|
|
|
|
|
|
required => 1, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has name => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
isa => 'Str', |
19
|
|
|
|
|
|
|
required => 1 |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
has content_type => ( |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
isa => 'Str', |
24
|
|
|
|
|
|
|
default => 'application/json' |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub n_val { |
28
|
|
|
|
|
|
|
my $self = shift; |
29
|
|
|
|
|
|
|
if (my $val = shift) { |
30
|
|
|
|
|
|
|
$self->set_property('n_val', $val); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
|
|
|
|
|
|
$self->get_property('n_val'); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub allow_multiples { |
38
|
|
|
|
|
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
if (my $val = shift) { |
41
|
|
|
|
|
|
|
my $bool = ($val == 1 ? 1 : 0); |
42
|
|
|
|
|
|
|
$self->set_property('allow_mult', $bool); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
|
|
|
|
|
|
return $self->get_property('allow_mult') ? 1 : 0; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get_keys { |
50
|
|
|
|
|
|
|
my ($self, $params) = @_; |
51
|
|
|
|
|
|
|
$self->client->get_keys($self->name, $params); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get { |
55
|
|
|
|
|
|
|
my ($self, $key, $r) = @_; |
56
|
|
|
|
|
|
|
my $obj = Net::Riak::Object->new( |
57
|
|
|
|
|
|
|
client => $self->client, |
58
|
|
|
|
|
|
|
bucket => $self, |
59
|
|
|
|
|
|
|
key => $key |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
$r ||= $self->r; |
62
|
|
|
|
|
|
|
$obj->load($r); |
63
|
|
|
|
|
|
|
$obj; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub delete_object { |
67
|
|
|
|
|
|
|
my ($self, $key, $dw) = @_; |
68
|
|
|
|
|
|
|
Net::Riak::Object->new( |
69
|
|
|
|
|
|
|
client => $self->client, |
70
|
|
|
|
|
|
|
bucket => $self, |
71
|
|
|
|
|
|
|
key => $key |
72
|
|
|
|
|
|
|
)->delete($dw); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub set_property { |
76
|
|
|
|
|
|
|
my ($self, $key, $value) = @_; |
77
|
|
|
|
|
|
|
$self->set_properties({$key => $value}); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub get_property { |
81
|
|
|
|
|
|
|
my ($self, $key, $params) = @_; |
82
|
|
|
|
|
|
|
my $props = $self->get_properties($params); |
83
|
|
|
|
|
|
|
return $props->{props}->{$key}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get_properties { |
87
|
|
|
|
|
|
|
my ($self, $params) = @_; |
88
|
|
|
|
|
|
|
$self->client->get_properties($self->name, $params); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub set_properties { |
92
|
|
|
|
|
|
|
my ($self, $props) = @_; |
93
|
|
|
|
|
|
|
$self->client->set_properties($self, $props); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub new_object { |
97
|
|
|
|
|
|
|
my ($self, $key, $data, @args) = @_; |
98
|
|
|
|
|
|
|
my %opts = ( |
99
|
|
|
|
|
|
|
data => $data, |
100
|
|
|
|
|
|
|
bucket => $self, |
101
|
|
|
|
|
|
|
client => $self->client, |
102
|
|
|
|
|
|
|
@args, |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
$opts{key} = $key if defined $key; |
105
|
|
|
|
|
|
|
my $object = Net::Riak::Object->new(%opts); |
106
|
|
|
|
|
|
|
$object; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=pod |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 NAME |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Net::Riak::Bucket |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 VERSION |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
version 0.1702 |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SYNOPSIS |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $client = Net::Riak->new(...); |
126
|
|
|
|
|
|
|
my $bucket = $client->bucket('foo'); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# retrieve an existing object |
129
|
|
|
|
|
|
|
my $obj1 = $bucket->get('foo'); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# create/store a new object |
132
|
|
|
|
|
|
|
my $obj2 = $bucket->new_object('foo2', {...}); |
133
|
|
|
|
|
|
|
$object->store; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
$bucket->delete_object($key, 3); # optional w val |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 DESCRIPTION |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The L<Net::Riak::Bucket> object allows you to access and change information about a Riak bucket, and provides methods to create or retrieve objects within the bucket. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 ATTRIBUTES |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 4 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item B<name> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my $name = $bucket->name; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Get the bucket name |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item B<r> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $r_value = $bucket->r; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
R value setting for this client (default 2) |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item B<w> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $w_value = $bucket->w; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
W value setting for this client (default 2) |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item B<dw> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
my $dw_value = $bucket->dw; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
DW value setting for this client (default 2) |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 METHODS |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=over 4 |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item new_object |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $obj = $bucket->new_object($key, $data, @args); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Create a new L<Net::Riak::Object> object. Additional Object constructor arguments can be passed after $data. If $data is a reference and no explicit Object content_type is given in @args, the data will be serialised and stored as JSON. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
If $key is passed as C<undef> then an autogenerated key will be provided by Riak. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item get |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
my $obj = $bucket->get($key, [$r]); |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Retrieve an object from Riak. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item delete_object |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
$bucket->delete_object($key); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Delete an object by key |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item n_val |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
my $n_val = $bucket->n_val; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Get/set the N-value for this bucket, which is the number of replicas that will be written of each object in the bucket. Set this once before you write any data to the bucket, and never change it again, otherwise unpredictable things could happen. This should only be used if you know what you are doing. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item allow_multiples |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
$bucket->allow_multiples(1|0); |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
If set to True, then writes with conflicting data will be stored and returned to the client. This situation can be detected by calling has_siblings() and get_siblings(). This should only be used if you know what you are doing. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item get_keys |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
my $keys = $bucket->get_keys; |
210
|
|
|
|
|
|
|
my $keys = $bucket->get_keys($args); |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Return an arrayref of the list of keys for a bucket. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Note for the PBC interface: you will need a separate instance of the client (i.e separate connection) if you want to preform actions on the keys whilst streaming them. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Optionally takes a hashref of named parameters. Supported parameters are: |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=over 4 |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item stream => 1 |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Uses key streaming mode to fetch the list of keys, which may be faster for large keyspaces. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=item cb => sub { } |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
A callback subroutine to be called for each key found (passed in as the only parameter). get_keys() returns nothing in callback mode. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=back |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item set_property |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
$bucket->set_property({n_val => 2}); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Set a bucket property. This should only be used if you know what you are doing. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item get_property |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
my $prop = $bucket->get_property('n_val'); |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Retrieve a bucket property. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item set_properties |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Set multiple bucket properties in one call. This should only be used if you know what you are doing. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=item get_properties |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Retrieve an associative array of all bucket properties, containing 'props' and 'keys' elements. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Accepts a hashref of parameters. Supported parameters are: |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=over 4 |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item props => 'true'|'false' |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Whether to return bucket properties. Defaults to 'true' if no parameters are given. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=item keys => 'true'|'false'|'stream' |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Whether to return bucket keys. If set to 'stream', uses key streaming mode, which may be faster for large keyspaces. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=item cb => sub { } |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
A callback subroutine to be called for each key found (passed in as the only parameter). Implies keys => 'stream'. Keys are omitted from the results hashref in callback mode. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=back |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=back |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head1 AUTHOR |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
franck cuny <franck@lumberjaph.net>, robin edwards <robin.ge@gmail.com> |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
This software is copyright (c) 2013 by linkfluence. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
279
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=cut |