blahblahblah has asked for the wisdom of the Perl Monks concerning the following question:
I have an open PPI document, and I want to insert an assignment statement at a certain point. $lastVar represents the statement after which I want to insert my new line.
I can successfully add a comment with the following:
However, I want to add a full statement. If PPI::Statement had a set_content method, this is sort of what I'd like to do:my $newStatement = PPI::Token::Comment->new(); $newStatement->set_content(qq{\n# $newVar = ${quote}$newValue${quote +};\n}); $lastVar->insert_after($newStatement);
Can anyone point me in the right direction? Do I need to create a new PPI::Something and the build it up piece by piece from a bunch of other PPI::Something's, or is there a simpler way to add a block of code to a document?my $newStatement = PPI::Statement->new(); $newStatement->set_content(qq{\n1; #testing\n});
Thanks,
Joe
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: how to add a PPI:Statement to a document?
by Anonymous Monk on Dec 29, 2007 at 11:39 UTC | |
by Anonymous Monk on Jan 02, 2008 at 07:20 UTC | |
by Anonymous Monk on Jan 02, 2008 at 07:28 UTC |
Back to
Seekers of Perl Wisdom