line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# This module forms the CouchDB parts of |
2
|
|
|
|
|
|
|
# Couchbase::Client's API |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Couchbase::Couch::Base; |
5
|
4
|
|
|
4
|
|
19
|
use strict; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
119
|
|
6
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
73
|
|
7
|
4
|
|
|
4
|
|
1569
|
use Couchbase::Couch::Handle; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
89
|
|
8
|
4
|
|
|
4
|
|
1560
|
use Couchbase::Couch::HandleInfo; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
88
|
|
9
|
4
|
|
|
4
|
|
1413
|
use Couchbase::Couch::Design; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
90
|
|
10
|
4
|
|
|
4
|
|
22
|
use Couchbase::Client::IDXConst; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
925
|
|
11
|
4
|
|
|
4
|
|
18
|
use JSON; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
19
|
|
12
|
4
|
|
|
4
|
|
366
|
use JSON::SL; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
127
|
|
13
|
4
|
|
|
4
|
|
20
|
use Data::Dumper; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
155
|
|
14
|
4
|
|
|
4
|
|
2044
|
use URI; |
|
4
|
|
|
|
|
14120
|
|
|
4
|
|
|
|
|
777
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _CouchCtorInit { |
18
|
0
|
|
|
0
|
|
|
my ($cls,$av) = @_; |
19
|
0
|
|
|
|
|
|
$av->[CTORIDX_JSON_ENCODE_METHOD] = \&encode_json; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# The following methods are defined in Client.xs |
23
|
|
|
|
|
|
|
# and alias to the memcached set() method, with |
24
|
|
|
|
|
|
|
# special behavior for converting objects into |
25
|
|
|
|
|
|
|
# JSON |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# couch_store, couch_set |
28
|
|
|
|
|
|
|
# couch_add |
29
|
|
|
|
|
|
|
# couch_replace |
30
|
|
|
|
|
|
|
# couch_cas |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my %STRMETH_MAP = ( |
33
|
|
|
|
|
|
|
GET => COUCH_METHOD_GET, |
34
|
|
|
|
|
|
|
POST => COUCH_METHOD_POST, |
35
|
|
|
|
|
|
|
PUT => COUCH_METHOD_PUT, |
36
|
|
|
|
|
|
|
DELETE => COUCH_METHOD_DELETE |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Returns a 'raw' request handle |
41
|
|
|
|
|
|
|
sub couch_handle_raw { |
42
|
0
|
|
|
0
|
0
|
|
my ($self,$meth,$path,$body) = @_; |
43
|
0
|
|
|
|
|
|
my $imeth = $STRMETH_MAP{$meth}; |
44
|
0
|
0
|
|
|
|
|
if (!defined $imeth) { |
45
|
0
|
|
|
|
|
|
die("Unknown method: $meth"); |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
return $self->_couch_handle_new(\%Couchbase::Couch::Handle::RawIterator::); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# gets a couch document. Quite simple.. |
51
|
|
|
|
|
|
|
sub couch_doc_get { |
52
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
53
|
0
|
|
|
|
|
|
my $ret = $self->get(@_); |
54
|
0
|
0
|
|
|
|
|
if ($ret->value) { |
55
|
0
|
|
|
|
|
|
$ret->[RETIDX_VALUE] = decode_json($ret->[RETIDX_VALUE]); |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
return $ret; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
{ |
61
|
4
|
|
|
4
|
|
30
|
no warnings 'once'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1721
|
|
62
|
|
|
|
|
|
|
*couch_doc_store = *Couchbase::Client::couch_set; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Gets a design document |
66
|
|
|
|
|
|
|
sub couch_design_get { |
67
|
0
|
|
|
0
|
1
|
|
my ($self,$path) = @_; |
68
|
0
|
|
|
|
|
|
my $handle = $self->_couch_handle_new( |
69
|
|
|
|
|
|
|
\%Couchbase::Couch::Handle::Slurpee::); |
70
|
0
|
|
|
|
|
|
my $design = $handle->slurp_jsonized(COUCH_METHOD_GET, "_design/" . $path, ""); |
71
|
0
|
|
|
|
|
|
bless $design, 'Couchbase::Couch::Design'; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# saves a design document |
75
|
|
|
|
|
|
|
sub couch_design_put { |
76
|
0
|
|
|
0
|
1
|
|
my ($self,$design,$path) = @_; |
77
|
0
|
0
|
|
|
|
|
if (ref $design) { |
78
|
0
|
|
|
|
|
|
$path = $design->{_id}; |
79
|
0
|
|
|
|
|
|
$design = encode_json($design); |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
my $handle = $self->_couch_handle_new(\%Couchbase::Couch::Handle::Slurpee::); |
82
|
0
|
|
|
|
|
|
return $handle->slurp_jsonized(COUCH_METHOD_PUT, $path, $design); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _process_viewpath_common { |
86
|
0
|
|
|
0
|
|
|
my ($orig,%options) = @_; |
87
|
0
|
|
|
|
|
|
my %qparams; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if (delete $options{ForUpdate}) { |
90
|
0
|
|
|
|
|
|
$qparams{include_docs} = "true"; |
91
|
|
|
|
|
|
|
} |
92
|
0
|
0
|
|
|
|
|
if (%options) { |
93
|
|
|
|
|
|
|
# TODO: pop any other known parameters? |
94
|
0
|
|
|
|
|
|
%qparams = (%qparams,%options); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
if (ref $orig eq 'ARRAY') { |
98
|
0
|
0
|
0
|
|
|
|
unless ($orig->[0] && $orig->[1]) { |
99
|
0
|
|
|
|
|
|
die("Path cannot be empty"); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Assume this is an array of [ design, view ] |
103
|
0
|
|
|
|
|
|
$orig = sprintf("_design/%s/_view/%s", @$orig); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
if (!$orig) { |
107
|
0
|
|
|
|
|
|
die("Path cannot be empty"); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
if (%qparams) { |
112
|
0
|
|
|
|
|
|
$orig = URI->new($orig); |
113
|
0
|
|
|
|
|
|
$orig->query_form(\%qparams); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
return $orig . ""; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# slurp an entire resultset of views |
120
|
|
|
|
|
|
|
sub couch_view_slurp { |
121
|
0
|
|
|
0
|
1
|
|
my ($self,$viewpath,%options) = @_; |
122
|
0
|
|
|
|
|
|
my $handle = $self->_couch_handle_new( |
123
|
|
|
|
|
|
|
\%Couchbase::Couch::Handle::Slurpee::); |
124
|
0
|
0
|
|
|
|
|
if (delete $options{ForUpdate}) { |
125
|
0
|
|
|
|
|
|
$viewpath .= "?include_docs=true"; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
$viewpath = _process_viewpath_common($viewpath,%options); |
128
|
0
|
|
|
|
|
|
$handle->slurp(COUCH_METHOD_GET, $viewpath, ""); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub couch_view_iterator { |
133
|
0
|
|
|
0
|
1
|
|
my ($self,$viewpath,%options) = @_; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
$viewpath = _process_viewpath_common($viewpath, %options); |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
my $handle = $self->_couch_handle_new( |
138
|
|
|
|
|
|
|
\%Couchbase::Couch::Handle::ViewIterator::); |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
$handle->_perl_initialize(); |
141
|
0
|
|
|
|
|
|
$handle->prepare(COUCH_METHOD_GET, $viewpath, ""); |
142
|
0
|
|
|
|
|
|
return $handle; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
0xf00d |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |