Policy/Miscellanea/RequireRcsKeywords.pm

filter: Statementstmt 92.3% 60 / 65 Branchbran 75.0% 6 / 8 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 93.3% 14 / 15 Podpod 83.3% 5 / 6 totaltotal 91.0% 91 / 100 CC 8 SCAR 8.1
CC
8
Cov
91%
violates
4.1
_find_wanted_nodes
4.0
default_themes
2.0
CRAP 2.2
« Policy/NamingConventions/ProhibitMixedCaseVars.pm ↑ Summary Deprecated.pm »
1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/Perl-Critic-Deprecated/lib/Perl/Critic/Policy/Miscellanea/RequireRcsKeywords.pm $
3 # $Date: 2013-10-29 09:11:44 -0700 (Tue, 29 Oct 2013) $
4 # $Author: thaljef $
5 # $Revision: 4214 $
6 ##############################################################################
7  
8 package Perl::Critic::Policy::Miscellanea::RequireRcsKeywords;
9  
10 1 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use List::MoreUtils qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use Perl::Critic::Utils qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
18 :booleans :characters :severities :data_conversion
19 1 };
20  
21 1 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 our $VERSION = '1.119';
24  
25 #-----------------------------------------------------------------------------
26  
27 1 Readonly::Scalar my $EXPL => [441];
28  
29 #-----------------------------------------------------------------------------
30  
31 11 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
32 return (
33 11 { name => 'keywords',
34 description => 'The keywords to require in all files.',
35 default_string => $EMPTY,
36 behavior => 'string list',
37 },
38 );
39 }
40  
41 15 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
42 0 ▶sub default_themes { return qw( deprecated pbp cosmetic ) }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
43 11 ▶sub applies_to { return 'PPI::Document' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
44  
45 #-----------------------------------------------------------------------------
46  
47 11 ▶sub initialize_if_enabled {
Subroutine initialize_if_enabled: called CC=2 SCAR=6.9
Pod documented
48 11 my ( $self, $config ) = @_;
49  
50 # Any of these lists
51 $self->{_keyword_sets} = [
52  
53 # Minimal svk/svn
54 11 [qw(Id)],
55  
56 # Expansive svk/svn
57 [qw(Revision HeadURL Date)],
58  
59 # cvs?
60 [qw(Revision Source Date)],
61 ];
62  
63 # Set configuration, if defined.
64 11 my @keywords = keys %{ $self->{_keywords} };
65 11 ▶ if (@keywords) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keywords) 4 7 11
66 4 $self->{_keyword_sets} = [ [@keywords] ];
67 }
68  
69 11 return $TRUE;
70 }
71  
72 #-----------------------------------------------------------------------------
73  
74 11 ▶sub violates {
Subroutine violates: called CC=4 SCAR=14.1
Pod documented
75 11 my ( $self, $elem, $doc ) = @_;
76 11 my @viols = ();
77  
78 11 my $nodes = $self->_find_wanted_nodes($doc);
79 11 for my $keywordset_ref ( @{ $self->{_keyword_sets} } ) {
80 23 ▶ if ( not $nodes ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $nodes) { } 0 23 23
81 my $desc
82 = 'RCS keywords '
83 0 . join( ', ', map {"\$$_\$"} @{$keywordset_ref} )
84 . ' not found';
85 0 push @viols, $self->violation( $desc, $EXPL, $doc );
86 } else {
87 my @missing_keywords = grep {
88 50 my $keyword_rx = qr< \$ $_ .* \$ >xms;
89 50 ▶ !!none {m/$keyword_rx/xms} @{$nodes}
Subroutine __ANON__: called CC=1 SCAR=0.0
90 23 } @{$keywordset_ref};
91  
92 23 ▶ if (@missing_keywords) {
Branch: 1 branch
BranchTrueFalseTotal
if (@missing_keywords) { } 15 8 23
93  
94 # Provisionally flag a violation. See below.
95 my $desc
96 = 'RCS keywords '
97 15 . join( ', ', map {"\$$_\$"} @missing_keywords )
98 . ' not found';
99 15 push @viols, $self->violation( $desc, $EXPL, $doc );
100 } else {
101  
102 # Hey! I'm ignoring @viols for other keyword sets
103 # because this one is complete.
104 8 return;
105 }
106 }
107 }
108  
109 3 return @viols;
110 }
111  
112 #-----------------------------------------------------------------------------
113  
114 11 ▶sub _find_wanted_nodes {
Subroutine _find_wanted_nodes: called CC=4 SCAR=13.9
115 11 my ( $self, $doc ) = @_;
116 11 my @wanted_types = qw(Pod Comment Quote::Single Quote::Literal End);
117 11 ▶ my @found = map { @{ $doc->find("PPI::Token::$_") || [] } } @wanted_types;
Condition100%2/2
$doc->find("PPI::Token::$_") || []
l!l
1837
MC/DC100%1/1
$doc->find("PPI::Token::$_") || []
$doc->find("PPI::Token::$_")
Truth table100%2/2
A
A= $doc->find("PPI::Token::$_")
Aresult
11
00
118 push @found,
119 2 grep { $_->content() =~ m/ \A qw\$ [^\$]* \$ \z /smx }
120 11 ▶ @{ $doc->find('PPI::Token::QuoteLike::Words') || [] };
Condition100%2/2
$doc->find('PPI::Token::QuoteLike::Words') || []
l!l
29
MC/DC100%1/1
$doc->find('PPI::Token::QuoteLike::Words') || []
$doc->find('PPI::Token::QuoteLike::Words')
Truth table100%2/2
A
A= $doc->find('PPI::Token::QuoteLike::Words')
Aresult
11
00
121 11 ▶ return @found ? \@found : $EMPTY; # Behave like PPI::Node::find()
Branch: 1 branch
BranchTrueFalseTotal
@found ? : 11 0 11
122 }
123  
124 1 1;
125  
126 __END__
« Policy/NamingConventions/ProhibitMixedCaseVars.pm ↑ Summary Deprecated.pm »