Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/ControlStructures/ProhibitPostfixControls.pm |
Statements | Executed 17 statements in 454µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 50µs | 67µs | supported_parameters | Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::
1 | 1 | 1 | 17µs | 17µs | BEGIN@10 | Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::
1 | 1 | 1 | 8µs | 30µs | BEGIN@13 | Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::
1 | 1 | 1 | 8µs | 11µs | BEGIN@12 | Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::
1 | 1 | 1 | 7µs | 19µs | BEGIN@11 | Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::
1 | 1 | 1 | 7µs | 654µs | BEGIN@15 | Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::
1 | 1 | 1 | 7µs | 58µs | BEGIN@16 | Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::
1 | 1 | 1 | 6µs | 7µs | default_severity | Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::
1 | 1 | 1 | 3µs | 3µs | CORE:sort (opcode) | Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::
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::ControlStructures::ProhibitPostfixControls; | ||||
9 | |||||
10 | 2 | 41µs | 1 | 17µs | # spent 17µs within Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::BEGIN@10 which was called:
# once (17µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 17µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::BEGIN@10 |
11 | 2 | 20µs | 2 | 31µs | # spent 19µs (7+12) within Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::BEGIN@11 which was called:
# once (7µs+12µs) by Module::Pluggable::Object::_require at line 11 # spent 19µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::BEGIN@11
# spent 12µs making 1 call to strict::import |
12 | 2 | 23µs | 2 | 15µs | # spent 11µs (8+4) within Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::BEGIN@12 which was called:
# once (8µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 11µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | 2 | 24µs | 2 | 51µs | # spent 30µs (8+22) within Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::BEGIN@13 which was called:
# once (8µs+22µs) by Module::Pluggable::Object::_require at line 13 # spent 30µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::BEGIN@13
# spent 22µs making 1 call to Exporter::import |
14 | |||||
15 | 2 | 25µs | 2 | 1.30ms | # spent 654µs (7+647) within Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::BEGIN@15 which was called:
# once (7µs+647µs) by Module::Pluggable::Object::_require at line 15 # spent 654µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::BEGIN@15
# spent 647µs making 1 call to Exporter::import |
16 | 2 | 271µs | 2 | 109µs | # spent 58µs (7+51) within Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::BEGIN@16 which was called:
# once (7µs+51µs) by Module::Pluggable::Object::_require at line 16 # spent 58µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::BEGIN@16
# spent 51µs making 1 call to base::import |
17 | |||||
18 | 1 | 600ns | our $VERSION = '1.121'; | ||
19 | |||||
20 | #----------------------------------------------------------------------------- | ||||
21 | |||||
22 | 1 | 4µs | 1 | 147µs | Readonly::Hash my %PAGES_OF => ( # spent 147µs making 1 call to Readonly::Hash |
23 | if => [ 93, 94 ], | ||||
24 | unless => [ 96, 97 ], | ||||
25 | until => [ 96, 97 ], | ||||
26 | for => [ 96 ], | ||||
27 | foreach => [ 96 ], | ||||
28 | while => [ 96 ], | ||||
29 | when => q<Similar to "if", postfix "when" should only be used with flow-control>, | ||||
30 | ); | ||||
31 | |||||
32 | #----------------------------------------------------------------------------- | ||||
33 | |||||
34 | # spent 67µs (50+17) within Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::supported_parameters which was called:
# once (50µs+17µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||||
35 | return ( | ||||
36 | { | ||||
37 | 1 | 39µs | 11 | 17µs | name => 'allow', # spent 9µs making 7 calls to Readonly::Hash::NEXTKEY, avg 1µs/call
# spent 4µs making 1 call to Readonly::Hash::FIRSTKEY
# spent 3µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::CORE:sort
# spent 2µs making 2 calls to Readonly::Scalar::FETCH, avg 1µs/call |
38 | description => 'The permitted postfix controls.', | ||||
39 | default_string => $EMPTY, | ||||
40 | behavior => 'enumeration', | ||||
41 | enumeration_values => [ sort keys %PAGES_OF ], | ||||
42 | enumeration_allow_multiple_values => 1, | ||||
43 | }, | ||||
44 | { | ||||
45 | name => 'flowcontrol', | ||||
46 | description => 'The exempt flow control functions.', | ||||
47 | default_string => 'carp cluck confess croak die exit goto warn', | ||||
48 | behavior => 'string list', | ||||
49 | }, | ||||
50 | ); | ||||
51 | } | ||||
52 | |||||
53 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
54 | sub default_themes { return qw(core pbp cosmetic) } | ||||
55 | sub applies_to { return 'PPI::Token::Word' } | ||||
56 | |||||
57 | #----------------------------------------------------------------------------- | ||||
58 | |||||
59 | sub violates { | ||||
60 | my ( $self, $elem, undef ) = @_; | ||||
61 | |||||
62 | my $expl = $PAGES_OF{$elem}; | ||||
63 | return if not $expl; | ||||
64 | |||||
65 | return if is_hash_key($elem); | ||||
66 | return if is_method_call($elem); | ||||
67 | return if is_subroutine_name($elem); | ||||
68 | return if is_included_module_name($elem); | ||||
69 | return if is_package_declaration($elem); | ||||
70 | |||||
71 | # Skip controls that are allowed | ||||
72 | return if exists $self->{_allow}->{ $elem->content() }; | ||||
73 | |||||
74 | # Skip Compound variety (these are good) | ||||
75 | my $stmnt = $elem->statement(); | ||||
76 | return if not $stmnt; | ||||
77 | return if $stmnt->isa('PPI::Statement::Compound'); | ||||
78 | return if $stmnt->isa('PPI::Statement::When'); | ||||
79 | |||||
80 | # Handle special cases | ||||
81 | my $content = $elem->content(); | ||||
82 | if ($content eq 'if' or $content eq 'when') { | ||||
83 | # Postfix 'if' allowed with loop breaks, or other | ||||
84 | # flow-controls like 'die', 'warn', and 'croak' | ||||
85 | return if $stmnt->isa('PPI::Statement::Break'); | ||||
86 | return if defined $self->{_flowcontrol}{ $stmnt->schild(0)->content() }; | ||||
87 | } | ||||
88 | |||||
89 | # If we get here, it must be postfix. | ||||
90 | my $desc = qq{Postfix control "$content" used}; | ||||
91 | return $self->violation($desc, $expl, $elem); | ||||
92 | } | ||||
93 | |||||
94 | 1 | 4µs | 1; | ||
95 | |||||
96 | __END__ | ||||
# spent 3µs within Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::CORE:sort which was called:
# once (3µs+0s) by Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls::supported_parameters at line 37 |