| 1 | package Perl::Critic::Policy::Community::WarningsSwitch; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Perl::Critic::Utils qw(:severities :classification :ppi); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = 'v1.0.4'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use constant DESC => 'Using -w switch'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use constant EXPL => 'Don\'t use -w (or -W), it\'s too eager. use warnings; instead.'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 8 | ▶ | sub supported_parameters { () } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 6 | ▶ | sub default_severity { $SEVERITY_LOW } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub default_themes { 'community' } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 8 | ▶ | sub applies_to { 'PPI::Document' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 8 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 8 | my ($self, $elem) = @_; | |||||||||||||||||||||||||||
| 21 | 8 | my $shebang = $elem->first_token; | |||||||||||||||||||||||||||
| 22 | 8 | ▶ | return () unless $shebang->isa('PPI::Token::Comment') and $shebang->content =~ m/^#!/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$shebang->isa("PPI::Token::Comment") and $shebang->content =~ /^#!/
MC/DC50%1/2
$shebang->isa("PPI::Token::Comment") and $shebang->content =~ /^#!/
$shebang->isa("PPI::Token::Comment")
$shebang->content =~ /^#!/
Truth table66%2/3
A and B
A= $shebang->isa("PPI::Token::Comment")B= $shebang->content =~ /^#!/
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 7 | ▶ | return $self->violation(DESC, EXPL, $elem) if $shebang->content =~ m/\h-[a-zA-Z]*[wW]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | return (); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | 1; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 NAME | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | Perl::Critic::Policy::Community::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::Community>. | ||||||||||||||||||||||||||||
| 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> | ||||||||||||||||||||||||||||