in reply to Similar plugins run serially
Warning!! What follows is just my curiosity in trying to solve the problem. It works as far as I have tested it, and that is exactly as far as you can see from the simple code that follows. Critisisms invited.
Using this main program
#! perl -sw use vars qw/@scanners/; use strict; use constant PLUGINS => 'c:/test/plugins/*'; BEGIN { @scanners = glob PLUGINS; for(@scanners) { require $_; warn $@ if $@; my ($module) = m!.*/([^\.]+)\Q.pm\E$!; $_ = eval{ "$module"->new() }; warn "Attempt to load: $module failed\n" if ( !$_ or $@ ); } @scanners = grep{ $_ } @scanners; } # call the 'scan' routine in each module, and # print out the results from the array reference returned. print @{&{$_}}, $/ for @scanners;
And these two modules
package method1; sub new{ my $class = shift; return bless \&scan, $class; } sub scan{ my @results = qw/foo bar baz/; #!do scan; return \@results; } 1;
method2.pm
package method2; sub new{ my $class = shift; return bless \&scan, $class; } sub scan{ my @results = qw/the quick brown fox/; #!do scan; return \@results; } 1;
I get these results.
C:\test>209857 foobarbaz thequickbrownfox C:\test>
which seems to indicate that the method works. However, whilst I cannot see anything wrong with the mechanism, it's the first time I tried anything like this so I am fully expecting to be told either that there is a much simpler way of doing this, or that there is something fundementally unsound in what I have done.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Similar plugins run serially
by Aristotle (Chancellor) on Nov 02, 2002 at 07:33 UTC |