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