« lib/Perl/Critic/Policy/Miscellanea/ProhibitUselessNoCritic.pm
↑ Summary
lib/Perl/Critic/Policy/Miscellanea/ProhibitUnrestrictedNoCritic.pm »
| 1 | package Perl::Critic::Policy::Documentation::RequirePodAtEnd; | ||||||||||
| 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 | 40 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 40 | ▶ | use List::Util qw(first); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 40 | ▶ | use Perl::Critic::Utils qw{ :severities }; | ||||||||
|
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 $POD_RX => qr{\A = (?: for|begin|end ) }xms; | |||||||||
| 18 | 40 | Readonly::Scalar my $DESC => q{POD before __END__}; | |||||||||
| 19 | 40 | Readonly::Scalar my $EXPL => [139, 140]; | |||||||||
| 20 | |||||||||||
| 21 | #----------------------------------------------------------------------------- | ||||||||||
| 22 | |||||||||||
| 23 | 90 | ▶ | sub supported_parameters { return () } | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | 76 | ▶ | 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 pbp ) } | ||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 26 | 31 | ▶ | sub applies_to { return 'PPI::Document' } | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 27 | |||||||||||
| 28 | #----------------------------------------------------------------------------- | ||||||||||
| 29 | |||||||||||
| 30 | 31 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: called CC=5 SCAR=18.2
Pod
documented
| |||||||||||
| 31 | 31 | my ( $self, undef, $doc ) = @_; | |||||||||
| 32 | |||||||||||
| 33 | # No POD means no violation | ||||||||||
| 34 | 31 | my $pods_ref = $doc->find('PPI::Token::Pod'); | |||||||||
| 35 | 31 | ▶ | return if !$pods_ref; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | |||||||||||
| 37 | # Look for first POD tag that isn't =for, =begin, or =end | ||||||||||
| 38 | 2 | ▶ | my $pod = first { $_ !~ $POD_RX} @{ $pods_ref }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 39 | 2 | ▶ | return if !$pod; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | 2 | my $end = $doc->find_first('PPI::Statement::End'); | |||||||||
| 42 | 2 | ▶ | if ($end) { # No __END__ means definite violation | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | my $pod_loc = $pod->location(); | |||||||||
| 44 | 0 | my $end_loc = $end->location(); | |||||||||
| 45 | 0 | ▶ | if ( $pod_loc->[0] > $end_loc->[0] ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | # POD is after __END__, or relative position couldn't be determined | ||||||||||
| 47 | 0 | return; | |||||||||
| 48 | } | ||||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 2 | return $self->violation( $DESC, $EXPL, $pod ); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 40 | 1; | |||||||||
| 55 | |||||||||||
| 56 | __END__ | ||||||||||