Added mod_init() and mod_void() to API::Std.
This commit is contained in:
1 parent
d950449424
commit
b6069b1424
2 files changed
+65
-1
No files matched your search
@@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log
|
|||||||
|
|
||||||
3.0 Indev
|
3.0 Indev
|
||||||
==================================================================
|
==================================================================
|
||||||
|
* Added mod_init() and mod_void() to API::Std.
|
||||||
* Use Class::Unload.
|
* Use Class::Unload.
|
||||||
* Handle SIGTERM, SIGINT and SIGHUP.
|
* Handle SIGTERM, SIGINT and SIGHUP.
|
||||||
* Added quit() to API::IRC.
|
* Added quit() to API::IRC.
|
||||||
|
|||||||
+64
-1
@@ -11,19 +11,82 @@ use Exporter;
|
|||||||
our @ISA = qw(Exporter);
|
our @ISA = qw(Exporter);
|
||||||
our @EXPORT_OK = qw(conf_get trans err);
|
our @EXPORT_OK = qw(conf_get trans err);
|
||||||
|
|
||||||
my %LANGE;
|
my (%LANGE, %MODULE);
|
||||||
|
|
||||||
|
|
||||||
# Initialize a module.
|
# Initialize a module.
|
||||||
sub mod_init
|
sub mod_init
|
||||||
{
|
{
|
||||||
|
my ($name, $author, $version, $autover, $pkg) = @_;
|
||||||
|
|
||||||
|
# Log/debug.
|
||||||
|
API::Log::dbug("MODULES: Attempting to load ".$name." (version ".$version.") by ".$author."...");
|
||||||
|
API::Log::alog("MODULES: Attempting to load ".$name." (version ".$version.") by ".$author."...");
|
||||||
|
|
||||||
|
# Check if this module is compatible with this version of Auto.
|
||||||
|
if ($autover ne "3.0.0d") {
|
||||||
|
API::Log::dbug("MODULES: Failed to load ".$name.": Incompatible with your version of Auto.");
|
||||||
|
API::Log::alog("MODULES: Failed to load ".$name.": Incompatible with your version of Auto.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run the module's _init sub.
|
||||||
|
my $mi = eval($pkg."::_init();");
|
||||||
|
|
||||||
|
if ($mi) {
|
||||||
|
# If successful, add to hash.
|
||||||
|
$MODULE{$name}{name} = $name;
|
||||||
|
$MODULE{$name}{version} = $version;
|
||||||
|
$MODULE{$name}{author} = $author;
|
||||||
|
$MODULE{$name}{pkg} = $pkg;
|
||||||
|
|
||||||
|
API::Log::dbug("MODULES: ".$name." successfully loaded.");
|
||||||
|
API::Log::alog("MODULES: ".$name." successfully loaded.");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Otherwise, return a failed to load message.
|
||||||
|
API::Log::dbug("MODULES: Failed to load ".$name.".");
|
||||||
|
API::Log::alog("MODULES: Failed to load ".$name.".");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Void a module.
|
# Void a module.
|
||||||
sub mod_void
|
sub mod_void
|
||||||
{
|
{
|
||||||
|
my ($module) = @_;
|
||||||
|
|
||||||
|
# Log/debug.
|
||||||
|
API::Log::dbug("MODULES: Attempting to unload module: ".$module."...");
|
||||||
|
API::Log::alog("MODULES: Attempting to unload module: ".$module."...");
|
||||||
|
|
||||||
|
# Check if this module exists.
|
||||||
|
unless (defined $MODULE{$module}) {
|
||||||
|
API::Log::dbug("MODULES: Failed to unload ".$module.". No such module?");
|
||||||
|
API::Log::alog("MODULES: Failed to unload ".$module.". No such module?");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run the module's _init sub.
|
||||||
|
my $mi = eval($MODULE{$module}{pkg}."::_void();");
|
||||||
|
|
||||||
|
if ($mi) {
|
||||||
|
# If successful, delete class from program and delete module from hash.
|
||||||
|
Class::Unload->unload($MODULE{$module}{pkg});
|
||||||
|
delete $MODULE{$module};
|
||||||
|
API::Log::dbug("MODULES: Successfully unloaded ".$module.".");
|
||||||
|
API::Log::alog("MODULES: Successfully unloaded ".$module.".");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Otherwise, return a failed to unload message.
|
||||||
|
API::Log::dbug("MODULES: Failed to unload ".$module.".");
|
||||||
|
API::Log::alog("MODULES: Failed to unload ".$module.".");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add a command to Auto.
|
# Add a command to Auto.
|
||||||
|
|||||||
Reference in new issue
Block a user