line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
26699
|
use 5.010001; |
|
40
|
|
|
|
|
157
|
|
4
|
|
|
|
|
|
|
|
5
|
40
|
|
|
40
|
|
240
|
use strict; |
|
40
|
|
|
|
|
88
|
|
|
40
|
|
|
|
|
821
|
|
6
|
40
|
|
|
40
|
|
220
|
use warnings; |
|
40
|
|
|
|
|
124
|
|
|
40
|
|
|
|
|
1057
|
|
7
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
248
|
use Readonly; |
|
40
|
|
|
|
|
105
|
|
|
40
|
|
|
|
|
2085
|
|
9
|
40
|
|
|
40
|
|
279
|
use English qw{ -no_match_vars }; |
|
40
|
|
|
|
|
102
|
|
|
40
|
|
|
|
|
337
|
|
10
|
40
|
|
|
40
|
|
14738
|
use Perl::Critic::Utils qw{ :severities :classification }; |
|
40
|
|
|
|
|
108
|
|
|
40
|
|
|
|
|
2027
|
|
11
|
40
|
|
|
40
|
|
13423
|
use parent 'Perl::Critic::Policy'; |
|
40
|
|
|
|
|
108
|
|
|
40
|
|
|
|
|
223
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.150'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => |
18
|
|
|
|
|
|
|
q{Pod NAME on line %d does not match the package declaration}; |
19
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
22
|
|
|
|
|
|
|
|
23
|
89
|
|
|
89
|
0
|
1662
|
sub supported_parameters { return () } |
24
|
74
|
|
|
74
|
1
|
361
|
sub default_severity { return $SEVERITY_LOWEST } |
25
|
84
|
|
|
84
|
1
|
351
|
sub default_themes { return qw( core cosmetic ) } |
26
|
29
|
|
|
29
|
1
|
104
|
sub applies_to { return 'PPI::Document' } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub prepare_to_scan_document { |
31
|
30
|
|
|
30
|
1
|
138
|
my ( $self, $document ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# idea: force NAME to match the file name in programs? |
34
|
30
|
|
|
|
|
129
|
return $document->is_module(); # mismatch is normal in program entry points |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub violates { |
38
|
29
|
|
|
29
|
1
|
128
|
my ( $self, $elem, $doc ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# No POD means no violation |
41
|
29
|
|
|
|
|
78
|
my $pods_ref = $doc->find('PPI::Token::Pod'); |
42
|
29
|
100
|
|
|
|
163
|
return if !$pods_ref; |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
|
|
5
|
for my $pod (@{$pods_ref}) { |
|
2
|
|
|
|
|
8
|
|
45
|
2
|
|
|
|
|
6
|
my $content = $pod->content; |
46
|
|
|
|
|
|
|
|
47
|
2
|
50
|
|
|
|
17
|
next if $content !~ m{^=head1 [ \t]+ NAME [ \t]*$ \s*}cgxms; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
my $line_number = $pod->line_number() + ( |
50
|
|
|
|
|
|
|
substr( $content, 0, $LAST_MATCH_START[0] + 1 ) =~ tr/\n/\n/ ); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
my ($pod_pkg) = $content =~ m{\G (\S+) }cgxms; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
0
|
if (!$pod_pkg) { |
55
|
0
|
|
|
|
|
0
|
return $self->violation( sprintf( $DESC, $line_number ), |
56
|
|
|
|
|
|
|
q{Empty name declaration}, $pod ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# idea: worry about POD escapes? |
60
|
0
|
|
|
|
|
0
|
$pod_pkg =~ s{\A [BCIL]<(.*)>\z}{$1}gxms; # unwrap |
61
|
0
|
|
|
|
|
0
|
$pod_pkg =~ s{\'}{::}gxms; # perl4 -> perl5 |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
0
|
foreach my $stmt ( @{ $doc->find('PPI::Statement::Package') || [] } ) { |
|
0
|
|
|
|
|
0
|
|
64
|
0
|
|
|
|
|
0
|
my $pkg = $stmt->namespace(); |
65
|
0
|
|
|
|
|
0
|
$pkg =~ s{\'}{::}gxms; |
66
|
0
|
0
|
|
|
|
0
|
return if $pkg eq $pod_pkg; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
return $self->violation( sprintf( $DESC, $line_number ), |
70
|
|
|
|
|
|
|
$EXPL, $pod ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
6
|
return; # no NAME section found |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=pod |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 NAME |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName - The C<=head1 NAME> section should match the package. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 AFFILIATION |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> distribution. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 DESCRIPTION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 CONFIGURATION |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This Policy is not configurable except for the standard options. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Chris Dolan <cdolan@cpan.org> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 COPYRIGHT |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Copyright (c) 2008-2023 Chris Dolan |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
112
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
113
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Local Variables: |
118
|
|
|
|
|
|
|
# mode: cperl |
119
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
120
|
|
|
|
|
|
|
# fill-column: 78 |
121
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
122
|
|
|
|
|
|
|
# c-indentation-style: bsd |
123
|
|
|
|
|
|
|
# End: |
124
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |