1 | # functions to handle using the plugins
|
---|
2 |
|
---|
3 | package plugin;
|
---|
4 |
|
---|
5 | require util;
|
---|
6 |
|
---|
7 | sub load_plugins {
|
---|
8 | my ($collection, $plugin_list) = @_;
|
---|
9 | my @plugin_objects = ();
|
---|
10 |
|
---|
11 | foreach $plugin (@$plugin_list) {
|
---|
12 | # find the plugin
|
---|
13 | my $colplugname = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib/plugins",
|
---|
14 | "${plugin}.pm");
|
---|
15 | my $mainplugname = &util::filename_cat($ENV{'GSDLHOME'},"perllib/plugins",
|
---|
16 | "${plugin}.pm");
|
---|
17 | if (-e $colplugname) { require $colplugname; }
|
---|
18 | elsif (-e $mainplugname) { require $mainplugname; }
|
---|
19 | else { die "ERROR - couldn't find plugin $plugin\n"; }
|
---|
20 |
|
---|
21 | # create a plugin object
|
---|
22 | my ($plugobj);
|
---|
23 | eval ("\$plugobj = new $plugin()");
|
---|
24 | die "$@" if $@;
|
---|
25 |
|
---|
26 | # add this object to the list
|
---|
27 | push (@plugin_objects, $plugobj);
|
---|
28 | }
|
---|
29 |
|
---|
30 | return \@plugin_objects;
|
---|
31 | }
|
---|
32 |
|
---|
33 | sub read {
|
---|
34 | my ($pluginfo, $base_dir, $file, $metadata, $processor) = @_;
|
---|
35 |
|
---|
36 | # pass this file by each of the plugins in turn until one
|
---|
37 | # is found which will process it
|
---|
38 | foreach $plugobj (@$pluginfo) {
|
---|
39 | if ($plugobj->read($pluginfo, $base_dir, $file,
|
---|
40 | $metadata, $processor)) {
|
---|
41 | return;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | if ($processor->{'verbosity'} >= 2) {
|
---|
46 | print STDERR "WARNING - no plugin could process " .
|
---|
47 | &util::filename_cat($base_dir,$file) . "\n";
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | 1;
|
---|