4 |
use strict; |
use strict; |
5 |
use warnings; |
use warnings; |
6 |
|
|
7 |
our $VERSION = '0.03_1'; |
our $VERSION = '0.04_1'; |
8 |
|
|
9 |
=head1 NAME |
=head1 NAME |
10 |
|
|
157 |
} elsif ($line =~ m/^$/) { |
} elsif ($line =~ m/^$/) { |
158 |
$in_text = 1; |
$in_text = 1; |
159 |
next; |
next; |
160 |
} elsif ($line =~ m/^(.+)=(.+)$/) { |
} elsif ($line =~ m/^(.+)=(.*)$/) { |
161 |
$self->{attrs}->{ $1 } = $2; |
$self->{attrs}->{ $1 } = $2; |
162 |
next; |
next; |
163 |
} |
} |
164 |
|
|
165 |
warn "draft ignored: $line\n"; |
warn "draft ignored: '$line'\n"; |
166 |
} |
} |
167 |
} |
} |
168 |
|
|
320 |
my $draft; |
my $draft; |
321 |
|
|
322 |
foreach my $attr_name (sort keys %{ $self->{attrs} }) { |
foreach my $attr_name (sort keys %{ $self->{attrs} }) { |
323 |
$draft .= $attr_name . '=' . $self->{attrs}->{$attr_name} . "\n"; |
next unless(my $v = $self->{attrs}->{$attr_name}); |
324 |
|
$draft .= $attr_name . '=' . $v . "\n"; |
325 |
} |
} |
326 |
|
|
327 |
if ($self->{kwords}) { |
if ($self->{kwords}) { |
736 |
return $self->{hints}->{$key}; |
return $self->{hints}->{$key}; |
737 |
} |
} |
738 |
|
|
739 |
|
=head2 hints |
740 |
|
|
741 |
|
More perlish version of C<hint>. This one returns hash. |
742 |
|
|
743 |
|
my %hints = $rec->hints; |
744 |
|
|
745 |
|
=cut |
746 |
|
|
747 |
|
sub hints { |
748 |
|
my $self = shift; |
749 |
|
return $self->{hints}; |
750 |
|
} |
751 |
|
|
752 |
package Search::Estraier::Node; |
package Search::Estraier::Node; |
753 |
|
|
767 |
|
|
768 |
my $node = new Search::HyperEstraier::Node( 'http://localhost:1978/node/test' ); |
my $node = new Search::HyperEstraier::Node( 'http://localhost:1978/node/test' ); |
769 |
|
|
770 |
|
or in more verbose form |
771 |
|
|
772 |
|
my $node = new Search::HyperEstraier::Node( |
773 |
|
url => 'http://localhost:1978/node/test', |
774 |
|
debug => 1, |
775 |
|
croak_on_error => 1 |
776 |
|
); |
777 |
|
|
778 |
|
with following arguments: |
779 |
|
|
780 |
|
=over 4 |
781 |
|
|
782 |
|
=item url |
783 |
|
|
784 |
|
URL to node |
785 |
|
|
786 |
|
=item debug |
787 |
|
|
788 |
|
dumps a B<lot> of debugging output |
789 |
|
|
790 |
|
=item croak_on_error |
791 |
|
|
792 |
|
very helpful during development. It will croak on all errors instead of |
793 |
|
silently returning C<-1> (which is convention of Hyper Estraier API in other |
794 |
|
languages). |
795 |
|
|
796 |
|
=back |
797 |
|
|
798 |
=cut |
=cut |
799 |
|
|
800 |
sub new { |
sub new { |
817 |
} else { |
} else { |
818 |
my $args = {@_}; |
my $args = {@_}; |
819 |
|
|
820 |
$self->{debug} = $args->{debug}; |
%$self = ( %$self, @_ ); |
821 |
|
|
822 |
warn "## Node debug on\n" if ($self->{debug}); |
warn "## Node debug on\n" if ($self->{debug}); |
823 |
} |
} |
824 |
|
|
1460 |
|
|
1461 |
$req->headers->header( 'Host' => $url->host . ":" . $url->port ); |
$req->headers->header( 'Host' => $url->host . ":" . $url->port ); |
1462 |
$req->headers->header( 'Connection', 'close' ); |
$req->headers->header( 'Connection', 'close' ); |
1463 |
$req->headers->header( 'Authorization', 'Basic ' . $self->{auth} ); |
$req->headers->header( 'Authorization', 'Basic ' . $self->{auth} ) if ($self->{auth}); |
1464 |
$req->content_type( $content_type ); |
$req->content_type( $content_type ); |
1465 |
|
|
1466 |
warn $req->headers->as_string,"\n" if ($self->{debug}); |
warn $req->headers->as_string,"\n" if ($self->{debug}); |
1474 |
|
|
1475 |
warn "## response status: ",$res->status_line,"\n" if ($self->{debug}); |
warn "## response status: ",$res->status_line,"\n" if ($self->{debug}); |
1476 |
|
|
|
return -1 if (! $res->is_success); |
|
|
|
|
1477 |
($self->{status}, $self->{status_message}) = split(/\s+/, $res->status_line, 2); |
($self->{status}, $self->{status_message}) = split(/\s+/, $res->status_line, 2); |
1478 |
|
|
1479 |
|
if (! $res->is_success) { |
1480 |
|
if ($self->{croak_on_error}) { |
1481 |
|
croak("can't get $url: ",$res->status_line); |
1482 |
|
} else { |
1483 |
|
return -1; |
1484 |
|
} |
1485 |
|
} |
1486 |
|
|
1487 |
$$resbody .= $res->content; |
$$resbody .= $res->content; |
1488 |
|
|
1489 |
warn "## response body:\n$$resbody\n" if ($resbody && $self->{debug}); |
warn "## response body:\n$$resbody\n" if ($resbody && $self->{debug}); |
1583 |
$reqbody .= '&credit=' . $credit if ($credit > 0); |
$reqbody .= '&credit=' . $credit if ($credit > 0); |
1584 |
|
|
1585 |
$self->shuttle_url( $self->{url} . '/_set_link', |
$self->shuttle_url( $self->{url} . '/_set_link', |
1586 |
'text/plain', |
'application/x-www-form-urlencoded', |
1587 |
$reqbody, |
$reqbody, |
1588 |
undef |
undef |
1589 |
) == 200; |
) == 200; |