Devel-StackTrace-AsHTML
view release on metacpan or search on metacpan
lib/Devel/StackTrace/AsHTML.pm view on Meta::CPAN
our $VERSION = '0.15';
use Data::Dumper;
use Devel::StackTrace;
use Scalar::Util;
no warnings 'qw';
my %enc = qw( & & > > < < " " ' ' );
# NOTE: because we don't know which encoding $str is in, or even if
# $str is a wide character (decoded strings), we just leave the low
# bits, including latin-1 range and encode everything higher as HTML
# entities. I know this is NOT always correct, but should mostly work
# in case $str is encoded in utf-8 bytes or wide chars. This is a
# necessary workaround since we're rendering someone else's code which
# we can't enforce string encodings.
sub encode_html {
my $str = shift;
$str =~ s/([^\x00-\x21\x23-\x25\x28-\x3b\x3d\x3f-\xff])/$enc{$1} || '&#' . ord($1) . ';' /ge;
utf8::downgrade($str);
( run in 0.253 second using v1.01-cache-2.11-cpan-26ccb49234f )