From: Ralf Ertzinger Date: Fri, 3 May 2013 20:14:07 +0000 (+0200) Subject: videosite-irssi: Modify to use videosite_reset() as a generic reset function, includi... X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=videosite.git;a=commitdiff_plain;h=b5479a104fa874bc5c0cd9784825eba9fd4bf69e videosite-irssi: Modify to use videosite_reset() as a generic reset function, including libvideosite unload --- diff --git a/videosite-irssi.pl b/videosite-irssi.pl index 3db9af1..5a85983 100644 --- a/videosite-irssi.pl +++ b/videosite-irssi.pl @@ -233,6 +233,22 @@ sub message_hook { } sub videosite_reset { + my $libpath; + + # Find out the script directory, and add it to @INC. + # This is necessary to find libvideosite.pm + $libpath = File::Spec->catfile(Irssi::get_irssi_dir(), 'scripts'); + + # If the library is already loaded unload it + foreach (keys(%INC)) { + if ($INC{$_} eq File::Spec->catfile($libpath, 'libvideosite.pm')) { + delete($INC{$_}); + } + } + + push(@INC, $libpath); + load 'libvideosite'; + unless(libvideosite::register_api({ io => sub { Irssi::print($_[0]) }, config_init => \&config_init, @@ -244,6 +260,7 @@ sub videosite_reset { color => \&colorpair, module_path => sub { return File::Spec->catfile(Irssi::get_irssi_dir(), 'scripts') }, quote => sub { s/%/%%/g; return $_ }, + reset => \&videosite_reset, _debug => sub { 1 }, })) { Irssi::print(sprintf("videosite API register failed: %s", $libvideosite::error)); @@ -259,11 +276,6 @@ sub videosite_reset { } sub videosite_init { - # Find out the script directory, and add it to @INC. - # This is necessary to find libvideosite.pm - - push(@INC, File::Spec->catfile(Irssi::get_irssi_dir(), 'scripts')); - load 'libvideosite'; if (videosite_reset()) { signal_add_last("message public", sub { message_hook(@_) });