[Parseperl-discuss] Moving an Expression
Brought to you by:
adamkennedy
From: Stuart J. <sa...@th...> - 2007-03-13 16:00:31
|
I have a line of code like: foo(bar("Hello World")); And I want to re-factor it into: bar("Hello World"); Of course the real statements are likely to be more complex, multiple lines, conditionals, etc. I can remove the 'foo' bareword easily enough but I can't figure out how to get rid of the outer list without loosing the inner 'bar' expression. Is PPI currently capable of such things? I have been trying variations on the code below. thanks, Stuart Johnston my $code = q{foo(bar("Hello World"));}; my $d = PPI::Document->new(\$code); my $foo = $d->find_first('PPI::Token::Word'); my $list = $foo->next_sibling; my $exp = $list->child(0); $exp->remove; $list->delete; $foo->insert_after($exp); |