| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/ValuesAndExpressions/ProhibitLeadingZeros.pm |
| Statements | Executed 162 statements in 1.11ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 144 | 1 | 1 | 284µs | 284µs | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::applies_to |
| 1 | 1 | 1 | 19µs | 19µs | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@10 |
| 1 | 1 | 1 | 8µs | 61µs | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@17 |
| 1 | 1 | 1 | 7µs | 28µs | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@14 |
| 1 | 1 | 1 | 7µs | 11µs | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@12 |
| 1 | 1 | 1 | 7µs | 18µs | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@11 |
| 1 | 1 | 1 | 7µs | 336µs | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@16 |
| 1 | 1 | 1 | 6µs | 8µs | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::default_severity |
| 1 | 1 | 1 | 6µs | 6µs | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::supported_parameters |
| 1 | 1 | 1 | 2µs | 2µs | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::CORE:qr (opcode) |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::_create_violation |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::_is_first_argument_of_chmod_or_umask |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::_is_fourth_argument_of_sysopen |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::_is_second_argument_of_mkdir |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::_is_third_argument_of_dbmopen |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::_previous_token_that_isnt_a_parenthesis |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::default_themes |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::violates |
| 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::ValuesAndExpressions::ProhibitLeadingZeros; | ||||
| 9 | |||||
| 10 | 2 | 41µs | 1 | 19µs | # spent 19µs within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::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::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@10 |
| 11 | 2 | 20µs | 2 | 29µs | # spent 18µs (7+11) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::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::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@11
# spent 11µs making 1 call to strict::import |
| 12 | 2 | 19µs | 2 | 15µs | # spent 11µs (7+4) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::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::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@12
# spent 4µs making 1 call to warnings::import |
| 13 | |||||
| 14 | 2 | 23µs | 2 | 49µs | # spent 28µs (7+21) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@14 which was called:
# once (7µs+21µs) by Module::Pluggable::Object::_require at line 14 # spent 28µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@14
# spent 21µs making 1 call to Exporter::import |
| 15 | |||||
| 16 | 2 | 24µs | 2 | 665µs | # spent 336µs (7+329) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@16 which was called:
# once (7µs+329µs) by Module::Pluggable::Object::_require at line 16 # spent 336µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@16
# spent 329µs making 1 call to Exporter::import |
| 17 | 2 | 567µs | 2 | 115µs | # spent 61µs (8+54) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@17 which was called:
# once (8µs+54µs) by Module::Pluggable::Object::_require at line 17 # spent 61µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::BEGIN@17
# spent 54µs making 1 call to base::import |
| 18 | |||||
| 19 | 1 | 600ns | our $VERSION = '1.121'; | ||
| 20 | |||||
| 21 | #----------------------------------------------------------------------------- | ||||
| 22 | |||||
| 23 | 1 | 9µs | 2 | 30µs | Readonly::Scalar my $LEADING_RX => qr<\A [+-]? (?: 0+ _* )+ [1-9]>xms; # spent 28µs making 1 call to Readonly::Scalar
# spent 2µs making 1 call to Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::CORE:qr |
| 24 | 1 | 2µs | 1 | 43µs | Readonly::Scalar my $EXPL => [ 58 ]; # spent 43µs making 1 call to Readonly::Scalar |
| 25 | |||||
| 26 | #----------------------------------------------------------------------------- | ||||
| 27 | |||||
| 28 | # spent 6µs within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::supported_parameters which was called:
# once (6µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||||
| 29 | return ( | ||||
| 30 | { | ||||
| 31 | 1 | 9µs | name => 'strict', | ||
| 32 | description => | ||||
| 33 | q<Don't allow any leading zeros at all. Otherwise builtins that deal with Unix permissions, e.g. chmod, don't get flagged.>, | ||||
| 34 | default_string => '0', | ||||
| 35 | behavior => 'boolean', | ||||
| 36 | }, | ||||
| 37 | ); | ||||
| 38 | } | ||||
| 39 | |||||
| 40 | 1 | 2µs | # spent 8µs (6+1) within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
| 41 | sub default_themes { return qw< core pbp bugs certrec > } | ||||
| 42 | 144 | 392µs | # spent 284µs within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::applies_to which was called 144 times, avg 2µs/call:
# 144 times (284µs+0s) by Perl::Critic::_critique at line 165 of Perl/Critic.pm, avg 2µs/call | ||
| 43 | |||||
| 44 | #----------------------------------------------------------------------------- | ||||
| 45 | |||||
| 46 | sub violates { | ||||
| 47 | my ( $self, $elem, undef ) = @_; | ||||
| 48 | |||||
| 49 | return if $elem !~ $LEADING_RX; | ||||
| 50 | return $self->_create_violation($elem) if $self->{_strict}; | ||||
| 51 | return if $self->_is_first_argument_of_chmod_or_umask($elem); | ||||
| 52 | return if $self->_is_second_argument_of_mkdir($elem); | ||||
| 53 | return if $self->_is_third_argument_of_dbmopen($elem); | ||||
| 54 | return if $self->_is_fourth_argument_of_sysopen($elem); | ||||
| 55 | return $self->_create_violation($elem); | ||||
| 56 | } | ||||
| 57 | |||||
| 58 | sub _create_violation { | ||||
| 59 | my ($self, $elem) = @_; | ||||
| 60 | |||||
| 61 | return $self->violation( | ||||
| 62 | qq<Integer with leading zeros: "$elem">, | ||||
| 63 | $EXPL, | ||||
| 64 | $elem | ||||
| 65 | ); | ||||
| 66 | } | ||||
| 67 | |||||
| 68 | sub _is_first_argument_of_chmod_or_umask { | ||||
| 69 | my ($self, $elem) = @_; | ||||
| 70 | |||||
| 71 | my $previous_token = _previous_token_that_isnt_a_parenthesis($elem); | ||||
| 72 | return if not $previous_token; | ||||
| 73 | |||||
| 74 | my $content = $previous_token->content(); | ||||
| 75 | return $content eq 'chmod' || $content eq 'umask'; | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | sub _is_second_argument_of_mkdir { | ||||
| 79 | my ($self, $elem) = @_; | ||||
| 80 | |||||
| 81 | # Preceding comma. | ||||
| 82 | my $previous_token = _previous_token_that_isnt_a_parenthesis($elem); | ||||
| 83 | return if not $previous_token; | ||||
| 84 | return if $previous_token->content() ne $COMMA; # Don't know what it is. | ||||
| 85 | |||||
| 86 | # Directory name. | ||||
| 87 | $previous_token = | ||||
| 88 | _previous_token_that_isnt_a_parenthesis($previous_token); | ||||
| 89 | return if not $previous_token; | ||||
| 90 | |||||
| 91 | $previous_token = | ||||
| 92 | _previous_token_that_isnt_a_parenthesis($previous_token); | ||||
| 93 | return if not $previous_token; | ||||
| 94 | |||||
| 95 | return $previous_token->content() eq 'mkdir'; | ||||
| 96 | } | ||||
| 97 | |||||
| 98 | sub _is_third_argument_of_dbmopen { | ||||
| 99 | my ($self, $elem) = @_; | ||||
| 100 | |||||
| 101 | # Preceding comma. | ||||
| 102 | my $previous_token = _previous_token_that_isnt_a_parenthesis($elem); | ||||
| 103 | return if not $previous_token; | ||||
| 104 | return if $previous_token->content() ne $COMMA; # Don't know what it is. | ||||
| 105 | |||||
| 106 | # File path. | ||||
| 107 | $previous_token = | ||||
| 108 | _previous_token_that_isnt_a_parenthesis($previous_token); | ||||
| 109 | return if not $previous_token; | ||||
| 110 | |||||
| 111 | # Another comma. | ||||
| 112 | $previous_token = | ||||
| 113 | _previous_token_that_isnt_a_parenthesis($previous_token); | ||||
| 114 | return if not $previous_token; | ||||
| 115 | return if $previous_token->content() ne $COMMA; # Don't know what it is. | ||||
| 116 | |||||
| 117 | # Variable name. | ||||
| 118 | $previous_token = | ||||
| 119 | _previous_token_that_isnt_a_parenthesis($previous_token); | ||||
| 120 | return if not $previous_token; | ||||
| 121 | |||||
| 122 | $previous_token = | ||||
| 123 | _previous_token_that_isnt_a_parenthesis($previous_token); | ||||
| 124 | return if not $previous_token; | ||||
| 125 | |||||
| 126 | return $previous_token->content() eq 'dbmopen'; | ||||
| 127 | } | ||||
| 128 | |||||
| 129 | sub _is_fourth_argument_of_sysopen { | ||||
| 130 | my ($self, $elem) = @_; | ||||
| 131 | |||||
| 132 | # Preceding comma. | ||||
| 133 | my $previous_token = _previous_token_that_isnt_a_parenthesis($elem); | ||||
| 134 | return if not $previous_token; | ||||
| 135 | return if $previous_token->content() ne $COMMA; # Don't know what it is. | ||||
| 136 | |||||
| 137 | # Mode. | ||||
| 138 | $previous_token = | ||||
| 139 | _previous_token_that_isnt_a_parenthesis($previous_token); | ||||
| 140 | while ($previous_token and $previous_token->content() ne $COMMA) { | ||||
| 141 | $previous_token = | ||||
| 142 | _previous_token_that_isnt_a_parenthesis($previous_token); | ||||
| 143 | } | ||||
| 144 | return if not $previous_token; | ||||
| 145 | return if $previous_token->content() ne $COMMA; # Don't know what it is. | ||||
| 146 | |||||
| 147 | # File name. | ||||
| 148 | $previous_token = | ||||
| 149 | _previous_token_that_isnt_a_parenthesis($previous_token); | ||||
| 150 | return if not $previous_token; | ||||
| 151 | |||||
| 152 | # Yet another comma. | ||||
| 153 | $previous_token = | ||||
| 154 | _previous_token_that_isnt_a_parenthesis($previous_token); | ||||
| 155 | return if not $previous_token; | ||||
| 156 | return if $previous_token->content() ne $COMMA; # Don't know what it is. | ||||
| 157 | |||||
| 158 | # File handle. | ||||
| 159 | $previous_token = | ||||
| 160 | _previous_token_that_isnt_a_parenthesis($previous_token); | ||||
| 161 | return if not $previous_token; | ||||
| 162 | |||||
| 163 | $previous_token = | ||||
| 164 | _previous_token_that_isnt_a_parenthesis($previous_token); | ||||
| 165 | return if not $previous_token; | ||||
| 166 | |||||
| 167 | return $previous_token->content() eq 'sysopen'; | ||||
| 168 | } | ||||
| 169 | |||||
| 170 | sub _previous_token_that_isnt_a_parenthesis { | ||||
| 171 | my ($elem) = @_; | ||||
| 172 | |||||
| 173 | my $previous_token = $elem->previous_token(); | ||||
| 174 | while ( | ||||
| 175 | $previous_token | ||||
| 176 | and ( | ||||
| 177 | not $previous_token->significant() | ||||
| 178 | or $previous_token->content() eq $LEFT_PAREN | ||||
| 179 | or $previous_token->content() eq $RIGHT_PAREN | ||||
| 180 | ) | ||||
| 181 | ) { | ||||
| 182 | $previous_token = $previous_token->previous_token(); | ||||
| 183 | } | ||||
| 184 | |||||
| 185 | return $previous_token; | ||||
| 186 | } | ||||
| 187 | |||||
| 188 | 1 | 3µs | 1; | ||
| 189 | |||||
| 190 | __END__ | ||||
# spent 2µs within Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros::CORE:qr which was called:
# once (2µs+0s) by Module::Pluggable::Object::_require at line 23 |