« Policy/Modules/ProhibitModuleShebang.pm
↑ Summary
Policy/Documentation/ProhibitDuplicateSeeAlso.pm »
| 1 | # Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # This file is part of Perl-Critic-Pulp. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # Perl-Critic-Pulp is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 6 | # it under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||
| 7 | # Free Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||
| 8 | # version. | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # Perl-Critic-Pulp is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||
| 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||
| 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||||||||||||||||||
| 13 | # for more details. | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||
| 16 | # with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | package Perl::Critic::Policy::Miscellanea::TextDomainUnused; | ||||||||||||||||||||||||||||
| 20 | 40 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 40 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 40 | ▶ | use Perl::Critic::Utils qw(is_function_call); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 40 | our $VERSION = 100; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 40 | ▶ | use constant supported_parameters => (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 40 | ▶ | use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOW; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 40 | ▶ | use constant default_themes => qw(pulp cosmetic); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 40 | ▶ | use constant applies_to => 'PPI::Document'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 14 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 14 | my ($self, $elem, $document) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 14 | ▶ | my $use = _find_use_locale_textdomain($document) || return; | ||||||||||||||||||||||||||
|
Condition50%1/2
_find_use_locale_textdomain($document) || (return)
MC/DC0%0/1
_find_use_locale_textdomain($document) || (return)
_find_use_locale_textdomain($document)
Truth table50%1/2
A
A= _find_use_locale_textdomain($document)
| |||||||||||||||||||||||||||||
| 38 | 14 | ▶ | if (_any_calls_locale_textdomain($document)) { return; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 7 | ▶ | if (_any_vars_locale_textdomain($document)) { return; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 5 | ▶ | if (_any_strings_locale_textdomain($document)) { return; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 2 | return $self->violation | |||||||||||||||||||||||||||
| 43 | ('Locale::TextDomain imported, but none of its functions used', | ||||||||||||||||||||||||||||
| 44 | '', | ||||||||||||||||||||||||||||
| 45 | $use); | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # return a PPI::Statement::Include which is a "use" or "require" of | ||||||||||||||||||||||||||||
| 49 | # Locale::TextDomain, or return false if there's no such | ||||||||||||||||||||||||||||
| 50 | 14 | ▶ | sub _find_use_locale_textdomain { | ||||||||||||||||||||||||||
|
Subroutine
_find_use_locale_textdomain: called CC=2 SCAR=7.5
| |||||||||||||||||||||||||||||
| 51 | 14 | my ($document) = @_; | |||||||||||||||||||||||||||
| 52 | 14 | ▶ | my $aref = $document->find ('PPI::Statement::Include') | ||||||||||||||||||||||||||
|
Condition50%1/2
$document->find('PPI::Statement::Include') || (return)
MC/DC0%0/1
$document->find('PPI::Statement::Include') || (return)
$document->find('PPI::Statement::Include')
Truth table50%1/2
A
A= $document->find('PPI::Statement::Include')
| |||||||||||||||||||||||||||||
| 53 | || return; # if no includes at all | ||||||||||||||||||||||||||||
| 54 | 14 | ▶ | return List::Util::first { $_->type ne 'no' | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.7
Branch: 1 branch
Condition50%1/2
$_->module || ''
MC/DC0%0/1
$_->module || ''
$_->module
Truth table50%1/2
A
A= $_->module
| |||||||||||||||||||||||||||||
| 55 | && ($_->module||'') eq 'Locale::TextDomain' | ||||||||||||||||||||||||||||
| 56 | 14 | } @$aref; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # The following qw() copied from @Locale::TextDomain::EXPORT of libintl-perl | ||||||||||||||||||||||||||||
| 61 | # 1.18, with $__ %__ moved to %vars below. __p and friends are new in 1.17, | ||||||||||||||||||||||||||||
| 62 | # but no need to check that. | ||||||||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||||||||
| 64 | 40 | my %funcs = map {($_=>1)} | |||||||||||||||||||||||||||
| 65 | qw(__ __x __n __nx __xn __p __px __np __npx | ||||||||||||||||||||||||||||
| 66 | N__ N__n N__p N__np); | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # and also as full names "Locale::TextDomain::__" | ||||||||||||||||||||||||||||
| 69 | 40 | foreach (keys %funcs) { | |||||||||||||||||||||||||||
| 70 | 520 | $funcs{"Locale::TextDomain::$_"} = 1; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # return true if $document has any of the Locale::TextDomain functions used, | ||||||||||||||||||||||||||||
| 74 | # like __() etc | ||||||||||||||||||||||||||||
| 75 | 14 | ▶ | sub _any_calls_locale_textdomain { | ||||||||||||||||||||||||||
|
Subroutine
_any_calls_locale_textdomain: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 76 | 14 | my ($document) = @_; | |||||||||||||||||||||||||||
| 77 | 14 | ▶ | my $aref = $document->find ('PPI::Token::Word') | ||||||||||||||||||||||||||
|
Condition50%1/2
$document->find('PPI::Token::Word') || (return)
MC/DC0%0/1
$document->find('PPI::Token::Word') || (return)
$document->find('PPI::Token::Word')
Truth table50%1/2
A
A= $document->find('PPI::Token::Word')
| |||||||||||||||||||||||||||||
| 78 | || return; # if no word tokens at all | ||||||||||||||||||||||||||||
| 79 | 50 | ▶ | return List::Util::first { $funcs{$_->content} | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | && is_function_call($_) | ||||||||||||||||||||||||||||
| 81 | 14 | } @$aref; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | ## no critic (RequireInterpolationOfMetachars) | ||||||||||||||||||||||||||||
| 85 | 40 | my %vars = ('$__' => 1, | |||||||||||||||||||||||||||
| 86 | '%__' => 1); | ||||||||||||||||||||||||||||
| 87 | ## use critic | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 7 | ▶ | sub _any_vars_locale_textdomain { | ||||||||||||||||||||||||||
|
Subroutine
_any_vars_locale_textdomain: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 90 | 7 | my ($document) = @_; | |||||||||||||||||||||||||||
| 91 | 7 | ▶ | my $aref = $document->find ('PPI::Token::Symbol') | ||||||||||||||||||||||||||
|
Condition100%2/2
$document->find('PPI::Token::Symbol') || (return)
MC/DC100%1/1
$document->find('PPI::Token::Symbol') || (return)
$document->find('PPI::Token::Symbol')
Truth table100%2/2
A
A= $document->find('PPI::Token::Symbol')
| |||||||||||||||||||||||||||||
| 92 | || return; # if no symbols at all | ||||||||||||||||||||||||||||
| 93 | 2 | ▶ | return List::Util::first { $vars{$_->symbol} } @$aref; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 5 | ▶ | sub _any_strings_locale_textdomain { | ||||||||||||||||||||||||||
|
Subroutine
_any_strings_locale_textdomain: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 96 | 5 | my ($document) = @_; | |||||||||||||||||||||||||||
| 97 | 5 | ▶ | my $aref = $document->find ('PPI::Token::Quote') | ||||||||||||||||||||||||||
|
Condition50%1/2
$document->find('PPI::Token::Quote') || (return)
MC/DC0%0/1
$document->find('PPI::Token::Quote') || (return)
$document->find('PPI::Token::Quote')
Truth table50%1/2
A
A= $document->find('PPI::Token::Quote')
| |||||||||||||||||||||||||||||
| 98 | || return; # if no strings at all | ||||||||||||||||||||||||||||
| 99 | 9 | ▶ | return List::Util::first { ($_->isa('PPI::Token::Quote::Interpolate') | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
Condition66%2/3
$_->isa("PPI::Token::Quote::Interpolate") or $_->isa("PPI::Token::Quote::Double")
MC/DC50%1/2
$_->isa("PPI::Token::Quote::Interpolate") or $_->isa("PPI::Token::Quote::Double")
$_->isa("PPI::Token::Quote::Interpolate")
$_->isa("PPI::Token::Quote::Double")
Truth table66%2/3
A or B
A= $_->isa("PPI::Token::Quote::Interpolate")B= $_->isa("PPI::Token::Quote::Double")
| |||||||||||||||||||||||||||||
| 100 | || $_->isa('PPI::Token::Quote::Double')) | ||||||||||||||||||||||||||||
| 101 | 5 | && $_->string =~ /\$__(\W|$)/ } @$aref; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 40 | 1; | |||||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||||||