| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/CodeLayout/ProhibitHardTabs.pm |
| Statements | Executed 19 statements in 443µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 15µs | 15µs | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@10 |
| 1 | 1 | 1 | 8µs | 8µs | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::supported_parameters |
| 1 | 1 | 1 | 7µs | 11µs | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@12 |
| 1 | 1 | 1 | 7µs | 27µs | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@13 |
| 1 | 1 | 1 | 7µs | 18µs | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@11 |
| 1 | 1 | 1 | 7µs | 192µs | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@15 |
| 1 | 1 | 1 | 7µs | 56µs | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@16 |
| 1 | 1 | 1 | 6µs | 7µs | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::default_severity |
| 1 | 1 | 1 | 1µs | 1µs | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::CORE:qr (opcode) |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::_allow_leading_tabs |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::_is_extended_regex |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::applies_to |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::default_themes |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::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::CodeLayout::ProhibitHardTabs; | ||||
| 9 | |||||
| 10 | 2 | 42µs | 1 | 15µs | # spent 15µs within Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@10 which was called:
# once (15µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 15µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@10 |
| 11 | 2 | 20µs | 2 | 29µs | # spent 18µs (7+11) within Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::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::CodeLayout::ProhibitHardTabs::BEGIN@11
# spent 11µs making 1 call to strict::import |
| 12 | 2 | 18µs | 2 | 14µs | # spent 11µs (7+4) within Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::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::CodeLayout::ProhibitHardTabs::BEGIN@12
# spent 4µs making 1 call to warnings::import |
| 13 | 2 | 22µs | 2 | 48µs | # spent 27µs (7+20) within Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@13 which was called:
# once (7µs+20µs) by Module::Pluggable::Object::_require at line 13 # spent 27µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@13
# spent 20µs making 1 call to Exporter::import |
| 14 | |||||
| 15 | 2 | 23µs | 2 | 377µs | # spent 192µs (7+185) within Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@15 which was called:
# once (7µs+185µs) by Module::Pluggable::Object::_require at line 15 # spent 192µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@15
# spent 185µs making 1 call to Exporter::import |
| 16 | 2 | 293µs | 2 | 106µs | # spent 56µs (7+50) within Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@16 which was called:
# once (7µs+50µs) by Module::Pluggable::Object::_require at line 16 # spent 56µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::BEGIN@16
# spent 50µs making 1 call to base::import |
| 17 | |||||
| 18 | 1 | 500ns | our $VERSION = '1.121'; | ||
| 19 | |||||
| 20 | #----------------------------------------------------------------------------- | ||||
| 21 | |||||
| 22 | 1 | 2µs | 1 | 28µs | Readonly::Scalar my $DESC => q{Hard tabs used}; # spent 28µs making 1 call to Readonly::Scalar |
| 23 | 1 | 2µs | 1 | 42µs | Readonly::Scalar my $EXPL => [ 20 ]; # spent 42µs making 1 call to Readonly::Scalar |
| 24 | |||||
| 25 | #----------------------------------------------------------------------------- | ||||
| 26 | |||||
| 27 | # The following regex should probably be "qr{^ .* [^\t]+ \t}xms" but it doesn't | ||||
| 28 | # match when I expect it to. I haven't figured out why, so I used "\S" to | ||||
| 29 | # approximately mean "not a tab", and that seemed to work. | ||||
| 30 | |||||
| 31 | 1 | 6µs | 2 | 22µs | Readonly::Scalar my $NON_LEADING_TAB_REGEX => qr{^ .* \S+ \t }xms; # spent 21µs making 1 call to Readonly::Scalar
# spent 1µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::CORE:qr |
| 32 | |||||
| 33 | #----------------------------------------------------------------------------- | ||||
| 34 | |||||
| 35 | # spent 8µs within Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::supported_parameters which was called:
# once (8µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||||
| 36 | return ( | ||||
| 37 | { | ||||
| 38 | 1 | 10µs | name => 'allow_leading_tabs', | ||
| 39 | description => 'Allow hard tabs before first non-whitespace character.', | ||||
| 40 | default_string => '1', | ||||
| 41 | behavior => 'boolean', | ||||
| 42 | }, | ||||
| 43 | ); | ||||
| 44 | } | ||||
| 45 | |||||
| 46 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
| 47 | sub default_themes { return qw( core cosmetic pbp ) } | ||||
| 48 | sub applies_to { return 'PPI::Token' } | ||||
| 49 | |||||
| 50 | #----------------------------------------------------------------------------- | ||||
| 51 | |||||
| 52 | sub violates { | ||||
| 53 | my ( $self, $elem, undef ) = @_; | ||||
| 54 | $elem =~ m{ \t }xms || return; | ||||
| 55 | |||||
| 56 | # The __DATA__ element is exempt | ||||
| 57 | return if $elem->parent->isa('PPI::Statement::Data'); | ||||
| 58 | |||||
| 59 | # If allowed, permit leading tabs in situations where whitespace s not significant. | ||||
| 60 | if ( $self->_allow_leading_tabs() ) { | ||||
| 61 | |||||
| 62 | return if $elem->location->[1] == 1; | ||||
| 63 | |||||
| 64 | return if _is_extended_regex($elem) | ||||
| 65 | && $elem !~ $NON_LEADING_TAB_REGEX; | ||||
| 66 | |||||
| 67 | return if $elem->isa('PPI::Token::QuoteLike::Words') | ||||
| 68 | && $elem !~ $NON_LEADING_TAB_REGEX; | ||||
| 69 | } | ||||
| 70 | |||||
| 71 | # If we get here, then it must be a violation... | ||||
| 72 | return $self->violation( $DESC, $EXPL, $elem ); | ||||
| 73 | } | ||||
| 74 | |||||
| 75 | #----------------------------------------------------------------------------- | ||||
| 76 | |||||
| 77 | sub _allow_leading_tabs { | ||||
| 78 | my ( $self ) = @_; | ||||
| 79 | return $self->{_allow_leading_tabs}; | ||||
| 80 | } | ||||
| 81 | |||||
| 82 | #----------------------------------------------------------------------------- | ||||
| 83 | |||||
| 84 | sub _is_extended_regex { | ||||
| 85 | my ($elem) = @_; | ||||
| 86 | |||||
| 87 | $elem->isa('PPI::Token::Regexp') | ||||
| 88 | || $elem->isa('PPI::Token::QuoteLike::Regexp') | ||||
| 89 | || return; | ||||
| 90 | |||||
| 91 | # Look for the /x modifier near the end | ||||
| 92 | return $elem =~ m{\b [gimso]* x [gimso]* $}xms; | ||||
| 93 | } | ||||
| 94 | |||||
| 95 | 1 | 4µs | 1; | ||
| 96 | |||||
| 97 | __END__ | ||||
# spent 1µs within Perl::Critic::Policy::CodeLayout::ProhibitHardTabs::CORE:qr which was called:
# once (1µs+0s) by Module::Pluggable::Object::_require at line 31 |