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 / ControlStructures / ProhibitCStyleForLoops.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/ControlStructures/ProhibitCStyleForLoops.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::ControlStructures::ProhibitCStyleForLoops;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :characters :severities };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC => q{C-style "for" loop used};
23 Readonly::Scalar my $EXPL => [ 100 ];
24
25 #-----------------------------------------------------------------------------
26
27 sub supported_parameters { return ()                         }
28 sub default_severity     { return $SEVERITY_LOW              }
29 sub default_themes       { return qw( core pbp maintenance ) }
30 sub applies_to           { return 'PPI::Structure::ForLoop'  }
31
32 #-----------------------------------------------------------------------------
33
34 sub violates {
35     my ( $self, $elem, undef ) = @_;
36
37     if ( _is_cstyle($elem) ) {
38         return $self->violation( $DESC, $EXPL, $elem );
39     }
40     return;    #ok!
41 }
42
43 sub _is_cstyle {
44     my $elem      = shift;
45     my $nodes_ref = $elem->find('PPI::Token::Structure');
46     return if !$nodes_ref;
47     my @semis     = grep { $_ eq $SCOLON } @{$nodes_ref};
48     return scalar @semis == 2;
49 }
50
51 1;
52
53 __END__
54
55 #-----------------------------------------------------------------------------
56
57 =pod
58
59 =head1 NAME
60
61 Perl::Critic::Policy::ControlStructures::ProhibitCStyleForLoops - Write C<for(0..20)> instead of C<for($i=0; $i<=20; $i++)>.
62
63 =head1 AFFILIATION
64
65 This Policy is part of the core L<Perl::Critic> distribution.
66
67
68 =head1 DESCRIPTION
69
70 The 3-part C<for> loop that Perl inherits from C is butt-ugly, and only
71 really necessary if you need irregular counting.  The very Perlish
72 C<..> operator is much more elegant and readable.
73
74   for($i=0; $i<=$max; $i++){      #ick!
75       do_something($i);
76   }
77
78   for(0..$max){                   #very nice
79     do_something($_);
80   }
81
82
83 =head1 CONFIGURATION
84
85 This Policy is not configurable except for the standard options.
86
87
88 =head1 AUTHOR
89
90 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
91
92 =head1 COPYRIGHT
93
94 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
95
96 This program is free software; you can redistribute it and/or modify
97 it under the same terms as Perl itself.  The full text of this license
98 can be found in the LICENSE file included with this module.
99
100 =cut
101
102 # Local Variables:
103 #   mode: cperl
104 #   cperl-indent-level: 4
105 #   fill-column: 78
106 #   indent-tabs-mode: nil
107 #   c-indentation-style: bsd
108 # End:
109 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :