mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 18:45:42 -04:00
make deparse smarter
This commit is contained in:
parent
923b2f270f
commit
c954380c04
1 changed files with 39 additions and 17 deletions
30
lib/eval.pl
30
lib/eval.pl
|
@ -172,13 +172,19 @@ no warnings;
|
|||
my $sub;
|
||||
{
|
||||
no strict; no warnings; no charnames;
|
||||
$sub = eval "use $]; sub{ $code\n }";
|
||||
$sub = eval "use $]; package botdeparse; sub{ $code\n }";
|
||||
}
|
||||
|
||||
my %methods = (map {$_ => botdeparse->can($_)} grep {botdeparse->can($_)} keys {%botdeparse::}->%*);
|
||||
|
||||
if( $@ ) { print STDOUT "Error: $@"; return }
|
||||
|
||||
my $dp = B::Deparse->new("-p", "-q", "-x7");
|
||||
my $ret = $dp->coderef2text($sub);
|
||||
|
||||
my @out;
|
||||
|
||||
my $clean_out = sub {
|
||||
my $ret = shift;
|
||||
$ret =~ s/\{//;
|
||||
$ret =~ s/package (?:\w+(?:::)?)+;//;
|
||||
$ret =~ s/no warnings;//;
|
||||
|
@ -186,8 +192,24 @@ no warnings;
|
|||
$ret =~ s/\s*\}\s*$//;
|
||||
$ret =~ s/\s*\$\^H\{[^}]+\}(\s+=\s+[^;]+;?)?\s*//g;
|
||||
$ret =~ s/\s*BEGIN\s*\{\s*[^}]*\s*\}\s*/ /;
|
||||
$ret =~ s/package botdeparse;//;
|
||||
$ret =~ s/no feature ':all';//;
|
||||
$ret =~ s/use feature [^;]+;//;
|
||||
$ret =~ s/^\s+|\s+$//g;
|
||||
return $ret;
|
||||
};
|
||||
|
||||
print STDOUT $ret;
|
||||
for my $sub (keys %methods) {
|
||||
my $ret = $clean_out->($dp->coderef2text($methods{$sub}));
|
||||
|
||||
push @out, "sub $sub {$ret} ";
|
||||
}
|
||||
|
||||
my $ret = $dp->coderef2text($sub);
|
||||
$ret = $clean_out->($ret);
|
||||
push @out, $ret;
|
||||
|
||||
print STDOUT join(' ', @out);
|
||||
}
|
||||
|
||||
eval "use utf8; \$\343\201\257 = 42; 'ש' =~ /([\p{Bidi_Class:L}\p{Bidi_Class:R}])/"; # attempt to automatically load the utf8 libraries.
|
||||
|
@ -201,7 +223,7 @@ use Text::ParseWords;
|
|||
eval {"\N{SPARKLE}"}; # force loading of some of the charnames stuff
|
||||
|
||||
# Required for perl_deparse
|
||||
use B::Deparse;
|
||||
use B::RecDeparse;
|
||||
|
||||
## Javascript Libs
|
||||
#BEGIN{ eval "use JavaScript::V8; require JSON::XS; JavaScript::V8::Context->new()->eval('1')"; }
|
||||
|
|
Loading…
Add table
Reference in a new issue