Skip to content

Instantly share code, notes, and snippets.

@Mons
Created March 23, 2016 23:27
Show Gist options
  • Select an option

  • Save Mons/e1fdb14640d6b8962d9f to your computer and use it in GitHub Desktop.

Select an option

Save Mons/e1fdb14640d6b8962d9f to your computer and use it in GitHub Desktop.
use AnyEvent::Handle;
BEGIN {
my $push_write = \&AnyEvent::Handle::push_write;
*AnyEvent::Handle::push_write = sub {
if (@_ > 2) {
goto &$push_write;
} else {
if(utf8::is_utf8 $_[1]) {
@_ = (@_);
$_[1] = "$_[1]";
my $latin = 1;
utf8::downgrade($_[1],1) or do { $latin = 0; utf8::encode($_[1]); };
warn("Received UTF8_ON string '".(
length($_[1]) > 16
? join(' ',unpack("(H2)*",substr($_[1], 0, 12)))."...+".(length($_[1]) - 12)."b"
: join(' ',unpack("(H2)*",$_[0]))
)."' from @{[ (caller)[1,2] ]}\n") unless $latin;
}
goto &$push_write;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment