3
0
mirror of https://github.com/pragma-/pbot.git synced 2025-01-25 19:44:26 +01:00

Rename Pluggable to Plugins

This commit is contained in:
Pragmatic Software 2015-09-06 22:52:39 -07:00
parent 729728a458
commit adfdccfd27
6 changed files with 36 additions and 36 deletions

View File

@ -48,7 +48,7 @@ use PBot::BlackList;
use PBot::Quotegrabs; use PBot::Quotegrabs;
use PBot::Timer; use PBot::Timer;
use PBot::Refresher; use PBot::Refresher;
use PBot::Pluggable; use PBot::Plugins;
sub new { sub new {
if(ref($_[1]) eq 'HASH') { if(ref($_[1]) eq 'HASH') {
@ -141,7 +141,7 @@ sub initialize {
%conf %conf
); );
$self->{pluggable} = PBot::Pluggable->new(pbot => $self, %conf); $self->{plugins} = PBot::Plugins->new(pbot => $self, %conf);
# load registry entries from file to overwrite defaults # load registry entries from file to overwrite defaults
$self->{registry}->load; $self->{registry}->load;

View File

@ -1,9 +1,9 @@
# File: Pluggable.pm # File: Plugins.pm
# Author: pragma- # Author: pragma-
# #
# Purpose: Loads and manages pluggable modules. # Purpose: Loads and manages plugins.
package PBot::Pluggable; package PBot::Plugins;
use warnings; use warnings;
use strict; use strict;
@ -28,7 +28,7 @@ sub initialize {
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__); $self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{modules} = {}; $self->{plugins} = {};
$self->{pbot}->{commands}->register(sub { $self->load_cmd(@_) }, "plug", 90); $self->{pbot}->{commands}->register(sub { $self->load_cmd(@_) }, "plug", 90);
$self->{pbot}->{commands}->register(sub { $self->unload_cmd(@_) }, "unplug", 90); $self->{pbot}->{commands}->register(sub { $self->unload_cmd(@_) }, "unplug", 90);
@ -40,52 +40,52 @@ sub initialize {
sub autoload { sub autoload {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot}->{logger}->log("Loading pluggable modules ...\n"); $self->{pbot}->{logger}->log("Loading plugins ...\n");
my $module_count = 0; my $plugin_count = 0;
my @modules = glob 'PBot/Pluggable/*.pm'; my @plugins = glob 'PBot/Plugins/*.pm';
foreach my $module (sort @modules) { foreach my $plugin (sort @plugins) {
$module = basename $module; $plugin = basename $plugin;
$module =~ s/.pm$//; $plugin =~ s/.pm$//;
# do not load modules that begin with an underscore # do not load plugins that begin with an underscore
next if $module =~ m/^_/; next if $plugin =~ m/^_/;
$module_count++ if $self->load($module, %conf) $plugin_count++ if $self->load($plugin, %conf)
} }
$self->{pbot}->{logger}->log("$module_count module" . ($module_count == 1 ? '' : 's') . " loaded.\n"); $self->{pbot}->{logger}->log("$plugin_count plugin" . ($plugin_count == 1 ? '' : 's') . " loaded.\n");
} }
sub load { sub load {
my ($self, $module, %conf) = @_; my ($self, $plugin, %conf) = @_;
$self->unload($module); $self->unload($plugin);
my $class = "PBot::Pluggable::$module"; my $class = "PBot::Plugins::$plugin";
$self->{pbot}->{refresher}->{refresher}->refresh_module("PBot/Pluggable/$module.pm"); $self->{pbot}->{refresher}->{refresher}->refresh_module("PBot/Plugins/$plugin.pm");
my $ret = eval { my $ret = eval {
eval "require $class"; eval "require $class";
if ($@) { if ($@) {
chomp $@; chomp $@;
$self->{pbot}->{logger}->log("Error loading $module: $@\n"); $self->{pbot}->{logger}->log("Error loading $plugin: $@\n");
return 0; return 0;
} }
$self->{pbot}->{logger}->log("Loading $module\n"); $self->{pbot}->{logger}->log("Loading $plugin\n");
my $mod = $class->new(pbot => $self->{pbot}, %conf); my $mod = $class->new(pbot => $self->{pbot}, %conf);
$self->{modules}->{$module} = $mod; $self->{plugins}->{$plugin} = $mod;
$self->{pbot}->{refresher}->{refresher}->update_cache("PBot/Pluggable/$module.pm"); $self->{pbot}->{refresher}->{refresher}->update_cache("PBot/Plugins/$plugin.pm");
return 1; return 1;
}; };
if ($@) { if ($@) {
chomp $@; chomp $@;
$self->{pbot}->{logger}->log("Error loading $module: $@\n"); $self->{pbot}->{logger}->log("Error loading $plugin: $@\n");
return 0; return 0;
} }
@ -93,21 +93,21 @@ sub load {
} }
sub unload { sub unload {
my ($self, $module) = @_; my ($self, $plugin) = @_;
$self->{pbot}->{refresher}->{refresher}->unload_module("PBot::Pluggable::$module"); $self->{pbot}->{refresher}->{refresher}->unload_module("PBot::Plugins::$plugin");
$self->{pbot}->{refresher}->{refresher}->unload_subs("PBot/Pluggable/$module.pm"); $self->{pbot}->{refresher}->{refresher}->unload_subs("PBot/Plugins/$plugin.pm");
if (exists $self->{modules}->{$module}) { if (exists $self->{plugins}->{$plugin}) {
eval { eval {
$self->{modules}->{$module}->unload; $self->{plugins}->{$plugin}->unload;
delete $self->{modules}->{$module}; delete $self->{plugins}->{$plugin};
}; };
if ($@) { if ($@) {
chomp $@; chomp $@;
$self->{pbot}->{logger}->log("Warning: got error unloading module $module: $@\n"); $self->{pbot}->{logger}->log("Warning: got error unloading plugin $plugin: $@\n");
} }
$self->{pbot}->{logger}->log("Pluggable module $module unloaded.\n"); $self->{pbot}->{logger}->log("Plugin $plugin unloaded.\n");
return 1; return 1;
} else { } else {
return 0; return 0;
@ -149,7 +149,7 @@ sub list_cmd {
my $count = 0; my $count = 0;
my $comma = ''; my $comma = '';
foreach my $plugin (sort keys $self->{modules}) { foreach my $plugin (sort keys $self->{plugins}) {
$result .= $comma . $plugin; $result .= $comma . $plugin;
$count++; $count++;
$comma = ', '; $comma = ', ';

View File

@ -3,7 +3,7 @@
# #
# Purpose: Kicks people that visibly auto-away with ACTIONs or nick-changes # Purpose: Kicks people that visibly auto-away with ACTIONs or nick-changes
package PBot::Pluggable::AntiAway; package PBot::Plugins::AntiAway;
use warnings; use warnings;
use strict; use strict;

View File

@ -3,7 +3,7 @@
# #
# Purpose: Temporarily bans people who immediately auto-rejoin after a kick. # Purpose: Temporarily bans people who immediately auto-rejoin after a kick.
package PBot::Pluggable::AntiKickAutoRejoin; package PBot::Plugins::AntiKickAutoRejoin;
use warnings; use warnings;
use strict; use strict;