2015-06-16 04:55:46 +02:00
|
|
|
# File: Refresher.pm
|
|
|
|
# Author: pragma_
|
|
|
|
#
|
|
|
|
# Purpose: Refreshes/reloads module subroutines. Does not refresh/reload
|
|
|
|
# module member data, only subroutines.
|
|
|
|
|
2017-03-05 22:33:31 +01:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2015-06-16 04:55:46 +02:00
|
|
|
package PBot::Refresher;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2019-07-11 03:40:53 +02:00
|
|
|
use feature 'unicode_strings';
|
|
|
|
|
2015-06-16 04:55:46 +02:00
|
|
|
use Module::Refresh;
|
|
|
|
use Carp ();
|
|
|
|
|
|
|
|
sub new {
|
2019-05-28 18:19:42 +02:00
|
|
|
if (ref($_[1]) eq 'HASH') {
|
2015-06-16 04:55:46 +02:00
|
|
|
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference");
|
|
|
|
}
|
|
|
|
|
|
|
|
my ($class, %conf) = @_;
|
|
|
|
|
|
|
|
my $self = bless {}, $class;
|
|
|
|
$self->initialize(%conf);
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub initialize {
|
|
|
|
my ($self, %conf) = @_;
|
|
|
|
|
|
|
|
my $pbot = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
|
|
|
|
$self->{pbot} = $pbot;
|
|
|
|
|
|
|
|
$self->{refresher} = Module::Refresh->new;
|
|
|
|
|
|
|
|
$pbot->{commands}->register(sub { return $self->refresh(@_) }, "refresh", 90);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub refresh {
|
|
|
|
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
|
2015-06-19 08:36:51 +02:00
|
|
|
my $result = eval {
|
2015-06-16 04:55:46 +02:00
|
|
|
if (not $arguments) {
|
|
|
|
$self->{pbot}->{logger}->log("Refreshing all modified modules\n");
|
|
|
|
$self->{refresher}->refresh;
|
2015-06-19 08:36:51 +02:00
|
|
|
return "Refreshed all modified modules.\n";
|
2015-06-16 04:55:46 +02:00
|
|
|
} else {
|
|
|
|
$self->{pbot}->{logger}->log("Refreshing module $arguments\n");
|
2018-01-23 08:48:25 +01:00
|
|
|
$self->{refresher}->refresh_module($arguments);
|
|
|
|
$self->{pbot}->{logger}->log("Refreshed module.\n");
|
|
|
|
return "Refreshed module.\n";
|
2015-06-16 04:55:46 +02:00
|
|
|
}
|
|
|
|
};
|
2015-06-19 08:36:51 +02:00
|
|
|
|
|
|
|
if ($@) {
|
|
|
|
$self->{pbot}->{logger}->log("Error refreshing: $@\n");
|
|
|
|
return $@;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
2015-06-16 04:55:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|