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) $
6 ##############################################################################
8 package Perl::Critic::Policy::InputOutput::ProhibitExplicitStdin;
14 use List::MoreUtils qw(any);
16 use Perl::Critic::Utils qw{ :severities :classification &parse_arg_list };
17 use base 'Perl::Critic::Policy';
19 our $VERSION = '1.088';
21 #-----------------------------------------------------------------------------
23 Readonly::Scalar my $DESC => q{Use "<>" or "<ARGV>" or a prompting module instead of "<STDIN>"};
24 Readonly::Scalar my $EXPL => [216,220,221];
26 #-----------------------------------------------------------------------------
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' }
33 #-----------------------------------------------------------------------------
36 my ( $self, $elem, undef ) = @_;
38 return if $elem ne '<STDIN>';
39 return $self->violation( $DESC, $EXPL, $elem );
47 #-----------------------------------------------------------------------------
53 Perl::Critic::Policy::InputOutput::ProhibitExplicitStdin - Use "<>" or "<ARGV>" or a prompting module instead of "<STDIN>".
57 This Policy is part of the core L<Perl::Critic> distribution.
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:
70 # ... do something with each input line ...
74 # ... do something with each input line ...
77 If you want to prompt for user input, try special purpose modules like
83 This Policy is not configurable except for the standard options.
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
92 my $content = join '', <STDIN>;
94 because it interprets that line as the nonsensical statement:
96 my $content = join '', < STDIN >;
98 When that PPI bug is fixed, this policy should start catching those
99 violations automatically.
103 Initial development of this policy was supported by a grant from the Perl Foundation.
107 Chris Dolan <cdolan@cpan.org>
111 Copyright (c) 2007-2008 Chris Dolan. Many rights reserved.
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
121 # cperl-indent-level: 4
123 # indent-tabs-mode: nil
124 # c-indentation-style: bsd
126 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :