/[Frey]/branches/zimbardo/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 /branches/zimbardo/lib/Frey/CouchAPI.pm

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

revision 1056 by dpavlin, Thu Apr 23 21:24:25 2009 UTC revision 1059 by dpavlin, Fri Apr 24 15:32:04 2009 UTC
# Line 118  warn "json ",dump( $json ), " config ", Line 118  warn "json ",dump( $json ), " config ",
118                          $status = 501;                          $status = 501;
119                  }                  }
120    
         } elsif ( $url =~ m{($regex_dbs)/$} ) {  
   
121  =head2 Database  =head2 Database
122    
123  L<http://wiki.apache.org/couchdb/HTTP_database_API> except compaction  L<http://wiki.apache.org/couchdb/HTTP_database_API> except compaction
124    
125  =cut  =cut
126    
127            } elsif (
128                       $url =~ m{($regex_dbs)/$}
129                    # DELETE doesn't have trailing slash
130                    || $method eq 'DELETE' && $url =~ m{($regex_dbs)$}
131            ) {
132    
133                  my $database = $1;                  my $database = $1;
134    
135                  my $dir = "$path/$database";                  my $dir = "$path/$database";
# Line 157  L<http://wiki.apache.org/couchdb/HTTP_da Line 161  L<http://wiki.apache.org/couchdb/HTTP_da
161                          }                          }
162                  }                  }
163    
164                    warn "## database $database $status ",dump( $json );
165    
166          } elsif ( $url =~ m{($regex_dbs)/([^?]+)\??(.+)?$} ) {          } elsif ( $url =~ m{($regex_dbs)/([^?]+)\??(.+)?$} ) {
167                  my ($database,$id,$args) = ($1,$2,$3);                  my ($database,$id,$args) = ($1,$2,$3);
168    
# Line 181  L<http://wiki.apache.org/couchdb/HTTP_Do Line 187  L<http://wiki.apache.org/couchdb/HTTP_Do
187                  warn "## database: $database id: $id -> $p ", dump( $arg ),"\n";                  warn "## database: $database id: $id -> $p ", dump( $arg ),"\n";
188    
189    
190                  if ( $id =~ m{_all_docs(\w+)?$} ) {                  if ( $id =~ m{_all_docs(\w*)$} ) {
191    
192                          my $by = $1;                          my $by = $1;
193                          my $offset = 0;                          my $offset = 0;
# Line 191  L<http://wiki.apache.org/couchdb/HTTP_Do Line 197  L<http://wiki.apache.org/couchdb/HTTP_Do
197                          my $total_rows = 0;                          my $total_rows = 0;
198    
199                          my @docs = grep { length $_ } map {                          my @docs = grep { length $_ } map {
200                                  return '' if defined $limit && $total_rows == $limit;  
201                                    if ( $limit > 0 && $total_rows == $limit ) {
202                                            '';
203                                    } else {
204                    
205                                  s{^$path/$database/}{};                                          s{^$path/$database/}{};
                                 return '' if defined $endkey && $_ gt $endkey;  
206    
207                                  if ( $startkey ) {                                          if ( defined $endkey && $_ gt $endkey ) {
208                                          if ( $_ ge $startkey ) {                                                  '';
209                                            } elsif ( $startkey ) {
210                                                    if ( $_ ge $startkey ) {
211                                                            $total_rows++;
212                                                            $_;
213                                                    } else {
214                                                            $offset++;
215                                                            '';
216                                                    }
217                                            } else {
218                                                  $total_rows++;                                                  $total_rows++;
219                                                  $_;                                                  $_;
                                         } else {  
                                                 $offset++;  
                                                 return '';  
220                                          }                                          }
                                 } else {  
                                         $total_rows++;  
                                         $_;  
221                                  }                                  }
222    
223                          } glob( "$path/$database/*" );                          } glob( "$path/$database/*" );
224    
225    
226                          warn "## docs $startkey -> $endkey limit $limit ", dump( @docs ); # if $debug;                          warn "## docs $startkey -> $endkey limit $limit ", dump( @docs ); # if $debug;
227    
228                          $json = {                          $json = {
# Line 250  L<http://wiki.apache.org/couchdb/HTTP_Do Line 262  L<http://wiki.apache.org/couchdb/HTTP_Do
262                                  push @{ $json->{rows} }, $rows->{$id};                                  push @{ $json->{rows} }, $rows->{$id};
263                          }                          }
264    
265                            $status = 200;
266    
267                  } elsif ( $method eq 'PUT' ) {                  } elsif ( $method eq 'PUT' ) {
268                    
269                          warn "## ",dump( $tx->req ); # if $debug;                          warn "## ",dump( $tx->req ) if $debug;
270    
271                          my $data = $tx->req->content->file->slurp;                          my $data = $tx->req->content->file->slurp;
272    
273                            my $db_path = "$path/$database";
274                            make_path $db_path unless -e $db_path;
275    
276                          Storable::store( from_json($data), $p );                          Storable::store( from_json($data), $p );
277                          my $rev = file_rev $p;                          my $rev = file_rev $p;
278                          warn "store $p $rev size ", -s $p, " bytes | $data\n";                          warn "store $p $rev size ", -s $p, " bytes | $data\n";
# Line 296  L<http://wiki.apache.org/couchdb/HTTP_Do Line 313  L<http://wiki.apache.org/couchdb/HTTP_Do
313                          $status = 501;                          $status = 501;
314                  }                  }
315    
316                  warn "WARNING: arg left from $url = ",dump( $arg ),$/ if keys %$arg;                  if ( keys %$arg ) {
317                            warn "WARNING: arg left from $url = ",dump( $arg ),$/;
318                            $status = 501;
319                    }
320    
321          }          }
322    

Legend:
Removed from v.1056  
changed lines
  Added in v.1059

  ViewVC Help
Powered by ViewVC 1.1.26