Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / ValuesAndExpressions / ProhibitVersionStrings.pm
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) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitVersionStrings;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC => q{Version string used};
23 Readonly::Scalar my $EXPL => q{Use a real number instead};
24
25 #-----------------------------------------------------------------------------
26
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' }
31
32 #-----------------------------------------------------------------------------
33
34 sub violates {
35     my ( $self, $elem, undef ) = @_;
36     if (
37         (
38                 $elem->type() eq 'use'
39             or  $elem->type() eq 'require'
40         )
41         and $elem->module ne 'lib'
42     ) {
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.
48
49         if ( $elem =~ m{ \b v? \d+ [.] \d+ [.] \d+ \b }mx ) {
50             return $self->violation( $DESC, $EXPL, $elem );
51         }
52     }
53     return;    #ok!
54 }
55
56 1;
57
58 __END__
59
60 #-----------------------------------------------------------------------------
61
62 =pod
63
64 =head1 NAME
65
66 Perl::Critic::Policy::ValuesAndExpressions::ProhibitVersionStrings - Don't use strings like C<v1.4> or C<1.4.5> when including other modules.
67
68 =head1 AFFILIATION
69
70 This Policy is part of the core L<Perl::Critic> distribution.
71
72
73 =head1 DESCRIPTION
74
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).
80
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
84
85
86 =head1 CONFIGURATION
87
88 This Policy is not configurable except for the standard options.
89
90
91 =head1 AUTHOR
92
93 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
94
95 =head1 COPYRIGHT
96
97 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
98
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.
102
103 =cut
104
105 # Local Variables:
106 #   mode: cperl
107 #   cperl-indent-level: 4
108 #   fill-column: 78
109 #   indent-tabs-mode: nil
110 #   c-indentation-style: bsd
111 # End:
112 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :