Subject: | forkit() corrupts UTF-8 text returned by sub - failing to decode it |
The default handler of data that is returned from forkit fails to
properly decode UTF-8, thus breaking text.
Part of code that demonstrates the problem:
$o->say({channel => '#test', body => 'Outside fork: '.$3}); #DBG
$o->forkit(
channel => $m->{channel},
who => $m->{who},
arguments => [$1, $2, $3],
run => sub
{
my ($body, $o, $n) = @_;
print 'Inside fork '.$n."\n"; return; #DBG
and the output in channel is:
<~user> ぁぃぅ
< bot> Outside fork: ぁぃぅ
< bot> Inside fork ãAAãACãAE
There is a workaround: adding 'use POE;' to code and providing a custom
handler via handler => 'say_handler' parameter to forkit() that does
decoding:
sub say_handler
{
my ($o, $body, $wheel_id) = @_[OBJECT, ARG0, ARG1];
chomp $body;
my $args = $o->{forks}{$wheel_id}{args};
$args->{body} = Encode::decode('UTF-8', $body);
$o->say($args);
return;
}