--- trunk/lib/Frey/CouchAPI.pm 2009/04/23 18:45:42 1050 +++ trunk/lib/Frey/CouchAPI.pm 2009/04/23 19:35:26 1051 @@ -1,5 +1,13 @@ package Frey::CouchAPI; +=head1 DESCRIPTION + +This is REST wrapper using L to implement Apache's CouchDB API + +=head1 Supported HTTP API + +=cut + use warnings; use strict; @@ -100,6 +108,12 @@ } elsif ( $url =~ m{($regex_dbs)/$} ) { +=head2 Database + +L except compaction + +=cut + my $database = $1; my $dir = "$config->{path}/$database"; @@ -122,6 +136,12 @@ } elsif ( $url =~ m{($regex_dbs)/([^?]+)\??(.+)?$} ) { my ($database,$id,$args) = ($1,$2,$3); +=head2 Document + +L + +=cut + my $arg; if ( $args ) { foreach my $a ( split(/[&;]/,$args) ) { @@ -135,7 +155,7 @@ warn "ERROR: path $path doesn't exist\n" unless -e $path; my $p = "$path/$database/$id"; - warn "## database: $database id: $id -> $p [$args]\n"; + warn "## database: $database id: $id -> $p ", dump( $arg ),"\n"; if ( $id =~ m{_all_docs(\w+)?$} ) { @@ -143,25 +163,32 @@ my $by = $1; my $offset = 0; my $startkey = delete $arg->{startkey}; -warn "STARTKEY: $startkey\n"; + my $endkey = delete $arg->{endkey}; + my $limit = delete $arg->{limit}; my $total_rows = 0; my @docs = grep { length $_ } map { + return '' if defined $limit && $total_rows == $limit; + s{^$path/$database/}{}; + return '' if defined $endkey && $_ gt $endkey; + if ( $startkey ) { - if ( $_ >= $startkey ) { + if ( $_ ge $startkey ) { $total_rows++; $_; } else { $offset++; + return ''; } } else { $total_rows++; $_; } + } glob( "$path/$database/*" ); - warn "## docs ", dump( @docs ) if $debug; + warn "## docs $startkey -> $endkey limit $limit ", dump( @docs ); # if $debug; $json = { total_rows => $total_rows, @@ -266,3 +293,9 @@ } 1; +__END__ + +=head1 SEE ALSO + +L +