Perl-Critic / PPI

53 stars 44 forks source link

Allow PPI::Element::insert_before to accept multiple elements, a string or document fragments #150

Open karenetheridge opened 9 years ago

karenetheridge commented 9 years ago

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;
karenetheridge commented 9 years ago

Unless I've missed something, the closest that exists today is...

...which doesn't work reliably - see #151.