source: trunk/gsdl/perllib/plugin.pm@ 2576

Last change on this file since 2576 was 1587, checked in by nzdl, 24 years ago

* empty log message *

  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
RevLine 
[537]1###########################################################################
2#
3# plugin.pm -- functions to handle using plugins
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
[4]25
26package plugin;
27
[134]28require util;
[4]29
30sub load_plugins {
[1431]31 my ($plugin_list) = shift @_;
32 ($verbosity, $outhandle) = @_; # globals
[4]33 my @plugin_objects = ();
34
[1243]35 $verbosity = 2 unless defined $verbosity;
[1431]36 $outhandle = STDERR unless defined $outhandle;
[1243]37
[809]38 foreach $pluginoptions (@$plugin_list) {
39 my $pluginname = shift @$pluginoptions;
40 next unless defined $pluginname;
41
[4]42 # find the plugin
[134]43 my $colplugname = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib/plugins",
[809]44 "${pluginname}.pm");
[134]45 my $mainplugname = &util::filename_cat($ENV{'GSDLHOME'},"perllib/plugins",
[809]46 "${pluginname}.pm");
[134]47 if (-e $colplugname) { require $colplugname; }
48 elsif (-e $mainplugname) { require $mainplugname; }
[809]49 else { die "ERROR - couldn't find plugin \"$pluginname\"\n"; }
[4]50
51 # create a plugin object
52 my ($plugobj);
[809]53 map { $_ = "\"$_\""; } @$pluginoptions;
54 my $options = join (",", @$pluginoptions);
[1244]55 $options =~ s/\$/\\\$/g;
[809]56 eval ("\$plugobj = new \$pluginname($options)");
[4]57 die "$@" if $@;
[809]58
[1243]59 # initialize plugin
[1424]60 $plugobj->init($verbosity, $outhandle);
[1243]61
[4]62 # add this object to the list
63 push (@plugin_objects, $plugobj);
64 }
65
66 return \@plugin_objects;
67}
68
[835]69
70sub begin {
71 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
72
73 map { $_->begin($pluginfo, $base_dir, $processor, $maxdocs); } @$pluginfo;
74}
75
[4]76sub read {
[809]77 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $aux) = @_;
[4]78
[809]79 $maxdocs = -1 unless defined $maxdocs && $maxdocs =~ /\d/;
[315]80 my $rv = 0;
81
[1454]82 # the .kill file is a handy (if not very elegant) way of aborting
83 # an import.pl or buildcol.pl process
84 if (-e &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, ".kill")) {
85 print $outhandle "Process killed by .kill file\n";
86 die "\n";
87 }
88
[4]89 # pass this file by each of the plugins in turn until one
90 # is found which will process it
91 foreach $plugobj (@$pluginfo) {
[315]92 $rv = $plugobj->read($pluginfo, $base_dir, $file,
[809]93 $metadata, $processor, $maxdocs, $aux);
[315]94 return $rv if defined $rv;
[4]95 }
[315]96
[1431]97 if ($verbosity >= 2) {
98 print $outhandle "WARNING - no plugin could process " .
[170]99 &util::filename_cat($base_dir,$file) . "\n";
100 }
[315]101 return 0;
[4]102}
103
[835]104sub end {
[1587]105 my ($pluginfo, $processor) = @_;
106 map { $_->end($processor); } @$pluginfo;
[835]107}
[4]108
1091;
Note: See TracBrowser for help on using the repository browser.