mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-23 11:12:42 +01:00
Rename LoadPackages to LoadModules
This commit is contained in:
parent
51c061f31d
commit
b990d482c1
@ -11,7 +11,7 @@ use parent 'PBot::Core::Class', 'PBot::Core::Registerable';
|
||||
|
||||
use PBot::Imports;
|
||||
|
||||
use PBot::Utils::LoadPackages qw/load_packages/;
|
||||
use PBot::Utils::LoadModules qw/load_modules/;
|
||||
|
||||
sub initialize {
|
||||
my ($self, %conf) = @_;
|
||||
@ -29,7 +29,7 @@ sub register_commands {
|
||||
|
||||
# register commands in Commands directory
|
||||
$self->{pbot}->{logger}->log("Registering commands:\n");
|
||||
load_packages($self, 'PBot::Core::Commands');
|
||||
load_modules($self, 'PBot::Core::Commands');
|
||||
}
|
||||
|
||||
sub register {
|
||||
|
@ -1166,7 +1166,7 @@ sub interpreter {
|
||||
if ($strictnamespace) { $namespace_regex = "(?:" . (quotemeta $namespace) . '|\\.\\*)'; }
|
||||
|
||||
$context->{arguments} = quotemeta($original_keyword) . " -channel $namespace_regex";
|
||||
my $matches = $self->{pbot}->{commands}->{packages}->{Factoids}->cmd_factfind($context);
|
||||
my $matches = $self->{pbot}->{commands}->{modules}->{Factoids}->cmd_factfind($context);
|
||||
|
||||
# found factfind matches
|
||||
if ($matches !~ m/^No factoids/) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
# File: IRCHandlers.pm
|
||||
#
|
||||
# Purpose: Pipes the PBot::Core::IRC default handler through PBot::Core::EventDispatcher,
|
||||
# and loads all the packages in the IRCHandlers directory.
|
||||
# and loads all the modules in the IRCHandlers directory.
|
||||
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
@ -11,7 +11,7 @@ use parent 'PBot::Core::Class';
|
||||
|
||||
use PBot::Imports;
|
||||
|
||||
use PBot::Utils::LoadPackages;
|
||||
use PBot::Utils::LoadModules;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
@ -33,7 +33,7 @@ sub add_handlers {
|
||||
|
||||
# send these events to on_init()
|
||||
$self->{pbot}->{conn}->add_handler([251, 252, 253, 254, 255, 302],
|
||||
sub { $self->{packages}->{Server}->on_init(@_) });
|
||||
sub { $self->{modules}->{Server}->on_init(@_) });
|
||||
|
||||
# ignore these events
|
||||
$self->{pbot}->{conn}->add_handler(
|
||||
@ -57,7 +57,7 @@ sub register_handlers {
|
||||
my ($self, %conf) = @_;
|
||||
|
||||
$self->{pbot}->{logger}->log("Registering IRC handlers:\n");
|
||||
load_packages($self, 'PBot::Core::IRCHandlers');
|
||||
load_modules($self, 'PBot::Core::IRCHandlers');
|
||||
}
|
||||
|
||||
# this default handler prepends 'irc.' to the event-type and then dispatches
|
||||
|
@ -1,57 +1,57 @@
|
||||
# File: LoadPackages.pm
|
||||
# File: LoadModules.pm
|
||||
#
|
||||
# Purpose: Loads all Perl package files in a given directory.
|
||||
# Purpose: Loads all Perl modules in a given directory, nonrecursively
|
||||
# (i.e. at one depth level).
|
||||
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
package PBot::Utils::LoadPackages;
|
||||
package PBot::Utils::LoadModules;
|
||||
|
||||
use PBot::Imports;
|
||||
|
||||
use File::Basename;
|
||||
|
||||
# export load_packages subroutine
|
||||
require Exporter;
|
||||
our @ISA = qw/Exporter/;
|
||||
our @EXPORT = qw/load_packages/;
|
||||
our @EXPORT = qw/load_modules/;
|
||||
|
||||
sub load_packages {
|
||||
sub load_modules {
|
||||
my ($self, $base) = @_;
|
||||
|
||||
my $base_path = join '/', split '::', $base;
|
||||
|
||||
foreach my $inc_path (@INC) {
|
||||
if (-d "$inc_path/$base_path") {
|
||||
my @packages = glob "$inc_path/$base_path/*.pm";
|
||||
my @modules = glob "$inc_path/$base_path/*.pm";
|
||||
|
||||
foreach my $package (sort @packages) {
|
||||
$self->{pbot}->{refresher}->{refresher}->refresh_module($package);
|
||||
foreach my $module (sort @modules) {
|
||||
$self->{pbot}->{refresher}->{refresher}->refresh_module($module);
|
||||
|
||||
my $name = basename $package;
|
||||
my $name = basename $module;
|
||||
$name =~ s/\.pm$//;
|
||||
|
||||
$self->{pbot}->{logger}->log(" $name\n");
|
||||
|
||||
eval {
|
||||
require "$package";
|
||||
require "$module";
|
||||
|
||||
my $class = $base . '::' . $name;
|
||||
$self->{packages}->{$name} = $class->new(pbot => $self->{pbot});
|
||||
$self->{pbot}->{refresher}->{refresher}->update_cache($package);
|
||||
$self->{modules}->{$name} = $class->new(pbot => $self->{pbot});
|
||||
$self->{pbot}->{refresher}->{refresher}->update_cache($module);
|
||||
};
|
||||
|
||||
# error loading a package
|
||||
# error loading a module
|
||||
if (my $exception = $@) {
|
||||
$self->{pbot}->{logger}->log("Error loading $package: $exception");
|
||||
$self->{pbot}->{logger}->log("Error loading $module: $exception");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
# packages loaded successfully
|
||||
# modules loaded successfully
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
# no packages found
|
||||
# no module found
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user