blib/lib/Perl/Critic/Policy/InputOutput/ProhibitExplicitStdin.pm

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