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 |
|
|
735 |
return $self->{hints}->{$key}; |
return $self->{hints}->{$key}; |
736 |
} |
} |
737 |
|
|
738 |
|
=head2 hints |
739 |
|
|
740 |
|
More perlish version of C<hint>. This one returns hash. |
741 |
|
|
742 |
|
my %hints = $rec->hints; |
743 |
|
|
744 |
|
=cut |
745 |
|
|
746 |
|
sub hints { |
747 |
|
my $self = shift; |
748 |
|
return $self->{hints}; |
749 |
|
} |
750 |
|
|
751 |
package Search::Estraier::Node; |
package Search::Estraier::Node; |
752 |
|
|
766 |
|
|
767 |
my $node = new Search::HyperEstraier::Node( 'http://localhost:1978/node/test' ); |
my $node = new Search::HyperEstraier::Node( 'http://localhost:1978/node/test' ); |
768 |
|
|
769 |
|
or in more verbose form |
770 |
|
|
771 |
|
my $node = new Search::HyperEstraier::Node( |
772 |
|
url => 'http://localhost:1978/node/test', |
773 |
|
debug => 1, |
774 |
|
croak_on_error => 1 |
775 |
|
); |
776 |
|
|
777 |
|
with following arguments: |
778 |
|
|
779 |
|
=over 4 |
780 |
|
|
781 |
|
=item url |
782 |
|
|
783 |
|
URL to node |
784 |
|
|
785 |
|
=item debug |
786 |
|
|
787 |
|
dumps a B<lot> of debugging output |
788 |
|
|
789 |
|
=item croak_on_error |
790 |
|
|
791 |
|
very helpful during development. It will croak on all errors instead of |
792 |
|
silently returning C<-1> (which is convention of Hyper Estraier API in other |
793 |
|
languages). |
794 |
|
|
795 |
|
=back |
796 |
|
|
797 |
=cut |
=cut |
798 |
|
|
799 |
sub new { |
sub new { |
816 |
} else { |
} else { |
817 |
my $args = {@_}; |
my $args = {@_}; |
818 |
|
|
819 |
$self->{debug} = $args->{debug}; |
%$self = ( %$self, @_ ); |
820 |
|
|
821 |
warn "## Node debug on\n" if ($self->{debug}); |
warn "## Node debug on\n" if ($self->{debug}); |
822 |
} |
} |
823 |
|
|
1459 |
|
|
1460 |
$req->headers->header( 'Host' => $url->host . ":" . $url->port ); |
$req->headers->header( 'Host' => $url->host . ":" . $url->port ); |
1461 |
$req->headers->header( 'Connection', 'close' ); |
$req->headers->header( 'Connection', 'close' ); |
1462 |
$req->headers->header( 'Authorization', 'Basic ' . $self->{auth} ); |
$req->headers->header( 'Authorization', 'Basic ' . $self->{auth} ) if ($self->{auth}); |
1463 |
$req->content_type( $content_type ); |
$req->content_type( $content_type ); |
1464 |
|
|
1465 |
warn $req->headers->as_string,"\n" if ($self->{debug}); |
warn $req->headers->as_string,"\n" if ($self->{debug}); |
1473 |
|
|
1474 |
warn "## response status: ",$res->status_line,"\n" if ($self->{debug}); |
warn "## response status: ",$res->status_line,"\n" if ($self->{debug}); |
1475 |
|
|
|
return -1 if (! $res->is_success); |
|
|
|
|
1476 |
($self->{status}, $self->{status_message}) = split(/\s+/, $res->status_line, 2); |
($self->{status}, $self->{status_message}) = split(/\s+/, $res->status_line, 2); |
1477 |
|
|
1478 |
|
if (! $res->is_success) { |
1479 |
|
if ($self->{croak_on_error}) { |
1480 |
|
croak("can't get $url: ",$res->status_line); |
1481 |
|
} else { |
1482 |
|
return -1; |
1483 |
|
} |
1484 |
|
} |
1485 |
|
|
1486 |
$$resbody .= $res->content; |
$$resbody .= $res->content; |
1487 |
|
|
1488 |
warn "## response body:\n$$resbody\n" if ($resbody && $self->{debug}); |
warn "## response body:\n$$resbody\n" if ($resbody && $self->{debug}); |