4 |
use strict; |
use strict; |
5 |
use warnings; |
use warnings; |
6 |
|
|
7 |
our $VERSION = '0.06_1'; |
our $VERSION = '0.08'; |
8 |
|
|
9 |
=head1 NAME |
=head1 NAME |
10 |
|
|
20 |
my $node = new Search::Estraier::Node( |
my $node = new Search::Estraier::Node( |
21 |
url => 'http://localhost:1978/node/test', |
url => 'http://localhost:1978/node/test', |
22 |
user => 'admin', |
user => 'admin', |
23 |
passwd => 'admin' |
passwd => 'admin', |
24 |
|
create => 1, |
25 |
|
label => 'Label for node', |
26 |
|
croak_on_error => 1, |
27 |
); |
); |
28 |
|
|
29 |
# create document |
# create document |
877 |
url => 'http://localhost:1978/node/test', |
url => 'http://localhost:1978/node/test', |
878 |
user => 'admin', |
user => 'admin', |
879 |
passwd => 'admin' |
passwd => 'admin' |
880 |
|
create => 1, |
881 |
|
label => 'optional node label', |
882 |
debug => 1, |
debug => 1, |
883 |
croak_on_error => 1 |
croak_on_error => 1 |
884 |
); |
); |
899 |
|
|
900 |
password for authentication |
password for authentication |
901 |
|
|
902 |
|
=item create |
903 |
|
|
904 |
|
create node if it doesn't exists |
905 |
|
|
906 |
|
=item label |
907 |
|
|
908 |
|
optional label for new node if C<create> is used |
909 |
|
|
910 |
=item debug |
=item debug |
911 |
|
|
912 |
dumps a B<lot> of debugging output |
dumps a B<lot> of debugging output |
950 |
size => -1.0, |
size => -1.0, |
951 |
}; |
}; |
952 |
|
|
953 |
|
if ($self->{create}) { |
954 |
|
if (! eval { $self->name } || $@) { |
955 |
|
my $name = $1 if ($self->{url} =~ m#/node/([^/]+)/*#); |
956 |
|
croak "can't find node name in '$self->{url}'" unless ($name); |
957 |
|
my $label = $self->{label} || $name; |
958 |
|
$self->master( |
959 |
|
action => 'nodeadd', |
960 |
|
name => $name, |
961 |
|
label => $label, |
962 |
|
) || croak "can't create node $name ($label)"; |
963 |
|
} |
964 |
|
} |
965 |
|
|
966 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
967 |
} |
} |
968 |
|
|
1053 |
|
|
1054 |
$node->put_doc( $document_draft ) or die "can't add document"; |
$node->put_doc( $document_draft ) or die "can't add document"; |
1055 |
|
|
1056 |
Return true on success or false on failture. |
Return true on success or false on failure. |
1057 |
|
|
1058 |
=cut |
=cut |
1059 |
|
|
1061 |
my $self = shift; |
my $self = shift; |
1062 |
my $doc = shift || return; |
my $doc = shift || return; |
1063 |
return unless ($self->{url} && $doc->isa('Search::Estraier::Document')); |
return unless ($self->{url} && $doc->isa('Search::Estraier::Document')); |
1064 |
$self->shuttle_url( $self->{url} . '/put_doc', |
if ($self->shuttle_url( $self->{url} . '/put_doc', |
1065 |
'text/x-estraier-draft', |
'text/x-estraier-draft', |
1066 |
$doc->dump_draft, |
$doc->dump_draft, |
1067 |
undef |
undef |
1068 |
) == 200; |
) == 200) { |
1069 |
|
$self->_clear_info; |
1070 |
|
return 1; |
1071 |
|
} |
1072 |
|
return undef; |
1073 |
} |
} |
1074 |
|
|
1075 |
|
|
1088 |
my $id = shift || return; |
my $id = shift || return; |
1089 |
return unless ($self->{url}); |
return unless ($self->{url}); |
1090 |
croak "id must be number, not '$id'" unless ($id =~ m/^\d+$/); |
croak "id must be number, not '$id'" unless ($id =~ m/^\d+$/); |
1091 |
$self->shuttle_url( $self->{url} . '/out_doc', |
if ($self->shuttle_url( $self->{url} . '/out_doc', |
1092 |
'application/x-www-form-urlencoded', |
'application/x-www-form-urlencoded', |
1093 |
"id=$id", |
"id=$id", |
1094 |
undef |
undef |
1095 |
) == 200; |
) == 200) { |
1096 |
|
$self->_clear_info; |
1097 |
|
return 1; |
1098 |
|
} |
1099 |
|
return undef; |
1100 |
} |
} |
1101 |
|
|
1102 |
|
|
1114 |
my $self = shift; |
my $self = shift; |
1115 |
my $uri = shift || return; |
my $uri = shift || return; |
1116 |
return unless ($self->{url}); |
return unless ($self->{url}); |
1117 |
$self->shuttle_url( $self->{url} . '/out_doc', |
if ($self->shuttle_url( $self->{url} . '/out_doc', |
1118 |
'application/x-www-form-urlencoded', |
'application/x-www-form-urlencoded', |
1119 |
"uri=" . uri_escape($uri), |
"uri=" . uri_escape($uri), |
1120 |
undef |
undef |
1121 |
) == 200; |
) == 200) { |
1122 |
|
$self->_clear_info; |
1123 |
|
return 1; |
1124 |
|
} |
1125 |
|
return undef; |
1126 |
} |
} |
1127 |
|
|
1128 |
|
|
1140 |
my $self = shift; |
my $self = shift; |
1141 |
my $doc = shift || return; |
my $doc = shift || return; |
1142 |
return unless ($self->{url} && $doc->isa('Search::Estraier::Document')); |
return unless ($self->{url} && $doc->isa('Search::Estraier::Document')); |
1143 |
$self->shuttle_url( $self->{url} . '/edit_doc', |
if ($self->shuttle_url( $self->{url} . '/edit_doc', |
1144 |
'text/x-estraier-draft', |
'text/x-estraier-draft', |
1145 |
$doc->dump_draft, |
$doc->dump_draft, |
1146 |
undef |
undef |
1147 |
) == 200; |
) == 200) { |
1148 |
|
$self->_clear_info; |
1149 |
|
return 1; |
1150 |
|
} |
1151 |
|
return undef; |
1152 |
} |
} |
1153 |
|
|
1154 |
|
|
1515 |
push @args, 'wwidth=' . $self->{wwidth}; |
push @args, 'wwidth=' . $self->{wwidth}; |
1516 |
push @args, 'hwidth=' . $self->{hwidth}; |
push @args, 'hwidth=' . $self->{hwidth}; |
1517 |
push @args, 'awidth=' . $self->{awidth}; |
push @args, 'awidth=' . $self->{awidth}; |
1518 |
push @args, 'skip=' . $self->{skip} if ($self->{skip}); |
push @args, 'skip=' . $cond->{skip} if ($cond->{skip}); |
1519 |
|
|
1520 |
return join('&', @args); |
return join('&', @args); |
1521 |
} |
} |
1662 |
croak "mode must be number, not '$mode'" unless ($mode =~ m/^\d+$/); |
croak "mode must be number, not '$mode'" unless ($mode =~ m/^\d+$/); |
1663 |
|
|
1664 |
$self->shuttle_url( $self->{url} . '/_set_user', |
$self->shuttle_url( $self->{url} . '/_set_user', |
1665 |
'text/plain', |
'application/x-www-form-urlencoded', |
1666 |
'name=' . uri_escape($name) . '&mode=' . $mode, |
'name=' . uri_escape($name) . '&mode=' . $mode, |
1667 |
undef |
undef |
1668 |
) == 200; |
) == 200; |
1695 |
undef |
undef |
1696 |
) == 200) { |
) == 200) { |
1697 |
# refresh node info after adding link |
# refresh node info after adding link |
1698 |
$self->_set_info; |
$self->_clear_info; |
1699 |
return 1; |
return 1; |
1700 |
} |
} |
1701 |
|
return undef; |
1702 |
} |
} |
1703 |
|
|
1704 |
=head2 admins |
=head2 admins |
1845 |
) or confess "shuttle_url failed"; |
) or confess "shuttle_url failed"; |
1846 |
|
|
1847 |
if ($status == $rest->{status}) { |
if ($status == $rest->{status}) { |
1848 |
|
|
1849 |
|
# refresh node info after sync |
1850 |
|
$self->_clear_info if ($action eq 'sync' || $action =~ m/^node(?:add|del|clr)$/); |
1851 |
|
|
1852 |
if ($rest->{returns} && wantarray) { |
if ($rest->{returns} && wantarray) { |
1853 |
|
|
1854 |
my @results; |
my @results; |
1906 |
|
|
1907 |
my @lines = split(/[\r\n]/,$resbody); |
my @lines = split(/[\r\n]/,$resbody); |
1908 |
|
|
1909 |
$self->{inform} = {}; |
$self->_clear_info; |
1910 |
|
|
1911 |
( $self->{inform}->{name}, $self->{inform}->{label}, $self->{inform}->{dnum}, |
( $self->{inform}->{name}, $self->{inform}->{label}, $self->{inform}->{dnum}, |
1912 |
$self->{inform}->{wnum}, $self->{inform}->{size} ) = split(/\t/, shift @lines, 5); |
$self->{inform}->{wnum}, $self->{inform}->{size} ) = split(/\t/, shift @lines, 5); |
1931 |
|
|
1932 |
} |
} |
1933 |
|
|
1934 |
|
=head2 _clear_info |
1935 |
|
|
1936 |
|
Clear information for node |
1937 |
|
|
1938 |
|
$node->_clear_info; |
1939 |
|
|
1940 |
|
On next call to C<name>, C<label>, C<doc_num>, C<word_num> or C<size> node |
1941 |
|
info will be fetch again from Hyper Estraier. |
1942 |
|
|
1943 |
|
=cut |
1944 |
|
sub _clear_info { |
1945 |
|
my $self = shift; |
1946 |
|
$self->{inform} = { |
1947 |
|
dnum => -1, |
1948 |
|
wnum => -1, |
1949 |
|
size => -1.0, |
1950 |
|
}; |
1951 |
|
} |
1952 |
|
|
1953 |
### |
### |
1954 |
|
|
1955 |
=head1 EXPORT |
=head1 EXPORT |