line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Couchbase::Couch::HandleInfo; |
2
|
|
|
|
|
|
|
# Subclass of Couchbase::Client::Return, with extra fields |
3
|
|
|
|
|
|
|
# for handling callbacks and http codes. This 'unimplements' |
4
|
|
|
|
|
|
|
# the cas method, which is not applicable to HTTP queries. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# ^^^^ This might change in the future, as CAS is actually encoded in the rev |
7
|
|
|
|
|
|
|
# field. |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
163
|
|
10
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
83
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
13
|
use Couchbase::Client::Return; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
175
|
|
13
|
4
|
|
|
4
|
|
19
|
use Couchbase::Client::IDXConst; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
835
|
|
14
|
4
|
|
|
4
|
|
18
|
use Couchbase::Client::Return; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
50
|
|
15
|
4
|
|
|
4
|
|
12
|
use JSON; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
19
|
|
16
|
4
|
|
|
4
|
|
340
|
use base qw(Couchbase::Client::Return); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
454
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Class::XSAccessor::Array { |
19
|
4
|
|
|
|
|
59
|
accessors => { |
20
|
|
|
|
|
|
|
http_code => COUCHIDX_HTTP, |
21
|
|
|
|
|
|
|
on_data => COUCHIDX_CALLBACK_DATA, |
22
|
|
|
|
|
|
|
on_complete => COUCHIDX_CALLBACK_COMPLETE, |
23
|
|
|
|
|
|
|
path => COUCHIDX_PATH, |
24
|
|
|
|
|
|
|
parent => COUCHIDX_CBO, |
25
|
|
|
|
|
|
|
errinfo => COUCHIDX_ERREXTRA, |
26
|
|
|
|
|
|
|
count => COUCHIDX_ROWCOUNT, |
27
|
|
|
|
|
|
|
_priv => COUCHIDX_UDATA |
28
|
|
|
|
|
|
|
} |
29
|
4
|
|
|
4
|
|
18
|
}; |
|
4
|
|
|
|
|
5
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub cas { |
32
|
0
|
|
|
0
|
1
|
|
warn ("This method is not implemented for " . __PACKAGE__); |
33
|
0
|
|
|
|
|
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# These two methods implement handling of HTTP errors as well |
38
|
|
|
|
|
|
|
sub is_ok { |
39
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
40
|
0
|
|
|
|
|
|
my $ret = $self->SUPER::is_ok(); |
41
|
0
|
0
|
|
|
|
|
if (!$ret) { |
42
|
0
|
|
|
|
|
|
return $ret; |
43
|
|
|
|
|
|
|
} |
44
|
0
|
0
|
|
|
|
|
if ($self->errinfo) { |
45
|
0
|
|
|
|
|
|
return 0; |
46
|
|
|
|
|
|
|
} |
47
|
0
|
0
|
0
|
|
|
|
if ($self->http_code > 299 && $self->http_code < 200) { |
48
|
0
|
|
|
|
|
|
return 0; |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
|
return $ret; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub errstr { |
54
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
55
|
0
|
|
|
|
|
|
my $ret = $self->SUPER::errstr; |
56
|
0
|
0
|
|
|
|
|
if (!$ret) { |
57
|
0
|
|
|
|
|
|
return $ret; |
58
|
|
|
|
|
|
|
} |
59
|
0
|
0
|
|
|
|
|
if ($self->http_code !~ /^2\d\d/) { |
60
|
0
|
|
|
|
|
|
$ret .= sprintf(" (HTTP=%d)", $self->http_code); |
61
|
|
|
|
|
|
|
} |
62
|
0
|
0
|
|
|
|
|
if ($self->errinfo) { |
63
|
0
|
0
|
|
|
|
|
if ($self->errinfo->{errors}) { |
|
|
0
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$ret .= " [There were some errors fetching individual rows. " |
65
|
|
|
|
|
|
|
."See ->errinfo]"; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} elsif ($self->errinfo->{error}) { |
68
|
0
|
|
|
|
|
|
$ret .= sprintf(" [Query Error (error=%s, reason=%s)]", |
69
|
|
|
|
|
|
|
$self->errinfo->{error}, $self->errinfo->{reason}); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
return $ret; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _extract_row_errors { |
76
|
0
|
|
|
0
|
|
|
my ($self,$hash) = @_; |
77
|
0
|
0
|
|
|
|
|
if (exists $hash->{errors}) { |
|
|
0
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$self->[COUCHIDX_ERREXTRA] = delete $hash->{errors}; |
79
|
|
|
|
|
|
|
} elsif (exists $hash->{error}) { |
80
|
0
|
|
|
|
|
|
$self->[COUCHIDX_ERREXTRA] = { reason => delete $hash->{reason}, |
81
|
|
|
|
|
|
|
error => delete $hash->{error} }; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _extract_item_count { |
86
|
0
|
|
|
0
|
|
|
my ($self,$hash) = @_; |
87
|
0
|
0
|
|
|
|
|
if (!defined $hash) { |
88
|
0
|
|
|
|
|
|
return; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$self->[COUCHIDX_ROWCOUNT] = $hash->{total_rows}; |
92
|
0
|
|
|
|
|
|
return $self->[COUCHIDX_ROWCOUNT]; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _extract_view_results { |
96
|
0
|
|
|
0
|
|
|
my $self = shift; |
97
|
0
|
|
|
|
|
|
my $json = delete $self->[RETIDX_VALUE]; |
98
|
0
|
0
|
|
|
|
|
if (defined $json) { |
99
|
0
|
|
|
|
|
|
$json = decode_json($json); |
100
|
0
|
|
|
|
|
|
$self->_extract_row_errors($json); |
101
|
0
|
|
|
|
|
|
$self->[RETIDX_VALUE] = delete $json->{rows}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
{ |
106
|
4
|
|
|
4
|
|
2628
|
no warnings 'once'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
231
|
|
107
|
|
|
|
|
|
|
*rows = *Couchbase::Client::Return::value; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |