Preliminary version , probably false positive on proper interpolation

https://metacpan.org/pod/PPI::Token::Quote::Double

https://metacpan.org/pod/PPIx::QuoteLike

https://metacpan.org/pod/Perl::Critic::Utils#is_method_call(-$element-)

#!/usr/bin/perl -- use strict; use warnings; use Perl::Critic; my $code = \<<'__CODE__'; say "$hi ->bye"; say "$hi -> bye"; say "$hi->bye"; # line 3 say "U @{[~~gmtime]} GOTS $account->balance LEFTZ"; __CODE__ print "$$code\n"; my $critic = Perl::Critic->new( -verbose => 11, ### these fail me -theme => 'yourmother', -include => ['interpolate', ], ); $critic->config()->add_policy( -policy => 'Perl::Critic::Policy::ValuesAndExpressions::SubMethodC +allsDontInterpolate', ); my @violations = $critic->critique( $code ); print @violations; exit( 0 ); BEGIN { package Perl::Critic::Policy::ValuesAndExpressions::SubMethodCalls +DontInterpolate; $INC{ join('/',split '::', __PACKAGE__).'.pm' } = __FILE__; our $VERSION = '0.01'; use strict; use warnings; use Readonly; use parent 'Perl::Critic::Policy'; use Perl::Critic::Utils qw{ :severities }; sub supported_parameters { return () } sub default_severity { return $SEVERITY_LOWEST } # didn't work sub default_themes { return qw< yourmother > } # sub default_themes { return qw< bugs maintenance yourmother +> } sub applies_to { return qw/PPI::Statement/ } Readonly::Scalar my $DESC => q{sub/method calls dont interpolate. This + won't output what you seem to expect.}; Readonly::Scalar my $EXPL => q{Maybe $foo->bar() should be @{[ $foo->b +ar ]} cause sub/method calls don't interpolate like $variables.)}; sub violates { my ( $self, $elem, undef ) = @_; my $qqs = $elem->find('PPI::Token::Quote::Double') ; for my $qq ( @$qqs ){ my $content = $qq->content ; if( $content =~ /(?<!\\)(?:\\\\)*[\$]/ and $content =~ m{\w->\ +w} ){ return $self->violation( $DESC, $EXPL, $elem ); } } return; } 1; }

In reply to Re^2: Perl::Critic policy to catch quoted execution? ( Perl::Critic::Policy::ValuesAndExpressions::SubMethodCallsDontInterpolate ) by Anonymous Monk
in thread Perl::Critic policy to catch quoted execution? by Your Mother

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.