File Coverage

blib/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitConstantPragma.pm
Criterion Covered Total %
statement 25 25 100.0
branch 2 2 100.0
condition 3 3 100.0
subroutine 11 11 100.0
pod 4 5 80.0
total 45 46 97.8


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::ValuesAndExpressions::ProhibitConstantPragma;
2              
3 40     40   26591 use 5.010001;
  40         163  
4 40     40   239 use strict;
  40         101  
  40         852  
5 40     40   237 use warnings;
  40         85  
  40         1177  
6 40     40   254 use Readonly;
  40         100  
  40         2171  
7              
8 40     40   272 use Perl::Critic::Utils qw{ :severities };
  40         113  
  40         2195  
9 40     40   5234 use parent 'Perl::Critic::Policy';
  40         109  
  40         222  
10              
11             our $VERSION = '1.146';
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly::Scalar my $DESC => q{Pragma "constant" used};
16             Readonly::Scalar my $EXPL => [ 55 ];
17              
18             #-----------------------------------------------------------------------------
19              
20 91     91 0 1673 sub supported_parameters { return () }
21 76     76 1 386 sub default_severity { return $SEVERITY_HIGH }
22 92     92 1 378 sub default_themes { return qw( core bugs pbp ) }
23 34     34 1 105 sub applies_to { return 'PPI::Statement::Include' }
24              
25             #-----------------------------------------------------------------------------
26              
27             sub violates {
28 63     63 1 207 my ( $self, $elem, undef ) = @_;
29 63 100 100     180 if ( $elem->type() eq 'use' && $elem->pragma() eq 'constant' ) {
30 2         156 return $self->violation( $DESC, $EXPL, $elem );
31             }
32 61         3271 return; #ok!
33             }
34              
35             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 :