line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::CouchDB::Bag; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
192
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with 'Catmandu::Bag'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub BUILD { |
9
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
10
|
0
|
|
|
|
|
|
$self->store->couch_db->create_db($self->name); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub generator { |
14
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
15
|
|
|
|
|
|
|
sub { |
16
|
0
|
|
|
0
|
|
|
state $i = 0; |
17
|
0
|
|
|
|
|
|
state $rows = do { |
18
|
0
|
|
|
|
|
|
$self->store->couch_db->method('GET'); |
19
|
0
|
|
|
|
|
|
my $res = $self->store->couch_db->_call($self->name.'/_all_docs'); |
20
|
0
|
|
|
|
|
|
$res->{rows}; |
21
|
|
|
|
|
|
|
}; |
22
|
0
|
|
|
|
|
|
while (my $row = $rows->[$i++]) { |
23
|
0
|
|
|
|
|
|
my $key = $row->{key}; |
24
|
0
|
0
|
|
|
|
|
if ($key =~ /^_design/) { |
25
|
0
|
|
|
|
|
|
next; |
26
|
|
|
|
|
|
|
} |
27
|
0
|
|
0
|
|
|
|
return $self->get($key) || next; |
28
|
|
|
|
|
|
|
} |
29
|
0
|
|
|
|
|
|
return; |
30
|
0
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub get { |
34
|
|
|
|
|
|
|
my ($self, $id) = @_; |
35
|
|
|
|
|
|
|
$self->store->couch_db->get_doc({dbname => $self->name, id => $id}); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub add { |
39
|
|
|
|
|
|
|
my ($self, $data) = @_; |
40
|
|
|
|
|
|
|
my ($id, $rev ) = $self->store->couch_db->put_doc({dbname => $self->name, doc => $data}); |
41
|
|
|
|
|
|
|
$data->{_id} = $id; |
42
|
|
|
|
|
|
|
$data->{_rev} = $rev; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub delete { |
46
|
|
|
|
|
|
|
my ($self, $id) = @_; |
47
|
|
|
|
|
|
|
$self->store->couch_db->del_doc({dbname => $self->name, id => $id}); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub delete_all { |
51
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
52
|
|
|
|
|
|
|
$self->each(sub { |
53
|
0
|
|
|
0
|
|
|
$self->delete($_[0]->{_id}); |
54
|
0
|
|
|
|
|
|
}); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |