From bf2ae02c00c26af95e6172d088efc8ffe42b0283 Mon Sep 17 00:00:00 2001 From: George Hartzell Date: Sat, 29 Mar 2014 14:12:00 -0700 Subject: [PATCH] Fix up PPI::Token::insert_{after,before}. I stumbled across this while trying to make Dist::Zilla::Plugin::PkgVersion work better with perlcritic. More info here: https://github.com/rjbs/Dist-Zilla/pull/168 The comments for PPI::Token::insert_{after,before} say that they may only insert statements, but the code inexplicably requires PPI::Structures. I think that requiring a Statement is appropriate the right thing, this commit makes the code match the comment. The tests in t still pass. I'll submit a pull request and hope for feedback from folks wise. --- lib/PPI/Token.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/PPI/Token.pm b/lib/PPI/Token.pm index 6f35e338..f8667b96 100644 --- a/lib/PPI/Token.pm +++ b/lib/PPI/Token.pm @@ -172,7 +172,7 @@ sub content { sub insert_before { my $self = shift; my $Element = _INSTANCE(shift, 'PPI::Element') or return undef; - if ( $Element->isa('PPI::Structure') ) { + if ( $Element->isa('PPI::Statement') ) { return $self->__insert_before($Element); } elsif ( $Element->isa('PPI::Token') ) { return $self->__insert_before($Element); @@ -184,7 +184,7 @@ sub insert_before { sub insert_after { my $self = shift; my $Element = _INSTANCE(shift, 'PPI::Element') or return undef; - if ( $Element->isa('PPI::Structure') ) { + if ( $Element->isa('PPI::Statement') ) { return $self->__insert_after($Element); } elsif ( $Element->isa('PPI::Token') ) { return $self->__insert_after($Element);