2021-06-19 06:23:34 +02:00
|
|
|
# File: Class.pm
|
|
|
|
#
|
|
|
|
# Purpose: Base class for PBot classes. This prevents each PBot class from
|
|
|
|
# needing to define the new() constructor and other boilerplate.
|
|
|
|
#
|
2021-07-11 00:00:22 +02:00
|
|
|
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
2020-02-08 20:04:13 +01:00
|
|
|
|
|
|
|
package PBot::Class;
|
|
|
|
|
2021-06-19 06:23:34 +02:00
|
|
|
use PBot::Imports;
|
2021-06-05 22:20:03 +02:00
|
|
|
|
2020-02-08 20:04:13 +01:00
|
|
|
sub new {
|
2021-06-19 06:23:34 +02:00
|
|
|
my ($class, %args) = @_;
|
|
|
|
|
|
|
|
# ensure class was passed a PBot instance
|
|
|
|
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-21 06:38:07 +02:00
|
|
|
my $self = bless { pbot => $args{pbot} }, $class;
|
2021-06-19 06:23:34 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$self->{pbot}->{logger}->log("Initializing $class\n");
|
2021-06-19 06:23:34 +02:00
|
|
|
$self->initialize(%args);
|
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
return $self;
|
2020-02-08 20:04:13 +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-08 20:04:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|