aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-09-21 21:50:50 +1200
committerDavid Phillips <david@sighup.nz>2018-09-21 21:50:50 +1200
commit47b4448199799aca7c0fb3e0090e244112c8959c (patch)
treeb79469ab87678500fe17af796a144042d2edcfa0
parentb65441dbdb62e575fbb69580342e50079c871d18 (diff)
downloadidalius-47b4448199799aca7c0fb3e0090e244112c8959c.tar.xz
Move module configuration to callback
This lets modules loaded dynamically (i.e. those not specified in configuation used at the start of execution) get configured correctly to e.g. record a reference to their configuration and register commands.
-rw-r--r--Plugin.pm7
-rwxr-xr-xidalius.pl17
2 files changed, 18 insertions, 6 deletions
diff --git a/Plugin.pm b/Plugin.pm
index 4aba6d2..1f3d080 100644
--- a/Plugin.pm
+++ b/Plugin.pm
@@ -3,7 +3,11 @@ package Plugin;
use strict;
use warnings;
-my $unload_callback;
+my $load_callback;
+
+sub set_load_callback {
+ ($load_callback) = @_;
+};
sub load_plugin {
my ($logger, $config, $module) = @_;
@@ -19,6 +23,7 @@ sub load_plugin {
$logger->($@);
return "Cannot load $module: $!";
};
+ $load_callback->($module);
return undef;
}
diff --git a/idalius.pl b/idalius.pl
index 627d91f..d6b0c06 100755
--- a/idalius.pl
+++ b/idalius.pl
@@ -23,14 +23,11 @@ sub log_info {
print "$stamp | @_\n";
}
+Plugin::set_load_callback(\&module_loaded_callback);
+
eval {
for my $module (@{$config->{_}->{plugins}}) {
Plugin::load_plugin(\&log_info, $config->{_}, $module);
- $module->configure(
- \&register_command,
- \&run_command,
- $config->{$module},
- $config->{_});
}
1;
} or do {
@@ -85,6 +82,16 @@ drop_priv();
$poe_kernel->run();
+sub module_loaded_callback {
+ my ($module) = @_;
+
+ $module->configure(
+ \&register_command,
+ \&run_command,
+ $config->{$module},
+ $config->{_});
+}
+
sub module_is_enabled {
my $module = $_[0];