| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/TestingAndDebugging/ProhibitNoWarnings.pm |
| Statements | Executed 28 statements in 649µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 16µs | 16µs | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@10 |
| 1 | 1 | 1 | 16µs | 19µs | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::supported_parameters |
| 1 | 1 | 1 | 11µs | 34µs | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@17 |
| 1 | 1 | 1 | 8µs | 12µs | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@12 |
| 1 | 1 | 1 | 7µs | 19µs | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@11 |
| 1 | 1 | 1 | 7µs | 29µs | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@13 |
| 1 | 1 | 1 | 7µs | 58µs | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@19 |
| 1 | 1 | 1 | 7µs | 387µs | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@18 |
| 1 | 1 | 1 | 7µs | 148µs | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@15 |
| 1 | 1 | 1 | 6µs | 7µs | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::default_severity |
| 1 | 1 | 1 | 4µs | 4µs | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::_parse_allow |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::__ANON__[:107] |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::__ANON__[:109] |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::__ANON__[:110] |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::__ANON__[:111] |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::__ANON__[:87] |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::_extract_potential_categories |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::applies_to |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::default_themes |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::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::TestingAndDebugging::ProhibitNoWarnings; | ||||
| 9 | |||||
| 10 | 2 | 40µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::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::TestingAndDebugging::ProhibitNoWarnings::BEGIN@10 |
| 11 | 2 | 20µs | 2 | 30µs | # spent 19µs (7+11) within Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@11 which was called:
# once (7µs+11µs) by Module::Pluggable::Object::_require at line 11 # spent 19µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@11
# spent 12µs making 1 call to strict::import |
| 12 | 2 | 19µs | 2 | 16µs | # spent 12µs (8+4) within Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@12 which was called:
# once (8µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 12µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@12
# spent 4µs making 1 call to warnings::import |
| 13 | 2 | 22µs | 2 | 50µs | # spent 29µs (7+21) within Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@13 which was called:
# once (7µs+21µs) by Module::Pluggable::Object::_require at line 13 # spent 29µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@13
# spent 21µs making 1 call to Exporter::import |
| 14 | |||||
| 15 | 2 | 25µs | 2 | 289µs | # spent 148µs (7+141) within Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@15 which was called:
# once (7µs+141µs) by Module::Pluggable::Object::_require at line 15 # spent 148µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@15
# spent 141µs making 1 call to Exporter::Tiny::import |
| 16 | |||||
| 17 | 2 | 26µs | 2 | 56µs | # spent 34µs (11+22) within Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@17 which was called:
# once (11µs+22µs) by Module::Pluggable::Object::_require at line 17 # spent 34µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@17
# spent 22µs making 1 call to Exporter::import |
| 18 | 2 | 28µs | 2 | 766µs | # spent 387µs (7+379) within Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@18 which was called:
# once (7µs+379µs) by Module::Pluggable::Object::_require at line 18 # spent 387µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@18
# spent 379µs making 1 call to Exporter::import |
| 19 | 2 | 430µs | 2 | 109µs | # spent 58µs (7+51) within Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@19 which was called:
# once (7µs+51µs) by Module::Pluggable::Object::_require at line 19 # spent 58µs making 1 call to Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::BEGIN@19
# spent 51µs making 1 call to base::import |
| 20 | |||||
| 21 | 1 | 600ns | our $VERSION = '1.121'; | ||
| 22 | |||||
| 23 | #----------------------------------------------------------------------------- | ||||
| 24 | |||||
| 25 | 1 | 2µs | 1 | 30µs | Readonly::Scalar my $DESC => q{Warnings disabled}; # spent 30µs making 1 call to Readonly::Scalar |
| 26 | 1 | 2µs | 1 | 44µs | Readonly::Scalar my $EXPL => [ 431 ]; # spent 44µs making 1 call to Readonly::Scalar |
| 27 | |||||
| 28 | #----------------------------------------------------------------------------- | ||||
| 29 | |||||
| 30 | # spent 19µs (16+2) within Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::supported_parameters which was called:
# once (16µs+2µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||||
| 31 | return ( | ||||
| 32 | { | ||||
| 33 | 1 | 14µs | 2 | 2µs | name => 'allow', # spent 2µs making 2 calls to Readonly::Scalar::FETCH, avg 1µs/call |
| 34 | description => 'Permitted warning categories.', | ||||
| 35 | default_string => $EMPTY, | ||||
| 36 | parser => \&_parse_allow, | ||||
| 37 | }, | ||||
| 38 | { | ||||
| 39 | name => 'allow_with_category_restriction', | ||||
| 40 | description => | ||||
| 41 | 'Allow "no warnings" if it restricts the kinds of warnings that are turned off.', | ||||
| 42 | default_string => '0', | ||||
| 43 | behavior => 'boolean', | ||||
| 44 | }, | ||||
| 45 | ); | ||||
| 46 | } | ||||
| 47 | |||||
| 48 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
| 49 | sub default_themes { return qw( core bugs pbp certrec ) } | ||||
| 50 | sub applies_to { return 'PPI::Statement::Include' } | ||||
| 51 | |||||
| 52 | #----------------------------------------------------------------------------- | ||||
| 53 | |||||
| 54 | # spent 4µs within Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings::_parse_allow which was called:
# once (4µs+0s) by Perl::Critic::PolicyParameter::parse_and_validate_config_value at line 231 of Perl/Critic/PolicyParameter.pm | ||||
| 55 | 1 | 500ns | my ($self, $parameter, $config_string) = @_; | ||
| 56 | |||||
| 57 | 1 | 1µs | $self->{_allow} = {}; | ||
| 58 | |||||
| 59 | 1 | 400ns | if( defined $config_string ) { | ||
| 60 | my $allowed = lc $config_string; #String of words | ||||
| 61 | my %allowed = hashify( $allowed =~ m/ (\w+) /gxms ); | ||||
| 62 | |||||
| 63 | $self->{_allow} = \%allowed; | ||||
| 64 | } | ||||
| 65 | |||||
| 66 | 1 | 4µs | return; | ||
| 67 | } | ||||
| 68 | |||||
| 69 | #----------------------------------------------------------------------------- | ||||
| 70 | |||||
| 71 | sub violates { | ||||
| 72 | |||||
| 73 | my ( $self, $elem, undef ) = @_; | ||||
| 74 | |||||
| 75 | return if $elem->type() ne 'no'; | ||||
| 76 | return if $elem->pragma() ne 'warnings'; | ||||
| 77 | |||||
| 78 | my @words = _extract_potential_categories( $elem ); | ||||
| 79 | @words >= 2 | ||||
| 80 | and 'no' eq $words[0] | ||||
| 81 | and 'warnings' eq $words[1] | ||||
| 82 | or throw_internal | ||||
| 83 | q<'no warnings' word list did not begin with qw{ no warnings }>; | ||||
| 84 | splice @words, 0, 2; | ||||
| 85 | |||||
| 86 | return if $self->{_allow_with_category_restriction} and @words; | ||||
| 87 | return if @words && all { exists $self->{_allow}->{$_} } @words; | ||||
| 88 | |||||
| 89 | #If we get here, then it must be a violation | ||||
| 90 | return $self->violation( $DESC, $EXPL, $elem ); | ||||
| 91 | } | ||||
| 92 | |||||
| 93 | #----------------------------------------------------------------------------- | ||||
| 94 | |||||
| 95 | # Traverse the element, accumulating and ultimately returning things | ||||
| 96 | # that might be warnings categories. These are: | ||||
| 97 | # * Words (because of the 'foo' in 'no warnings foo => "bar"'); | ||||
| 98 | # * Quotes (because of 'no warnings "foo"'); | ||||
| 99 | # * qw{} strings (obviously); | ||||
| 100 | # * Nodes (because of 'no warnings ( "foo", "bar" )'). | ||||
| 101 | # We don't lop off the 'no' and 'warnings' because we recurse. | ||||
| 102 | # RT #74647. | ||||
| 103 | |||||
| 104 | { | ||||
| 105 | |||||
| 106 | 1 | 2µs | Readonly::Array my @HANDLER => ( | ||
| 107 | [ 'PPI::Token::Word' => sub { return $_[0]->content() } ], | ||||
| 108 | [ 'PPI::Token::QuoteLike::Words' => | ||||
| 109 | sub { return $_[0]->literal() }, ], | ||||
| 110 | [ 'PPI::Token::Quote' => sub { return $_[0]->string() } ], | ||||
| 111 | 1 | 6µs | 1 | 106µs | [ 'PPI::Node' => sub { _extract_potential_categories( $_[0] ) } ], # spent 106µs making 1 call to Readonly::Array |
| 112 | ); | ||||
| 113 | |||||
| 114 | sub _extract_potential_categories { | ||||
| 115 | my ( $elem ) = @_; | ||||
| 116 | |||||
| 117 | my @words; | ||||
| 118 | foreach my $child ( $elem->schildren() ) { | ||||
| 119 | foreach my $hdlr ( @HANDLER ) { | ||||
| 120 | $child->isa( $hdlr->[0] ) | ||||
| 121 | or next; | ||||
| 122 | push @words, $hdlr->[1]->( $child ); | ||||
| 123 | last; | ||||
| 124 | } | ||||
| 125 | } | ||||
| 126 | |||||
| 127 | return @words; | ||||
| 128 | } | ||||
| 129 | |||||
| 130 | } | ||||
| 131 | |||||
| 132 | 1 | 5µs | 1; | ||
| 133 | |||||
| 134 | __END__ |