| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package ArangoDB::AbstractDocument; |
|
2
|
8
|
|
|
8
|
|
9061
|
use strict; |
|
|
8
|
|
|
|
|
20
|
|
|
|
8
|
|
|
|
|
364
|
|
|
3
|
8
|
|
|
8
|
|
46
|
use warnings; |
|
|
8
|
|
|
|
|
16
|
|
|
|
8
|
|
|
|
|
226
|
|
|
4
|
8
|
|
|
8
|
|
41
|
use utf8; |
|
|
8
|
|
|
|
|
23
|
|
|
|
8
|
|
|
|
|
51
|
|
|
5
|
8
|
|
|
8
|
|
410
|
use 5.008001; |
|
|
8
|
|
|
|
|
37
|
|
|
|
8
|
|
|
|
|
829
|
|
|
6
|
8
|
|
|
8
|
|
47
|
use Scalar::Util qw(weaken); |
|
|
8
|
|
|
|
|
13
|
|
|
|
8
|
|
|
|
|
805
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use overload |
|
9
|
0
|
|
|
0
|
|
|
q{""} => sub { shift->document_handle }, |
|
10
|
8
|
|
|
8
|
|
49
|
fallback => 1; |
|
|
8
|
|
|
|
|
14
|
|
|
|
8
|
|
|
|
|
105
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
0
|
|
|
0
|
0
|
|
my ( $class, $conn, $doc ) = @_; |
|
14
|
0
|
0
|
|
|
|
|
die "Invalid argument for $class : undef" unless defined $doc; |
|
15
|
0
|
|
|
|
|
|
my $self = bless { connection => $conn, }, $class; |
|
16
|
0
|
|
|
|
|
|
weaken( $self->{connection} ); |
|
17
|
0
|
|
|
|
|
|
my $id = CORE::delete $doc->{_id}; |
|
18
|
0
|
|
|
|
|
|
my $rev = CORE::delete $doc->{_rev}; |
|
19
|
0
|
|
0
|
|
|
|
$self->{is_persistent} = defined $id && defined $rev; |
|
20
|
0
|
0
|
|
|
|
|
if ( $self->{is_persistent} ) { |
|
21
|
0
|
|
|
|
|
|
( $self->{_collection_id}, $self->{_id} ) = split '/', $id; |
|
22
|
0
|
|
|
|
|
|
$self->{_document_handle} = $id; |
|
23
|
0
|
|
|
|
|
|
$self->{_rev} = $rev; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
0
|
|
|
|
|
|
map { $self->{$_} = CORE::delete $doc->{$_} } grep {/^_/} keys %$doc; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$self->{document} = $doc; |
|
27
|
0
|
|
|
|
|
|
return $self; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub id { |
|
31
|
0
|
|
|
0
|
0
|
|
$_[0]->{_id}; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub revision { |
|
35
|
0
|
|
|
0
|
0
|
|
$_[0]->{_rev}; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub collection_id { |
|
39
|
0
|
|
|
0
|
0
|
|
$_[0]->{_collection_id}; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub document_handle { |
|
43
|
0
|
|
|
0
|
0
|
|
$_[0]->{_document_handle}; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub content { |
|
47
|
0
|
|
|
0
|
0
|
|
return $_[0]->{document}; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get { |
|
51
|
0
|
|
|
0
|
0
|
|
my ( $self, $attr_name ) = @_; |
|
52
|
0
|
|
|
|
|
|
return $self->{document}{$attr_name}; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub set { |
|
56
|
0
|
|
|
0
|
0
|
|
my ( $self, $attr_name, $value ) = @_; |
|
57
|
0
|
|
|
|
|
|
$self->{document}{$attr_name} = $value; |
|
58
|
0
|
|
|
|
|
|
return $self; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub fetch { |
|
62
|
0
|
|
|
0
|
0
|
|
my ( $self, $no_etag ) = @_; |
|
63
|
0
|
|
|
|
|
|
my @header; |
|
64
|
0
|
0
|
|
|
|
|
if ( !$no_etag ) { |
|
65
|
0
|
|
|
|
|
|
push @header, 'If-None-Match' => $self->{_rev}; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
0
|
|
|
|
|
|
my $res = eval { $self->{connection}->http_get( $self->_api_path, \@header ) }; |
|
|
0
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if ($@) { |
|
69
|
0
|
|
|
|
|
|
$self->_server_error_handler( $@, 'fetch' ); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
0
|
0
|
0
|
|
|
|
if ( !defined $res || ref($res) eq 'HASH' ) { |
|
72
|
0
|
|
|
|
|
|
$self->{_rev} = delete $res->{_rev}; |
|
73
|
0
|
|
|
|
|
|
$self->{document} = { map { $_ => $res->{$_} } grep { $_ !~ /^_/ } keys %$res }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
|
75
|
0
|
|
|
|
|
|
return $self; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub save { |
|
79
|
0
|
|
|
0
|
0
|
|
my ( $self, $with_rev_check ) = @_; |
|
80
|
0
|
|
|
|
|
|
eval { |
|
81
|
0
|
0
|
|
|
|
|
my $rev |
|
82
|
|
|
|
|
|
|
= $with_rev_check |
|
83
|
|
|
|
|
|
|
? '?rev=' . $self->{_rev} |
|
84
|
|
|
|
|
|
|
: q{}; |
|
85
|
0
|
|
|
|
|
|
$self->{connection}->http_put( $self->_api_path . $rev, $self->content ); |
|
86
|
|
|
|
|
|
|
}; |
|
87
|
0
|
0
|
|
|
|
|
if ($@) { |
|
88
|
0
|
|
|
|
|
|
$self->_server_error_handler( $@, 'update' ); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
0
|
|
|
|
|
|
$self->fetch(1); |
|
91
|
0
|
|
|
|
|
|
return $self; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub delete { |
|
95
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
96
|
0
|
|
|
|
|
|
eval { $self->{connection}->http_delete( $self->_api_path ) }; |
|
|
0
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
if ($@) { |
|
98
|
0
|
|
|
|
|
|
$self->_server_error_handler( $@, 'delete' ); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
0
|
|
|
|
|
|
return $self; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _api_path { |
|
104
|
0
|
|
|
0
|
|
|
die 'Abstract method'; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _server_error_handler { |
|
108
|
0
|
|
|
0
|
|
|
die 'Abstract method'; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
|
112
|
|
|
|
|
|
|
__END__ |