3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-02 10:09:32 +01:00
pbot/lib/PBot/Plugin/Base.pm

40 lines
1.0 KiB
Perl
Raw Normal View History

2021-07-14 04:45:56 +02:00
# File: Base.pm
2021-06-19 06:23:34 +02:00
#
# Purpose: Base class for PBot plugins.
2021-07-11 00:00:22 +02:00
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
2020-02-09 04:48:05 +01:00
2021-07-14 04:45:56 +02:00
package PBot::Plugin::Base;
2020-02-09 04:48:05 +01:00
2021-06-19 06:23:34 +02:00
use PBot::Imports;
2020-02-09 04:48:05 +01:00
sub new {
2021-06-19 06:23:34 +02:00
my ($class, %args) = @_;
if (not exists $args{pbot}) {
2020-02-15 23:38:32 +01:00
my ($package, $filename, $line) = caller(0);
my (undef, undef, undef, $subroutine) = caller(1);
Carp::croak("Missing pbot reference to " . $class . ", created by $subroutine at $filename:$line");
}
2021-07-13 23:04:14 +02:00
my $self = bless {}, $class;
2021-06-19 06:23:34 +02:00
$self->{pbot} = $args{pbot};
$self->initialize(%args);
2020-02-15 23:38:32 +01:00
return $self;
2020-02-09 04:48:05 +01:00
}
sub initialize {
2020-02-15 23:38:32 +01:00
my ($package, $filename, $line) = caller(0);
my (undef, undef, undef, $subroutine) = caller(1);
Carp::croak("Missing initialize subroutine in $subroutine at $filename:$line");
2020-02-09 04:48:05 +01:00
}
sub unload {
2020-02-15 23:38:32 +01:00
my ($package, $filename, $line) = caller(0);
my (undef, undef, undef, $subroutine) = caller(1);
Carp::croak("Missing unload subroutine in $subroutine at $filename:$line");
2020-02-09 04:48:05 +01:00
}
1;