diff options
author | Timo Sirainen <cras@irssi.org> | 2001-07-29 09:17:53 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2001-07-29 09:17:53 +0000 |
commit | 6c2f9c685aaf4aa79c9ea3f29efe0c22aa0a98ee (patch) | |
tree | 0f6377555e2b9cdc881731fd06dc3723632150ac /src/perl/irssi-core.pl | |
parent | 2d5edb8c4d56f75f4dab93929072cc2699ec5ccd (diff) | |
download | irssi-6c2f9c685aaf4aa79c9ea3f29efe0c22aa0a98ee.zip |
--enable-perl* -> --with-perl*. Added a new libfe_perl which handles /SCRIPT
commands. /RUN -> /SCRIPT LOAD, /PERLFLUSH -> /SCRIPT FLUSH, /PERL ->
/SCRIPT EXEC. Added /SCRIPT UNLOAD, /SCRIPT LIST. Lots of cleanups.
filename_complete() has extra argument for "default directory" which is
searched if no path is given when completing.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1680 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/perl/irssi-core.pl')
-rw-r--r-- | src/perl/irssi-core.pl | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/perl/irssi-core.pl b/src/perl/irssi-core.pl new file mode 100644 index 00000000..94517242 --- /dev/null +++ b/src/perl/irssi-core.pl @@ -0,0 +1,44 @@ +# NOTE: this is printed through printf()-like function, +# so no extra percent characters. + +# %%s can be used once, it contains the +# use Irssi; use Irssi::Irc; etc.. +package Irssi::Core; + +use Symbol qw(delete_package); +use strict; + +sub destroy { + my $package = "Irssi::Script::".$_[0]; + delete_package($package); +} + +sub eval_data { + my ($data, $id) = @_; + destroy($id); + + my $package = "Irssi::Script::$id"; + my $eval = qq{package $package; %s sub handler { $data; }}; + { + # hide our variables within this block + my ($filename, $package, $data); + eval $eval; + } + die $@ if $@; + + eval {$package->handler;}; + die $@ if $@; +} + +sub eval_file { + my ($filename, $id) = @_; + + local *FH; + open FH, $filename or die "File not found: $filename"; + local($/) = undef; + my $data = <FH>; + close FH; + $/ = '\n'; + + eval_data($data, id); +} |