Filename | /var/www/foswiki11/lib/Foswiki/Form/ListFieldDefinition.pm |
Statements | Executed 10 statements in 480µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 17µs | 30µs | BEGIN@14 | Foswiki::Form::ListFieldDefinition::
1 | 1 | 1 | 9µs | 23µs | BEGIN@16 | Foswiki::Form::ListFieldDefinition::
1 | 1 | 1 | 9µs | 14µs | BEGIN@15 | Foswiki::Form::ListFieldDefinition::
1 | 1 | 1 | 4µs | 4µs | BEGIN@18 | Foswiki::Form::ListFieldDefinition::
0 | 0 | 0 | 0s | 0s | finish | 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 | 28µs | 2 | 44µs | # spent 30µs (17+13) within Foswiki::Form::ListFieldDefinition::BEGIN@14 which was called:
# once (17µs+13µs) by Foswiki::Form::BEGIN@43 at line 14 # spent 30µs making 1 call to Foswiki::Form::ListFieldDefinition::BEGIN@14
# spent 13µs making 1 call to strict::import |
15 | 2 | 27µs | 2 | 20µs | # spent 14µs (9+5) within Foswiki::Form::ListFieldDefinition::BEGIN@15 which was called:
# once (9µs+5µs) by Foswiki::Form::BEGIN@43 at line 15 # spent 14µs making 1 call to Foswiki::Form::ListFieldDefinition::BEGIN@15
# spent 5µs making 1 call to warnings::import |
16 | 2 | 25µs | 2 | 37µs | # spent 23µs (9+14) within Foswiki::Form::ListFieldDefinition::BEGIN@16 which was called:
# once (9µs+14µs) by Foswiki::Form::BEGIN@43 at line 16 # spent 23µs making 1 call to Foswiki::Form::ListFieldDefinition::BEGIN@16
# spent 14µs making 1 call to Assert::import |
17 | |||||
18 | 2 | 384µs | 1 | 4µs | # spent 4µs within Foswiki::Form::ListFieldDefinition::BEGIN@18 which was called:
# once (4µs+0s) by Foswiki::Form::BEGIN@43 at line 18 # spent 4µs making 1 call to Foswiki::Form::ListFieldDefinition::BEGIN@18 |
19 | 1 | 12µ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 | sub finish { | ||||
32 | my $this = shift; | ||||
33 | $this->SUPER::finish(); | ||||
34 | undef $this->{_options}; | ||||
35 | undef $this->{_descriptions}; | ||||
36 | } | ||||
37 | |||||
38 | # PROTECTED - parse the {value} and extract a list of options. | ||||
39 | # Done lazily to avoid repeated topic reads. | ||||
40 | sub getOptions { | ||||
41 | |||||
42 | # $web and $topic are where the form definition lives | ||||
43 | my $this = shift; | ||||
44 | |||||
45 | return $this->{_options} if $this->{_options}; | ||||
46 | |||||
47 | my @vals = (); | ||||
48 | my %descr = (); | ||||
49 | |||||
50 | @vals = split( /,/, $this->{value} ); | ||||
51 | if ( !scalar(@vals) ) { | ||||
52 | my $topic = $this->{definingTopic} || $this->{name}; | ||||
53 | my $session = $this->{session}; | ||||
54 | |||||
55 | my ( $fieldWeb, $fieldTopic ) = | ||||
56 | $session->normalizeWebTopicName( $this->{web}, $topic ); | ||||
57 | |||||
58 | $fieldWeb = Foswiki::Sandbox::untaint( $fieldWeb, | ||||
59 | \&Foswiki::Sandbox::validateWebName ); | ||||
60 | $fieldTopic = Foswiki::Sandbox::untaint( $fieldTopic, | ||||
61 | \&Foswiki::Sandbox::validateTopicName ); | ||||
62 | |||||
63 | if ( $session->topicExists( $fieldWeb, $fieldTopic ) ) { | ||||
64 | |||||
65 | my $meta = Foswiki::Meta->load( $session, $fieldWeb, $fieldTopic ); | ||||
66 | next unless $meta->haveAccess('VIEW'); | ||||
67 | |||||
68 | # Process SEARCHES for Lists | ||||
69 | my $text = $meta->expandMacros( $meta->text() ); | ||||
70 | |||||
71 | # SMELL: yet another table parser | ||||
72 | my $inBlock = 0; | ||||
73 | foreach ( split( /\r?\n/, $text ) ) { | ||||
74 | if (/^\s*\|\s*\*Name\*\s*\|/) { | ||||
75 | $inBlock = 1; | ||||
76 | } | ||||
77 | elsif (/^\s*\|\s*([^|]*?)\s*\|(?:\s*([^|]*?)\s*\|)?/) { | ||||
78 | if ($inBlock) { | ||||
79 | push( @vals, TAINT($1) ); | ||||
80 | $descr{$1} = $2 if defined $2; | ||||
81 | } | ||||
82 | } | ||||
83 | else { | ||||
84 | $inBlock = 0; | ||||
85 | } | ||||
86 | } | ||||
87 | } | ||||
88 | } | ||||
89 | @vals = map { $_ =~ s/^\s*(.*)\s*$/$1/; $_; } @vals; | ||||
90 | |||||
91 | $this->{_options} = \@vals; | ||||
92 | $this->{_descriptions} = \%descr; | ||||
93 | |||||
94 | return $this->{_options}; | ||||
95 | } | ||||
96 | |||||
97 | 1 | 3µs | 1; | ||
98 | __END__ |