From 8cff244256b23635100ec5c16095161cedc33553 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 27 Jul 2021 12:25:56 -0700 Subject: [PATCH] Simplify VERSION.pm --- lib/PBot/Core.pm | 7 +++-- lib/PBot/Core/Commands/Version.pm | 12 +++++---- lib/PBot/VERSION.pm | 43 +++++++++---------------------- 3 files changed, 22 insertions(+), 40 deletions(-) diff --git a/lib/PBot/Core.pm b/lib/PBot/Core.pm index 785f2312..a7b8a9f1 100644 --- a/lib/PBot/Core.pm +++ b/lib/PBot/Core.pm @@ -134,6 +134,9 @@ sub initialize { # prepare and open logger $self->{logger} = PBot::Core::Logger->new(pbot => $self, filename => "$conf{data_dir}/log/log", %conf); + # log the version + $self->{logger}->log(PBot::VERSION::BUILD_NAME . ' version ' . PBot::VERSION::BUILD_REVISION . ' ' . PBot::VERSION::BUILD_DATE . "\n"); + # log command-line arguments $self->{logger}->log("Args: @ARGV\n") if @ARGV; @@ -158,10 +161,6 @@ sub initialize { # create commands so the modules can register new commands $self->{commands} = PBot::Core::Commands->new(pbot => $self, filename => "$conf{data_dir}/commands", %conf); - # prepare the version information and `version` command - $self->{version} = PBot::VERSION->new(pbot => $self, %conf); - $self->{logger}->log($self->{version}->version . "\n"); - # prepare registry $self->{registry} = PBot::Core::Registry->new(pbot => $self, filename => "$conf{data_dir}/registry", %conf); diff --git a/lib/PBot/Core/Commands/Version.pm b/lib/PBot/Core/Commands/Version.pm index e2d0f6b9..55777748 100644 --- a/lib/PBot/Core/Commands/Version.pm +++ b/lib/PBot/Core/Commands/Version.pm @@ -11,8 +11,6 @@ use parent 'PBot::Core::Class'; use PBot::Imports; -use PBot::VERSION qw/BUILD_REVISION BUILD_DATE/; - use LWP::UserAgent; sub initialize { @@ -22,7 +20,11 @@ sub initialize { $self->{pbot}->{commands}->register(sub { $self->cmd_version(@_) }, 'version'); # initialize last_check version data - $self->{last_check} = {timestamp => 0, version => BUILD_REVISION, date => BUILD_DATE}; + $self->{last_check} = { + timestamp => 0, + version => PBot::VERSION::BUILD_REVISION, + date => PBot::VERSION::BUILD_DATE, + }; } sub cmd_version { @@ -61,9 +63,9 @@ sub cmd_version { my $result = '/say '; $result .= "$target_nick: " if $target_nick; - $result .= $self->{pbot}->{version}->version; + $result .= PBot::VERSION::BUILD_NAME . ' version ' . PBot::VERSION::BUILD_REVISION . ' ' . PBot::VERSION::BUILD_DATE; - if ($self->{last_check}->{version} > BUILD_REVISION) { + if ($self->{last_check}->{version} > PBot::VERSION::BUILD_REVISION) { $result .= "; new version available: $self->{last_check}->{version} $self->{last_check}->{date}!"; } diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index f7b2d01e..25342112 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -1,48 +1,29 @@ # File: VERSION.pm # -# Purpose: Keeps track of bot version. All of PBot is considered a single -# 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. +# Purpose: Keeps track of bot version constants. # -# 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. +# Rather than each PBot::Core package having its own version identifier, all +# of PBot is considered a single package. The BUILD_REVSION constant is the +# count of git commits to the PBot repository. +# +# See also the version command in PBot::Core::Commands::Version. It can compare +# the local PBot version against latest version on GitHub (or the URL in +# the `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. +# identifiers as a template for versioned $HOME/PBot/Plugin/ plugins. # SPDX-FileCopyrightText: 2021 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::VERSION; -use parent 'PBot::Core::Class'; -use PBot::Imports; - -use Exporter qw/import/; -our @EXPORT = (); -our %EXPORT_TAGS = ( - 'all' => [qw/BUILD_NAME BUILD_REVISION BUILD_DATE/], -); -our @EXPORT_OK = ( - @{ $EXPORT_TAGS{all} }, -); - -# These are set automatically by the /misc/update_version script +# These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4317, + BUILD_REVISION => 4318, BUILD_DATE => "2021-07-27", }; -sub initialize { - # nothing to do here -} - -sub version { - return BUILD_NAME . " version " . BUILD_REVISION . " " . BUILD_DATE; -} - 1;