← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/local/src/github.com/foswiki/core/bin/view
  Run on Sun Dec 4 17:17:59 2011
Reported on Sun Dec 4 17:26:59 2011

Filename/usr/local/src/github.com/foswiki/core/lib/Foswiki/Form/Select.pm
StatementsExecuted 70 statements in 1.57ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
411195µs428µsFoswiki::Form::Select::::newFoswiki::Form::Select::new
411101µs227µsFoswiki::Form::Select::::finishFoswiki::Form::Select::finish
11136µs45µsFoswiki::Form::Select::::BEGIN@3Foswiki::Form::Select::BEGIN@3
11130µs100µsFoswiki::Form::Select::::BEGIN@9Foswiki::Form::Select::BEGIN@9
11126µs48µsFoswiki::Form::Select::::BEGIN@4Foswiki::Form::Select::BEGIN@4
11110µs10µsFoswiki::Form::Select::::BEGIN@6Foswiki::Form::Select::BEGIN@6
4119µs9µsFoswiki::Form::Select::::CORE:substFoswiki::Form::Select::CORE:subst (opcode)
4117µs7µsFoswiki::Form::Select::::CORE:matchFoswiki::Form::Select::CORE:match (opcode)
0000s0sFoswiki::Form::Select::::getDefaultValueFoswiki::Form::Select::getDefaultValue
0000s0sFoswiki::Form::Select::::getOptionsFoswiki::Form::Select::getOptions
0000s0sFoswiki::Form::Select::::isMultiValuedFoswiki::Form::Select::isMultiValued
0000s0sFoswiki::Form::Select::::renderForEditFoswiki::Form::Select::renderForEdit
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# See bottom of file for license and copyright information
2package Foswiki::Form::Select;
3254µs254µ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
use strict;
# spent 45µs making 1 call to Foswiki::Form::Select::BEGIN@3 # spent 9µs making 1 call to strict::import
4252µs270µ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
use warnings;
# spent 48µs making 1 call to Foswiki::Form::Select::BEGIN@4 # spent 22µs making 1 call to warnings::import
5
6265µs110µs
# spent 10µs within Foswiki::Form::Select::BEGIN@6 which was called: # once (10µs+0s) by Foswiki::Form::createField at line 6
use Foswiki::Form::ListFieldDefinition ();
# spent 10µs making 1 call to Foswiki::Form::Select::BEGIN@6
7114µsour @ISA = ('Foswiki::Form::ListFieldDefinition');
8
921.08ms2171µ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
use Assert;
# 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
sub new {
1220132µs my $class = shift;
134217µ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;
171671µs47µ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};
2349µ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
34The default for a select is always the empty string, as there is no way in
35Foswiki form definitions to indicate selected values. This defers the decision
36on a value to the browser.
37
38=cut
39
40sub getDefaultValue {
41 return '';
42}
43
44sub 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()
77Break 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
sub finish {
852497µs my $this = shift;
864125µ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
94sub isMultiValued { return shift->{type} =~ /\+multi/; }
95
96sub 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/&lt\;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
14216µs1;
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
sub Foswiki::Form::Select::CORE:match; # opcode
# 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
sub Foswiki::Form::Select::CORE:subst; # opcode