/[Frey]/trunk/lib/Frey/CouchAPI.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/CouchAPI.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1050 by dpavlin, Thu Apr 23 18:45:42 2009 UTC revision 1051 by dpavlin, Thu Apr 23 19:35:26 2009 UTC
# Line 1  Line 1 
1  package Frey::CouchAPI;  package Frey::CouchAPI;
2    
3    =head1 DESCRIPTION
4    
5    This is REST wrapper using L<Mojo::Transaction> to implement Apache's CouchDB API
6    
7    =head1 Supported HTTP API
8    
9    =cut
10    
11  use warnings;  use warnings;
12  use strict;  use strict;
13    
# Line 100  warn "json ",dump( $json ), " config ", Line 108  warn "json ",dump( $json ), " config ",
108    
109          } elsif ( $url =~ m{($regex_dbs)/$} ) {          } elsif ( $url =~ m{($regex_dbs)/$} ) {
110    
111    =head2 Database
112    
113    L<http://wiki.apache.org/couchdb/HTTP_database_API> except compaction
114    
115    =cut
116    
117                  my $database = $1;                  my $database = $1;
118                  my $dir = "$config->{path}/$database";                  my $dir = "$config->{path}/$database";
119    
# Line 122  warn "json ",dump( $json ), " config ", Line 136  warn "json ",dump( $json ), " config ",
136          } elsif ( $url =~ m{($regex_dbs)/([^?]+)\??(.+)?$} ) {          } elsif ( $url =~ m{($regex_dbs)/([^?]+)\??(.+)?$} ) {
137                  my ($database,$id,$args) = ($1,$2,$3);                  my ($database,$id,$args) = ($1,$2,$3);
138    
139    =head2 Document
140    
141    L<http://wiki.apache.org/couchdb/HTTP_Document_API>
142    
143    =cut
144    
145                  my $arg;                  my $arg;
146                  if ( $args ) {                  if ( $args ) {
147                          foreach my $a ( split(/[&;]/,$args) ) {                          foreach my $a ( split(/[&;]/,$args) ) {
# Line 135  warn "json ",dump( $json ), " config ", Line 155  warn "json ",dump( $json ), " config ",
155                  warn "ERROR: path $path doesn't exist\n" unless -e $path;                  warn "ERROR: path $path doesn't exist\n" unless -e $path;
156    
157                  my $p = "$path/$database/$id";                  my $p = "$path/$database/$id";
158                  warn "## database: $database id: $id -> $p [$args]\n";                  warn "## database: $database id: $id -> $p ", dump( $arg ),"\n";
159    
160    
161                  if ( $id =~ m{_all_docs(\w+)?$} ) {                  if ( $id =~ m{_all_docs(\w+)?$} ) {
# Line 143  warn "json ",dump( $json ), " config ", Line 163  warn "json ",dump( $json ), " config ",
163                          my $by = $1;                          my $by = $1;
164                          my $offset = 0;                          my $offset = 0;
165                          my $startkey = delete $arg->{startkey};                          my $startkey = delete $arg->{startkey};
166  warn "STARTKEY: $startkey\n";                          my $endkey   = delete $arg->{endkey};
167                            my $limit    = delete $arg->{limit};
168                          my $total_rows = 0;                          my $total_rows = 0;
169    
170                          my @docs = grep { length $_ } map {                          my @docs = grep { length $_ } map {
171                                    return '' if defined $limit && $total_rows == $limit;
172            
173                                  s{^$path/$database/}{};                                  s{^$path/$database/}{};
174                                    return '' if defined $endkey && $_ gt $endkey;
175    
176                                  if ( $startkey ) {                                  if ( $startkey ) {
177                                          if ( $_ >= $startkey ) {                                          if ( $_ ge $startkey ) {
178                                                  $total_rows++;                                                  $total_rows++;
179                                                  $_;                                                  $_;
180                                          } else {                                          } else {
181                                                  $offset++;                                                  $offset++;
182                                                    return '';
183                                          }                                          }
184                                  } else {                                  } else {
185                                          $total_rows++;                                          $total_rows++;
186                                          $_;                                          $_;
187                                  }                                  }
188    
189                          } glob( "$path/$database/*" );                          } glob( "$path/$database/*" );
190    
191                          warn "## docs ", dump( @docs ) if $debug;                          warn "## docs $startkey -> $endkey limit $limit ", dump( @docs ); # if $debug;
192    
193                          $json = {                          $json = {
194                                  total_rows =>  $total_rows,                                  total_rows =>  $total_rows,
# Line 266  sub database_get { Line 293  sub database_get {
293  }  }
294    
295  1;  1;
296    __END__
297    
298    =head1 SEE ALSO
299    
300    L<http://wiki.apache.org/couchdb/Reference>
301    

Legend:
Removed from v.1050  
changed lines
  Added in v.1051

  ViewVC Help
Powered by ViewVC 1.1.26