File Coverage

blib/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitVersionStrings.pm
Criterion Covered Total %
statement 30 30 100.0
branch 8 8 100.0
condition n/a
subroutine 11 11 100.0
pod 4 5 80.0
total 53 54 98.1


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::ValuesAndExpressions::ProhibitVersionStrings;
2              
3 40     40   318374 use 5.010001;
  40         176  
4 40     40   237 use strict;
  40         96  
  40         1277  
5 40     40   221 use warnings;
  40         97  
  40         977  
6 40     40   589 use Readonly;
  40         116  
  40         2102  
7              
8 40     40   267 use Perl::Critic::Utils qw{ :severities };
  40         114  
  40         2346  
9 40     40   5392 use parent 'Perl::Critic::Policy';
  40         108  
  40         385  
10              
11             our $VERSION = '1.148';
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly::Scalar my $DESC => q{Version string used};
16             Readonly::Scalar my $EXPL => q{Use a real number instead};
17              
18             #-----------------------------------------------------------------------------
19              
20 93     93 0 1738 sub supported_parameters { return () }
21 88     88 1 405 sub default_severity { return $SEVERITY_MEDIUM }
22 86     86 1 405 sub default_themes { return qw(core pbp maintenance) }
23 34     34 1 113 sub applies_to { return 'PPI::Statement::Include' }
24              
25             #-----------------------------------------------------------------------------
26              
27             sub violates {
28 80     80 1 209 my ($self, $elem, undef) = @_;
29              
30 80         150 my $version;
31              
32 80 100       229 if ( my $module = $elem->module() ) {
33 72 100       2100 return if $module eq 'lib';
34              
35 71         213 $version = $elem->module_version();
36             } else {
37 8         261 $version = $elem->schild(1);
38             }
39              
40 79 100       3531 return if not defined $version;
41 22 100       104 return if not $version->isa('PPI::Token::Number::Version');
42              
43 14         64 return $self->violation($DESC, $EXPL, $elem);
44             }
45              
46             1;
47              
48             __END__
49              
50             #-----------------------------------------------------------------------------
51              
52             =pod
53              
54             =head1 NAME
55              
56             Perl::Critic::Policy::ValuesAndExpressions::ProhibitVersionStrings - Don't use strings like C<v1.4> or C<1.4.5> when including other modules.
57              
58              
59             =head1 AFFILIATION
60              
61             This Policy is part of the core L<Perl::Critic|Perl::Critic>
62             distribution.
63              
64              
65             =head1 DESCRIPTION
66              
67             Whenever you C<use> or C<require> a module, you can specify a minimum
68             version requirement. To ensure compatibility with older Perls, this
69             version number should be expressed as a floating-point number. Do not
70             use v-strings or three-part numbers. The Perl convention for
71             expressing version numbers as floats is: version + (patch level /
72             1000).
73              
74             use Foo v1.2 qw(foo bar); # not ok
75             use Foo 1.2.03 qw(foo bar); # not ok
76             use Foo 1.00203 qw(foo bar); # ok
77              
78              
79             =head1 CONFIGURATION
80              
81             This Policy is not configurable except for the standard options.
82              
83              
84             =head1 AUTHOR
85              
86             Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
87              
88             =head1 COPYRIGHT
89              
90             Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
91              
92             This program is free software; you can redistribute it and/or modify
93             it under the same terms as Perl itself. The full text of this license
94             can be found in the LICENSE file included with this module.
95              
96             =cut
97              
98             # Local Variables:
99             # mode: cperl
100             # cperl-indent-level: 4
101             # fill-column: 78
102             # indent-tabs-mode: nil
103             # c-indentation-style: bsd
104             # End:
105             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :