From b990d482c1c72e32b3054d98845e6956fe373502 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 22 Jul 2021 05:36:46 -0700 Subject: [PATCH] Rename LoadPackages to LoadModules --- lib/PBot/Core/Commands.pm | 4 +-- lib/PBot/Core/Factoids.pm | 2 +- lib/PBot/Core/IRCHandlers.pm | 8 ++--- .../Utils/{LoadPackages.pm => LoadModules.pm} | 34 +++++++++---------- 4 files changed, 24 insertions(+), 24 deletions(-) rename lib/PBot/Utils/{LoadPackages.pm => LoadModules.pm} (57%) diff --git a/lib/PBot/Core/Commands.pm b/lib/PBot/Core/Commands.pm index b010631d..c8728399 100644 --- a/lib/PBot/Core/Commands.pm +++ b/lib/PBot/Core/Commands.pm @@ -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 { diff --git a/lib/PBot/Core/Factoids.pm b/lib/PBot/Core/Factoids.pm index 2f197ef6..df38f085 100644 --- a/lib/PBot/Core/Factoids.pm +++ b/lib/PBot/Core/Factoids.pm @@ -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/) { diff --git a/lib/PBot/Core/IRCHandlers.pm b/lib/PBot/Core/IRCHandlers.pm index b2c9afe9..7c480351 100644 --- a/lib/PBot/Core/IRCHandlers.pm +++ b/lib/PBot/Core/IRCHandlers.pm @@ -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 # 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 diff --git a/lib/PBot/Utils/LoadPackages.pm b/lib/PBot/Utils/LoadModules.pm similarity index 57% rename from lib/PBot/Utils/LoadPackages.pm rename to lib/PBot/Utils/LoadModules.pm index 32917e12..c6c2bb8e 100644 --- a/lib/PBot/Utils/LoadPackages.pm +++ b/lib/PBot/Utils/LoadModules.pm @@ -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 # 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; }