source: main/tags/2.00/gsdl/perllib/plugin.pm@ 27368

Last change on this file since 27368 was 537, checked in by sjboddie, 25 years ago

added GPL headers

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