| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Theme.pm |
| Statements | Executed 620 statements in 1.62ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 141 | 1 | 1 | 923µs | 11.9ms | Perl::Critic::Theme::policy_is_thematic |
| 2 | 2 | 2 | 36µs | 39µs | Perl::Critic::Theme::cook_rule |
| 1 | 1 | 1 | 23µs | 41µs | Perl::Critic::Theme::_init |
| 1 | 1 | 1 | 15µs | 15µs | Perl::Critic::Theme::BEGIN@10 |
| 1 | 1 | 1 | 13µs | 92µs | Perl::Critic::Theme::BEGIN@23 |
| 1 | 1 | 1 | 12µs | 73µs | Perl::Critic::Theme::BEGIN@21 |
| 1 | 1 | 1 | 11µs | 52µs | Perl::Critic::Theme::new |
| 1 | 1 | 1 | 10µs | 174µs | Perl::Critic::Theme::BEGIN@18 |
| 1 | 1 | 1 | 9µs | 376µs | Perl::Critic::Theme::BEGIN@13 |
| 1 | 1 | 1 | 8µs | 13µs | Perl::Critic::Theme::BEGIN@16 |
| 1 | 1 | 1 | 7µs | 26µs | Perl::Critic::Theme::BEGIN@14 |
| 1 | 1 | 1 | 7µs | 293µs | Perl::Critic::Theme::BEGIN@20 |
| 1 | 1 | 1 | 7µs | 18µs | Perl::Critic::Theme::BEGIN@11 |
| 1 | 1 | 1 | 6µs | 11µs | Perl::Critic::Theme::BEGIN@12 |
| 1 | 1 | 1 | 4µs | 5µs | Perl::Critic::Theme::CORE:regcomp (opcode) |
| 14 | 7 | 1 | 3µs | 3µs | Perl::Critic::Theme::CORE:subst (opcode) |
| 1 | 1 | 1 | 1µs | 1µs | Perl::Critic::Theme::CORE:qr (opcode) |
| 1 | 1 | 1 | 300ns | 300ns | Perl::Critic::Theme::CORE:match (opcode) |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Theme::rule |
| 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::Theme; | ||||
| 9 | |||||
| 10 | 2 | 38µs | 1 | 15µs | # spent 15µs within Perl::Critic::Theme::BEGIN@10 which was called:
# once (15µs+0s) by Perl::Critic::Config::BEGIN@25 at line 10 # spent 15µs making 1 call to Perl::Critic::Theme::BEGIN@10 |
| 11 | 2 | 19µs | 2 | 30µs | # spent 18µs (7+11) within Perl::Critic::Theme::BEGIN@11 which was called:
# once (7µs+11µs) by Perl::Critic::Config::BEGIN@25 at line 11 # spent 18µs making 1 call to Perl::Critic::Theme::BEGIN@11
# spent 11µs making 1 call to strict::import |
| 12 | 2 | 19µs | 2 | 16µs | # spent 11µs (6+5) within Perl::Critic::Theme::BEGIN@12 which was called:
# once (6µs+5µs) by Perl::Critic::Config::BEGIN@25 at line 12 # spent 11µs making 1 call to Perl::Critic::Theme::BEGIN@12
# spent 5µs making 1 call to warnings::import |
| 13 | 2 | 24µs | 2 | 743µs | # spent 376µs (9+367) within Perl::Critic::Theme::BEGIN@13 which was called:
# once (9µs+367µs) by Perl::Critic::Config::BEGIN@25 at line 13 # spent 376µs making 1 call to Perl::Critic::Theme::BEGIN@13
# spent 367µs making 1 call to English::import |
| 14 | 2 | 21µs | 2 | 45µs | # spent 26µs (7+19) within Perl::Critic::Theme::BEGIN@14 which was called:
# once (7µs+19µs) by Perl::Critic::Config::BEGIN@25 at line 14 # spent 26µs making 1 call to Perl::Critic::Theme::BEGIN@14
# spent 19µs making 1 call to Exporter::import |
| 15 | |||||
| 16 | 2 | 20µs | 2 | 18µs | # spent 13µs (8+5) within Perl::Critic::Theme::BEGIN@16 which was called:
# once (8µs+5µs) by Perl::Critic::Config::BEGIN@25 at line 16 # spent 13µs making 1 call to Perl::Critic::Theme::BEGIN@16
# spent 5µs making 1 call to Exporter::import |
| 17 | |||||
| 18 | 2 | 27µs | 2 | 339µs | # spent 174µs (10+164) within Perl::Critic::Theme::BEGIN@18 which was called:
# once (10µs+164µs) by Perl::Critic::Config::BEGIN@25 at line 18 # spent 174µs making 1 call to Perl::Critic::Theme::BEGIN@18
# spent 164µs making 1 call to Exporter::Tiny::import |
| 19 | |||||
| 20 | 2 | 23µs | 2 | 579µs | # spent 293µs (7+286) within Perl::Critic::Theme::BEGIN@20 which was called:
# once (7µs+286µs) by Perl::Critic::Config::BEGIN@25 at line 20 # spent 293µs making 1 call to Perl::Critic::Theme::BEGIN@20
# spent 286µs making 1 call to Exporter::import |
| 21 | 2 | 28µs | 2 | 134µs | # spent 73µs (12+61) within Perl::Critic::Theme::BEGIN@21 which was called:
# once (12µs+61µs) by Perl::Critic::Config::BEGIN@25 at line 21 # spent 73µs making 1 call to Perl::Critic::Theme::BEGIN@21
# spent 61µs making 1 call to Exporter::import |
| 22 | use Perl::Critic::Exception::Configuration::Option::Global::ParameterValue | ||||
| 23 | 2 | 466µs | 2 | 170µs | # spent 92µs (13+78) within Perl::Critic::Theme::BEGIN@23 which was called:
# once (13µs+78µs) by Perl::Critic::Config::BEGIN@25 at line 23 # spent 92µs making 1 call to Perl::Critic::Theme::BEGIN@23
# spent 78µs making 1 call to Exporter::import |
| 24 | |||||
| 25 | #----------------------------------------------------------------------------- | ||||
| 26 | |||||
| 27 | 1 | 700ns | our $VERSION = '1.121'; | ||
| 28 | |||||
| 29 | #----------------------------------------------------------------------------- | ||||
| 30 | |||||
| 31 | 1 | 2µs | 1 | 26µs | Readonly::Array our @EXPORT_OK => qw{ # spent 26µs making 1 call to Readonly::Array |
| 32 | $RULE_INVALID_CHARACTER_REGEX | ||||
| 33 | cook_rule | ||||
| 34 | }; | ||||
| 35 | |||||
| 36 | #----------------------------------------------------------------------------- | ||||
| 37 | |||||
| 38 | 1 | 6µs | 2 | 26µs | Readonly::Scalar our $RULE_INVALID_CHARACTER_REGEX => # spent 24µs making 1 call to Readonly::Scalar
# spent 1µs making 1 call to Perl::Critic::Theme::CORE:qr |
| 39 | qr/ ( [^()\s\w\d+\-*&|!] ) /xms; | ||||
| 40 | |||||
| 41 | #----------------------------------------------------------------------------- | ||||
| 42 | |||||
| 43 | 1 | 800ns | 1 | 20µs | Readonly::Scalar my $CONFIG_KEY => 'theme'; # spent 20µs making 1 call to Readonly::Scalar |
| 44 | |||||
| 45 | #----------------------------------------------------------------------------- | ||||
| 46 | |||||
| 47 | # spent 52µs (11+41) within Perl::Critic::Theme::new which was called:
# once (11µs+41µs) by Perl::Critic::Config::_validate_and_save_theme at line 659 of Perl/Critic/Config.pm | ||||
| 48 | |||||
| 49 | 1 | 2µs | my ( $class, %args ) = @_; | ||
| 50 | 1 | 2µs | my $self = bless {}, $class; | ||
| 51 | 1 | 3µs | 1 | 41µs | $self->_init( %args ); # spent 41µs making 1 call to Perl::Critic::Theme::_init |
| 52 | 1 | 4µs | return $self; | ||
| 53 | } | ||||
| 54 | |||||
| 55 | #----------------------------------------------------------------------------- | ||||
| 56 | |||||
| 57 | # spent 41µs (23+18) within Perl::Critic::Theme::_init which was called:
# once (23µs+18µs) by Perl::Critic::Theme::new at line 51 | ||||
| 58 | |||||
| 59 | 1 | 1µs | my ($self, %args) = @_; | ||
| 60 | 1 | 3µs | 1 | 1µs | my $rule = $args{-rule} || $EMPTY; # spent 1µs making 1 call to Readonly::Scalar::FETCH |
| 61 | |||||
| 62 | 1 | 10µs | 3 | 7µs | if ( $rule =~ m/$RULE_INVALID_CHARACTER_REGEX/xms ) { # spent 5µs making 1 call to Perl::Critic::Theme::CORE:regcomp
# spent 1µs making 1 call to Readonly::Scalar::FETCH
# spent 300ns making 1 call to Perl::Critic::Theme::CORE:match |
| 63 | throw_global_value | ||||
| 64 | option_name => $CONFIG_KEY, | ||||
| 65 | option_value => $rule, | ||||
| 66 | message_suffix => qq{contains an invalid character: "$1".}; | ||||
| 67 | } | ||||
| 68 | |||||
| 69 | 1 | 5µs | 1 | 11µs | $self->{_rule} = cook_rule( $rule ); # spent 11µs making 1 call to Perl::Critic::Theme::cook_rule |
| 70 | |||||
| 71 | 1 | 4µs | return $self; | ||
| 72 | } | ||||
| 73 | |||||
| 74 | #----------------------------------------------------------------------------- | ||||
| 75 | |||||
| 76 | sub rule { | ||||
| 77 | my $self = shift; | ||||
| 78 | return $self->{_rule}; | ||||
| 79 | } | ||||
| 80 | |||||
| 81 | #----------------------------------------------------------------------------- | ||||
| 82 | |||||
| 83 | # spent 11.9ms (923µs+11.0) within Perl::Critic::Theme::policy_is_thematic which was called 141 times, avg 85µs/call:
# 141 times (923µs+11.0ms) by Perl::Critic::Config::_policy_is_thematic at line 281 of Perl/Critic/Config.pm, avg 85µs/call | ||||
| 84 | |||||
| 85 | 141 | 98µs | my ($self, %args) = @_; | ||
| 86 | 141 | 332µs | 141 | 11.0ms | my $policy = $args{-policy} # spent 11.0ms making 141 calls to Perl::Critic::Policy::to_string, avg 78µs/call |
| 87 | || throw_internal 'The -policy argument is required'; | ||||
| 88 | 141 | 39µs | ref $policy | ||
| 89 | || throw_internal 'The -policy must be an object'; | ||||
| 90 | |||||
| 91 | 141 | 381µs | my $rule = $self->{_rule} or return 1; | ||
| 92 | my %themes = hashify( $policy->get_themes() ); | ||||
| 93 | |||||
| 94 | # This bit of magic turns the rule into a perl expression that can be | ||||
| 95 | # eval-ed for truth. Each theme name in the rule is translated to 1 or 0 | ||||
| 96 | # if the $policy belongs in that theme. For example: | ||||
| 97 | # | ||||
| 98 | # 'bugs && (pbp || core)' ...could become... '1 && (0 || 1)' | ||||
| 99 | |||||
| 100 | my $as_code = $rule; #Making a copy, so $rule is preserved | ||||
| 101 | $as_code =~ s/ ( [\w\d]+ ) /exists $themes{$1} || 0/gexms; | ||||
| 102 | my $is_thematic = eval $as_code; ## no critic (ProhibitStringyEval) | ||||
| 103 | |||||
| 104 | if ($EVAL_ERROR) { | ||||
| 105 | throw_global_value | ||||
| 106 | option_name => $CONFIG_KEY, | ||||
| 107 | option_value => $rule, | ||||
| 108 | message_suffix => q{contains a syntax error.}; | ||||
| 109 | } | ||||
| 110 | |||||
| 111 | return $is_thematic; | ||||
| 112 | } | ||||
| 113 | |||||
| 114 | #----------------------------------------------------------------------------- | ||||
| 115 | |||||
| 116 | # spent 39µs (36+3) within Perl::Critic::Theme::cook_rule which was called 2 times, avg 19µs/call:
# once (26µs+2µs) by Perl::Critic::Config::_validate_and_save_theme at line 640 of Perl/Critic/Config.pm
# once (10µs+900ns) by Perl::Critic::Theme::_init at line 69 | ||||
| 117 | 2 | 700ns | my ($raw_rule) = @_; | ||
| 118 | 2 | 400ns | return if not defined $raw_rule; | ||
| 119 | |||||
| 120 | #Translate logical operators | ||||
| 121 | 2 | 7µs | 2 | 800ns | $raw_rule =~ s{\b not \b}{!}ixmsg; # "not" -> "!" # spent 800ns making 2 calls to Perl::Critic::Theme::CORE:subst, avg 400ns/call |
| 122 | 2 | 7µs | 2 | 300ns | $raw_rule =~ s{\b and \b}{&&}ixmsg; # "and" -> "&&" # spent 300ns making 2 calls to Perl::Critic::Theme::CORE:subst, avg 150ns/call |
| 123 | 2 | 4µs | 2 | 400ns | $raw_rule =~ s{\b or \b}{||}ixmsg; # "or" -> "||" # spent 400ns making 2 calls to Perl::Critic::Theme::CORE:subst, avg 200ns/call |
| 124 | |||||
| 125 | #Translate algebra operators (for backward compatibility) | ||||
| 126 | 2 | 3µs | 2 | 400ns | $raw_rule =~ s{\A [-] }{!}ixmsg; # "-" -> "!" e.g. difference # spent 400ns making 2 calls to Perl::Critic::Theme::CORE:subst, avg 200ns/call |
| 127 | 2 | 3µs | 2 | 400ns | $raw_rule =~ s{ [-] }{&& !}ixmsg; # "-" -> "&& !" e.g. difference # spent 400ns making 2 calls to Perl::Critic::Theme::CORE:subst, avg 200ns/call |
| 128 | 2 | 3µs | 2 | 300ns | $raw_rule =~ s{ [*] }{&&}ixmsg; # "*" -> "&&" e.g. intersection # spent 300ns making 2 calls to Perl::Critic::Theme::CORE:subst, avg 150ns/call |
| 129 | 2 | 4µs | 2 | 400ns | $raw_rule =~ s{ [+] }{||}ixmsg; # "+" -> "||" e.g. union # spent 400ns making 2 calls to Perl::Critic::Theme::CORE:subst, avg 200ns/call |
| 130 | |||||
| 131 | 2 | 1µs | my $cooked_rule = lc $raw_rule; #Is now cooked! | ||
| 132 | 2 | 6µs | return $cooked_rule; | ||
| 133 | } | ||||
| 134 | |||||
| 135 | |||||
| 136 | 1 | 4µs | 1; | ||
| 137 | |||||
| 138 | __END__ | ||||
# spent 300ns within Perl::Critic::Theme::CORE:match which was called:
# once (300ns+0s) by Perl::Critic::Theme::_init at line 62 | |||||
# spent 1µs within Perl::Critic::Theme::CORE:qr which was called:
# once (1µs+0s) by Perl::Critic::Config::BEGIN@25 at line 38 | |||||
# spent 5µs (4+1000ns) within Perl::Critic::Theme::CORE:regcomp which was called:
# once (4µs+1000ns) by Perl::Critic::Theme::_init at line 62 | |||||
# spent 3µs within Perl::Critic::Theme::CORE:subst which was called 14 times, avg 214ns/call:
# 2 times (800ns+0s) by Perl::Critic::Theme::cook_rule at line 121, avg 400ns/call
# 2 times (400ns+0s) by Perl::Critic::Theme::cook_rule at line 127, avg 200ns/call
# 2 times (400ns+0s) by Perl::Critic::Theme::cook_rule at line 126, avg 200ns/call
# 2 times (400ns+0s) by Perl::Critic::Theme::cook_rule at line 123, avg 200ns/call
# 2 times (400ns+0s) by Perl::Critic::Theme::cook_rule at line 129, avg 200ns/call
# 2 times (300ns+0s) by Perl::Critic::Theme::cook_rule at line 122, avg 150ns/call
# 2 times (300ns+0s) by Perl::Critic::Theme::cook_rule at line 128, avg 150ns/call |