diff options
Diffstat (limited to 'Plugin.pm')
-rw-r--r-- | Plugin.pm | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Plugin.pm b/Plugin.pm new file mode 100644 index 0000000..4aba6d2 --- /dev/null +++ b/Plugin.pm @@ -0,0 +1,34 @@ +package Plugin; + +use strict; +use warnings; + +my $unload_callback; + +sub load_plugin { + my ($logger, $config, $module) = @_; + (my $path = $module) =~ s,::,/,g; + + return "$module is already loaded, no changes made" if grep {$_ eq $module} @{$config->{active_plugins}}; + + eval { + require $path . ".pm"; + push @{$config->{active_plugins}}, $module; + } or do { + chomp $@; + $logger->($@); + return "Cannot load $module: $!"; + }; + return undef; +} + +sub unload_plugin { + my ($logger, $config, $module) = @_; + + return "$module is not loaded, no changes made" unless grep {$_ eq $module} @{$config->{active_plugins}}; + + my @new_plugins = grep {$_ ne $module} @{$config->{active_plugins}}; + $config->{active_plugins} = \@new_plugins; + return undef; +} +1; |