Perl-Critic / PPI

53 stars 44 forks source link

please implement "replace" method #189

Closed rjbs closed 1 year ago

rjbs commented 8 years ago

The method $elem->replace($elem) is documented but unimplemented. It would be very useful. Right now I'm using the undocumented, untested, unused __replace_child method, and I feel awful about it.

Please provide a means to do this legitimately.

gugod commented 6 years ago

I use insert_before + remove to achieve replacing element with a manually constructed one.

$elem->insert_before($new_elem);
$elem->remove;

Although I'm not sure if this breaks consistency of the PPI::Document object in question, for the purpose of rewriting code, this seems to work.

oalders commented 3 years ago

At the very least, maybe the docs could indicate that replace is aspirational. I had forgotten about this and it bit me again today.

oalders commented 3 years ago

Link to a PR which addresses this https://github.com/Perl-Critic/PPI/pull/254

oalders commented 1 year ago

Closed via #254