Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Form/ListFieldDefinition.pm |
Statements | Executed 34 statements in 956µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
8 | 2 | 2 | 154µs | 284µs | finish | Foswiki::Form::ListFieldDefinition::
1 | 1 | 1 | 28µs | 36µs | BEGIN@14 | Foswiki::Form::ListFieldDefinition::
1 | 1 | 1 | 21µs | 39µs | BEGIN@15 | Foswiki::Form::ListFieldDefinition::
1 | 1 | 1 | 17µs | 55µs | BEGIN@16 | Foswiki::Form::ListFieldDefinition::
1 | 1 | 1 | 10µs | 10µs | BEGIN@18 | Foswiki::Form::ListFieldDefinition::
0 | 0 | 0 | 0s | 0s | getOptions | Foswiki::Form::ListFieldDefinition::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | =begin TML | ||||
4 | |||||
5 | ---++ package Foswiki::Form::ListFieldDefinition | ||||
6 | Form field definitions that accept lists of values in the field definition. | ||||
7 | This is different to being multi-valued, which means the field type | ||||
8 | can *store* multiple values. | ||||
9 | |||||
10 | =cut | ||||
11 | |||||
12 | package Foswiki::Form::ListFieldDefinition; | ||||
13 | |||||
14 | 2 | 46µs | 2 | 43µs | # spent 36µs (28+8) within Foswiki::Form::ListFieldDefinition::BEGIN@14 which was called:
# once (28µs+8µs) by Foswiki::Form::BEGIN@43 at line 14 # spent 36µs making 1 call to Foswiki::Form::ListFieldDefinition::BEGIN@14
# spent 8µs making 1 call to strict::import |
15 | 2 | 44µs | 2 | 57µs | # spent 39µs (21+18) within Foswiki::Form::ListFieldDefinition::BEGIN@15 which was called:
# once (21µs+18µs) by Foswiki::Form::BEGIN@43 at line 15 # spent 39µs making 1 call to Foswiki::Form::ListFieldDefinition::BEGIN@15
# spent 18µs making 1 call to warnings::import |
16 | 2 | 70µs | 2 | 93µs | # spent 55µs (17+38) within Foswiki::Form::ListFieldDefinition::BEGIN@16 which was called:
# once (17µs+38µs) by Foswiki::Form::BEGIN@43 at line 16 # spent 55µs making 1 call to Foswiki::Form::ListFieldDefinition::BEGIN@16
# spent 38µs making 1 call to Assert::import |
17 | |||||
18 | 2 | 629µs | 1 | 10µs | # spent 10µs within Foswiki::Form::ListFieldDefinition::BEGIN@18 which was called:
# once (10µs+0s) by Foswiki::Form::BEGIN@43 at line 18 # spent 10µs making 1 call to Foswiki::Form::ListFieldDefinition::BEGIN@18 |
19 | 1 | 16µs | our @ISA = ('Foswiki::Form::FieldDefinition'); | ||
20 | |||||
21 | =begin TML | ||||
22 | |||||
23 | ---++ ObjectMethod finish() | ||||
24 | Break circular references. | ||||
25 | |||||
26 | =cut | ||||
27 | |||||
28 | # Note to developers; please undef *all* fields in the object explicitly, | ||||
29 | # whether they are references or not. That way this method is "golden | ||||
30 | # documentation" of the live fields in the object. | ||||
31 | # spent 284µs (154+130) within Foswiki::Form::ListFieldDefinition::finish which was called 8 times, avg 35µs/call:
# 4 times (97µs+61µs) by Foswiki::Form::finish at line 151 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Form.pm, avg 40µs/call
# 4 times (57µs+69µs) by Foswiki::Form::Select::finish at line 86 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Form/Select.pm, avg 31µs/call | ||||
32 | 24 | 146µs | my $this = shift; | ||
33 | 8 | 130µs | $this->SUPER::finish(); # spent 130µs making 8 calls to Foswiki::Form::FieldDefinition::finish, avg 16µs/call | ||
34 | undef $this->{_options}; | ||||
35 | } | ||||
36 | |||||
37 | # PROTECTED - parse the {value} and extract a list of options. | ||||
38 | # Done lazily to avoid repeated topic reads. | ||||
39 | sub getOptions { | ||||
40 | |||||
41 | # $web and $topic are where the form definition lives | ||||
42 | my $this = shift; | ||||
43 | |||||
44 | return $this->{_options} if $this->{_options}; | ||||
45 | |||||
46 | my @vals = (); | ||||
47 | |||||
48 | @vals = split( /,/, $this->{value} ); | ||||
49 | if ( !scalar(@vals) ) { | ||||
50 | my $topic = $this->{definingTopic} || $this->{name}; | ||||
51 | my $session = $this->{session}; | ||||
52 | |||||
53 | my ( $fieldWeb, $fieldTopic ) = | ||||
54 | $session->normalizeWebTopicName( $this->{web}, $topic ); | ||||
55 | |||||
56 | $fieldWeb = Foswiki::Sandbox::untaint( $fieldWeb, | ||||
57 | \&Foswiki::Sandbox::validateWebName ); | ||||
58 | $fieldTopic = Foswiki::Sandbox::untaint( $fieldTopic, | ||||
59 | \&Foswiki::Sandbox::validateTopicName ); | ||||
60 | |||||
61 | if ( $session->topicExists( $fieldWeb, $fieldTopic ) ) { | ||||
62 | |||||
63 | my $meta = Foswiki::Meta->load( $session, $fieldWeb, $fieldTopic ); | ||||
64 | next unless $meta->haveAccess('VIEW'); | ||||
65 | |||||
66 | # Process SEARCHES for Lists | ||||
67 | my $text = $meta->expandMacros( $meta->text() ); | ||||
68 | |||||
69 | # SMELL: yet another table parser | ||||
70 | my $inBlock = 0; | ||||
71 | foreach ( split( /\r?\n/, $text ) ) { | ||||
72 | if (/^\s*\|\s*\*Name\*\s*\|/) { | ||||
73 | $inBlock = 1; | ||||
74 | } | ||||
75 | elsif (/^\s*\|\s*([^|]*?)\s*\|/) { | ||||
76 | push( @vals, TAINT($1) ) if ($inBlock); | ||||
77 | } | ||||
78 | else { | ||||
79 | $inBlock = 0; | ||||
80 | } | ||||
81 | } | ||||
82 | } | ||||
83 | } | ||||
84 | @vals = map { $_ =~ s/^\s*(.*)\s*$/$1/; $_; } @vals; | ||||
85 | |||||
86 | $this->{_options} = \@vals; | ||||
87 | |||||
88 | return $this->{_options}; | ||||
89 | } | ||||
90 | |||||
91 | 1 | 6µs | 1; | ||
92 | __END__ |