| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/CodeLayout/ProhibitQuotedWordLists.pm |
| Statements | Executed 18 statements in 491µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 18µs | 18µs | Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@10 |
| 1 | 1 | 1 | 8µs | 8µs | Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::supported_parameters |
| 1 | 1 | 1 | 8µs | 582µs | Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@16 |
| 1 | 1 | 1 | 8µs | 70µs | Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@17 |
| 1 | 1 | 1 | 7µs | 20µs | Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@11 |
| 1 | 1 | 1 | 7µs | 11µs | Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@12 |
| 1 | 1 | 1 | 7µs | 29µs | Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@14 |
| 1 | 1 | 1 | 6µs | 7µs | Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::default_severity |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::_is_literal |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::applies_to |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::default_themes |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::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::ProhibitQuotedWordLists; | ||||
| 9 | |||||
| 10 | 2 | 43µs | 1 | 18µs | # spent 18µs within Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@10 which was called:
# once (18µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 18µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@10 |
| 11 | 2 | 21µs | 2 | 33µs | # spent 20µs (7+13) within Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@11 which was called:
# once (7µs+13µs) by Module::Pluggable::Object::_require at line 11 # spent 20µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@11
# spent 13µs making 1 call to strict::import |
| 12 | 2 | 20µs | 2 | 15µs | # spent 11µs (7+4) within Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::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::ProhibitQuotedWordLists::BEGIN@12
# spent 4µs making 1 call to warnings::import |
| 13 | |||||
| 14 | 2 | 25µs | 2 | 52µs | # spent 29µs (7+22) within Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@14 which was called:
# once (7µs+22µs) by Module::Pluggable::Object::_require at line 14 # spent 29µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@14
# spent 22µs making 1 call to Exporter::import |
| 15 | |||||
| 16 | 2 | 25µs | 2 | 1.16ms | # spent 582µs (8+575) within Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@16 which was called:
# once (8µs+575µs) by Module::Pluggable::Object::_require at line 16 # spent 582µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@16
# spent 575µs making 1 call to Exporter::import |
| 17 | 2 | 340µs | 2 | 132µs | # spent 70µs (8+62) within Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@17 which was called:
# once (8µs+62µs) by Module::Pluggable::Object::_require at line 17 # spent 70µs making 1 call to Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::BEGIN@17
# spent 62µs making 1 call to base::import |
| 18 | |||||
| 19 | 1 | 500ns | our $VERSION = '1.121'; | ||
| 20 | |||||
| 21 | #----------------------------------------------------------------------------- | ||||
| 22 | |||||
| 23 | 1 | 2µs | 1 | 29µs | Readonly::Scalar my $DESC => q{List of quoted literal words}; # spent 29µs making 1 call to Readonly::Scalar |
| 24 | 1 | 900ns | 1 | 21µs | Readonly::Scalar my $EXPL => q{Use 'qw()' instead}; # spent 21µs making 1 call to Readonly::Scalar |
| 25 | |||||
| 26 | #----------------------------------------------------------------------------- | ||||
| 27 | |||||
| 28 | # spent 8µs within Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::supported_parameters which was called:
# once (8µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||||
| 29 | return ( | ||||
| 30 | { | ||||
| 31 | 1 | 10µs | name => 'min_elements', | ||
| 32 | description => 'The minimum number of words in a list that will be complained about.', | ||||
| 33 | default_string => '2', | ||||
| 34 | behavior => 'integer', | ||||
| 35 | integer_minimum => 1, | ||||
| 36 | }, | ||||
| 37 | { | ||||
| 38 | name => 'strict', | ||||
| 39 | description => 'Complain even if there are non-word characters in the values.', | ||||
| 40 | default_string => '0', | ||||
| 41 | behavior => 'boolean', | ||||
| 42 | }, | ||||
| 43 | ); | ||||
| 44 | } | ||||
| 45 | |||||
| 46 | 1 | 1µs | # spent 7µs (6+1) within Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::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 ) } | ||||
| 48 | sub applies_to { return 'PPI::Structure::List' } | ||||
| 49 | |||||
| 50 | #----------------------------------------------------------------------------- | ||||
| 51 | |||||
| 52 | sub violates { | ||||
| 53 | my ( $self, $elem, undef ) = @_; | ||||
| 54 | |||||
| 55 | # Don't worry about subroutine calls | ||||
| 56 | my $sibling = $elem->sprevious_sibling(); | ||||
| 57 | return if not $sibling; | ||||
| 58 | |||||
| 59 | return if $sibling->isa('PPI::Token::Symbol'); | ||||
| 60 | return if $sibling->isa('PPI::Token::Operator') and $sibling eq '->'; | ||||
| 61 | return if $sibling->isa('PPI::Token::Word') and not is_included_module_name($sibling); | ||||
| 62 | |||||
| 63 | # Get the list elements | ||||
| 64 | my $expr = $elem->schild(0); | ||||
| 65 | return if not $expr; | ||||
| 66 | my @children = $expr->schildren(); | ||||
| 67 | return if not @children; | ||||
| 68 | |||||
| 69 | my $count = 0; | ||||
| 70 | for my $child ( @children ) { | ||||
| 71 | next if $child->isa('PPI::Token::Operator') && $child eq $COMMA; | ||||
| 72 | |||||
| 73 | # All elements must be literal strings, | ||||
| 74 | # and must contain 1 or more word characters. | ||||
| 75 | |||||
| 76 | return if not _is_literal($child); | ||||
| 77 | |||||
| 78 | my $string = $child->string(); | ||||
| 79 | return if $string =~ m{ \s }xms; | ||||
| 80 | return if $string eq $EMPTY; | ||||
| 81 | return if not $self->{_strict} and $string !~ m{\A [\w-]+ \z}xms; | ||||
| 82 | $count++; | ||||
| 83 | } | ||||
| 84 | |||||
| 85 | # Were there enough? | ||||
| 86 | return if $count < $self->{_min_elements}; | ||||
| 87 | |||||
| 88 | # If we get here, then all elements were literals | ||||
| 89 | return $self->violation( $DESC, $EXPL, $elem ); | ||||
| 90 | } | ||||
| 91 | |||||
| 92 | sub _is_literal { | ||||
| 93 | my $elem = shift; | ||||
| 94 | return $elem->isa('PPI::Token::Quote::Single') | ||||
| 95 | || $elem->isa('PPI::Token::Quote::Literal'); | ||||
| 96 | } | ||||
| 97 | |||||
| 98 | 1 | 3µs | 1; | ||
| 99 | |||||
| 100 | __END__ |