Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Documentation/RequirePackageMatchesPodName.pm |
Statements | Executed 21 statements in 611µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 17µs | 17µs | BEGIN@10 | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
1 | 1 | 1 | 14µs | 408µs | BEGIN@16 | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
1 | 1 | 1 | 10µs | 34µs | BEGIN@15 | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
1 | 1 | 1 | 8µs | 61µs | BEGIN@18 | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
1 | 1 | 1 | 8µs | 14µs | BEGIN@13 | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
1 | 1 | 1 | 7µs | 399µs | BEGIN@17 | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
1 | 1 | 1 | 7µs | 19µs | BEGIN@12 | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
1 | 1 | 1 | 6µs | 8µs | default_severity | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
1 | 1 | 1 | 2µs | 2µs | supported_parameters | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
1 | 1 | 1 | 2µs | 2µs | CORE:qr (opcode) | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
0 | 0 | 0 | 0s | 0s | prepare_to_scan_document | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | ############################################################################## | ||||
2 | # $URL$ | ||||
3 | # $Date$ | ||||
4 | # $Author$ | ||||
5 | # $Revision$ | ||||
6 | ############################################################################## | ||||
7 | |||||
8 | package Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName; | ||||
9 | |||||
10 | 2 | 42µs | 1 | 17µs | # spent 17µs within Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@10 which was called:
# once (17µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 17µs making 1 call to Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@10 |
11 | |||||
12 | 2 | 20µs | 2 | 31µs | # spent 19µs (7+12) within Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@12 which was called:
# once (7µs+12µs) by Module::Pluggable::Object::_require at line 12 # spent 19µs making 1 call to Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@12
# spent 12µs making 1 call to strict::import |
13 | 2 | 24µs | 2 | 21µs | # spent 14µs (8+7) within Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@13 which was called:
# once (8µs+7µs) by Module::Pluggable::Object::_require at line 13 # spent 14µs making 1 call to Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@13
# spent 7µs making 1 call to warnings::import |
14 | |||||
15 | 2 | 25µs | 2 | 57µs | # spent 34µs (10+23) within Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@15 which was called:
# once (10µs+23µs) by Module::Pluggable::Object::_require at line 15 # spent 34µs making 1 call to Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@15
# spent 23µs making 1 call to Exporter::import |
16 | 2 | 27µs | 2 | 802µs | # spent 408µs (14+394) within Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@16 which was called:
# once (14µs+394µs) by Module::Pluggable::Object::_require at line 16 # spent 408µs making 1 call to Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@16
# spent 394µs making 1 call to English::import |
17 | 2 | 25µs | 2 | 790µs | # spent 399µs (7+391) within Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@17 which was called:
# once (7µs+391µs) by Module::Pluggable::Object::_require at line 17 # spent 399µs making 1 call to Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@17
# spent 391µs making 1 call to Exporter::import |
18 | 2 | 424µs | 2 | 115µs | # spent 61µs (8+54) within Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@18 which was called:
# once (8µs+54µs) by Module::Pluggable::Object::_require at line 18 # spent 61µs making 1 call to Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::BEGIN@18
# spent 54µs making 1 call to base::import |
19 | |||||
20 | 1 | 600ns | our $VERSION = '1.121'; | ||
21 | |||||
22 | #----------------------------------------------------------------------------- | ||||
23 | |||||
24 | 1 | 10µs | 2 | 30µs | Readonly::Scalar my $PKG_RX => qr{ [[:alpha:]](?:[\w:\']*\w)? }xms; # spent 28µs making 1 call to Readonly::Scalar
# spent 2µs making 1 call to Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::CORE:qr |
25 | 1 | 900ns | 1 | 22µs | Readonly::Scalar my $DESC => # spent 22µs making 1 call to Readonly::Scalar |
26 | q{Pod NAME on line %d does not match the package declaration}; | ||||
27 | 1 | 900ns | 1 | 20µs | Readonly::Scalar my $EXPL => q{}; # spent 20µs making 1 call to Readonly::Scalar |
28 | |||||
29 | #----------------------------------------------------------------------------- | ||||
30 | |||||
31 | 1 | 4µs | # spent 2µs within Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::supported_parameters which was called:
# once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||
32 | 1 | 2µs | # spent 8µs (6+1) within Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
33 | sub default_themes { return qw( core cosmetic ) } | ||||
34 | sub applies_to { return 'PPI::Document' } | ||||
35 | |||||
36 | #----------------------------------------------------------------------------- | ||||
37 | |||||
38 | sub prepare_to_scan_document { | ||||
39 | my ( $self, $document ) = @_; | ||||
40 | |||||
41 | # idea: force NAME to match the file name in programs? | ||||
42 | return $document->is_module(); # mismatch is normal in program entry points | ||||
43 | } | ||||
44 | |||||
45 | sub violates { | ||||
46 | my ( $self, $elem, $doc ) = @_; | ||||
47 | |||||
48 | # No POD means no violation | ||||
49 | my $pods_ref = $doc->find('PPI::Token::Pod'); | ||||
50 | return if !$pods_ref; | ||||
51 | |||||
52 | for my $pod (@{$pods_ref}) { | ||||
53 | my $content = $pod->content; | ||||
54 | |||||
55 | next if $content !~ m{^=head1 [ \t]+ NAME [ \t]*$ \s*}cgxms; | ||||
56 | |||||
57 | my $line_number = $pod->line_number() + ( | ||||
58 | substr( $content, 0, $LAST_MATCH_START[0] + 1 ) =~ tr/\n/\n/ ); | ||||
59 | |||||
60 | my ($pod_pkg) = $content =~ m{\G (\S+) }cgxms; | ||||
61 | |||||
62 | if (!$pod_pkg) { | ||||
63 | return $self->violation( sprintf( $DESC, $line_number ), | ||||
64 | q{Empty name declaration}, $pod ); | ||||
65 | } | ||||
66 | |||||
67 | # idea: worry about POD escapes? | ||||
68 | $pod_pkg =~ s{\A [CL]<(.*)>\z}{$1}gxms; # unwrap | ||||
69 | $pod_pkg =~ s{\'}{::}gxms; # perl4 -> perl5 | ||||
70 | |||||
71 | foreach my $stmt ( @{ $doc->find('PPI::Statement::Package') || [] } ) { | ||||
72 | my $pkg = $stmt->namespace(); | ||||
73 | $pkg =~ s{\'}{::}gxms; | ||||
74 | return if $pkg eq $pod_pkg; | ||||
75 | } | ||||
76 | |||||
77 | return $self->violation( sprintf( $DESC, $line_number ), | ||||
78 | $EXPL, $pod ); | ||||
79 | } | ||||
80 | |||||
81 | return; # no NAME section found | ||||
82 | } | ||||
83 | |||||
84 | 1 | 6µs | 1; | ||
85 | |||||
86 | __END__ | ||||
# spent 2µs within Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName::CORE:qr which was called:
# once (2µs+0s) by Module::Pluggable::Object::_require at line 24 |