--- trunk/Estraier.pm 2006/01/05 23:38:32 42 +++ trunk/Estraier.pm 2006/01/06 00:04:28 43 @@ -387,7 +387,7 @@ sub set_max { my $self = shift; my $max = shift; - croak "set_max needs number" unless ($max =~ m/^\d+$/); + croak "set_max needs number, not '$max'" unless ($max =~ m/^\d+$/); $self->{max} = $max; } @@ -662,7 +662,7 @@ sub get_doc { my $self = shift; my $num = shift; - croak "expect number as argument" unless ($num =~ m/^\d+$/); + croak "expect number as argument, not '$num'" unless ($num =~ m/^\d+$/); return undef if ($num < 0 || $num > $self->{docs}); return $self->{docs}->[$num]; } @@ -750,7 +750,7 @@ sub set_proxy { my $self = shift; my ($host,$port) = @_; - croak "proxy port must be number" unless ($port =~ m/^\d+$/); + croak "proxy port must be number, not '$port'" unless ($port =~ m/^\d+$/); $self->{pxhost} = $host; $self->{pxport} = $port; } @@ -767,7 +767,7 @@ sub set_timeout { my $self = shift; my $sec = shift; - croak "timeout must be number" unless ($sec =~ m/^\d+$/); + croak "timeout must be number, not '$sec'" unless ($sec =~ m/^\d+$/); $self->{timeout} = $sec; } @@ -841,7 +841,7 @@ my $self = shift; my $id = shift || return; return unless ($self->{url}); - croak "id must be number" unless ($id =~ m/^\d+$/); + croak "id must be number, not '$id'" unless ($id =~ m/^\d+$/); $self->shuttle_url( $self->{url} . '/out_doc', 'application/x-www-form-urlencoded', "id=$id", @@ -894,6 +894,66 @@ } +=head2 get_doc + +Retreive document + + my $doc = $node->get_doc( document_id ) or die "can't get document"; + +Return true on success or false on failture. + +=cut + +sub get_doc { + my $self = shift; + my $id = shift || return; + return $self->_fetch_doc( id => $id ); +} + +=head2 get_doc_by_uri + +Retreive document + + my $doc = $node->get_doc_by_uri( 'file:///document_uri' ) or die "can't get document"; + +Return true on success or false on failture. + +=cut + +sub get_doc_by_uri { + my $self = shift; + my $uri = shift || return; + return $self->_fetch_doc( uri => $uri ); +} + +=head2 _fetch_doc + +Private function used for implementation of C and C. + + my $doc = $node->fetch_doc( id => 42 ); + my $doc = $node->fetch_doc( uri => 'file://uri/42' ); + +=cut + +sub _fetch_doc { + my $self = shift; + my ($name,$val) = @_; + return unless ($name && defined($val) && $self->{url}); + if ($name eq 'id') { + croak "id must be numberm not '$val'" unless ($val =~ m/^\d+$/); + } + my $rv = $self->shuttle_url( $self->{url} . '/get_doc', + 'application/x-www-form-urlencoded', + "$name=$val", + my $draft, + ); + return if ($rv != 200); + return new Search::Estraier::Document($draft); +} + + + + =head2 shuttle_url This is method which uses C to communicate with Hyper Estraier node