← 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/ProhibitComplexRegexes.pm
StatementsExecuted 26 statements in 488µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11116µs16µsPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::BEGIN@10Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@10
11112µs41µsPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::BEGIN@16Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@16
11110µs14µsPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::BEGIN@12Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@12
1118µs38µsPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::BEGIN@14Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@14
1117µs25µsPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::BEGIN@17Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@17
1117µs423µsPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::BEGIN@15Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@15
1117µs201µsPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::BEGIN@19Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@19
1117µs64µsPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::BEGIN@21Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@21
1117µs18µsPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::BEGIN@11Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@11
1116µs6µsPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::supported_parametersPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::supported_parameters
1116µs7µsPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::default_severityPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::default_severity
0000s0sPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::applies_toPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::applies_to
0000s0sPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::default_themesPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::default_themes
0000s0sPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::::violatesPerl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::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::ProhibitComplexRegexes;
9
10243µs116µs
# spent 16µs within Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@10 which was called: # once (16µs+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11223µs229µs
# spent 18µs (7+11) within Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@11 which was called: # once (7µs+11µs) by Module::Pluggable::Object::_require at line 11
use strict;
# spent 18µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@11 # spent 11µs making 1 call to strict::import
12220µs218µs
# spent 14µs (10+4) within Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@12 which was called: # once (10µs+4µs) by Module::Pluggable::Object::_require at line 12
use warnings;
# spent 14µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@12 # spent 4µs making 1 call to warnings::import
13
14222µs269µs
# spent 38µs (8+31) within Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@14 which was called: # once (8µs+31µs) by Module::Pluggable::Object::_require at line 14
use Carp;
# spent 38µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@14 # spent 31µs making 1 call to Exporter::import
15224µs2839µs
# spent 423µs (7+416) within Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@15 which was called: # once (7µs+416µs) by Module::Pluggable::Object::_require at line 15
use English qw(-no_match_vars);
# spent 423µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@15 # spent 416µs making 1 call to English::import
16221µs252µs
# spent 41µs (12+30) within Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@16 which was called: # once (12µs+30µs) by Module::Pluggable::Object::_require at line 16
use List::Util qw{ min };
# spent 41µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@16 # spent 11µs making 1 call to List::Util::import
17221µs242µs
# spent 25µs (7+17) within Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@17 which was called: # once (7µs+17µs) by Module::Pluggable::Object::_require at line 17
use Readonly;
# spent 25µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@17 # spent 17µs making 1 call to Exporter::import
18
19224µs2395µs
# spent 201µs (7+194) within Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@19 which was called: # once (7µs+194µs) by Module::Pluggable::Object::_require at line 19
use Perl::Critic::Utils qw{ :booleans :severities };
# spent 201µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@19 # spent 194µs making 1 call to Exporter::import
20
212273µs2121µs
# spent 64µs (7+57) within Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@21 which was called: # once (7µs+57µs) by Module::Pluggable::Object::_require at line 21
use base 'Perl::Critic::Policy';
# spent 64µs making 1 call to Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::BEGIN@21 # spent 57µs making 1 call to base::import
22
231600nsour $VERSION = '1.121';
24
25#-----------------------------------------------------------------------------
26
2712µs130µsReadonly::Scalar my $DESC => q{Split long regexps into smaller qr// chunks};
# spent 30µs making 1 call to Readonly::Scalar
2812µs144µsReadonly::Scalar my $EXPL => [261];
# spent 44µs making 1 call to Readonly::Scalar
29
3011µs124µsReadonly::Scalar my $MAX_LITERAL_LENGTH => 7;
# spent 24µs making 1 call to Readonly::Scalar
311900ns120µsReadonly::Scalar my $MAX_VARIABLE_LENGTH => 4;
# spent 20µs making 1 call to Readonly::Scalar
32
33#-----------------------------------------------------------------------------
34
35
# spent 6µs within Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::supported_parameters which was called: # once (6µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters {
36 return (
37 {
3818µs name => 'max_characters',
39 description =>
40 'The maximum number of characters to allow in a regular expression.',
41 default_string => '60',
42 behavior => 'integer',
43 integer_minimum => 1,
44 },
45 );
46}
47
4811µs
# spent 7µs (6+1) within Perl::Critic::Policy::RegularExpressions::ProhibitComplexRegexes::default_severity which was called: # once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm
sub default_severity { return $SEVERITY_MEDIUM }
49sub default_themes { return qw( core pbp maintenance ) }
50sub applies_to { return qw(PPI::Token::Regexp::Match
51 PPI::Token::Regexp::Substitute
52 PPI::Token::QuoteLike::Regexp) }
53
54#-----------------------------------------------------------------------------
55
56sub violates {
57 my ( $self, $elem, $document ) = @_;
58
59 # Optimization: if its short enough now, parsing won't make it longer
60 return if $self->{_max_characters} >= length $elem->get_match_string();
61
62 my $re = $document->ppix_regexp_from_element( $elem )
63 or return; # Abort on syntax error.
64 $re->failures()
65 and return; # Abort if parse errors found.
66 my $qr = $re->regular_expression()
67 or return; # Abort if no regular expression.
68
69 my $length = 0;
70 # We use map { $_->tokens() } qr->children() rather than just
71 # $qr->tokens() because we are not interested in the delimiters.
72 foreach my $token ( map { $_->tokens() } $qr->children() ) {
73
74 # Do not count whitespace or comments
75 $token->significant() or next;
76
77 if ( $token->isa( 'PPIx::Regexp::Token::Interpolation' ) ) {
78
79 # Do not penalize long variable names
80 $length += min( $MAX_VARIABLE_LENGTH, length $token->content() );
81
82 } elsif ( $token->isa( 'PPIx::Regexp::Token::Literal' ) ) {
83
84 # Do not penalize long literals like \p{...}
85 $length += min( $MAX_LITERAL_LENGTH, length $token->content() );
86
87 } else {
88
89 # Take everything else at face value
90 $length += length $token->content();
91
92 }
93
94 }
95
96 return if $self->{_max_characters} >= $length;
97
98 return $self->violation( $DESC, $EXPL, $elem );
99}
100
10114µs1;
102
103__END__