| 1 | # Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Perl-Critic-Pulp is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 4 | # it under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||
| 5 | # Free Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||
| 6 | # version. | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # Perl-Critic-Pulp is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||
| 9 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||
| 10 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||||||||||||||||||
| 11 | # for more details. | ||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||
| 13 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||
| 14 | # with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | package Perl::Critic::Policy::Modules::ProhibitModuleShebang; | ||||||||||||||||||||||||||||
| 17 | 40 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 40 | ▶ | use List::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 40 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 40 | ▶ | use Perl::Critic::Utils 0.21; # version 0.21 for shebang_line() | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 40 | ▶ | use Perl::Critic::Pulp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 40 | ▶ | use Perl::Critic::Pulp::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||
| 28 | #use Smart::Comments; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 40 | our $VERSION = 100; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 40 | ▶ | use constant supported_parameters => | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | ({ name => 'allow_bin_false', | ||||||||||||||||||||||||||||
| 34 | description => 'Whether to allow #!/bin/false', | ||||||||||||||||||||||||||||
| 35 | behavior => 'boolean', | ||||||||||||||||||||||||||||
| 36 | default_string => '1', | ||||||||||||||||||||||||||||
| 37 | 40 | }); | |||||||||||||||||||||||||||
| 38 | 40 | ▶ | use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOW; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 40 | ▶ | use constant default_themes => ('pulp', 'cosmetic'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 40 | ▶ | use constant applies_to => 'PPI::Document'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # only ever gives one violation | ||||||||||||||||||||||||||||
| 43 | 40 | ▶ | use constant default_maximum_violations_per_document => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 7 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 7 | my ($self, $elem, $document) = @_; | |||||||||||||||||||||||||||
| 47 | ### ProhibitModuleShebang elem: $elem->content | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 7 | my $filename = $document->filename; | |||||||||||||||||||||||||||
| 50 | 7 | ▶ | (defined $filename && $filename =~ /\.pm$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $filename and $filename =~ /\.pm$/
MC/DC50%1/2
defined $filename and $filename =~ /\.pm$/
defined $filename
$filename =~ /\.pm$/
Truth table66%2/3
A and B
A= defined $filenameB= $filename =~ /\.pm$/
| |||||||||||||||||||||||||||||
| 51 | or return; # only .pm files are modules | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 6 | ▶ | my $shebang = Perl::Critic::Utils::shebang_line($document) | ||||||||||||||||||||||||||
|
Condition100%2/2
Perl::Critic::Utils::shebang_line($document) || (return)
MC/DC100%1/1
Perl::Critic::Utils::shebang_line($document) || (return)
Perl::Critic::Utils::shebang_line($document)
Truth table100%2/2
A
A= Perl::Critic::Utils::shebang_line($document)
| |||||||||||||||||||||||||||||
| 54 | || return; # no #! at all | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 4 | ▶ | if ($self->{'_allow_bin_false'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 3 | ▶ | if ($shebang =~ m{^#!\s*/bin/false\s*$}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 1 | return; # /bin/false allowed | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 3 | return $self->violation ('Don\'t use #! in a module file', | |||||||||||||||||||||||||||
| 62 | '', | ||||||||||||||||||||||||||||
| 63 | $document); | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 40 | 1; | |||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||