← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:11 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/RegularExpressions/ProhibitEnumeratedClasses.pm
StatementsExecuted 26 statements in 730µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11127µs27µsPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::BEGIN@10Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@10
1118µs146µsPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::BEGIN@16Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@16
1118µs28µsPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::BEGIN@17Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@17
1118µs57µsPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::BEGIN@21Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@21
1117µs11µsPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::BEGIN@12Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@12
1117µs389µsPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::BEGIN@15Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@15
1117µs19µsPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::BEGIN@11Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@11
1117µs204µsPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::BEGIN@19Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@19
1117µs32µsPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::BEGIN@14Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@14
1115µs7µsPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::default_severityPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::default_severity
1112µs2µsPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::supported_parametersPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::supported_parameters
0000s0sPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::__ANON__[:82]Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::__ANON__[:82]
0000s0sPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::_fixupPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::_fixup
0000s0sPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::_get_character_class_violationsPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::_get_character_class_violations
0000s0sPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::applies_toPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::applies_to
0000s0sPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::default_themesPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::default_themes
0000s0sPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::::violatesPerl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::violates
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1##############################################################################
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6##############################################################################
7
8package Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses;
9
10241µs127µs
# spent 27µs within Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@10 which was called: # once (27µs+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11220µs230µs
# spent 19µs (7+12) within Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@11 which was called: # once (7µs+12µs) by Module::Pluggable::Object::_require at line 11
use strict;
# spent 19µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@11 # spent 12µs making 1 call to strict::import
12221µs215µs
# spent 11µs (7+4) within Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@12 which was called: # once (7µs+4µs) by Module::Pluggable::Object::_require at line 12
use warnings;
# spent 11µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@12 # spent 4µs making 1 call to warnings::import
13
14222µs257µs
# spent 32µs (7+25) within Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@14 which was called: # once (7µs+25µs) by Module::Pluggable::Object::_require at line 14
use Carp qw(carp);
# spent 32µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@14 # spent 25µs making 1 call to Exporter::import
15224µs2770µs
# spent 389µs (7+382) within Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@15 which was called: # once (7µs+382µs) by Module::Pluggable::Object::_require at line 15
use English qw(-no_match_vars);
# spent 389µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@15 # spent 382µs making 1 call to English::import
16223µs2284µs
# spent 146µs (8+138) within Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@16 which was called: # once (8µs+138µs) by Module::Pluggable::Object::_require at line 16
use List::MoreUtils qw(all);
# spent 146µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@16 # spent 138µs making 1 call to Exporter::Tiny::import
17222µs248µs
# spent 28µs (8+20) within Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@17 which was called: # once (8µs+20µs) by Module::Pluggable::Object::_require at line 17
use Readonly;
# spent 28µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@17 # spent 20µs making 1 call to Exporter::import
18
19224µs2402µs
# spent 204µs (7+198) within Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@19 which was called: # once (7µs+198µs) by Module::Pluggable::Object::_require at line 19
use Perl::Critic::Utils qw{ :booleans :severities hashify };
# spent 204µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@19 # spent 198µs making 1 call to Exporter::import
20
212502µs2106µs
# spent 57µs (8+49) within Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@21 which was called: # once (8µs+49µs) by Module::Pluggable::Object::_require at line 21
use base 'Perl::Critic::Policy';
# spent 57µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::BEGIN@21 # spent 49µs making 1 call to base::import
22
231700nsour $VERSION = '1.121';
24
25#-----------------------------------------------------------------------------
26
2712µs130µsReadonly::Scalar my $DESC => q{Use named character classes};
# spent 30µs making 1 call to Readonly::Scalar
2812µs144µsReadonly::Scalar my $EXPL => [248];
# spent 44µs making 1 call to Readonly::Scalar
29
30112µs1338µsReadonly::Array my @PATTERNS => ( # order matters: most to least specific
# spent 338µs making 1 call to Readonly::Array
31 [q{ },'\\t','\\r','\\n'] => ['\\s', '\\S'],
32 ['A-Z','a-z','0-9','_'] => ['\\w', '\\W'], # RT 69322
33 ['A-Z','a-z'] => ['[[:alpha:]]','[[:^alpha:]]'],
34 ['A-Z'] => ['[[:upper:]]','[[:^upper:]]'],
35 ['a-z'] => ['[[:lower:]]','[[:^lower:]]'],
36 ['0-9'] => ['\\d','\\D'],
37 ['\w'] => [undef, '\\W'],
38 ['\s'] => [undef, '\\S'],
39);
40
41#-----------------------------------------------------------------------------
42
4314µs
# spent 2µs within Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::supported_parameters which was called: # once (2µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters { return qw() }
4412µs
# spent 7µs (5+1) within Perl::Critic::Policy::RegularExpressions::ProhibitEnumeratedClasses::default_severity which was called: # once (5µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm
sub default_severity { return $SEVERITY_LOWEST }
45sub default_themes { return qw( core pbp cosmetic unicode ) }
46sub applies_to { return qw(PPI::Token::Regexp::Match
47 PPI::Token::Regexp::Substitute
48 PPI::Token::QuoteLike::Regexp) }
49
50#-----------------------------------------------------------------------------
51
52
53sub violates {
54 my ( $self, $elem, $document ) = @_;
55
56 # optimization: don't bother parsing the regexp if there are no character classes
57 return if $elem !~ m/\[/xms;
58
59 my $re = $document->ppix_regexp_from_element( $elem ) or return;
60 $re->failures() and return;
61
62 my $anyofs = $re->find( 'PPIx::Regexp::Structure::CharClass' )
63 or return;
64 foreach my $anyof ( @{ $anyofs } ) {
65 my $violation;
66 $violation = $self->_get_character_class_violations( $elem, $anyof )
67 and return $violation;
68 }
69
70 return; # OK
71}
72
73sub _get_character_class_violations {
74 my ($self, $elem, $anyof) = @_;
75
76 my %elements;
77 foreach my $element ( $anyof->children() ) {
78 $elements{ _fixup( $element ) } = 1;
79 }
80
81 for (my $i = 0; $i < @PATTERNS; $i += 2) { ##no critic (CStyleForLoop)
82 if (all { exists $elements{$_} } @{$PATTERNS[$i]}) {
83 my $neg = $anyof->negated();
84 my $improvement = $PATTERNS[$i + 1]->[$neg ? 1 : 0];
85 next if !defined $improvement;
86
87 if ($neg && ! defined $PATTERNS[$i + 1]->[0]) {
88 # the [^\w] => \W rule only applies if \w is the only token.
89 # that is it does not apply to [^\w\s]
90 next if 1 != scalar keys %elements;
91 }
92
93 my $orig = join q{}, '[', ($neg ? q{^} : ()), @{$PATTERNS[$i]}, ']';
94 return $self->violation( $DESC . " ($orig vs. $improvement)", $EXPL, $elem );
95 }
96 }
97
98 return; # OK
99}
100
10111µs128µsReadonly::Hash my %ORDINALS => (
# spent 28µs making 1 call to Readonly::Hash
102 ord "\n" => '\\n',
103 ord "\f" => '\\f',
104 ord "\r" => '\\r',
105 ord q< > => q< >,
106);
107
108sub _fixup {
109 my ( $element ) = @_;
110 if ( $element->isa( 'PPIx::Regexp::Token::Literal' ) ) {
111 my $ord = $element->ordinal();
112 exists $ORDINALS{$ord} and return $ORDINALS{$ord};
113 return $element->content();
114 } elsif ( $element->isa( 'PPIx::Regexp::Node' ) ) {
115 return join q{}, map{ _fixup( $_ ) } $element->elements();
116 } else {
117 return $element->content();
118 }
119}
120
12119µs1;
122
123__END__