1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitVersionStrings.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitVersionStrings;
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $DESC => q{Version string used};
23 Readonly::Scalar my $EXPL => q{Use a real number instead};
25 #-----------------------------------------------------------------------------
27 sub supported_parameters { return () }
28 sub default_severity { return $SEVERITY_MEDIUM }
29 sub default_themes { return qw(core pbp maintenance) }
30 sub applies_to { return 'PPI::Statement::Include' }
32 #-----------------------------------------------------------------------------
35 my ( $self, $elem, undef ) = @_;
38 $elem->type() eq 'use'
39 or $elem->type() eq 'require'
41 and $elem->module ne 'lib'
43 #This is a pretty crude way to verify that a version string is
44 #being used. But there are several permutations of the syntax
45 #for C<use> and C<require>. Also PPI doesn't parses strings
46 #like "5.6.1" as an integer that is being concatenated to a
47 #float. I'm not sure if this should be reported as a bug.
49 if ( $elem =~ m{ \b v? \d+ [.] \d+ [.] \d+ \b }mx ) {
50 return $self->violation( $DESC, $EXPL, $elem );
60 #-----------------------------------------------------------------------------
66 Perl::Critic::Policy::ValuesAndExpressions::ProhibitVersionStrings - Don't use strings like C<v1.4> or C<1.4.5> when including other modules.
70 This Policy is part of the core L<Perl::Critic> distribution.
75 Whenever you C<use> or C<require> a module, you can specify a minimum
76 version requirement. To ensure compatibility with older Perls, this
77 version number should be expressed as a floating-point number. Do not
78 use v-strings or three-part numbers. The Perl convention for expressing
79 version numbers as floats is: version + (patch level / 1000).
81 use Foo v1.2 qw(foo bar); # not ok
82 use Foo 1.2.03 qw(foo bar); # not ok
83 use Foo 1.00203 qw(foo bar); # ok
88 This Policy is not configurable except for the standard options.
93 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
97 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
99 This program is free software; you can redistribute it and/or modify
100 it under the same terms as Perl itself. The full text of this license
101 can be found in the LICENSE file included with this module.
107 # cperl-indent-level: 4
109 # indent-tabs-mode: nil
110 # c-indentation-style: bsd
112 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :