From: Vincent Pit Date: Sun, 25 Jul 2010 19:47:54 +0000 (+0200) Subject: Add some linefeeds X-Git-Tag: rt63842~8 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=e4de83a1e5557e69ecdaa3ac6c61a73b73da0bc0;p=perl%2Fmodules%2FB-RecDeparse.git Add some linefeeds --- diff --git a/lib/B/RecDeparse.pm b/lib/B/RecDeparse.pm index 15adc07..4f7b636 100644 --- a/lib/B/RecDeparse.pm +++ b/lib/B/RecDeparse.pm @@ -81,9 +81,13 @@ sub _parse_args { sub new { my $class = shift; $class = ref($class) || $class || __PACKAGE__; + my ($deparse, $level) = _parse_args(@_); + my $self = bless $class->SUPER::new(@$deparse), $class; + $self->{brd_level} = $level; + return $self; } @@ -92,22 +96,27 @@ sub _recurse { } sub compile { - my $bd = B::Deparse->new(); my @args = @_; + + my $bd = B::Deparse->new(); my ($deparse, $level) = _parse_args(@args); + my $compiler = $bd->coderef2text(B::Deparse::compile(@$deparse)); $compiler =~ s/ ['"]? B::Deparse ['"]? \s* -> \s* (new) \s* \( ([^\)]*) \) /B::RecDeparse->$1(deparse => [ $2 ], level => $level)/gx; $compiler = eval 'sub ' . $compiler; die if $@; + return $compiler; } sub init { my $self = shift; + $self->{brd_cur} = 0; $self->{brd_sub} = 0; + $self->SUPER::init(@_); } @@ -115,9 +124,11 @@ my $key = $; . __PACKAGE__ . $;; if (FOOL_SINGLE_DELIM) { my $oldsd = *B::Deparse::single_delim{CODE}; + no warnings 'redefine'; *B::Deparse::single_delim = sub { my $body = $_[2]; + if ((caller 1)[0] eq __PACKAGE__ and $body =~ s/^$key//) { return $body; } else { @@ -128,16 +139,20 @@ if (FOOL_SINGLE_DELIM) { sub pp_entersub { my $self = shift; + my $body = do { local $self->{brd_sub} = 1; $self->SUPER::pp_entersub(@_); }; + $body =~ s/^&\s*(\w)/$1/ if $self->_recurse; + return $body; } sub pp_refgen { my $self = shift; + return do { local $self->{brd_sub} = 0; $self->SUPER::pp_refgen(@_); @@ -146,21 +161,25 @@ sub pp_refgen { sub pp_gv { my $self = shift; + my $body; if ($self->{brd_sub} <= 0 || !$self->_recurse) { $body = $self->SUPER::pp_gv(@_); } else { my $gv = $self->gv_or_padgv($_[0]); + $body = do { local @{$self}{qw/brd_sub brd_cur/} = (0, $self->{brd_cur} + 1); 'sub ' . $self->indent($self->deparse_sub($gv->CV)); }; + if (FOOL_SINGLE_DELIM) { $body = $key . $body; } else { $body .= '->'; } } + return $body; }