4 |
use strict; |
use strict; |
5 |
use warnings; |
use warnings; |
6 |
|
|
7 |
our $VERSION = '0.06_1'; |
our $VERSION = '0.06'; |
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 |
|
|
1751 |
}, |
}, |
1752 |
userlist => { |
userlist => { |
1753 |
status => 200, |
status => 200, |
1754 |
returns => qw/name passwd flags fname misc/, |
returns => [ qw/name passwd flags fname misc/ ], |
1755 |
}, |
}, |
1756 |
useradd => { |
useradd => { |
1757 |
required => qw/name passwd flags/, |
required => [ qw/name passwd flags/ ], |
1758 |
optional => qw/fname misc/, |
optional => [ qw/fname misc/ ], |
1759 |
status => 200, |
status => 200, |
1760 |
}, |
}, |
1761 |
userdel => { |
userdel => { |
1762 |
required => qw/name/, |
required => [ qw/name/ ], |
1763 |
status => 200, |
status => 200, |
1764 |
}, |
}, |
1765 |
nodelist => { |
nodelist => { |
1766 |
status => 200, |
status => 200, |
1767 |
returns => qw/name label doc_num word_num size/, |
returns => [ qw/name label doc_num word_num size/ ], |
1768 |
}, |
}, |
1769 |
nodeadd => { |
nodeadd => { |
1770 |
required => qw/name/, |
required => [ qw/name/ ], |
1771 |
optional => qw/label/, |
optional => [ qw/label/ ], |
1772 |
status => 200, |
status => 200, |
1773 |
}, |
}, |
1774 |
nodedel => { |
nodedel => { |
1775 |
required => qw/name/, |
required => [ qw/name/ ], |
1776 |
status => 200, |
status => 200, |
1777 |
}, |
}, |
1778 |
nodeclr => { |
nodeclr => { |
1779 |
required => qw/name/, |
required => [ qw/name/ ], |
1780 |
status => 200, |
status => 200, |
1781 |
}, |
}, |
1782 |
nodertt => { |
nodertt => { |
1807 |
map { |
map { |
1808 |
croak "need parametar '$_' for action '$action'" unless ($args->{$_}); |
croak "need parametar '$_' for action '$action'" unless ($args->{$_}); |
1809 |
push @args, $_ . '=' . uri_escape( $args->{$_} ); |
push @args, $_ . '=' . uri_escape( $args->{$_} ); |
1810 |
} ( keys %{ $rest->{required} } ); |
} ( @{ $rest->{required} } ); |
1811 |
|
|
1812 |
map { |
map { |
1813 |
push @args, $_ . '=' . uri_escape( $args->{$_} ) if ($args->{$_}); |
push @args, $_ . '=' . uri_escape( $args->{$_} ) if ($args->{$_}); |
1814 |
} ( keys %{ $rest->{optional} } ); |
} ( @{ $rest->{optional} } ); |
1815 |
|
|
1816 |
} |
} |
1817 |
|
|
1819 |
|
|
1820 |
my $resbody; |
my $resbody; |
1821 |
|
|
1822 |
if ($self->shuttle_url( |
my $status = $self->shuttle_url( |
1823 |
'http://' . $uri->host_port . '/master?action=' . $action , |
'http://' . $uri->host_port . '/master?action=' . $action , |
1824 |
'application/x-www-form-urlencoded', |
'application/x-www-form-urlencoded', |
1825 |
join('&', @args), |
join('&', @args), |
1826 |
\$resbody, |
\$resbody, |
1827 |
1, |
1, |
1828 |
) == $rest->{status}) { |
) or confess "shuttle_url failed"; |
|
return 0E0 unless ($rest->{returns}); |
|
1829 |
|
|
1830 |
if (wantarray) { |
if ($status == $rest->{status}) { |
1831 |
|
if ($rest->{returns} && wantarray) { |
1832 |
|
|
1833 |
my @results; |
my @results; |
1834 |
|
my $fields = $#{$rest->{returns}}; |
1835 |
|
|
1836 |
foreach my $line ( split(/[\r\n]/,$resbody) ) { |
foreach my $line ( split(/[\r\n]/,$resbody) ) { |
1837 |
my @e = split(/\t/, $line); |
my @e = split(/\t/, $line, $fields + 1); |
1838 |
my $row; |
my $row; |
1839 |
map { $row->{$_} = shift @e; } @{ $rest->{returns} }; |
foreach my $i ( 0 .. $fields) { |
1840 |
|
$row->{ $rest->{returns}->[$i] } = $e[ $i ]; |
1841 |
|
} |
1842 |
push @results, $row; |
push @results, $row; |
1843 |
} |
} |
1844 |
|
|
1845 |
return @results; |
return @results; |
|
} else { |
|
1846 |
|
|
1847 |
carp "calling master action '$action', but not expecting array back, returning whole body"; |
} elsif ($resbody) { |
1848 |
|
chomp $resbody; |
1849 |
return $resbody; |
return $resbody; |
1850 |
|
} else { |
1851 |
|
return 0E0; |
1852 |
} |
} |
1853 |
} |
} |
1854 |
|
|
1855 |
|
carp "expected status $rest->{status}, but got $status"; |
1856 |
|
return undef; |
1857 |
} |
} |
1858 |
|
|
1859 |
=head1 PRIVATE METHODS |
=head1 PRIVATE METHODS |