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: 61301
Status: resolved
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: andyb [...] operamail.com
Cc:
AdminCc:

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



Subject: Bug in policy ValuesAndExpressions::ProhibitCommaSeparatedStatements
Hi, The following seems to be a bug in Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements The following piece of code causes the error to be reported beneath it: # cal table suffixes based on mode has q{_cal_table_suffixes} => ( isa => q{HashRef}, is => q{ro}, lazy_build => 1, ); sub _build__cal_table_suffixes { my ( $self ) = @_; return { 1 => $self->pb_cal_pipeline_conf()->{cal_table_suffix}, 2 => $self->pb_cal_pipeline_conf()->{mode2_cal_table_suffix}, }; } not ok 49 - Test::Perl::Critic for "lib/npg_pipeline/roles/business/harold_calibration_reqs.pm" # Failed test 'Test::Perl::Critic for "lib/npg_pipeline/roles/business/harold_calibration_reqs.pm"' # at /Users/ajb/dev/perl/5.10.1/lib/site_perl/5.10.1/Test/Perl/Critic.pm line 110. # # Perl::Critic found these violations in "lib/npg_pipeline/roles/business/harold_calibration_reqs.pm": # Comma used to separate statements at line 202, column 5. See pages 68,71 of PBP. (Severity: 4) Whereas if I declare the HashRef into a scalar, and then return the scalar sub _build__cal_table_suffixes { my ( $self ) = @_; my $return = { 1 => $self->pb_cal_pipeline_conf()->{cal_table_suffix}, 2 => $self->pb_cal_pipeline_conf()->{mode2_cal_table_suffix}, }; return $return; } ok 49 - Test::Perl::Critic for "lib/npg_pipeline/roles/business/harold_calibration_reqs.pm" With laziness and the idea of less code introduces less errors, I see not being allowed to directly create the anonymous hash in the return to be a bug, rather than an improvement to code readability and maintainability. (I would be happy to see and follow an explicit policy which disallowed this, but not based inside another unrelated policy). Thanks for Perl::Critic, I hope that this bug report is useful. Cheers Andy
Thanks for the report. Actually, the bug turns out to be in PPI. The perlref documentation says (in a somewhat roundabout way) that in "return { foo => 1 }" the curly brackets are interpreted as a hash constructor, not a block. RT ticket 61305 has been filed in the PPI queue over this. The proposed fix (if accepted) amounts to adding "'return' => 'PPI::Structure::Constructor'" to the %CURLY_CLASSES hash at or about line 1068 in PPI::Lexer. In the meantime, another way to force both Perl and PPI to interpret curly brackets as a hash constructor is with a leading "+" (i.e. "return +{ foo => 1 }". Yes, it looks funny, but it is documented in perlref also, in pretty much the same place.
This appears to me to be fixed by PPI 1.215. SVN commit 4047 bumps the PPI dependency to that version, and adds a test for compliance to t/ValuesAndExpressions/ProibitCommaSeparatedStatements.