lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitSpecialLiteralHeredocTerminator.pm

filter: Statementstmt 81.2% 26 / 32 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 80.0% 4 / 5 totaltotal 80.0% 40 / 50 CC 2 SCAR 6.1
CC
2
Cov
76%
violates
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
« lib/Perl/Critic/Policy/Modules/RequireEndWithOne.pm ↑ Summary lib/Perl/Critic/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm »
1 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 40 our $VERSION = '1.156';
13  
14 #-----------------------------------------------------------------------------
15  
16 40 Readonly::Hash my %SPECIAL_LITERAL => map { '__' . $_ . '__' => 1 }
17 qw( FILE LINE PACKAGE END DATA );
18 40 Readonly::Scalar my $DESC =>
19 q{Heredoc terminator must not be a special literal};
20  
21 #-----------------------------------------------------------------------------
22  
23 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
24 74 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
25 73 ▶sub default_themes { return qw(core maintenance) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
26 31 ▶sub applies_to { return 'PPI::Token::HereDoc' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
27  
28 #-----------------------------------------------------------------------------
29  
30 0 ▶sub violates {
Subroutine violates: not called CC=2 SCAR=17.9
Pod documented
31 0 my ( $self, $elem, undef ) = @_;
32  
33 # remove << and (optional) quotes from around terminator
34 0 ( my $heredoc_terminator = $elem ) =~
35 s{ \A << ~? \s* (["']?) (.*) \1 \z }{$2}xms;
36  
37 0 ▶ if ( $SPECIAL_LITERAL{ $heredoc_terminator } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SPECIAL_LITERAL{$heredoc_terminator}) 0 0 0
38 0 my $expl = qq{Used "$heredoc_terminator" as heredoc terminator};
39 0 return $self->violation( $DESC, $expl, $elem );
40 }
41  
42 0 return; #ok!
43 }
44  
45 40 1;
46  
47 __END__
« lib/Perl/Critic/Policy/Modules/RequireEndWithOne.pm ↑ Summary lib/Perl/Critic/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm »