Changeset 18743 for lang/perl/CouchDB-Object
- Timestamp:
- 09/03/08 19:44:42 (5 years ago)
- Location:
- lang/perl/CouchDB-Object/trunk
- Files:
-
- 1 removed
- 8 modified
-
Makefile.PL (modified) (1 diff)
-
lib/CouchDB/Object.pm (modified) (1 diff)
-
lib/CouchDB/Object/Documents.pm (deleted)
-
lib/CouchDB/Object/Response.pm (modified) (3 diffs)
-
t/00_compile.t (modified) (1 diff)
-
t/04_open_doc.t (modified) (3 diffs)
-
t/05_remove_doc.t (modified) (1 diff)
-
t/06_all_docs.t (modified) (3 diffs)
-
t/07_query.t (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/CouchDB-Object/trunk/Makefile.PL
r18660 r18743 4 4 5 5 requires 'Moose'; 6 requires 'MooseX::AttributeHelpers';7 6 requires 'MooseX::Types::URI'; 8 7 requires 'Data::Dump::Streamer'; -
lang/perl/CouchDB-Object/trunk/lib/CouchDB/Object.pm
r18660 r18743 33 33 34 34 my $res = $self->request(GET => $self->uri_for('_all_dbs')); 35 return $self->ping ? map { $self->db($_) } @{ $res-> parsed_content } : ();35 return $self->ping ? map { $self->db($_) } @{ $res->content } : (); 36 36 } 37 37 -
lang/perl/CouchDB-Object/trunk/lib/CouchDB/Object/Response.pm
r18660 r18743 6 6 use JSON::XS (); 7 7 use CouchDB::Object::Document; 8 use CouchDB::Object::Documents;9 8 10 9 has 'http_response' => ( … … 29 28 has 'content' => ( 30 29 is => 'ro', 31 isa => ' Hash::AsObject',30 isa => 'Object', # XXX 32 31 required => 1, 33 32 ); … … 40 39 my ($class, $res) = @_; 41 40 42 my $content = {};43 $content = JSON::XS->new->decode($res->content) if $res->content_type =~ /json/i;44 45 41 return $class->new( 46 42 http_response => $res, 47 uri => $res->request->uri ,48 content => Hash::AsObject->new($content),43 uri => $res->request->uri->clone, 44 content => $class->parse_content($res), 49 45 ); 50 46 } 51 47 52 sub to_document {53 my $self = shift;48 sub parse_content { 49 my ($class, $res) = @_; 54 50 55 if (exists $self->content->{_id}) { 56 return CouchDB::Object::Document->new_from_json($self->content); 51 my $content = $res->content_type =~ /json/i ? JSON::XS->new->decode($res->content) : {}; 52 53 if (ref $content->{rows} eq 'ARRAY') { # _all_docs 54 my @docs = grep { exists $_->{id} and exists $_->{value} } @{ $content->{rows} }; 55 for my $doc (@docs) { 56 my $id = delete $doc->{id}; 57 $doc = CouchDB::Object::Document->new_from_json($doc->{value}); 58 $doc->id($id) if defined $id; 59 } 60 $content->{rows} = \@docs; 57 61 } 58 elsif (exists $self->content->{rows}) { 59 return CouchDB::Object::Documents->new_from_json($self->content); 62 elsif (ref $content->{new_revs} eq 'ARRAY') { # _bulk_docs 63 for my $doc (@{ $content->{new_revs} }) { 64 $doc = CouchDB::Object::Document->new_from_json($doc); 65 } 66 } 67 68 if (exists $content->{_id} and exists $content->{_rev}) { 69 return CouchDB::Object::Document->new_from_json($content); 60 70 } 61 71 else { 62 return ;72 return Hash::AsObject->new($content); 63 73 } 64 74 } -
lang/perl/CouchDB-Object/trunk/t/00_compile.t
r17771 r18743 1 1 use strict; 2 use Test::More tests => 7;2 use Test::More tests => 5; 3 3 4 4 BEGIN { 5 5 use_ok 'CouchDB::Object'; 6 use_ok 'CouchDB::Object::Utils';7 use_ok 'CouchDB::Object::UserAgent';8 use_ok 'CouchDB::Object::Server';9 6 use_ok 'CouchDB::Object::Database'; 10 7 use_ok 'CouchDB::Object::Document'; 11 8 use_ok 'CouchDB::Object::Response'; 9 use_ok 'CouchDB::Object::UserAgent'; 12 10 } -
lang/perl/CouchDB-Object/trunk/t/04_open_doc.t
r18660 r18743 8 8 } 9 9 else { 10 plan tests => 1 0;10 plan tests => 12; 11 11 } 12 12 … … 18 18 my $res = $db->open_doc('doc id 4'); 19 19 ok $res->is_success; # 200 20 my $doc = $res->to_document; 20 my $doc = $res->content; 21 isa_ok $doc => 'CouchDB::Object::Document'; 21 22 is $doc->id => 'doc id 4'; 22 23 ok $doc->rev; … … 29 30 my $res = $db->open_doc('doc id 3'); 30 31 ok $res->is_success; # 200 31 my $doc = $res->to_document; 32 my $doc = $res->content; 33 isa_ok $doc => 'CouchDB::Object::Document'; 32 34 is $doc->id => 'doc id 3'; 33 35 ok $doc->rev; -
lang/perl/CouchDB-Object/trunk/t/05_remove_doc.t
r18660 r18743 16 16 for (1..5) { 17 17 my $id = "doc id $_"; 18 my $doc = $db->open_doc($id)-> to_document;18 my $doc = $db->open_doc($id)->content; 19 19 ok $db->remove_doc($doc)->is_success; # 200 20 20 ok $db->open_doc($id)->is_error; # 404 -
lang/perl/CouchDB-Object/trunk/t/06_all_docs.t
r18660 r18743 8 8 } 9 9 else { 10 plan tests => 2 4;10 plan tests => 22; 11 11 } 12 12 … … 18 18 ok $res->is_success; 19 19 20 my $docs = $res-> to_document;21 is $docs->total_ docs => 5;20 my $docs = $res->content; 21 is $docs->total_rows => 5; 22 22 is $docs->offset => 0; 23 23 24 is $docs->count => 5; 25 for my $doc ($docs->all) { # 2 x 5 = 10 24 for my $doc (@{ $docs->rows }) { # 2 x 5 = 10 26 25 ok $doc->id; 27 26 ok $doc->rev; … … 33 32 ok $res->is_success; 34 33 35 my $docs = $res-> to_document;36 is $docs->total_ docs => 5;34 my $docs = $res->content; 35 is $docs->total_rows => 5; 37 36 is $docs->offset => 0; 38 37 39 is $docs->count => 3; 40 for my $doc ($docs->all) { # 2 x 3 = 6 38 for my $doc (@{ $docs->rows }) { # 2 x 3 = 6 41 39 ok $doc->id; 42 40 ok $doc->rev; -
lang/perl/CouchDB-Object/trunk/t/07_query.t
r18660 r18743 1 1 use strict; 2 2 use t::CouchDB; 3 use String::TT qw(strip tt);3 use String::TT qw(strip); 4 4 5 5 my $couch = test_couch(); … … 9 9 } 10 10 else { 11 plan tests => 8;11 plan tests => 7; 12 12 } 13 13 … … 16 16 17 17 { # doc 3 only 18 my $res = $db->query(strip ttq[18 my $res = $db->query(strip q[ 19 19 function(doc) { 20 20 if (doc.title == "doc 3") { … … 25 25 ok $res->is_success; 26 26 27 my $docs = $res-> to_document;28 is $docs->total_ docs => 1;27 my $docs = $res->content; 28 is $docs->total_rows => 1; 29 29 is $docs->offset => 0; 30 is $docs->count => 1;31 30 32 for my $doc ( $docs->all) { # 1 x 4 = 431 for my $doc (@{ $docs->rows }) { # 1 x 4 = 4 33 32 is $doc->id => 'doc id 3'; 34 33 ok $doc->rev;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)