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

Last change on this file since 2018 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
Line 
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###########################################################################
25
26package plugin;
27
28require util;
29
30sub load_plugins {
31 my ($plugin_list) = shift @_;
32 ($verbosity, $outhandle) = @_; # globals
33 my @plugin_objects = ();
34
35 $verbosity = 2 unless defined $verbosity;
36 $outhandle = STDERR unless defined $outhandle;
37
38 foreach $pluginoptions (@$plugin_list) {
39 my $pluginname = shift @$pluginoptions;
40 next unless defined $pluginname;
41
42 # find the plugin
43 my $colplugname = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib/plugins",
44 "${pluginname}.pm");
45 my $mainplugname = &util::filename_cat($ENV{'GSDLHOME'},"perllib/plugins",
46 "${pluginname}.pm");
47 if (-e $colplugname) { require $colplugname; }
48 elsif (-e $mainplugname) { require $mainplugname; }
49 else { die "ERROR - couldn't find plugin \"$pluginname\"\n"; }
50
51 # create a plugin object
52 my ($plugobj);
53 map { $_ = "\"$_\""; } @$pluginoptions;
54 my $options = join (",", @$pluginoptions);
55 $options =~ s/\$/\\\$/g;
56 eval ("\$plugobj = new \$pluginname($options)");
57 die "$@" if $@;
58
59 # initialize plugin
60 $plugobj->init($verbosity, $outhandle);
61
62 # add this object to the list
63 push (@plugin_objects, $plugobj);
64 }
65
66 return \@plugin_objects;
67}
68
69
70sub begin {
71 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
72
73 map { $_->begin($pluginfo, $base_dir, $processor, $maxdocs); } @$pluginfo;
74}
75
76sub read {
77 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $aux) = @_;
78
79 $maxdocs = -1 unless defined $maxdocs && $maxdocs =~ /\d/;
80 my $rv = 0;
81
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
89 # pass this file by each of the plugins in turn until one
90 # is found which will process it
91 foreach $plugobj (@$pluginfo) {
92 $rv = $plugobj->read($pluginfo, $base_dir, $file,
93 $metadata, $processor, $maxdocs, $aux);
94 return $rv if defined $rv;
95 }
96
97 if ($verbosity >= 2) {
98 print $outhandle "WARNING - no plugin could process " .
99 &util::filename_cat($base_dir,$file) . "\n";
100 }
101 return 0;
102}
103
104sub end {
105 my ($pluginfo, $processor) = @_;
106 map { $_->end($processor); } @$pluginfo;
107}
108
1091;
Note: See TracBrowser for help on using the repository browser.