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

Last change on this file since 835 was 835, checked in by davidb, 24 years ago

added 'begin' and 'end' function for plugins

  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 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) = @_;
32 my @plugin_objects = ();
33
34 foreach $pluginoptions (@$plugin_list) {
35 my $pluginname = shift @$pluginoptions;
36 next unless defined $pluginname;
37
38 # find the plugin
39 my $colplugname = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib/plugins",
40 "${pluginname}.pm");
41 my $mainplugname = &util::filename_cat($ENV{'GSDLHOME'},"perllib/plugins",
42 "${pluginname}.pm");
43 if (-e $colplugname) { require $colplugname; }
44 elsif (-e $mainplugname) { require $mainplugname; }
45 else { die "ERROR - couldn't find plugin \"$pluginname\"\n"; }
46
47 # create a plugin object
48 my ($plugobj);
49 map { $_ = "\"$_\""; } @$pluginoptions;
50 my $options = join (",", @$pluginoptions);
51 eval ("\$plugobj = new \$pluginname($options)");
52 die "$@" if $@;
53
54 # add this object to the list
55 push (@plugin_objects, $plugobj);
56 }
57
58 return \@plugin_objects;
59}
60
61
62sub begin {
63 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
64
65 map { $_->begin($pluginfo, $base_dir, $processor, $maxdocs); } @$pluginfo;
66}
67
68sub read {
69 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $aux) = @_;
70
71 $maxdocs = -1 unless defined $maxdocs && $maxdocs =~ /\d/;
72 my $rv = 0;
73
74 # pass this file by each of the plugins in turn until one
75 # is found which will process it
76 foreach $plugobj (@$pluginfo) {
77 $rv = $plugobj->read($pluginfo, $base_dir, $file,
78 $metadata, $processor, $maxdocs, $aux);
79 return $rv if defined $rv;
80 }
81
82 if (defined $processor->{'verbosity'} && $processor->{'verbosity'} >= 2) {
83 print STDERR "WARNING - no plugin could process " .
84 &util::filename_cat($base_dir,$file) . "\n";
85 }
86 return 0;
87}
88
89sub end {
90 my ($pluginfo) = @_;
91 map { $_->end(); } @$pluginfo;
92}
93
941;
Note: See TracBrowser for help on using the repository browser.