Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 20062
Status: rejected
Priority: 0/
Queue: Perl-Critic

People
Owner: thaljef [...] cpan.org
Requestors: MichaelRWolf [...] att.net
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.17
Fixed in: (no value)



Subject: HERE docs triggers spurious error and confuses reported line number
HERE docs confuse the parser. A spurious severity 5 error is created (Variable declared in a conditional statement... Declare variables outside of the condition). The line number is wrong. It's too high by 3+N, where N is the number of lines in a single previous HERE doc. (I didn't try it with multiple previous here docs, though I'd expect it to be dependant.) PPI::Version 1.115 Perl::Critic::Version 0.17 perlcritic version 0.17 Perl v5.8.7 on cygwin
Subject: perlcritic_heredoc_fix.pl
#!/usr/bin/perl use warnings; use strict; my $line_changing = " 1\n 2\n"; my $tr_format = "<tr>\n\t %s\n\t</tr>"; foreach my $var_name (qw(foo bar bas)) { printf $tr_fmt, $var_name; }
Subject: perlcritic_heredoc_bug.pl
#!/usr/bin/perl use warnings; use strict; my $line_changing = <<END_line_changing 1 2 3 END_line_changing my $tr_format = <<END_TR_FORMAT <tr> %s </tr> END_TR_FORMAT foreach my $var_name (qw(foo bar bas)) { printf $tr_fmt, $var_name; }
Sorry for the slow reply... perlcritic_heredoc_bug.pl doesn't compile because it needs semi-colons after "<<END_line_changing" and "<<END_TR_FORMAT". Without the semi-colons, the $tr_format declaraion and foreach loop are all part of the same statement, which explains why Perl::Critic throws the warning about conditional variable declaration at an earlier line. Ultimately, PPI does not ensure that your code is actually valid Perl. Doing so would require compiling the code with the interpreter, and that's exactly what PPI is _not_ intended to do. So in practice, you probably should run "perl -c" on you code before running perlcritic. -Jeff