3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-29 23:39:24 +01:00

Minor clean-up and polish

- add more comments to VERSION.pm
- minor clean up of logging messages
- minor refactoring
- VERSION.pm will no longer be updated as its own distinct commit
This commit is contained in:
Pragmatic Software 2021-07-27 12:01:42 -07:00
parent 837046a34b
commit 67d2dd5d95
5 changed files with 40 additions and 16 deletions

View File

@ -219,6 +219,8 @@ sub initialize {
return; return;
} }
); );
$self->{logger}->log("PBot::Core initialized.\n");
} }
sub random_nick { sub random_nick {

View File

@ -10,12 +10,15 @@ package PBot::Core::Class;
use PBot::Imports; use PBot::Imports;
our $quiet = 0; my %import_opts;
sub import { sub import {
my ($package, %opts) = @_; my ($package, %opts) = @_;
$quiet = $opts{quiet}; if (%opts) {
# set import options for package
$import_opts{$package} = \%opts;
}
} }
sub new { sub new {
@ -25,18 +28,24 @@ sub new {
if (not exists $args{pbot}) { if (not exists $args{pbot}) {
my ($package, $filename, $line) = caller(0); my ($package, $filename, $line) = caller(0);
my (undef, undef, undef, $subroutine) = caller(1); my (undef, undef, undef, $subroutine) = caller(1);
Carp::croak("Missing pbot reference to " . $class . ", created by $subroutine at $filename:$line"); Carp::croak("Missing pbot reference to $class, created by $subroutine at $filename:$line");
} }
# create class instance
my $self = bless { pbot => $args{pbot} }, $class; my $self = bless { pbot => $args{pbot} }, $class;
$self->{pbot}->{logger}->log("Initializing $class\n") unless $quiet; # log class initialization unless quieted
unless (exists $import_opts{$class} and $import_opts{$class}{quiet}) {
$self->{pbot}->{logger}->log("Initializing $class\n")
}
$self->initialize(%args); $self->initialize(%args);
return $self; return $self;
} }
sub initialize { sub initialize {
# ensure class has an initialize() subroutine
my ($package, $filename, $line) = caller(0); my ($package, $filename, $line) = caller(0);
my (undef, undef, undef, $subroutine) = caller(1); my (undef, undef, undef, $subroutine) = caller(1);
Carp::croak("Missing initialize subroutine in $subroutine at $filename:$line"); Carp::croak("Missing initialize subroutine in $subroutine at $filename:$line");

View File

@ -54,12 +54,10 @@ our %factoid_metadata = (
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
my $filename = $conf{filename};
$self->{storage} = PBot::Core::Storage::DualIndexSQLiteObject->new( $self->{storage} = PBot::Core::Storage::DualIndexSQLiteObject->new(
pbot => $self->{pbot}, pbot => $self->{pbot},
name => 'Factoids', name => 'Factoids',
filename => $filename, filename => $conf{filename},
); );
} }

View File

@ -29,18 +29,20 @@ sub autoload {
my $data_dir = $self->{pbot}->{registry}->get_value('general', 'data_dir'); my $data_dir = $self->{pbot}->{registry}->get_value('general', 'data_dir');
$self->{pbot}->{logger}->log("Loading plugins ...\n");
my $plugin_count = 0; my $plugin_count = 0;
my $fh; my $fh;
if (not open $fh, "<$data_dir/plugin_autoload") { if (not open $fh, "<$data_dir/plugin_autoload") {
$self->{pbot}->{logger}->log("warning: file $data_dir/plugin_autoload does not exist; skipping autoloading of Plugins\n"); $self->{pbot}->{logger}->log("Plugins: autoload: file $data_dir/plugin_autoload does not exist; skipping autoloading of Plugins\n");
return; return;
} }
chomp(my @plugins = <$fh>); chomp(my @plugins = <$fh>);
close $fh; close $fh;
$self->{pbot}->{logger}->log("Loading plugins:\n");
$conf{quiet} = 1;
foreach my $plugin (sort @plugins) { foreach my $plugin (sort @plugins) {
# do not load plugins that begin with a comment # do not load plugins that begin with a comment
next if $plugin =~ m/^\s*#/; next if $plugin =~ m/^\s*#/;
@ -48,6 +50,9 @@ sub autoload {
$plugin = basename $plugin; $plugin = basename $plugin;
$plugin =~ s/.pm$//; $plugin =~ s/.pm$//;
$self->{pbot}->{logger}->log(" $plugin\n");
$plugin_count++ if $self->load($plugin, %conf); $plugin_count++ if $self->load($plugin, %conf);
} }
@ -66,7 +71,7 @@ sub load {
$self->{pbot}->{refresher}->{refresher}->refresh_module($module); $self->{pbot}->{refresher}->{refresher}->refresh_module($module);
my $ret = eval { my $ret = eval {
$self->{pbot}->{logger}->log("Loading $plugin\n"); $self->{pbot}->{logger}->log("Loading $plugin\n") unless $conf{quiet};
require "$module"; require "$module";
my $class = "PBot::Plugin::$plugin"; my $class = "PBot::Plugin::$plugin";
$self->{plugins}->{$plugin} = $class->new(pbot => $self->{pbot}, %conf); $self->{plugins}->{$plugin} = $class->new(pbot => $self->{pbot}, %conf);

View File

@ -1,7 +1,17 @@
# File: VERSION.pm # File: VERSION.pm
# #
# Purpose: Keeps track of bot version. Can compare current version against # Purpose: Keeps track of bot version. All of PBot is considered a single
# latest version on github or URL in `version.check_url` registry entry. # entity. The BUILD_REVSION constant in this file is the count of git commits
# to the PBot repository when this file was updated. This file is updated by
# the /misc/update_version script after any commits that alter PBot's behavior.
#
# See also PBot::Core::Commands::Version, which can compare current version
# against latest version on github or URL in `version.check_url` registry
# entry to notify users of the availability of a new version.
#
# TODO: The PBot::Plugin::* plugins probably should have their own version
# identifiers as a template for using versioned $HOME/PBot/Plugin/ plugins. I
# don't want to micro-manage version identifiers for PBot::Core stuff though.
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com> # SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
@ -20,11 +30,11 @@ our @EXPORT_OK = (
@{ $EXPORT_TAGS{all} }, @{ $EXPORT_TAGS{all} },
); );
# These are set automatically by the misc/update_version script # These are set automatically by the /misc/update_version script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 4315, BUILD_REVISION => 4317,
BUILD_DATE => "2021-07-26", BUILD_DATE => "2021-07-27",
}; };
sub initialize { sub initialize {