Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Form/Checkbox.pm |
Statements | Executed 15 statements in 1.02ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 87µs | 164µs | new | Foswiki::Form::Checkbox::
1 | 1 | 1 | 42µs | 57µs | BEGIN@4 | Foswiki::Form::Checkbox::
1 | 1 | 1 | 32µs | 67µs | BEGIN@5 | Foswiki::Form::Checkbox::
1 | 1 | 1 | 15µs | 15µs | BEGIN@7 | Foswiki::Form::Checkbox::
1 | 1 | 1 | 2µs | 2µs | CORE:subst (opcode) | Foswiki::Form::Checkbox::
0 | 0 | 0 | 0s | 0s | getDefaultValue | Foswiki::Form::Checkbox::
0 | 0 | 0 | 0s | 0s | isMultiValued | Foswiki::Form::Checkbox::
0 | 0 | 0 | 0s | 0s | renderForEdit | Foswiki::Form::Checkbox::
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::Checkbox; | ||||
3 | |||||
4 | 2 | 70µs | 2 | 71µs | # spent 57µs (42+14) within Foswiki::Form::Checkbox::BEGIN@4 which was called:
# once (42µs+14µs) by Foswiki::Form::createField at line 4 # spent 57µs making 1 call to Foswiki::Form::Checkbox::BEGIN@4
# spent 14µs making 1 call to strict::import |
5 | 2 | 65µs | 2 | 102µs | # spent 67µs (32+35) within Foswiki::Form::Checkbox::BEGIN@5 which was called:
# once (32µs+35µs) by Foswiki::Form::createField at line 5 # spent 67µs making 1 call to Foswiki::Form::Checkbox::BEGIN@5
# spent 35µs making 1 call to warnings::import |
6 | |||||
7 | 2 | 771µs | 1 | 15µs | # spent 15µs within Foswiki::Form::Checkbox::BEGIN@7 which was called:
# once (15µs+0s) by Foswiki::Form::createField at line 7 # spent 15µs making 1 call to Foswiki::Form::Checkbox::BEGIN@7 |
8 | 1 | 25µs | our @ISA = ('Foswiki::Form::ListFieldDefinition'); | ||
9 | |||||
10 | # spent 164µs (87+77) within Foswiki::Form::Checkbox::new which was called:
# once (87µs+77µs) by Foswiki::Form::createField at line 311 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Form.pm | ||||
11 | 7 | 87µs | my ( $class, @args ) = @_; | ||
12 | 1 | 74µs | my $this = $class->SUPER::new(@args); # spent 74µs making 1 call to Foswiki::Form::FieldDefinition::new | ||
13 | $this->{size} ||= 0; | ||||
14 | 1 | 2µs | $this->{size} =~ s/\D//g; # spent 2µs making 1 call to Foswiki::Form::Checkbox::CORE:subst | ||
15 | $this->{size} ||= 0; | ||||
16 | $this->{size} = 4 if ( $this->{size} < 1 ); | ||||
17 | |||||
18 | return $this; | ||||
19 | } | ||||
20 | |||||
21 | # Checkboxes can't provide a default from the form spec | ||||
22 | sub getDefaultValue { return; } | ||||
23 | |||||
24 | # Checkbox store multiple values | ||||
25 | sub isMultiValued { return 1; } | ||||
26 | |||||
27 | sub renderForEdit { | ||||
28 | my ( $this, $topicObject, $value ) = @_; | ||||
29 | |||||
30 | my $session = $this->{session}; | ||||
31 | my $extra = ''; | ||||
32 | if ( $this->{type} =~ m/\+buttons/ ) { | ||||
33 | my $boxes = scalar( @{ $this->getOptions() } ); | ||||
34 | $extra = CGI::br(); | ||||
35 | $extra .= CGI::button( | ||||
36 | -class => 'foswikiCheckbox', | ||||
37 | -value => $session->i18n->maketext('Set all'), | ||||
38 | -onClick => 'checkAll(this,2,' . $boxes . ',true)' | ||||
39 | ); | ||||
40 | $extra .= ' '; | ||||
41 | $extra .= CGI::button( | ||||
42 | -class => 'foswikiCheckbox', | ||||
43 | -value => $session->i18n->maketext('Clear all'), | ||||
44 | -onClick => 'checkAll(this,1,' . $boxes . ',false)' | ||||
45 | ); | ||||
46 | } | ||||
47 | $value = '' unless defined($value) && length($value); | ||||
48 | my %isSelected = map { $_ => 1 } split( /\s*,\s*/, $value ); | ||||
49 | my %attrs; | ||||
50 | foreach my $item ( @{ $this->getOptions() } ) { | ||||
51 | |||||
52 | # NOTE: Does not expand $item in title | ||||
53 | $attrs{$item} = { | ||||
54 | class => $this->cssClasses('foswikiCheckbox'), | ||||
55 | title => $topicObject->expandMacros($item), | ||||
56 | }; | ||||
57 | |||||
58 | if ( $isSelected{$item} ) { | ||||
59 | $attrs{$item}{checked} = 'checked'; | ||||
60 | } | ||||
61 | } | ||||
62 | $value = CGI::checkbox_group( | ||||
63 | -name => $this->{name}, | ||||
64 | -values => $this->getOptions(), | ||||
65 | -columns => $this->{size}, | ||||
66 | -attributes => \%attrs | ||||
67 | ); | ||||
68 | |||||
69 | # Item2410: We need a dummy control to detect the case where | ||||
70 | # all checkboxes have been deliberately unchecked | ||||
71 | # Item3061: | ||||
72 | # Don't use CGI, it will insert the sticky value from the query | ||||
73 | # once again and we need an empty field here. | ||||
74 | $value .= '<input type="hidden" name="' . $this->{name} . '" value="" />'; | ||||
75 | return ( $extra, $value ); | ||||
76 | } | ||||
77 | |||||
78 | 1 | 6µs | 1; | ||
79 | __END__ | ||||
# spent 2µs within Foswiki::Form::Checkbox::CORE:subst which was called:
# once (2µs+0s) by Foswiki::Form::Checkbox::new at line 14 |