/[webpac2]/trunk/lib/WebPAC/Output/Estraier.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Output/Estraier.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 209 by dpavlin, Wed Nov 23 00:14:05 2005 UTC revision 210 by dpavlin, Mon Dec 5 17:47:04 2005 UTC
# Line 8  use base qw/WebPAC::Common/; Line 8  use base qw/WebPAC::Common/;
8  use HyperEstraier;  use HyperEstraier;
9  use Text::Iconv;  use Text::Iconv;
10  use Data::Dumper;  use Data::Dumper;
11    use LWP::Simple;
12    use URI::Escape;
13    
14  =head1 NAME  =head1 NAME
15    
# Line 15  WebPAC::Output::Estraier - Create Hyper Line 17  WebPAC::Output::Estraier - Create Hyper
17    
18  =head1 VERSION  =head1 VERSION
19    
20  Version 0.01  Version 0.02
21    
22  =cut  =cut
23    
24  our $VERSION = '0.01';  our $VERSION = '0.02';
25    
26  =head1 SYNOPSIS  =head1 SYNOPSIS
27    
# Line 33  type C<search>. Line 35  type C<search>.
35  Connect to Hyper Estraier index using HTTP  Connect to Hyper Estraier index using HTTP
36    
37   my $est = new WebPAC::Output::Estraier(   my $est = new WebPAC::Output::Estraier(
38          url => 'http://localhost:1978/node/webpac2',          masterurl => 'http://localhost:1978/',
39          user => 'admin',          user => 'admin',
40          passwd => 'admin',          passwd => 'admin',
41          database => 'demo',          database => 'demo',
# Line 44  Options are: Line 46  Options are:
46    
47  =over 4  =over 4
48    
49  =item url  =item masterurl
50    
51  URI to C<estmaster> node  URI to C<estmaster> node
52    
# Line 79  sub new { Line 81  sub new {
81    
82          my $log = $self->_get_logger;          my $log = $self->_get_logger;
83    
84          foreach my $p (qw/url user passwd/) {          $log->debug("self: ", sub { Dumper($self) });
85    
86            foreach my $p (qw/masterurl user passwd database/) {
87                  $log->logdie("need $p") unless ($self->{$p});                  $log->logdie("need $p") unless ($self->{$p});
88          }          }
89    
90          $log->info("opening Hyper Estraier index $self->{'url'}");          my $url = $self->{masterurl} . '/node/' . $self->{database};
91            $url =~ s#//#/#g;
92            $self->{url} = $url;
93    
94            $log->info("opening Hyper Estraier index $self->{url}");
95    
96            my @nodes = $self->est_master( action => 'nodelist' );
97    
98            if (! grep(/$self->{database}/, @nodes)) {
99                    $log->info("creating index $url");
100                    $self->est_master(
101                            action => 'nodeadd',
102                            name => $self->{database},
103                            label => "WebPAC $self->{database}",
104                    ) || $log->logdie("can't create Hyper Estraier node $self->{database}");
105            }
106    
107          $self->{'db'} = HyperEstraier::Node->new($self->{'url'});          $self->{'db'} = HyperEstraier::Node->new($self->{url});
108          $self->{'db'}->set_auth($self->{'user'}, $self->{'passwd'});          $self->{'db'}->set_auth($self->{'user'}, $self->{passwd});
109    
110          my $encoding = $self->{'encoding'} || 'ISO-8859-2';          my $encoding = $self->{'encoding'} || 'ISO-8859-2';
111          $log->info("using encoding $encoding");          $log->info("using encoding $encoding");
# Line 179  sub add { Line 198  sub add {
198          return 1;          return 1;
199  }  }
200    
201    =head2 est_master
202    
203    Issue administrative commands to C<estmaster> process and receive response
204    as array of lines
205    
206      my $nodelist = $self->est_master( action => nodelist );
207    
208    =cut
209    
210    my $estmaster_actions = {
211            userdel => [ qw/name/ ],
212            nodelist => [],
213            nodeadd => [ qw/name label/ ],
214            nodedel => [ qw/name/ ],
215    };
216    
217    sub est_master {
218            my $self = shift;
219            my $args = {@_};
220            my $log = $self->_get_logger;
221    
222            $log->debug(Dumper($args));
223    
224            my $action = $args->{action} || $log->logconfess("no action specified");
225    
226            $log->logdie("action '$action' isn't supported") unless ($estmaster_actions->{$action});
227    
228            my $url = $self->{masterurl} . '/master?action=' . $action;
229    
230            foreach my $arg (@{ $estmaster_actions->{$action} }) {
231                    $log->logdie("missing parametar $arg for action $action") unless ($args->{$arg});
232                    $url .= '&' . $arg . '=' . uri_escape( $args->{$arg} );
233            }
234    
235            $log->debug("calling $url");
236    
237            my $tsv = get($url);
238    
239            if (! $tsv) {
240                    $log->warn("unable to call $url");
241                    return;
242            }
243    
244            return split(/\n/, $tsv);
245    }
246    
247  =head1 AUTHOR  =head1 AUTHOR
248    
249  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>

Legend:
Removed from v.209  
changed lines
  Added in v.210

  ViewVC Help
Powered by ViewVC 1.1.26