File Coverage

blib/lib/Perl/Critic/Policy/Freenode/WarningsSwitch.pm
Criterion Covered Total %
statement 26 27 96.3
branch 4 4 100.0
condition 2 3 66.6
subroutine 10 11 90.9
pod 4 5 80.0
total 46 50 92.0


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Freenode::WarningsSwitch;
2              
3 1     1   542 use strict;
  1         2  
  1         23  
4 1     1   4 use warnings;
  1         2  
  1         24  
5              
6 1     1   5 use Perl::Critic::Utils qw(:severities :classification :ppi);
  1         1  
  1         42  
7 1     1   299 use parent 'Perl::Critic::Policy';
  1         2  
  1         5  
8              
9             our $VERSION = '0.032';
10              
11 1     1   66 use constant DESC => 'Using -w switch';
  1         2  
  1         45  
12 1     1   5 use constant EXPL => 'Don\'t use -w (or -W), it\'s too eager. use warnings; instead.';
  1         1  
  1         239  
13              
14 8     8 0 20331 sub supported_parameters { () }
15 6     6 1 88 sub default_severity { $SEVERITY_LOW }
16 0     0 1 0 sub default_themes { 'freenode' }
17 8     8 1 28712 sub applies_to { 'PPI::Document' }
18              
19             sub violates {
20 8     8 1 68 my ($self, $elem) = @_;
21 8         41 my $shebang = $elem->first_token;
22 8 100 66     217 return () unless $shebang->isa('PPI::Token::Comment') and $shebang->content =~ m/^#!/;
23            
24 7 100       50 return $self->violation(DESC, EXPL, $elem) if $shebang->content =~ m/\h-[a-zA-Z]*[wW]/;
25            
26 1         7 return ();
27             }
28              
29             1;
30              
31             =head1 NAME
32              
33             Perl::Critic::Policy::Freenode::WarningsSwitch - Scripts should not use the -w
34             switch on the shebang line
35              
36             =head1 DESCRIPTION
37              
38             The C<-w> switch enables warnings globally in a perl program, including for any
39             modules that did not explicitly enable or disable any warnings. The C<-W>
40             switch enables warnings even for modules that explicitly disabled them. The
41             primary issue with this is enabling warnings for code that you did not write.
42             Some of these modules may not be designed to run with warnings enabled, but
43             still work fine. Instead, use L<warnings> within your own code only.
44              
45             #!/usr/bin/perl -w # not ok
46             #!/usr/bin/perl -W # not ok
47             use warnings; # ok
48              
49             =head1 AFFILIATION
50              
51             This policy is part of L<Perl::Critic::Freenode>.
52              
53             =head1 CONFIGURATION
54              
55             This policy is not configurable except for the standard options.
56              
57             =head1 AUTHOR
58              
59             Dan Book, C<dbook@cpan.org>
60              
61             =head1 COPYRIGHT AND LICENSE
62              
63             Copyright 2015, Dan Book.
64              
65             This library is free software; you may redistribute it and/or modify it under
66             the terms of the Artistic License version 2.0.
67              
68             =head1 SEE ALSO
69              
70             L<Perl::Critic>, L<warnings>