r575@llin: dpavlin | 2006-05-10 16:10:56 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 10 May 2006 14:08:15 +0000 (14:08 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 10 May 2006 14:08:15 +0000 (14:08 +0000)
 use Search::Estraier 0.06 new master API to create nodes, so code here is siplified

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@458 07558da8-63fa-0310-ba24-9fe276d99e06

Makefile.PL
lib/WebPAC/Output/Estraier.pm
t/7-est.t

index 1ad3880..91093d0 100644 (file)
@@ -28,6 +28,7 @@ WriteMakefile(
        'File::Path' => 0,
        'Biblio::Isis' => 0.13,
        'MARC::Fast' => 0.02,
+       'Search::Estraier' => 0.06,
     },
     dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
     clean               => { FILES => 'WebPAC-* pod2html Makefile tags' },
index ddce207..a4f1847 100644 (file)
@@ -5,7 +5,7 @@ use strict;
 
 use base qw/WebPAC::Common/;
 
-use Search::Estraier;
+use Search::Estraier 0.06;
 use Encode qw/from_to/;
 use Data::Dumper;
 use LWP;
@@ -17,11 +17,11 @@ WebPAC::Output::Estraier - Create Hyper Estraier full text index
 
 =head1 VERSION
 
-Version 0.10
+Version 0.11
 
 =cut
 
-our $VERSION = '0.10';
+our $VERSION = '0.11';
 
 =head1 SYNOPSIS
 
@@ -98,33 +98,24 @@ sub new {
        my $url = $self->{masterurl} . '/node/' . $self->{database};
        $self->{url} = $url;
 
+       $self->{db} = Search::Estraier::Node->new(
+               url => $url,
+               user => $self->{user},
+               passwd => $self->{passwd},
+               debug => $self->{debug},
+               create => 1,
+               label => "WebPAC $self->{database}",
+       );
+
+       $log->info("using index $self->{url} with encoding $self->{encoding}");
+
        if ($self->{clean}) {
-               $log->debug("nodedel $self->{database}");
-               $self->master( action => 'nodedel', name => $self->{database} );
+               $log->debug("clean $self->{database}");
+               $self->master( action => 'nodeclr', name => $self->{database} );
        } else {
                $log->debug("opening index $self->{url}");
        }
 
-       my $nodes = $self->master( action => 'nodelist' );
-
-       $log->debug("nodes found: $nodes");
-
-       if ($nodes !~ m/^$self->{database}\t/sm) {
-               my $label = $self->{label} || 'WebPAC ' . $self->{database};
-               $log->warn("creating index $url ($label)");
-               $self->master(
-                       action => 'nodeadd',
-                       name => $self->{database},
-                       label => $self->convert( $label ),
-               ) || $log->logdie("can't create Hyper Estraier node $self->{database}");
-       }
-
-       $self->{db} = Search::Estraier::Node->new( debug => $self->{debug} );
-       $self->{db}->set_url($self->{url});
-       $self->{db}->set_auth($self->{user}, $self->{passwd});
-
-       $log->info("using index $self->{url} with encoding $self->{encoding}");
-
        $self ? return $self : return undef;
 }
 
@@ -209,51 +200,6 @@ sub add {
        return 1;
 }
 
-#
-# REST parametars validation data
-#
-
-my $estraier_rest = {
-       master => {
-               userdel => [ qw/name/ ],
-               nodelist => [],
-               nodeadd => [ qw/name label/ ],
-               nodedel => [ qw/name/ ],
-       },
-       node => {
-               _set_link => [ qw/url label credit/ ],
-       },
-};
-
-=head2 master
-
-Issue administrative commands to C<estmaster> process and receive response
-as array of lines
-
-  my $nodelist = $est->master( action => 'nodelist' );
-
-=cut
-
-sub master {
-       my $self = shift;
-
-       my $args = {@_};
-       my $log = $self->_get_logger;
-
-       my $action = $args->{action} || $log->logconfess("no action specified");
-
-       $log->logdie("action '$action' isn't supported") unless ($estraier_rest->{master}->{$action});
-
-       $log->debug("master action: $action");
-
-       return $self->estcall(
-               validate => 'master',
-               rest_url => $self->{masterurl} . '/master?action=' . $action ,
-               action => $action,
-               %{ $args },
-       );
-}
-
 =head2 add_link
 
   $est->add_link(
@@ -295,106 +241,24 @@ sub add_link {
        );
 }
 
-=head2 estcall
 
-Workhourse which does actual calls to Hyper Estraier
+=head2 master
 
-  $self->estcall(
-       rest_url => '/master?action=' . $action,
-       validate => 'master',
-       # ...
-  );
+Issue administrative commands to C<estmaster> process. See documentation for
+C<master> in L<Search::Estraier>::Node.
 
-C<rest_url> is relative URL to C<estmaster> and C<validate> is entry into
-internal hash which will check if all parametars are available before
-calling function.
+  $self->master(
+       action => 'nodeclr',
+       name => 'foobar',
+  );
 
 =cut
 
-sub estcall {
+sub master {
        my $self = shift;
-       my $args = {@_};
-       my $log = $self->_get_logger;
-
-       $log->debug("estcall: ",Dumper($args));
-
-       foreach my $p (qw/rest_url validate action/) {
-               $log->die("ectcall needs $p parametar") unless ($args->{$p});
-       }
-
-       my $url = $args->{rest_url};
-       my $del = '?';
-       $del = '&' if ($url =~ m#\?#);
-
-       my $url_args;
-
-       foreach my $arg (@{ $estraier_rest->{ $args->{validate} }->{ $args->{action} } }) {
-               $log->logdie("missing parametar $arg for action $args->{action}") unless ($args->{$arg});
-               $url_args .= $del . $arg . '=' . uri_escape( $args->{$arg} );
-               $del = '&';
-       }
-
-       $url .= $url_args if ($url_args);
-
-       $log->debug("calling $url");
-
-       my $res = $self->est_ua()->get($url);
-
-       if ($res->is_success) {
-               #$log->debug( $res->content );
-               return split(/\n/, $res->content) if wantarray;
-               return $res->content || 0E0;
-       } else {
-               $log->warn("unable to call $url: " . $res->status_line);
-               return;
-       }
-
+       $self->{db}->master( @_ );
 }
 
-=head2 est_ua
-
-This is helper function to create C<LWP::UserAgent> object with Super User
-priviledges
-
-  my $ua = $self->est_ua( user => 'admin', passwd => 'admin' );
-
-=cut
-
-                                           
-
-sub est_ua {
-       my $self = shift;
-
-       return $self->{_master_ua} if ($self->{_master_ua});
-
-       {
-               package AdminUserAgent;
-               use base qw/LWP::UserAgent/;
-               sub new {
-                       my $self = LWP::UserAgent::new(@_);
-                       $self->agent("webpac/$VERSION");
-                       $self;
-               }
-               sub get_basic_credentials {
-                       my($self, $realm, $uri) = @_;
-                       return ($self->{user}, $self->{passwd});
-               }
-               sub set_basic_credentials {
-                       my ($self, $user, $passwd) = @_;
-                       $self->{user} = $user;
-                       $self->{passwd} = $passwd;
-               }
-       };
-
-       $self->{_master_ua} = AdminUserAgent->new( ) || sub {
-               my $log = $self->_get_logger;
-               $log->logdie("can't create LWP::UserAgent: $!");
-       };
-
-       $self->{_master_ua}->set_basic_credentials($self->{user}, $self->{passwd});
-
-       return $self->{_master_ua};
-}
 
 =head2 convert
 
index 7f52840..d47dd43 100755 (executable)
--- a/t/7-est.t
+++ b/t/7-est.t
@@ -2,7 +2,7 @@
 
 use strict;
 
-use Test::More tests => 12;
+use Test::More tests => 10;
 use Test::Exception;
 use Cwd qw/abs_path/;
 use File::Temp qw/tempdir/;
@@ -30,10 +30,6 @@ my $config = {
 
 ok(my $est = new WebPAC::Output::Estraier( %{ $config } ), "new WebPAC::Output::Estraier");
 
-ok(my $list = $est->master( action => 'nodelist' ), "nodelist");
-
-like($list , qr/$config->{database}/, "found $config->{database}");
-
 my $ds = {
        'Source' => {
                'name' => 'Izvor: ',