Note: this has been heavily edited.
With help from stackoverflow, I have a way to get started.
use B::Deparse; use B::Concise qw(set_style); sub foo() { my $x=1; $x+=1; my $z=0; } my $deparse = B::Deparse->new("-p", "-l", "-sC"); $body = $deparse->coderef2text(\&foo); print($body, "\n"); my $walker = B::Concise::compile('-basic', 'foo', \&foo); B::Concise::set_style_standard('debug'); B::Concise::walk_output(\my $buf); $walker->(); # walks and renders into $buf; print($buf); package B::Deparse; sub lineseq { my($self, $root, $cx, @ops) = @_; my($expr, @exprs); my $out_cop = $self->{'curcop'}; my $out_seq = defined($out_cop) ? $out_cop->cop_seq : undef; my $limit_seq; if (defined $root) { $limit_seq = $out_seq; my $nseq; $nseq = $self->find_scope_st($root->sibling) if ${$root->sibling}; $limit_seq = $nseq if !defined($limit_seq) or defined($nseq) && $nseq < $limit_seq; } $limit_seq = $self->{'limit_seq'} if defined($self->{'limit_seq'}) && (!defined($limit_seq) || $self->{'limit_seq'} < $limit_seq); local $self->{'limit_seq'} = $limit_seq; my $fn = sub { my ($text, $i) = @_; my $op = $ops[$i]; push @exprs, sprintf("# op: 0x%x\n%s ", $$op, $text); }; $self->walk_lineseq($root, \@ops, $fn); # $self->walk_lineseq($root, \@ops, # sub { push @exprs, $_[0]} ); my $sep = $cx ? '; ' : ";\n"; my $body = join($sep, grep {length} @exprs); my $subs = ""; if (defined $root && defined $limit_seq && !$self->{'in_format'}) { $subs = join "\n", $self->seq_subs($limit_seq); } return join($sep, grep {length} $body, $subs); }
In reply to Re^2: RFC: Location via B::Deparse
by rockyb
in thread RFC: Location via B::Deparse
by rockyb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |