Perl/Critic/Policy/BadStrings.pm

filter: Statementstmt 97.2% 35 / 36 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 83.3% 5 / 6 totaltotal 93.1% 54 / 58 CC 3 SCAR 3.1
CC
3
Cov
95%
initialize_if_enabled
2.0
default_themes
2.0
violates
2.0
CRAP 1.4
« File/FindStrings.pm ↑ Summary
1 #!/usr/bin/perl
2  
3 #
4 # Copyright (C) 2017 Joelle Maslak
5 # All Rights Reserved - See License
6 #
7  
8 package Perl::Critic::Policy::BadStrings;
9 1 $Perl::Critic::Policy::BadStrings::VERSION = '1.000';
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: Search for bad strings in source files
13  
14  
15 1 ▶use File::FindStrings::Boilerplate 'script';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use Perl::Critic::Utils qw( :severities :classification :ppi :booleans );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use File::FindStrings qw(find_words_in_string);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 Readonly::Scalar my $DESC => 'Bad string in source file';
25 1 Readonly::Scalar my $EXPL => 'A "bad string" was found in the source file';
26  
27 2 ▶sub default_severity { return $SEVERITY_MEDIUM; }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
28 4 ▶sub supported_parameters { return qw(words); }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
29 0 ▶sub default_themes { return qw(badstrings); }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
30 4 ▶sub applies_to { return 'PPI::Document'; }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
31  
32 4 ▶sub initialize_if_enabled ( $self, $config ) {
Subroutine initialize_if_enabled: called CC=2 SCAR=7.0
Pod documented
33 4 $self->{_words} = [];
34  
35 4 my $w = $config->get('words');
36 4 ▶ if ( defined($w) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $w) 4 0 4
37 # Regex shamelessly stolen from Perl::Critic::logicLAB::REquireSheBang
38 4 push $self->{_words}->@*, split( m{ \s* [||]+ \s* }xsm, $w );
39 }
40  
41 4 return $TRUE;
42 }
43  
44 4 ▶sub violates ( $self, $elem, $doc ) {
Subroutine violates: called CC=2 SCAR=6.9
Pod documented
45 4 my $content = $elem->content();
46  
47 4 my (@matches) = find_words_in_string( $content, $self->{_words}->@* );
48  
49 4 ▶ if (@matches) {
Branch: 1 branch
BranchTrueFalseTotal
if (@matches) { } 2 2 4
50 2 return $self->violation( $DESC . ': "' . $matches[0]->{word} . '"', $EXPL, $elem );
51 } else {
52 2 return;
53 }
54 }
55  
56 1 1;
57  
58 __END__
« File/FindStrings.pm ↑ Summary