« 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
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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') || []
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')
| |||||||||||||
| 64 | 0 | my $pkg = $stmt->namespace(); | |||||||||||
| 65 | 0 | $pkg =~ s{\'}{::}gxms; | |||||||||||
| 66 | 0 | ▶ | return if $pkg eq $pod_pkg; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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__ | ||||||||||||