Skip to content

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

@karenetheridge

Description

@karenetheridge

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions