lib/Perl/Critic/Policy/Documentation/RequirePackageMatchesPodName.pm

filter: Statementstmt 76.0% 38 / 50 Branchbran 37.5% 3 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 13 / 13 Podpod 83.3% 5 / 6 totaltotal 73.7% 59 / 80 CC 8 SCAR 23.3
CC
8
Cov
68%
violates
24.3
BEGIN
1.0
BEGIN
1.0
CRAP 10.3
« lib/Perl/Critic/Policy/InputOutput/RequireEncodingWithUTF8Layer.pm ↑ Summary lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitCommaSeparatedStatements.pm »
1 package Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use English qw{ -no_match_vars };
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use Perl::Critic::Utils qw{ :severities :classification };
Subroutine BEGIN: called CC=1 SCAR=0.0
11 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 40 our $VERSION = '1.156';
14  
15 #-----------------------------------------------------------------------------
16  
17 40 Readonly::Scalar my $DESC =>
18 q{Pod NAME on line %d does not match the package declaration};
19 40 Readonly::Scalar my $EXPL => q{};
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_LOWEST }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
25 83 ▶sub default_themes { return qw( core cosmetic ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
26 30 ▶sub applies_to { return 'PPI::Document' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
27  
28 #-----------------------------------------------------------------------------
29  
30 31 ▶sub prepare_to_scan_document {
Subroutine prepare_to_scan_document: called CC=1 SCAR=0.0
Pod documented
31 31 my ( undef, $document ) = @_;
32  
33 # idea: force NAME to match the file name in programs?
34 31 return $document->is_module(); # mismatch is normal in program entry points
35 }
36  
37 30 ▶sub violates {
Subroutine violates: called CC=8 SCAR=31.9
Pod documented
38 30 my ( $self, undef, $doc ) = @_;
39  
40 # No POD means no violation
41 30 my $pods_ref = $doc->find('PPI::Token::Pod');
42 30 ▶ return if !$pods_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $pods_ref 28 2 30
43  
44 2 for my $pod (@{$pods_ref}) {
45 2 my $content = $pod->content;
46  
47 2 ▶ next if $content !~ m{^=head1 [ \t]+ NAME [ \t]*$ \s*}cgxms;
Branch: 1 branch
BranchTrueFalseTotal
unless $content =~ /^=head1 [ \t]+ NAME [ \t]*$ \s*/cgmsx 2 0 2
48  
49 0 my $line_number = $pod->line_number() + (
50 substr( $content, 0, $LAST_MATCH_START[0] + 1 ) =~ tr/\n/\n/ );
51  
52 0 my ($pod_pkg) = $content =~ m{\G (\S+) }cgxms;
53  
54 0 ▶ if (!$pod_pkg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pod_pkg) 0 0 0
55 0 return $self->violation( sprintf( $DESC, $line_number ),
56 q{Empty name declaration}, $pod );
57 }
58  
59 # idea: worry about POD escapes?
60 0 $pod_pkg =~ s{\A [BCIL]<(.*)>\z}{$1}gxms; # unwrap
61 0 $pod_pkg =~ s{\'}{::}gxms; # perl4 -> perl5
62  
63 0 ▶ foreach my $stmt ( @{ $doc->find('PPI::Statement::Package') || [] } ) {
Condition0%0/2
$doc->find('PPI::Statement::Package') || []
l!l
00
MC/DC0%0/1
$doc->find('PPI::Statement::Package') || []
$doc->find('PPI::Statement::Package')
Truth table0%0/2
A
A= $doc->find('PPI::Statement::Package')
Aresult
11
00
64 0 my $pkg = $stmt->namespace();
65 0 $pkg =~ s{\'}{::}gxms;
66 0 ▶ return if $pkg eq $pod_pkg;
Branch: 1 branch
BranchTrueFalseTotal
if $pkg eq $pod_pkg 0 0 0
67 }
68  
69 0 return $self->violation( sprintf( $DESC, $line_number ),
70 $EXPL, $pod );
71 }
72  
73 2 return; # no NAME section found
74 }
75  
76 40 1;
77  
78 __END__
« lib/Perl/Critic/Policy/InputOutput/RequireEncodingWithUTF8Layer.pm ↑ Summary lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitCommaSeparatedStatements.pm »