Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Modules/RequireVersionVar.pm |
Statements | Executed 20 statements in 608µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 19µs | 19µs | BEGIN@10 | Perl::Critic::Policy::Modules::RequireVersionVar::
1 | 1 | 1 | 8µs | 59µs | BEGIN@18 | Perl::Critic::Policy::Modules::RequireVersionVar::
1 | 1 | 1 | 7µs | 11µs | BEGIN@12 | Perl::Critic::Policy::Modules::RequireVersionVar::
1 | 1 | 1 | 7µs | 154µs | BEGIN@15 | Perl::Critic::Policy::Modules::RequireVersionVar::
1 | 1 | 1 | 7µs | 28µs | BEGIN@13 | Perl::Critic::Policy::Modules::RequireVersionVar::
1 | 1 | 1 | 7µs | 148µs | BEGIN@17 | Perl::Critic::Policy::Modules::RequireVersionVar::
1 | 1 | 1 | 6µs | 18µs | BEGIN@11 | Perl::Critic::Policy::Modules::RequireVersionVar::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::Modules::RequireVersionVar::
1 | 1 | 1 | 2µs | 2µs | supported_parameters | Perl::Critic::Policy::Modules::RequireVersionVar::
0 | 0 | 0 | 0s | 0s | __ANON__[:62] | Perl::Critic::Policy::Modules::RequireVersionVar::
0 | 0 | 0 | 0s | 0s | _is_our_version | Perl::Critic::Policy::Modules::RequireVersionVar::
0 | 0 | 0 | 0s | 0s | _is_package_argument_version | Perl::Critic::Policy::Modules::RequireVersionVar::
0 | 0 | 0 | 0s | 0s | _is_package_version | Perl::Critic::Policy::Modules::RequireVersionVar::
0 | 0 | 0 | 0s | 0s | _is_readonly_version | Perl::Critic::Policy::Modules::RequireVersionVar::
0 | 0 | 0 | 0s | 0s | _is_vars_version | Perl::Critic::Policy::Modules::RequireVersionVar::
0 | 0 | 0 | 0s | 0s | _is_version_declaration | Perl::Critic::Policy::Modules::RequireVersionVar::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::Modules::RequireVersionVar::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::Modules::RequireVersionVar::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::Modules::RequireVersionVar::
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::RequireVersionVar; | ||||
9 | |||||
10 | 2 | 43µs | 1 | 19µs | # spent 19µs within Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@10 which was called:
# once (19µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 19µs making 1 call to Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@10 |
11 | 2 | 23µs | 2 | 30µs | # spent 18µs (6+12) within Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@11 which was called:
# once (6µs+12µs) by Module::Pluggable::Object::_require at line 11 # spent 18µs making 1 call to Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@11
# spent 12µs making 1 call to strict::import |
12 | 2 | 22µs | 2 | 15µs | # spent 11µs (7+4) within Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@12 which was called:
# once (7µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 11µs making 1 call to Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | 2 | 22µs | 2 | 49µs | # spent 28µs (7+21) within Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@13 which was called:
# once (7µs+21µs) by Module::Pluggable::Object::_require at line 13 # spent 28µs making 1 call to Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@13
# spent 21µs making 1 call to Exporter::import |
14 | |||||
15 | 2 | 24µs | 2 | 301µs | # spent 154µs (7+147) within Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@15 which was called:
# once (7µs+147µs) by Module::Pluggable::Object::_require at line 15 # spent 154µs making 1 call to Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@15
# spent 147µs making 1 call to Exporter::Tiny::import |
16 | |||||
17 | 2 | 26µs | 2 | 289µs | # spent 148µs (7+141) within Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@17 which was called:
# once (7µs+141µs) by Module::Pluggable::Object::_require at line 17 # spent 148µs making 1 call to Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@17
# spent 141µs making 1 call to Exporter::import |
18 | 2 | 433µs | 2 | 110µs | # spent 59µs (8+51) within Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@18 which was called:
# once (8µs+51µs) by Module::Pluggable::Object::_require at line 18 # spent 59µs making 1 call to Perl::Critic::Policy::Modules::RequireVersionVar::BEGIN@18
# spent 51µs making 1 call to base::import |
19 | |||||
20 | 1 | 600ns | our $VERSION = '1.121'; | ||
21 | |||||
22 | #----------------------------------------------------------------------------- | ||||
23 | |||||
24 | 1 | 2µs | 1 | 29µs | Readonly::Scalar my $DESC => q{No package-scoped "$VERSION" variable found}; ## no critic (RequireInterpolation) # spent 29µs making 1 call to Readonly::Scalar |
25 | 1 | 2µs | 1 | 45µs | Readonly::Scalar my $EXPL => [ 404 ]; # spent 45µs making 1 call to Readonly::Scalar |
26 | |||||
27 | #----------------------------------------------------------------------------- | ||||
28 | |||||
29 | 1 | 4µs | # spent 2µs within Perl::Critic::Policy::Modules::RequireVersionVar::supported_parameters which was called:
# once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||
30 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::Modules::RequireVersionVar::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
31 | sub default_themes { return qw(core pbp readability) } | ||||
32 | sub applies_to { return 'PPI::Document' } | ||||
33 | |||||
34 | #----------------------------------------------------------------------------- | ||||
35 | |||||
36 | sub violates { | ||||
37 | my ( $self, $elem, $doc ) = @_; | ||||
38 | |||||
39 | return if $doc->find_first( \&_is_version_declaration ); | ||||
40 | |||||
41 | #If we get here, then no $VERSION was found | ||||
42 | return $self->violation( $DESC, $EXPL, $doc ); | ||||
43 | } | ||||
44 | |||||
45 | #----------------------------------------------------------------------------- | ||||
46 | |||||
47 | sub _is_version_declaration { ## no critic (ArgUnpacking) | ||||
48 | return 1 if _is_our_version(@_); | ||||
49 | return 1 if _is_vars_version(@_); | ||||
50 | return 1 if _is_package_version(@_); | ||||
51 | return 1 if _is_readonly_version(@_); | ||||
52 | return 1 if _is_package_argument_version(@_); | ||||
53 | return 0; | ||||
54 | } | ||||
55 | |||||
56 | #----------------------------------------------------------------------------- | ||||
57 | |||||
58 | sub _is_our_version { | ||||
59 | my (undef, $elem) = @_; | ||||
60 | $elem->isa('PPI::Statement::Variable') || return 0; | ||||
61 | $elem->type() eq 'our' || return 0; | ||||
62 | return any { $_ eq '$VERSION' } $elem->variables(); ## no critic (RequireInterpolation) | ||||
63 | } | ||||
64 | |||||
65 | #----------------------------------------------------------------------------- | ||||
66 | |||||
67 | sub _is_vars_version { | ||||
68 | my (undef, $elem) = @_; | ||||
69 | $elem->isa('PPI::Statement::Include') || return 0; | ||||
70 | $elem->pragma() eq 'vars' || return 0; | ||||
71 | return $elem =~ m{ \$VERSION }xms; #Crude, but usually works | ||||
72 | } | ||||
73 | |||||
74 | #----------------------------------------------------------------------------- | ||||
75 | |||||
76 | sub _is_package_version { | ||||
77 | my (undef, $elem) = @_; | ||||
78 | $elem->isa('PPI::Token::Symbol') || return 0; | ||||
79 | return $elem =~ m{ \A \$ \S+ ::VERSION \z }xms; | ||||
80 | #TODO: ensure that it is in _this_ package! | ||||
81 | } | ||||
82 | |||||
83 | #----------------------------------------------------------------------------- | ||||
84 | |||||
85 | sub _is_readonly_version { | ||||
86 | |||||
87 | #--------------------------------------------------------------- | ||||
88 | # Readonly VERSION statements usually come in one of two forms: | ||||
89 | # | ||||
90 | # Readonly our $VERSION = 1.0; | ||||
91 | # Readonly::Scalar our $VERSION = 1.0; | ||||
92 | #--------------------------------------------------------------- | ||||
93 | |||||
94 | my (undef, $elem) = @_; | ||||
95 | $elem->isa('PPI::Token::Symbol') || return 0; | ||||
96 | return 0 if $elem !~ m{ \A \$VERSION \z }xms; | ||||
97 | |||||
98 | my $psib = $elem->sprevious_sibling() || return 0; | ||||
99 | return 0 if $psib ne 'our'; | ||||
100 | |||||
101 | my $ppsib = $psib->sprevious_sibling() || return 0; | ||||
102 | return $ppsib eq 'Readonly' || $ppsib eq 'Readonly::Scalar'; | ||||
103 | } | ||||
104 | |||||
105 | #----------------------------------------------------------------------------- | ||||
106 | |||||
107 | sub _is_package_argument_version { | ||||
108 | my (undef, $elem) = @_; | ||||
109 | $elem->isa( 'PPI::Statement::Package' ) or return 0; | ||||
110 | # Perldoc for 5.12.3 documents the statement as | ||||
111 | # package NAMESPACE VERSION | ||||
112 | # with no comma, and the compiler in fact does not accept one. | ||||
113 | my $ver = $elem->schild( 2 ) | ||||
114 | or return 0; | ||||
115 | return $ver->isa( 'PPI::Token::Number' ); | ||||
116 | } | ||||
117 | |||||
118 | 1 | 3µs | 1; | ||
119 | |||||
120 | __END__ |