PPI
PPI copied to clipboard
Allow PPI::Element::insert_before to accept multiple elements, a string or document fragments
PPI::Element::insert_before is documented as:
In future, this method may be enhanced to allow the insertion of multiple
Elements, inline-parsed code strings or L<PPI::Document::Fragment> objects.
Indeed, this method (and insert_after
) appear to be the ideal natural interfaces for inserting a new code snippet into an existing document. Unless I've missed something, the closest that exists today is:
my $element; # the element in the existing document to insert before
my $doc = PPI::Document->new(\$code_snippet);
$element->insert_before($_) foreach $doc->schildren;
Unless I've missed something, the closest that exists today is...
...which doesn't work reliably - see #151.