--- trunk/Estraier.pm 2006/01/05 23:00:22 40 +++ trunk/Estraier.pm 2006/01/05 23:32:31 41 @@ -690,7 +690,7 @@ bless($self, $class); if (@_) { - $self->{debug} = 1; + $self->{debug} = shift; warn "## Node debug on\n"; } @@ -774,14 +774,68 @@ =head2 put_doc - $node->put_doc( $document_draft ); +Add a document + + $node->put_doc( $document_draft ) or die "can't add document"; + +Return true on success or false on failture. =cut sub put_doc { my $self = shift; my $doc = shift || return; - $self->shuttle_url( $self->{url} . '/put_doc', 'text/x-estraier-draft', $doc->dump_draft, undef); + return unless ($self->{url}); + $self->shuttle_url( $self->{url} . '/put_doc', + 'text/x-estraier-draft', + $doc->dump_draft, + undef + ) == 200; +} + + +=head2 out_doc + +Remove a document + + $node->out_doc( document_id ) or "can't remove document"; + +Return true on success or false on failture. + +=cut + +sub out_doc { + my $self = shift; + my $id = shift || return; + return unless ($self->{url}); + croak "id must be number" unless ($id =~ m/^\d+$/); + $self->shuttle_url( $self->{url} . '/out_doc', + 'application/x-www-form-urlencoded', + "id=$id", + undef + ) == 200; +} + + +=head2 out_doc_by_uri + +Remove a registrated document using it's uri + + $node->out_doc_by_uri( 'file:///document_url' ) or "can't remove document"; + +Return true on success or false on failture. + +=cut + +sub out_doc_by_uri { + my $self = shift; + my $uri = shift || return; + return unless ($self->{url}); + $self->shuttle_url( $self->{url} . '/out_doc', + 'application/x-www-form-urlencoded', + "uri=$uri", + undef + ) == 200; } =head2 shuttle_url @@ -803,7 +857,7 @@ $self->{status} = -1; - warn "## $url\n"; + warn "## $url\n" if ($self->{debug}); $url = new URI($url); if ( @@ -862,7 +916,7 @@ carp "can't send headers to network:\n$headers\n" and return -1; if ($reqbody) { - warn $reqbody if ($self->{debug}); + warn "$reqbody\n" if ($self->{debug}); print $sock $reqbody or carp "can't send request body to network:\n$$reqbody\n" and return -1; }