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