Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the PPI CPAN distribution.

Report information
The Basics
Id: 67842
Status: new
Priority: 0/
Queue: PPI

People
Owner: Nobody in particular
Requestors: gernotk [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: insert operation fails with two instances of PPI::Document (problems with destructor of PPI::Document?)
Date: Fri, 29 Apr 2011 20:52:52 +0200
To: bug-PPI [...] rt.cpan.org
From: Gernot Kieseritzky <gernotk [...] gmail.com>
Download (untitled) / with headers
text/plain 1.2k
Hi! I'd like to programmatically replace code lines in a large number of modules. This is what I did, roughly (see attached source file for a complete test case): # 1st document my $doc = PPI::Document->new(...); my $els = $doc->find(...); foreach my $el ( @$els ) { ... my $replacement_code = '...'; # 2nd temporary (!) document my $doc2 = PPI::Document->new( \$replacement_code ); my $replacement_el = $doc2->find_first(...); $el->insert_before($replacement_el); $el->delete; # push @trashcan, $doc2; } # unexpected result! PPI::Dumper->new($doc)->print; In the above example, the resulting document tree would be incomplete, i.e. $replacement_el lacks its children elements inside document $doc after being inserted into $doc. For example when I would expect in place of $el in $doc: ... PPI::Document PPI::Statement::Sub PPI::Token::Word 'sub' PPI::Token::Word 'FOO_0' PPI::Token::Prototype '()' PPI::Structure::Block { ... } ... I would only get: ... PPI::Document PPI::Statement::Sub ... However, when I keep the temporary $doc2 instance of PPI::Document around, like so: push @trashcan, $doc2 everything works as expected. Could this be a bug in the destructor of PPI::Document? Tested with PPI 1.215, Perl v5.10.1 Thanks, Gernot Kieseritzky
Download test_ppi.pl
text/x-perl 2.6k

Message body is not shown because sender requested not to inline it.



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.