« blib/lib/Perl/Critic/Policy/ControlStructures/ProhibitCascadingIfElse.pm
↑ Summary
blib/lib/Perl/Critic/Policy/Modules/ProhibitMultiplePackages.pm »
| 1 | package Perl::Critic::Policy::ValuesAndExpressions::ProhibitConstantPragma; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 40 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 40 | ▶ | use Perl::Critic::Utils qw{ :severities }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 40 | our $VERSION = '1.150'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 40 | Readonly::Scalar my $DESC => q{Pragma "constant" used}; | |||||||||||||||||||||||||||
| 16 | 40 | Readonly::Scalar my $EXPL => [ 55 ]; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 90 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 75 | ▶ | sub default_severity { return $SEVERITY_HIGH } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 92 | ▶ | sub default_themes { return qw( core bugs pbp ) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 33 | ▶ | sub applies_to { return 'PPI::Statement::Include' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub violates { | ||||||||||||||||||||||||||||
| 28 | 61 | ▶ | my ( $self, $elem, undef ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 61 | ▶ | if ( $elem->type() eq 'use' && $elem->pragma() eq 'constant' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$elem->type eq "use" and $elem->pragma eq "constant"
MC/DC0%0/2
$elem->type eq "use" and $elem->pragma eq "constant"
$elem->type eq "use"
$elem->pragma eq "constant"
Truth table66%2/3
A and B
A= $elem->type eq "use"B= $elem->pragma eq "constant"
| |||||||||||||||||||||||||||||
| 30 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 61 | return; #ok! | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 40 | 1; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | __END__ | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =pod | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =head1 NAME | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | Perl::Critic::Policy::ValuesAndExpressions::ProhibitConstantPragma - Don't C<< use constant FOO => 15 >>. | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =head1 AFFILIATION | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | This Policy is part of the core L<Perl::Critic|Perl::Critic> distribution. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | Named constants are a good thing. But don't use the C<constant> | ||||||||||||||||||||||||||||
| 55 | pragma because barewords don't interpolate. Instead use the | ||||||||||||||||||||||||||||
| 56 | L<Readonly|Readonly> module. | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | use constant FOOBAR => 42; #not ok | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | use Readonly; | ||||||||||||||||||||||||||||
| 61 | Readonly my $FOOBAR => 42; #ok | ||||||||||||||||||||||||||||
| 62 | Readonly::Scalar my $FOOBAR => 42; #ok | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | This Policy is not configurable except for the standard options. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 79 | it under the same terms as Perl itself. The full text of this license | ||||||||||||||||||||||||||||
| 80 | can be found in the LICENSE file included with this module. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =cut | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # Local Variables: | ||||||||||||||||||||||||||||
| 85 | # mode: cperl | ||||||||||||||||||||||||||||
| 86 | # cperl-indent-level: 4 | ||||||||||||||||||||||||||||
| 87 | # fill-column: 78 | ||||||||||||||||||||||||||||
| 88 | # indent-tabs-mode: nil | ||||||||||||||||||||||||||||
| 89 | # c-indentation-style: bsd | ||||||||||||||||||||||||||||
| 90 | # End: | ||||||||||||||||||||||||||||
| 91 | # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : | ||||||||||||||||||||||||||||