Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Form/Select.pm |
Statements | Executed 70 statements in 1.57ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
4 | 1 | 1 | 195µs | 428µs | new | Foswiki::Form::Select::
4 | 1 | 1 | 101µs | 227µs | finish | Foswiki::Form::Select::
1 | 1 | 1 | 36µs | 45µs | BEGIN@3 | Foswiki::Form::Select::
1 | 1 | 1 | 30µs | 100µs | BEGIN@9 | Foswiki::Form::Select::
1 | 1 | 1 | 26µs | 48µs | BEGIN@4 | Foswiki::Form::Select::
1 | 1 | 1 | 10µs | 10µs | BEGIN@6 | Foswiki::Form::Select::
4 | 1 | 1 | 9µs | 9µs | CORE:subst (opcode) | Foswiki::Form::Select::
4 | 1 | 1 | 7µs | 7µs | CORE:match (opcode) | Foswiki::Form::Select::
0 | 0 | 0 | 0s | 0s | getDefaultValue | Foswiki::Form::Select::
0 | 0 | 0 | 0s | 0s | getOptions | Foswiki::Form::Select::
0 | 0 | 0 | 0s | 0s | isMultiValued | Foswiki::Form::Select::
0 | 0 | 0 | 0s | 0s | renderForEdit | Foswiki::Form::Select::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | package Foswiki::Form::Select; | ||||
3 | 2 | 54µs | 2 | 54µs | # spent 45µs (36+9) within Foswiki::Form::Select::BEGIN@3 which was called:
# once (36µs+9µs) by Foswiki::Form::createField at line 3 # spent 45µs making 1 call to Foswiki::Form::Select::BEGIN@3
# spent 9µs making 1 call to strict::import |
4 | 2 | 52µs | 2 | 70µs | # spent 48µs (26+22) within Foswiki::Form::Select::BEGIN@4 which was called:
# once (26µs+22µs) by Foswiki::Form::createField at line 4 # spent 48µs making 1 call to Foswiki::Form::Select::BEGIN@4
# spent 22µs making 1 call to warnings::import |
5 | |||||
6 | 2 | 65µs | 1 | 10µs | # spent 10µs within Foswiki::Form::Select::BEGIN@6 which was called:
# once (10µs+0s) by Foswiki::Form::createField at line 6 # spent 10µs making 1 call to Foswiki::Form::Select::BEGIN@6 |
7 | 1 | 14µs | our @ISA = ('Foswiki::Form::ListFieldDefinition'); | ||
8 | |||||
9 | 2 | 1.08ms | 2 | 171µs | # spent 100µs (30+70) within Foswiki::Form::Select::BEGIN@9 which was called:
# once (30µs+70µs) by Foswiki::Form::createField at line 9 # spent 100µs making 1 call to Foswiki::Form::Select::BEGIN@9
# spent 70µs making 1 call to Assert::import |
10 | |||||
11 | # spent 428µs (195+233) within Foswiki::Form::Select::new which was called 4 times, avg 107µs/call:
# 4 times (195µs+233µs) by Foswiki::Form::createField at line 311 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Form.pm, avg 107µs/call | ||||
12 | 20 | 132µs | my $class = shift; | ||
13 | 4 | 217µs | my $this = $class->SUPER::new(@_); # spent 217µs making 4 calls to Foswiki::Form::FieldDefinition::new, avg 54µs/call | ||
14 | |||||
15 | # Parse the size to get min and max | ||||
16 | $this->{size} ||= 1; | ||||
17 | 16 | 71µs | 4 | 7µs | if ( $this->{size} =~ /^\s*(\d+)\.\.(\d+)\s*$/ ) { # spent 7µs making 4 calls to Foswiki::Form::Select::CORE:match, avg 2µs/call |
18 | $this->{minSize} = $1; | ||||
19 | $this->{maxSize} = $2; | ||||
20 | } | ||||
21 | else { | ||||
22 | $this->{minSize} = $this->{size}; | ||||
23 | 4 | 9µs | $this->{minSize} =~ s/[^\d]//g; # spent 9µs making 4 calls to Foswiki::Form::Select::CORE:subst, avg 2µs/call | ||
24 | $this->{minSize} ||= 1; | ||||
25 | $this->{maxSize} = $this->{minSize}; | ||||
26 | } | ||||
27 | |||||
28 | return $this; | ||||
29 | } | ||||
30 | |||||
31 | =begin TML | ||||
32 | |||||
33 | ---++ getDefaultValue() -> $value | ||||
34 | The default for a select is always the empty string, as there is no way in | ||||
35 | Foswiki form definitions to indicate selected values. This defers the decision | ||||
36 | on a value to the browser. | ||||
37 | |||||
38 | =cut | ||||
39 | |||||
40 | sub getDefaultValue { | ||||
41 | return ''; | ||||
42 | } | ||||
43 | |||||
44 | sub getOptions { | ||||
45 | my $this = shift; | ||||
46 | |||||
47 | return $this->{_options} if $this->{_options}; | ||||
48 | |||||
49 | my $vals = $this->SUPER::getOptions(@_); | ||||
50 | if ( $this->{type} =~ /\+values/ ) { | ||||
51 | |||||
52 | # create a values map | ||||
53 | |||||
54 | $this->{valueMap} = (); | ||||
55 | $this->{_options} = (); | ||||
56 | my $str; | ||||
57 | foreach my $val (@$vals) { | ||||
58 | if ( $val =~ /^(.*[^\\])*=(.*)$/ ) { | ||||
59 | $str = TAINT( $1 || '' ); | ||||
60 | $val = $2; | ||||
61 | $str =~ s/\\=/=/g; | ||||
62 | } | ||||
63 | else { | ||||
64 | $str = $val; | ||||
65 | } | ||||
66 | $this->{valueMap}{$val} = Foswiki::urlDecode($str); | ||||
67 | push @{ $this->{_options} }, $val; | ||||
68 | } | ||||
69 | } | ||||
70 | |||||
71 | return $vals; | ||||
72 | } | ||||
73 | |||||
74 | =begin TML | ||||
75 | |||||
76 | ---++ ObjectMethod finish() | ||||
77 | Break circular references. | ||||
78 | |||||
79 | =cut | ||||
80 | |||||
81 | # Note to developers; please undef *all* fields in the object explicitly, | ||||
82 | # whether they are references or not. That way this method is "golden | ||||
83 | # documentation" of the live fields in the object. | ||||
84 | # spent 227µs (101+125) within Foswiki::Form::Select::finish which was called 4 times, avg 57µs/call:
# 4 times (101µs+125µs) by Foswiki::Form::finish at line 151 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Form.pm, avg 57µs/call | ||||
85 | 24 | 97µs | my $this = shift; | ||
86 | 4 | 125µs | $this->SUPER::finish(); # spent 125µs making 4 calls to Foswiki::Form::ListFieldDefinition::finish, avg 31µs/call | ||
87 | undef $this->{minSize}; | ||||
88 | undef $this->{maxSize}; | ||||
89 | undef $this->{valueMap}; | ||||
90 | |||||
91 | return; | ||||
92 | } | ||||
93 | |||||
94 | sub isMultiValued { return shift->{type} =~ /\+multi/; } | ||||
95 | |||||
96 | sub renderForEdit { | ||||
97 | my ( $this, $topicObject, $value ) = @_; | ||||
98 | |||||
99 | my $choices = ''; | ||||
100 | |||||
101 | my %isSelected = map { $_ => 1 } split( /\s*,\s*/, $value ); | ||||
102 | foreach my $option ( @{ $this->getOptions() } ) { | ||||
103 | my %params = ( class => 'foswikiOption', ); | ||||
104 | $params{selected} = 'selected' if $isSelected{$option}; | ||||
105 | if ( defined( $this->{valueMap}{$option} ) ) { | ||||
106 | $params{value} = $option; | ||||
107 | $option = $this->{valueMap}{$option}; | ||||
108 | } | ||||
109 | $option =~ s/<nop/<\;nop/go; | ||||
110 | $choices .= CGI::option( \%params, $option ); | ||||
111 | } | ||||
112 | my $size = scalar( @{ $this->getOptions() } ); | ||||
113 | if ( $size > $this->{maxSize} ) { | ||||
114 | $size = $this->{maxSize}; | ||||
115 | } | ||||
116 | elsif ( $size < $this->{minSize} ) { | ||||
117 | $size = $this->{minSize}; | ||||
118 | } | ||||
119 | my $params = { | ||||
120 | class => $this->cssClasses('foswikiSelect'), | ||||
121 | name => $this->{name}, | ||||
122 | size => $this->{size}, | ||||
123 | }; | ||||
124 | if ( $this->isMultiValued() ) { | ||||
125 | $params->{'multiple'} = 'multiple'; | ||||
126 | $value = CGI::Select( $params, $choices ); | ||||
127 | |||||
128 | # Item2410: We need a dummy control to detect the case where | ||||
129 | # all checkboxes have been deliberately unchecked | ||||
130 | # Item3061: | ||||
131 | # Don't use CGI, it will insert the value from the query | ||||
132 | # once again and we need an empt field here. | ||||
133 | $value .= | ||||
134 | '<input type="hidden" name="' . $this->{name} . '" value="" />'; | ||||
135 | } | ||||
136 | else { | ||||
137 | $value = CGI::Select( $params, $choices ); | ||||
138 | } | ||||
139 | return ( '', $value ); | ||||
140 | } | ||||
141 | |||||
142 | 1 | 6µs | 1; | ||
143 | __END__ | ||||
# spent 7µs within Foswiki::Form::Select::CORE:match which was called 4 times, avg 2µs/call:
# 4 times (7µs+0s) by Foswiki::Form::Select::new at line 17, avg 2µs/call | |||||
# spent 9µs within Foswiki::Form::Select::CORE:subst which was called 4 times, avg 2µs/call:
# 4 times (9µs+0s) by Foswiki::Form::Select::new at line 23, avg 2µs/call |