This is not the cleanest approach, but it's one (untested) way:
package main; use lib 'plugins'; main(); sub main { load_plugins(); init_plugins(); } sub load_plugins { for my $plugin (<plugins/*.pm>) { (my $package = $plugin) =~ s/\.pm//; require $plugin; } } my @plugins; sub register_plugin { my ($class, $plugin_subref) = @_ push @plugins, $plugin_subref; } sub init_plugins { $_->() for @plugins; } package ExamplePlugin; sub import { my $caller = caller(); $caller->register_plugin( \&init ); } sub init { # initialization code here } 1;
In reply to Re: Same function multiples unknown modules
by chromatic
in thread Same function multiples unknown modules
by Delusional
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |