|
|
|
@ -1,10 +1,12 @@
@@ -1,10 +1,12 @@
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
|
|
|
# ----------------------------------------------------------------------------- |
|
|
|
|
# Author(s) : Bill Atkins |
|
|
|
|
# Title : MOS core |
|
|
|
|
# Title : MOS core tools |
|
|
|
|
# Date : 12.21.02 |
|
|
|
|
# Desc : the hamster that keep MOS going |
|
|
|
|
# QoTP : got milkbone tools? |
|
|
|
|
# Notes : for more information see the plugin documentation |
|
|
|
|
# License : under the same terms as mos.pl |
|
|
|
|
# ---------------------------------------------------------------------- |
|
|
|
|
# ----------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
package Milkbone; |
|
|
|
|
|
|
|
|
@ -12,6 +14,7 @@ use strict;
@@ -12,6 +14,7 @@ use strict;
|
|
|
|
|
use warnings; |
|
|
|
|
|
|
|
|
|
use Carp qw(longmess); |
|
|
|
|
use PAR; |
|
|
|
|
use Milkbone::HookEntry; |
|
|
|
|
use Benchmark; |
|
|
|
|
|
|
|
|
@ -21,7 +24,7 @@ require Exporter;
@@ -21,7 +24,7 @@ require Exporter;
|
|
|
|
|
|
|
|
|
|
our @ISA = qw( Exporter ); |
|
|
|
|
our @EXPORT = qw( hook is_running abort queued_hook register_hook option path data %ARGS slurp |
|
|
|
|
deregister_hook strip_html user_file set_option MOSLoop set_interval unload_plugin load_plugin init_plugin reload_core); |
|
|
|
|
deregister_hook strip_html user_file set_option MOSLoop set_interval unload_plugin load_plugin init_plugin reload_core reload_plugin); |
|
|
|
|
our @EXPORT_OK = qw( ); |
|
|
|
|
|
|
|
|
|
my ($running, $dirty); |
|
|
|
@ -68,8 +71,9 @@ sub init
@@ -68,8 +71,9 @@ sub init
|
|
|
|
|
sub load_options |
|
|
|
|
{ |
|
|
|
|
my ($directive, $temp, @args); |
|
|
|
|
my $file = $ARGS{-file} || "mb.conf"; |
|
|
|
|
|
|
|
|
|
open(GLOBAL, "<mb.conf") or die "Can't open config file: $!"; |
|
|
|
|
open(GLOBAL, "<$file") or die "Can't open config file: $!"; |
|
|
|
|
|
|
|
|
|
while(<GLOBAL>) |
|
|
|
|
{ |
|
|
|
@ -227,6 +231,14 @@ sub load_plugins
@@ -227,6 +231,14 @@ sub load_plugins
|
|
|
|
|
init_plugin($_) for(@plugins); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub reload_plugin |
|
|
|
|
{ |
|
|
|
|
my ($plugin) = @_; |
|
|
|
|
unload_plugin($_); |
|
|
|
|
load_plugin($_); |
|
|
|
|
init_plugin($_); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub hook |
|
|
|
|
{ |
|
|
|
|
my ($hook, %args) = @_; |
|
|
|
@ -264,7 +276,6 @@ sub register_hook
@@ -264,7 +276,6 @@ sub register_hook
|
|
|
|
|
my $entry = new Milkbone::HookEntry($hook, $coderef, $args, $package); |
|
|
|
|
|
|
|
|
|
push @{$hooks{$hook}}, $entry; |
|
|
|
|
print "$hook registered by $file\n"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub deregister_hook |
|
|
|
@ -273,14 +284,14 @@ sub deregister_hook
@@ -273,14 +284,14 @@ sub deregister_hook
|
|
|
|
|
my ($package, $file, $line) = caller; |
|
|
|
|
my @temp = @{$hooks{$hook}}; |
|
|
|
|
|
|
|
|
|
print "$hook deregistered by $file\n"; |
|
|
|
|
|
|
|
|
|
die "Required hook missing" if !exists($hooks{$hook}) and $hook eq "tick"; |
|
|
|
|
warn "Unregistered hook deleted: $hook" if !exists($hooks{$hook}); |
|
|
|
|
|
|
|
|
|
@temp = grep { ($_->{package} ne $package) } @{$hooks{$hook}}; |
|
|
|
|
@temp = grep { ($_->{package} ne $package) } @temp; |
|
|
|
|
|
|
|
|
|
@{$hooks{$hook}} = @temp; |
|
|
|
|
|
|
|
|
|
# delete $hooks{$hook} unless @temp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub MOSLoop |
|
|
|
@ -289,7 +300,7 @@ sub MOSLoop
@@ -289,7 +300,7 @@ sub MOSLoop
|
|
|
|
|
while(is_running) |
|
|
|
|
{ |
|
|
|
|
hook("tick"); |
|
|
|
|
select(undef, undef, undef, $interval) if $i++ % 5 == 0 && $interval; |
|
|
|
|
# select(undef, undef, undef, $interval) if $i++ % 5 == 0 && $interval; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|