1 |
#! perl |
2 |
|
3 |
use Storable qw/nfreeze thaw/; |
4 |
|
5 |
my %global; # for use by eval'ed commands |
6 |
|
7 |
cf::register_extcmd perl_eval => sub { |
8 |
my ($pl, $data) = @_; |
9 |
|
10 |
my ($token, $data) = split / /, $data, 2; |
11 |
|
12 |
unless ($pl->ob->flag (cf::FLAG_WIZ)) { |
13 |
$pl->send ("ext $token error permission denied"); |
14 |
return; |
15 |
} |
16 |
|
17 |
my ($code, $arg) = split /\0/, $data, 2; |
18 |
|
19 |
$arg = eval { thaw $arg }; |
20 |
my @res = eval $code; |
21 |
|
22 |
$@ ? $pl->send ("ext $token error $@") |
23 |
: $pl->send ("ext $token ok " . nfreeze \@res); |
24 |
}; |