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:
88473
Status:
new
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
dan.p.mcgee [...] gmail.com
Cc:
AdminCc:

BugTracker
Severity:
(no value)
Broken in:
(no value)
Fixed in:
(no value)



Subject: "use constant" Inconsistency
Date: Fri, 6 Sep 2013 15:50:09 -0400
To: bug-Perl-Critic@rt.cpan.org
From: Dan McGee <dan.p.mcgee@gmail.com>
Perl::Critic 1.118 (as distributed as libperl-critic-perl with with Ubuntu 13.04) seems to contradict itself regarding the use of "use constant". A line that assigns an arbitrary constant number to a variable produces this warning, which includes the "constant" pragma in its recommended alternatives:

42 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead at line 13, column 31.  Unnamed numeric literals make code less maintainable.  (Severity: 2)

However, inserting the constant pragma as suggested turns a minor warning into a more severe warning and splatters magenta all over my terminal:

use constant {
    LUCKY_NUMBER => 42
}

Pragma "constant" used at line 13, column 1.  See page 55 of PBP.  (Severity: 4)

Although I learned a lot about constants in Perl from the experience, Perl::Critic probably shouldn't be recommending a fix that it likes even less than the original problem.

Thanks for reading, and hope this is helpful!

Dan


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.