B-DeparseTree
view release on metacpan or search on metacpan
lib/B/DeparseTree/P522.pm view on Meta::CPAN
# my $deparse_old = B::Deparse->new("-l", "-sC");
# print $deparse_old->coderef2text(\&baz);
# exit 1;
my $deparse = __PACKAGE__->new("-l", "-c", "-sC");
my $info = $deparse->coderef2info(\&baz);
import Data::Printer colored => 0;
Data::Printer::p($info);
print "\n", '=' x 30, "\n";
# print $deparse->indent($deparse->deparse_subname('fib')->{text});
# print "\n", '=' x 30, "\n";
# print "\n", '-' x 30, "\n";
while (my($key, $value) = each %{$deparse->{optree}}) {
my $parent_op_name = 'undef';
if ($value->{parent}) {
my $parent = $deparse->{optree}{$value->{parent}};
$parent_op_name = $parent->{op}->name if $parent->{op};
}
printf("0x%x %s/%s of %s |\n%s",
$key, $value->{op}->name, $value->{type},
$parent_op_name, $deparse->indent($value->{text}));
printf " ## line %s\n", $value->{cop} ? $value->{cop}->line : 'undef';
print '-' x 30, "\n";
}
}
# FIXME:
# Different in 5.20. Go over differences to see if okay in 5.20.
sub pp_chdir {
my ($self, $op, $cx) = @_;
if (($op->flags & (OPf_SPECIAL|OPf_KIDS)) == (OPf_SPECIAL|OPf_KIDS)) {
my $kw = $self->keyword("chdir");
my $kid = $self->const_sv($op->first)->PV;
my $code = $kw
. ($cx >= 16 || $self->{'parens'} ? "($kid)" : " $kid");
maybe_targmy(@_, sub { $_[3] }, $code);
} else {
maybe_targmy(@_, \&unop, "chdir")
}
}
# Not in Perl 5.20 and presumeably < 5.20. No harm in adding to 5.20?
*pp_ncomplement = *pp_complement;
unless (caller) {
eval "use Data::Printer;";
eval {
our($Fileparse_fstype);
sub fib($) {
my $x = shift;
return 1 if $x <= 1;
return(fib($x-1) + fib($x-2))
}
sub fileparse {
no strict;
# my($fullname,@suffices) = @_;
my $tail = '';
$tail = $1 . $tail;
# Ensure taint is propagated from the path to its pieces.
$tail .= $taint;
wantarray ? ($basename .= $taint, $dirpath .= $taint, $tail)
: ($basename .= $taint);
}
sub baz {
no strict;
if ($basename =~ s/$pat//s) {
}
}
};
my $deparse = __PACKAGE__->new("-l", "-c");
my $info = $deparse->coderef2info(\&fileparse);
# my $info = $deparse->coderef2info(\&baz);
import Data::Printer colored => 0;
Data::Printer::p($info);
print "\n", '=' x 30, "\n";
# print $deparse->($deparse->deparse_subname('fib')->{text});
# print "\n", '=' x 30, "\n";
# print "\n", '-' x 30, "\n";
while (my($key, $value) = each %{$deparse->{optree}}) {
my $parent_op_name = 'undef';
if ($value->{parent}) {
my $parent = $deparse->{optree}{$value->{parent}};
$parent_op_name = $parent->{op}->name if $parent->{op};
}
if (eval{$value->{op}->name}) {
printf("0x%x %s/%s of %s |\n%s",
$key, $value->{op}->name, $value->{type},
$parent_op_name, $deparse->{text});
} else {
printf("0x%x %s of %s |\n",
$key, $value->{type},
$parent_op_name);
}
printf " ## line %s\n", $value->{cop} ? $value->{cop}->line : 'undef';
print '-' x 30, "\n";
}
# use B::Deparse;
# my $deparse_old = B::Deparse->new("-l", "-sC");
# print $deparse_old->coderef2text(\&baz);
}
1;
( run in 0.707 second using v1.01-cache-2.11-cpan-39bf76dae61 )