3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-17 09:29:30 +01:00
pbot/PBot/Class.pm

41 lines
1.1 KiB
Perl
Raw Normal View History

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.
#
# 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/.
package PBot::Class;
2021-06-19 06:23:34 +02:00
use PBot::Imports;
sub new {
2021-06-19 06:23:34 +02:00
my ($class, %args) = @_;
2020-02-15 23:38:32 +01:00
my $self = bless {}, $class;
2021-06-19 06:23:34 +02:00
# 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-06-19 06:23:34 +02:00
$self->{pbot} = $args{pbot};
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;
}
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");
}
1;