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 / InputOutput / ProhibitExplicitStdin.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/InputOutput/ProhibitExplicitStdin.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::InputOutput::ProhibitExplicitStdin;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14 use List::MoreUtils qw(any);
15
16 use Perl::Critic::Utils qw{ :severities :classification &parse_arg_list };
17 use base 'Perl::Critic::Policy';
18
19 our $VERSION = '1.088';
20
21 #-----------------------------------------------------------------------------
22
23 Readonly::Scalar my $DESC => q{Use "<>" or "<ARGV>" or a prompting module instead of "<STDIN>"};
24 Readonly::Scalar my $EXPL => [216,220,221];
25
26 #-----------------------------------------------------------------------------
27
28 sub supported_parameters { return ()                                }
29 sub default_severity     { return $SEVERITY_HIGH                    }
30 sub default_themes       { return qw( core pbp maintenance )        }
31 sub applies_to           { return 'PPI::Token::QuoteLike::Readline' }
32
33 #-----------------------------------------------------------------------------
34
35 sub violates {
36     my ( $self, $elem, undef ) = @_;
37
38     return if $elem ne '<STDIN>';
39     return $self->violation( $DESC, $EXPL, $elem );
40 }
41
42
43 1;
44
45 __END__
46
47 #-----------------------------------------------------------------------------
48
49 =pod
50
51 =head1 NAME
52
53 Perl::Critic::Policy::InputOutput::ProhibitExplicitStdin - Use "<>" or "<ARGV>" or a prompting module instead of "<STDIN>".
54
55 =head1 AFFILIATION
56
57 This Policy is part of the core L<Perl::Critic> distribution.
58
59
60 =head1 DESCRIPTION
61
62 Perl has a useful magic filehandle called C<*ARGV> that checks the
63 command line and if there are any arguments, opens and reads those as
64 files.  If there are no arguments, C<*ARGV> behaves like C<*STDIN>
65 instead.  This behavior is almost always what you want if you want to
66 create a program that reads from C<STDIN>.  This is often written in
67 one of the following two equivalent forms:
68
69   while (<ARGV>) {
70     # ... do something with each input line ...
71   }
72   # or, equivalently:
73   while (<>) {
74     # ... do something with each input line ...
75   }
76
77 If you want to prompt for user input, try special purpose modules like
78 L<IO::Prompt>.
79
80
81 =head1 CONFIGURATION
82
83 This Policy is not configurable except for the standard options.
84
85
86 =head1 CAVEATS
87
88 Due to a bug in the current version of PPI (v1.119_03) and earlier,
89 the readline operator is often misinterpreted as less-than and
90 greater-than operators after a comma.  Therefore, this policy misses important cases like
91
92   my $content = join '', <STDIN>;
93
94 because it interprets that line as the nonsensical statement:
95
96   my $content = join '', < STDIN >;
97
98 When that PPI bug is fixed, this policy should start catching those
99 violations automatically.
100
101 =head1 CREDITS
102
103 Initial development of this policy was supported by a grant from the Perl Foundation.
104
105 =head1 AUTHOR
106
107 Chris Dolan <cdolan@cpan.org>
108
109 =head1 COPYRIGHT
110
111 Copyright (c) 2007-2008 Chris Dolan.  Many rights reserved.
112
113 This program is free software; you can redistribute it and/or modify
114 it under the same terms as Perl itself.  The full text of this license
115 can be found in the LICENSE file included with this module
116
117 =cut
118
119 # Local Variables:
120 #   mode: cperl
121 #   cperl-indent-level: 4
122 #   fill-column: 78
123 #   indent-tabs-mode: nil
124 #   c-indentation-style: bsd
125 # End:
126 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :