+ warn "# _couchdb_put $couchdb/$database/$entity.$id = $json";
+ $client->put( "$couchdb/$database/$entity.$id" => $json => sub {
+ my ($client,$tx) = @_;
+ if ($tx->error) {
+ die $tx->error;
+ }
+ my $response = $tx->res->json;
+ warn "## CouchDB response ",dump($response);
+ $couchdb_rev->{$database}->{$entity}->{$id} = $response->{rev} || die "no rev";
+ })->process;
+}
+
+sub _couchdb_get {
+ my ( $url ) = @_;
+ my $client = Mojo::Client->new;
+ my $return = $client->get( "$couchdb/$url" )->res->json;
+ warn "# _couchdb_get $url = ",dump($return);
+ return $return;
+}
+
+our $id2nr;
+
+
+sub _render_jsonp {
+ my ( $self, $json ) = @_;
+#warn "## _render_json ",dump($json);
+ my $data = $self->render( json => $json, partial => 1 );
+warn "## _render_json $data";
+ if ( my $callback = $self->param('callback') ) {
+ $data = "$callback($data)";
+ }
+ $self->render( data => $data, format => 'js' );
+}
+
+#get '/' => 'index';
+
+get '/_replicate' => sub {