Changeset 19718
- Timestamp:
- 09/22/08 12:04:47 (5 years ago)
- Location:
- lang/perl/CouchDB-Object/trunk
- Files:
-
- 3 modified
-
lib/CouchDB/Object/Database.pm (modified) (2 diffs)
-
lib/CouchDB/Object/Document.pm (modified) (2 diffs)
-
t/04_documents.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/CouchDB-Object/trunk/lib/CouchDB/Object/Database.pm
r19688 r19718 92 92 93 93 sub bulk_docs { 94 my ($self, @docs) = @_;94 my ($self, $docs) = @_; 95 95 96 my $body = sprintf '{ "docs": [%s] }', join ',', map { $_->to_json } @docs; 96 my $body = { docs => [ map { $_->to_hash } @$docs ] }; 97 $body = CouchDB::Object::JSON->encode($body); 98 97 99 my $header = HTTP::Headers->new('Content-Type' => 'application/json'); 98 100 my $res = $self->request(POST => $self->uri_for('_bulk_docs'), $header, $body); … … 100 102 # merge 101 103 if ($res->is_success) { 102 my $ea = each_array(@ docs, @{ $res->content->{new_revs} });104 my $ea = each_array(@$docs, @{ $res->content->{new_revs} }); 103 105 while (my ($doc, $content) = $ea->()) { 104 106 $doc->id($content->{id}) if exists $content->{id}; -
lang/perl/CouchDB-Object/trunk/lib/CouchDB/Object/Document.pm
r19447 r19718 44 44 sub to_json { 45 45 my $self = shift; 46 return CouchDB::Object::JSON->encode($self->to_hash); 47 } 48 49 sub to_hash { 50 my $self = shift; 46 51 47 52 my $hash = {}; … … 49 54 $hash->{_rev} = $self->rev if $self->has_rev; 50 55 51 $hash = Hash::Merge::merge({%{ $self->_fields }}, $hash); 52 return CouchDB::Object::JSON->encode($hash); 56 return Hash::Merge::merge({%{ $self->_fields }}, $hash); 53 57 } 54 58 -
lang/perl/CouchDB-Object/trunk/t/04_documents.t
r19688 r19718 9 9 } 10 10 else { 11 plan tests => 287;11 plan tests => 316; 12 12 } 13 13 … … 16 16 END { $db->drop if $couch->ping } 17 17 18 my $json = read_json('t/docs.json');19 my @docs = map { CouchDB::Object::Document->new_from_json($_) } @$json;20 21 18 # /{dbname}/_bulk_docs (bulk_docs) 22 { # 3 23 my $res = $db->bulk_docs(@docs); 19 { # 32 20 my $json = read_json('t/docs.json'); 21 my @docs = map { CouchDB::Object::Document->new_from_json($_) } @$json; 22 my $res = $db->bulk_docs(\@docs); 24 23 ok $res->is_success; 25 24 ok $res->content->{ok}; 26 ok $res->content->{new_revs}; 25 26 for my $doc (@docs) { # 1 x 30 = 30 27 ok $doc->has_rev; 28 } 27 29 } 28 30
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)