Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/PolicyParameter/Behavior/Enumeration.pm |
Statements | Executed 167 statements in 755µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
8 | 1 | 1 | 146µs | 196µs | initialize_parameter | Perl::Critic::PolicyParameter::Behavior::Enumeration::
5 | 1 | 1 | 90µs | 160µs | __ANON__[:93] | Perl::Critic::PolicyParameter::Behavior::Enumeration::
3 | 1 | 1 | 42µs | 76µs | __ANON__[:127] | Perl::Critic::PolicyParameter::Behavior::Enumeration::
1 | 1 | 1 | 15µs | 15µs | BEGIN@10 | Perl::Critic::PolicyParameter::Behavior::Enumeration::
1 | 1 | 1 | 12µs | 16µs | BEGIN@12 | Perl::Critic::PolicyParameter::Behavior::Enumeration::
1 | 1 | 1 | 7µs | 57µs | BEGIN@18 | Perl::Critic::PolicyParameter::Behavior::Enumeration::
1 | 1 | 1 | 7µs | 290µs | BEGIN@16 | Perl::Critic::PolicyParameter::Behavior::Enumeration::
1 | 1 | 1 | 7µs | 73µs | BEGIN@15 | Perl::Critic::PolicyParameter::Behavior::Enumeration::
1 | 1 | 1 | 7µs | 18µs | BEGIN@11 | Perl::Critic::PolicyParameter::Behavior::Enumeration::
0 | 0 | 0 | 0s | 0s | generate_parameter_description | Perl::Critic::PolicyParameter::Behavior::Enumeration::
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::PolicyParameter::Behavior::Enumeration; | ||||
9 | |||||
10 | 2 | 40µs | 1 | 15µs | # spent 15µs within Perl::Critic::PolicyParameter::Behavior::Enumeration::BEGIN@10 which was called:
# once (15µs+0s) by Perl::Critic::PolicyParameter::BEGIN@25 at line 10 # spent 15µs making 1 call to Perl::Critic::PolicyParameter::Behavior::Enumeration::BEGIN@10 |
11 | 2 | 19µs | 2 | 30µs | # spent 18µs (7+11) within Perl::Critic::PolicyParameter::Behavior::Enumeration::BEGIN@11 which was called:
# once (7µs+11µs) by Perl::Critic::PolicyParameter::BEGIN@25 at line 11 # spent 18µs making 1 call to Perl::Critic::PolicyParameter::Behavior::Enumeration::BEGIN@11
# spent 12µs making 1 call to strict::import |
12 | 2 | 21µs | 2 | 19µs | # spent 16µs (12+4) within Perl::Critic::PolicyParameter::Behavior::Enumeration::BEGIN@12 which was called:
# once (12µs+4µs) by Perl::Critic::PolicyParameter::BEGIN@25 at line 12 # spent 16µs making 1 call to Perl::Critic::PolicyParameter::Behavior::Enumeration::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | |||||
14 | use Perl::Critic::Exception::Fatal::PolicyDefinition | ||||
15 | 2 | 24µs | 2 | 139µs | # spent 73µs (7+66) within Perl::Critic::PolicyParameter::Behavior::Enumeration::BEGIN@15 which was called:
# once (7µs+66µs) by Perl::Critic::PolicyParameter::BEGIN@25 at line 15 # spent 73µs making 1 call to Perl::Critic::PolicyParameter::Behavior::Enumeration::BEGIN@15
# spent 66µs making 1 call to Exporter::import |
16 | 2 | 27µs | 2 | 574µs | # spent 290µs (7+283) within Perl::Critic::PolicyParameter::Behavior::Enumeration::BEGIN@16 which was called:
# once (7µs+283µs) by Perl::Critic::PolicyParameter::BEGIN@25 at line 16 # spent 290µs making 1 call to Perl::Critic::PolicyParameter::Behavior::Enumeration::BEGIN@16
# spent 283µs making 1 call to Exporter::import |
17 | |||||
18 | 2 | 421µs | 2 | 57µs | # spent 57µs (7+50) within Perl::Critic::PolicyParameter::Behavior::Enumeration::BEGIN@18 which was called:
# once (7µs+50µs) by Perl::Critic::PolicyParameter::BEGIN@25 at line 18 # spent 57µs making 1 call to Perl::Critic::PolicyParameter::Behavior::Enumeration::BEGIN@18
# spent 50µs making 1 call to base::import, recursion: max depth 1, sum of overlapping time 50µs |
19 | |||||
20 | 1 | 600ns | our $VERSION = '1.121'; | ||
21 | |||||
22 | #----------------------------------------------------------------------------- | ||||
23 | |||||
24 | # spent 196µs (146+50) within Perl::Critic::PolicyParameter::Behavior::Enumeration::initialize_parameter which was called 8 times, avg 24µs/call:
# 8 times (146µs+50µs) by Perl::Critic::PolicyParameter::_initialize_from_behavior at line 115 of Perl/Critic/PolicyParameter.pm, avg 24µs/call | ||||
25 | 8 | 2µs | my ($self, $parameter, $specification) = @_; | ||
26 | |||||
27 | 8 | 3µs | my $valid_values = $specification->{enumeration_values} | ||
28 | or throw_policy_definition | ||||
29 | 'No enumeration_values given for ' | ||||
30 | . $parameter->get_name() | ||||
31 | . $PERIOD; | ||||
32 | 8 | 4µs | ref $valid_values eq 'ARRAY' | ||
33 | or throw_policy_definition | ||||
34 | 'The value given for enumeration_values for ' | ||||
35 | . $parameter->get_name() | ||||
36 | . ' is not an array reference.'; | ||||
37 | 8 | 3µs | scalar @{$valid_values} > 1 | ||
38 | or throw_policy_definition | ||||
39 | 'There were not at least two valid values given for' | ||||
40 | . ' enumeration_values for ' | ||||
41 | . $parameter->get_name() | ||||
42 | . $PERIOD; | ||||
43 | |||||
44 | # Unfortunately, this has to be a reference, rather than a regular hash, | ||||
45 | # due to a problem in Devel::Cycle | ||||
46 | # (http://rt.cpan.org/Ticket/Display.html?id=25360) which causes | ||||
47 | # t/92_memory_leaks.t to fall over. | ||||
48 | 8 | 33µs | 8 | 26µs | my $value_lookup = { hashify( @{$valid_values} ) }; # spent 26µs making 8 calls to Perl::Critic::Utils::hashify, avg 3µs/call |
49 | 8 | 14µs | 8 | 10µs | $parameter->_get_behavior_values()->{enumeration_values} = $value_lookup; # spent 10µs making 8 calls to Perl::Critic::PolicyParameter::_get_behavior_values, avg 1µs/call |
50 | |||||
51 | 8 | 3µs | my $allow_multiple_values = | ||
52 | $specification->{enumeration_allow_multiple_values}; | ||||
53 | |||||
54 | 8 | 3µs | if ($allow_multiple_values) { | ||
55 | $parameter->_set_parser( | ||||
56 | # spent 160µs (90+70) within Perl::Critic::PolicyParameter::Behavior::Enumeration::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/PolicyParameter/Behavior/Enumeration.pm:93] which was called 5 times, avg 32µs/call:
# 5 times (90µs+70µs) by Perl::Critic::PolicyParameter::parse_and_validate_config_value at line 231 of Perl/Critic/PolicyParameter.pm, avg 32µs/call | ||||
57 | # Normally bad thing, obscuring a variable in a outer scope | ||||
58 | # with a variable with the same name is being done here in | ||||
59 | # order to remain consistent with the parser function interface. | ||||
60 | 5 | 1µs | my ($policy, $parameter, $config_string) = @_; ## no critic(Variables::ProhibitReusedNames) | ||
61 | |||||
62 | 5 | 500ns | my @potential_values; | ||
63 | 5 | 6µs | 5 | 6µs | my $value_string = $parameter->get_default_string(); # spent 6µs making 5 calls to Perl::Critic::PolicyParameter::get_default_string, avg 1µs/call |
64 | |||||
65 | 5 | 800ns | if (defined $config_string) { | ||
66 | $value_string = $config_string; | ||||
67 | } | ||||
68 | |||||
69 | 5 | 2µs | if ( defined $value_string ) { | ||
70 | 5 | 8µs | 5 | 10µs | @potential_values = words_from_string($value_string); # spent 10µs making 5 calls to Perl::Critic::Utils::words_from_string, avg 2µs/call |
71 | |||||
72 | my @bad_values = | ||||
73 | 5 | 5µs | grep { not exists $value_lookup->{$_} } @potential_values; | ||
74 | 5 | 2µs | if (@bad_values) { | ||
75 | $policy->throw_parameter_value_exception( | ||||
76 | $parameter->get_name(), | ||||
77 | $value_string, | ||||
78 | undef, | ||||
79 | q{contains invalid values: } | ||||
80 | . join (q{, }, @bad_values) | ||||
81 | . q{. Allowed values are: } | ||||
82 | . join (q{, }, sort keys %{$value_lookup}) | ||||
83 | . qq{.\n}, | ||||
84 | ); | ||||
85 | } | ||||
86 | } | ||||
87 | |||||
88 | 5 | 9µs | 5 | 7µs | my %actual_values = hashify(@potential_values); # spent 7µs making 5 calls to Perl::Critic::Utils::hashify, avg 1µs/call |
89 | |||||
90 | 5 | 14µs | 5 | 46µs | $policy->__set_parameter_value($parameter, \%actual_values); # spent 46µs making 5 calls to Perl::Critic::Policy::__set_parameter_value, avg 9µs/call |
91 | |||||
92 | 5 | 13µs | return; | ||
93 | } | ||||
94 | 5 | 18µs | 5 | 8µs | ); # spent 8µs making 5 calls to Perl::Critic::PolicyParameter::_set_parser, avg 2µs/call |
95 | } else { | ||||
96 | $parameter->_set_parser( | ||||
97 | # spent 76µs (42+34) within Perl::Critic::PolicyParameter::Behavior::Enumeration::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/PolicyParameter/Behavior/Enumeration.pm:127] which was called 3 times, avg 25µs/call:
# 3 times (42µs+34µs) by Perl::Critic::PolicyParameter::parse_and_validate_config_value at line 231 of Perl/Critic/PolicyParameter.pm, avg 25µs/call | ||||
98 | # Normally bad thing, obscuring a variable in a outer scope | ||||
99 | # with a variable with the same name is being done here in | ||||
100 | # order to remain consistent with the parser function interface. | ||||
101 | 3 | 900ns | my ($policy, $parameter, $config_string) = @_; ## no critic(Variables::ProhibitReusedNames) | ||
102 | |||||
103 | 3 | 4µs | 3 | 4µs | my $value_string = $parameter->get_default_string(); # spent 4µs making 3 calls to Perl::Critic::PolicyParameter::get_default_string, avg 1µs/call |
104 | |||||
105 | 3 | 600ns | if (defined $config_string) { | ||
106 | $value_string = $config_string; | ||||
107 | } | ||||
108 | |||||
109 | 3 | 8µs | 3 | 4µs | if ( # spent 4µs making 3 calls to Readonly::Scalar::FETCH, avg 1µs/call |
110 | defined $value_string | ||||
111 | and $EMPTY ne $value_string | ||||
112 | and not defined $value_lookup->{$value_string} | ||||
113 | ) { | ||||
114 | $policy->throw_parameter_value_exception( | ||||
115 | $parameter->get_name(), | ||||
116 | $value_string, | ||||
117 | undef, | ||||
118 | q{is not one of the allowed values: } | ||||
119 | . join (q{, }, sort keys %{$value_lookup}) | ||||
120 | . qq{.\n}, | ||||
121 | ); | ||||
122 | } | ||||
123 | |||||
124 | 3 | 6µs | 3 | 27µs | $policy->__set_parameter_value($parameter, $value_string); # spent 27µs making 3 calls to Perl::Critic::Policy::__set_parameter_value, avg 9µs/call |
125 | |||||
126 | 3 | 8µs | return; | ||
127 | } | ||||
128 | 3 | 12µs | 3 | 5µs | ); # spent 5µs making 3 calls to Perl::Critic::PolicyParameter::_set_parser, avg 2µs/call |
129 | } | ||||
130 | |||||
131 | 8 | 19µs | return; | ||
132 | } | ||||
133 | |||||
134 | #----------------------------------------------------------------------------- | ||||
135 | |||||
136 | sub generate_parameter_description { | ||||
137 | my ($self, $parameter) = @_; | ||||
138 | |||||
139 | my $description = $parameter->_get_description_with_trailing_period(); | ||||
140 | if ( $description ) { | ||||
141 | $description .= qq{\n}; | ||||
142 | } | ||||
143 | |||||
144 | my %values = %{$parameter->_get_behavior_values()->{enumeration_values}}; | ||||
145 | return | ||||
146 | $description | ||||
147 | . 'Valid values: ' | ||||
148 | . join (', ', sort keys %values) | ||||
149 | . $PERIOD; | ||||
150 | } | ||||
151 | |||||
152 | #----------------------------------------------------------------------------- | ||||
153 | |||||
154 | 1 | 2µs | 1; | ||
155 | |||||
156 | __END__ |