Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Modules/RequireFilenameMatchesPackage.pm |
Statements | Executed 6212 statements in 10.6ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
144 | 1 | 1 | 10.7ms | 27.1ms | violates | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
144 | 1 | 1 | 774µs | 1.12ms | prepare_to_scan_document | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
144 | 1 | 1 | 372µs | 372µs | CORE:subst (opcode) | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
144 | 1 | 1 | 262µs | 262µs | applies_to | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
1 | 1 | 1 | 16µs | 16µs | BEGIN@10 | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
1 | 1 | 1 | 8µs | 57µs | BEGIN@19 | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
1 | 1 | 1 | 8µs | 28µs | BEGIN@13 | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
1 | 1 | 1 | 8µs | 11µs | BEGIN@12 | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
1 | 1 | 1 | 7µs | 18µs | BEGIN@11 | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
1 | 1 | 1 | 7µs | 332µs | BEGIN@17 | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
1 | 1 | 1 | 5µs | 5µs | BEGIN@15 | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
1 | 1 | 1 | 2µs | 2µs | supported_parameters | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::
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::Modules::RequireFilenameMatchesPackage; | ||||
9 | |||||
10 | 2 | 39µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@10 which was called:
# once (16µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 16µs making 1 call to Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@10 |
11 | 2 | 24µs | 2 | 29µs | # spent 18µs (7+11) within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@11 which was called:
# once (7µs+11µs) by Module::Pluggable::Object::_require at line 11 # spent 18µs making 1 call to Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | 2 | 22µs | 2 | 15µs | # spent 11µs (8+4) within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@12 which was called:
# once (8µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 11µs making 1 call to Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | 2 | 20µs | 2 | 48µs | # spent 28µs (8+20) within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@13 which was called:
# once (8µs+20µs) by Module::Pluggable::Object::_require at line 13 # spent 28µs making 1 call to Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@13
# spent 20µs making 1 call to Exporter::import |
14 | |||||
15 | 2 | 22µs | 1 | 5µs | # spent 5µs within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@15 which was called:
# once (5µs+0s) by Module::Pluggable::Object::_require at line 15 # spent 5µs making 1 call to Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@15 |
16 | |||||
17 | 2 | 25µs | 2 | 658µs | # spent 332µs (7+325) within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@17 which was called:
# once (7µs+325µs) by Module::Pluggable::Object::_require at line 17 # spent 332µs making 1 call to Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@17
# spent 325µs making 1 call to Exporter::import |
18 | |||||
19 | 2 | 314µs | 2 | 106µs | # spent 57µs (8+49) within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@19 which was called:
# once (8µs+49µs) by Module::Pluggable::Object::_require at line 19 # spent 57µs making 1 call to Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::BEGIN@19
# spent 49µs making 1 call to base::import |
20 | |||||
21 | 1 | 600ns | our $VERSION = '1.121'; | ||
22 | |||||
23 | #----------------------------------------------------------------------------- | ||||
24 | |||||
25 | 1 | 2µs | 1 | 29µs | Readonly::Scalar my $DESC => q{Package declaration must match filename}; # spent 29µs making 1 call to Readonly::Scalar |
26 | 1 | 1µs | 1 | 20µs | Readonly::Scalar my $EXPL => q{Correct the filename or package statement}; # spent 20µs making 1 call to Readonly::Scalar |
27 | |||||
28 | #----------------------------------------------------------------------------- | ||||
29 | |||||
30 | 1 | 5µs | # spent 2µs within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::supported_parameters which was called:
# once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||
31 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
32 | sub default_themes { return qw(core bugs) } | ||||
33 | 144 | 426µs | # spent 262µs within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::applies_to which was called 144 times, avg 2µs/call:
# 144 times (262µs+0s) by Perl::Critic::_critique at line 165 of Perl/Critic.pm, avg 2µs/call | ||
34 | |||||
35 | #----------------------------------------------------------------------------- | ||||
36 | |||||
37 | # spent 1.12ms (774µs+345µs) within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::prepare_to_scan_document which was called 144 times, avg 8µs/call:
# 144 times (774µs+345µs) by Perl::Critic::_critique at line 157 of Perl/Critic.pm, avg 8µs/call | ||||
38 | 144 | 57µs | my ( $self, $document ) = @_; | ||
39 | 144 | 604µs | 144 | 345µs | return $document->is_module(); # Must be a library or module. # spent 345µs making 144 calls to Perl::Critic::Document::is_module, avg 2µs/call |
40 | } | ||||
41 | |||||
42 | #----------------------------------------------------------------------------- | ||||
43 | |||||
44 | # spent 27.1ms (10.7+16.4) within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::violates which was called 144 times, avg 188µs/call:
# 144 times (10.7ms+16.4ms) by Perl::Critic::_critique at line 183 of Perl/Critic.pm, avg 188µs/call | ||||
45 | 144 | 63µs | my ($self, $elem, $doc) = @_; | ||
46 | |||||
47 | # 'Foo::Bar' -> ('Foo', 'Bar') | ||||
48 | 144 | 294µs | 144 | 2.00ms | my $pkg_node = $doc->find_first('PPI::Statement::Package'); # spent 2.00ms making 144 calls to Perl::Critic::Document::find_first, avg 14µs/call |
49 | 144 | 462µs | 144 | 98µs | return if not $pkg_node; # spent 98µs making 144 calls to PPI::Util::TRUE, avg 682ns/call |
50 | 144 | 376µs | 144 | 6.42ms | my $pkg = $pkg_node->namespace(); # spent 6.42ms making 144 calls to PPI::Statement::Package::namespace, avg 45µs/call |
51 | 144 | 66µs | return if $pkg eq 'main'; | ||
52 | 144 | 1.19ms | my @pkg_parts = split m/(?:\'|::)/xms, $pkg; | ||
53 | |||||
54 | |||||
55 | # 'lib/Foo/Bar.pm' -> ('lib', 'Foo', 'Bar') | ||||
56 | 144 | 421µs | 144 | 3.55ms | my $filename = $pkg_node->logical_filename() || $doc->filename(); # spent 3.55ms making 144 calls to PPI::Element::logical_filename, avg 25µs/call |
57 | 144 | 42µs | return if not $filename; | ||
58 | |||||
59 | 144 | 974µs | 144 | 2.27ms | my @path = File::Spec->splitpath($filename); # spent 2.27ms making 144 calls to File::Spec::Unix::splitpath, avg 16µs/call |
60 | 144 | 50µs | $filename = $path[2]; | ||
61 | 144 | 800µs | 144 | 372µs | $filename =~ s/ [.] \w+ \z //xms; # spent 372µs making 144 calls to Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::CORE:subst, avg 3µs/call |
62 | my @path_parts = | ||||
63 | 144 | 2.79ms | 1152 | 1.71ms | grep {$_ ne $EMPTY} File::Spec->splitdir($path[1]), $filename; # spent 1.21ms making 1008 calls to Readonly::Scalar::FETCH, avg 1µs/call
# spent 500µs making 144 calls to File::Spec::Unix::splitdir, avg 3µs/call |
64 | |||||
65 | |||||
66 | # To succeed, at least the lastmost must match | ||||
67 | # Beyond that, the search terminates if a dirname is an impossible package name | ||||
68 | 144 | 27µs | my $matched_any; | ||
69 | 144 | 216µs | while (@pkg_parts && @path_parts) { | ||
70 | 720 | 230µs | my $pkg_part = pop @pkg_parts; | ||
71 | 720 | 162µs | my $path_part = pop @path_parts; | ||
72 | 720 | 118µs | if ($pkg_part eq $path_part) { | ||
73 | 720 | 71µs | $matched_any = 1; | ||
74 | 720 | 135µs | next; | ||
75 | } | ||||
76 | |||||
77 | # if it's a path that's not a possible package (like 'Foo-Bar-1.00'), that's OK | ||||
78 | last if ($path_part =~ m/\W/xms); | ||||
79 | |||||
80 | # Mismatched name | ||||
81 | return $self->violation( $DESC, $EXPL, $pkg_node ); | ||||
82 | } | ||||
83 | |||||
84 | 144 | 528µs | return if $matched_any; | ||
85 | return $self->violation( $DESC, $EXPL, $pkg_node ); | ||||
86 | } | ||||
87 | |||||
88 | 1 | 3µs | 1; | ||
89 | |||||
90 | #----------------------------------------------------------------------------- | ||||
91 | |||||
92 | __END__ | ||||
# spent 372µs within Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::CORE:subst which was called 144 times, avg 3µs/call:
# 144 times (372µs+0s) by Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::violates at line 61, avg 3µs/call |