Filename | /var/www/foswikidev/core/lib/Foswiki/Configure/Section.pm |
Statements | Executed 10 statements in 1.02ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.44ms | 1.52ms | BEGIN@19 | Foswiki::Configure::Section::
1 | 1 | 1 | 15µs | 27µs | BEGIN@16 | Foswiki::Configure::Section::
1 | 1 | 1 | 12µs | 41µs | BEGIN@23 | Foswiki::Configure::Section::
1 | 1 | 1 | 9µs | 12µs | BEGIN@17 | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | _addToVobCache | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | addChild | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | find | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | find_also_dependencies | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | getAllValueKeys | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | getPath | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | getSectionObject | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | getValueObject | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | hasDeep | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | new | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | promoteSetting | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | prune | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | search | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | unparent | Foswiki::Configure::Section::
0 | 0 | 0 | 0s | 0s | visit | Foswiki::Configure::Section::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | package Foswiki::Configure::Section; | ||||
3 | |||||
4 | =begin TML | ||||
5 | |||||
6 | ---+ package Foswiki::Configure::Section | ||||
7 | |||||
8 | A collection node in a configuration item tree; a collection | ||||
9 | of configuration items and subsections. | ||||
10 | |||||
11 | IMPORTANT: there are some naming conventions for fields that apply to | ||||
12 | all subclasses of this class. See Foswiki::Configure::Item for details. | ||||
13 | |||||
14 | =cut | ||||
15 | |||||
16 | 2 | 25µs | 2 | 38µs | # spent 27µs (15+12) within Foswiki::Configure::Section::BEGIN@16 which was called:
# once (15µs+12µs) by Foswiki::Configure::LoadSpec::BEGIN@61 at line 16 # spent 27µs making 1 call to Foswiki::Configure::Section::BEGIN@16
# spent 12µs making 1 call to strict::import |
17 | 2 | 22µs | 2 | 16µs | # spent 12µs (9+4) within Foswiki::Configure::Section::BEGIN@17 which was called:
# once (9µs+4µs) by Foswiki::Configure::LoadSpec::BEGIN@61 at line 17 # spent 12µs making 1 call to Foswiki::Configure::Section::BEGIN@17
# spent 4µs making 1 call to warnings::import |
18 | |||||
19 | 2 | 121µs | 1 | 1.52ms | # spent 1.52ms (1.44+86µs) within Foswiki::Configure::Section::BEGIN@19 which was called:
# once (1.44ms+86µs) by Foswiki::Configure::LoadSpec::BEGIN@61 at line 19 # spent 1.52ms making 1 call to Foswiki::Configure::Section::BEGIN@19 |
20 | 1 | 10µs | our @ISA = ('Foswiki::Configure::Item'); | ||
21 | |||||
22 | # Attributes legal on a section header | ||||
23 | 1 | 7µs | 1 | 30µs | # spent 41µs (12+30) within Foswiki::Configure::Section::BEGIN@23 which was called:
# once (12µs+30µs) by Foswiki::Configure::LoadSpec::BEGIN@61 at line 26 # spent 30µs making 1 call to constant::import |
24 | EXPERT => {}, | ||||
25 | SORTED => {} | ||||
26 | 1 | 830µs | 1 | 41µs | }; # spent 41µs making 1 call to Foswiki::Configure::Section::BEGIN@23 |
27 | |||||
28 | =begin TML | ||||
29 | |||||
30 | ---++ ClassMethod new(@opts) | ||||
31 | * =@opts= - array of key-value options, e.g. headline => 'Security Settings' | ||||
32 | |||||
33 | Constructor. | ||||
34 | |||||
35 | =cut | ||||
36 | |||||
37 | sub new { | ||||
38 | my ( $class, @opts ) = @_; | ||||
39 | |||||
40 | my $this = $class->SUPER::new( | ||||
41 | children => [], | ||||
42 | headline => 'UNKNOWN', | ||||
43 | typename => 'SECTION', | ||||
44 | _vobCache => {}, # Do not serialise | ||||
45 | @opts | ||||
46 | ); | ||||
47 | |||||
48 | return $this; | ||||
49 | } | ||||
50 | |||||
51 | =begin TML | ||||
52 | |||||
53 | ---++ ObjectMethod addChild($child) | ||||
54 | Add a child node under this node. | ||||
55 | |||||
56 | =cut | ||||
57 | |||||
58 | sub addChild { | ||||
59 | my ( $this, $child ) = @_; | ||||
60 | foreach my $kid ( @{ $this->{children} } ) { | ||||
61 | die "Subnode already present; cannot add again" if $child eq $kid; | ||||
62 | } | ||||
63 | $child->{_parent} = $this; | ||||
64 | $child->{depth} = $this->{depth} + 1; | ||||
65 | |||||
66 | push( @{ $this->{children} }, $child ); | ||||
67 | |||||
68 | $this->_addToVobCache($child); | ||||
69 | } | ||||
70 | |||||
71 | # The _vobCache provides fast access to value items | ||||
72 | sub _addToVobCache { | ||||
73 | my ( $this, $child ) = @_; | ||||
74 | |||||
75 | if ( $child->isa('Foswiki::Configure::Section') ) { | ||||
76 | while ( my ( $k, $v ) = each %{ $child->{_vobCache} } ) { | ||||
77 | $this->{_vobCache}->{$k} = $v; | ||||
78 | } | ||||
79 | } | ||||
80 | else { | ||||
81 | $this->{_vobCache}->{ $child->{keys} } = $child; | ||||
82 | } | ||||
83 | $this->{_parent}->_addToVobCache($child) if $this->{_parent}; | ||||
84 | } | ||||
85 | |||||
86 | # See Foswiki::Configure::Item | ||||
87 | sub hasDeep { | ||||
88 | my ( $this, $attrname ) = @_; | ||||
89 | return 1 if $this->{$attrname}; | ||||
90 | foreach my $kid ( @{ $this->{children} } ) { | ||||
91 | return 1 if $kid->hasDeep($attrname); | ||||
92 | } | ||||
93 | return 0; | ||||
94 | } | ||||
95 | |||||
96 | # See Foswiki::Configure::Item | ||||
97 | sub unparent { | ||||
98 | my $this = shift; | ||||
99 | |||||
100 | if ( $this->{children} ) { | ||||
101 | foreach my $c ( @{ $this->{children} } ) { | ||||
102 | $c->unparent(); | ||||
103 | } | ||||
104 | } | ||||
105 | $this->SUPER::unparent(); | ||||
106 | } | ||||
107 | |||||
108 | # See Foswiki::Configure::Item | ||||
109 | sub prune { | ||||
110 | my ( $this, $depth ) = @_; | ||||
111 | |||||
112 | if ( $depth == 0 ) { | ||||
113 | delete $this->{children}; | ||||
114 | } | ||||
115 | elsif ( $this->{children} ) { | ||||
116 | foreach my $c ( @{ $this->{children} } ) { | ||||
117 | $c->prune( $depth - 1 ); | ||||
118 | } | ||||
119 | } | ||||
120 | } | ||||
121 | |||||
122 | # See Foswiki::Configure::Item | ||||
123 | # Visit each of the children of this node in turn. | ||||
124 | sub visit { | ||||
125 | my ( $this, $visitor ) = @_; | ||||
126 | my %visited; | ||||
127 | return 0 unless $visitor->startVisit($this); | ||||
128 | foreach my $child ( @{ $this->{children} } ) { | ||||
129 | if ( $visited{$child} ) { | ||||
130 | die join( ' ', @{ $this->{children} } ); | ||||
131 | } | ||||
132 | $visited{$child} = 1; | ||||
133 | return 0 unless $child->visit($visitor); | ||||
134 | |||||
135 | } | ||||
136 | return 0 unless $visitor->endVisit($this); | ||||
137 | return 1; | ||||
138 | } | ||||
139 | |||||
140 | # See Foswiki::Configure::Item | ||||
141 | sub getSectionObject { | ||||
142 | my ( $this, $head, $depth ) = @_; | ||||
143 | if ( $this->{headline} eq $head | ||||
144 | && ( !defined $depth || $this->{depth} == $depth ) ) | ||||
145 | { | ||||
146 | return $this; | ||||
147 | } | ||||
148 | foreach my $child ( @{ $this->{children} } ) { | ||||
149 | my $cvo = $child->getSectionObject( $head, $depth ); | ||||
150 | return $cvo if $cvo; | ||||
151 | } | ||||
152 | return undef; | ||||
153 | } | ||||
154 | |||||
155 | # Implements Foswiki::Configure::Item | ||||
156 | # Keys are only present on leaf items, so recursively query until we | ||||
157 | # find the appropriate leaf Value. | ||||
158 | sub getValueObject { | ||||
159 | my ( $this, $keys ) = @_; | ||||
160 | return $this->{_vobCache}->{$keys}; | ||||
161 | } | ||||
162 | |||||
163 | # Implements Foswiki::Configure::Item | ||||
164 | sub getAllValueKeys { | ||||
165 | my $this = shift; | ||||
166 | return keys %{ $this->{_vobCache} }; | ||||
167 | } | ||||
168 | |||||
169 | # Implements Foswiki::Configure::Item | ||||
170 | sub promoteSetting { | ||||
171 | my ( $this, $setting ) = @_; | ||||
172 | my $on_me = 1; | ||||
173 | |||||
174 | foreach my $child ( @{ $this->{children} } ) { | ||||
175 | $on_me = 0 unless $child->promoteSetting($setting); | ||||
176 | } | ||||
177 | |||||
178 | if ($on_me) { | ||||
179 | $this->{$setting} = 1; | ||||
180 | } | ||||
181 | else { | ||||
182 | delete $this->{$setting}; | ||||
183 | } | ||||
184 | |||||
185 | return $this->{$setting}; | ||||
186 | } | ||||
187 | |||||
188 | # Implements Foswiki::Configure::Item | ||||
189 | sub getPath { | ||||
190 | my $this = shift; | ||||
191 | |||||
192 | my @path; | ||||
193 | @path = $this->{_parent}->getPath() if ( $this->{_parent} ); | ||||
194 | push( @path, $this->{headline} ) if $this->{headline}; | ||||
195 | |||||
196 | return @path; | ||||
197 | } | ||||
198 | |||||
199 | # Implements Foswiki::Configure::Item | ||||
200 | sub search { | ||||
201 | my ( $this, $re ) = @_; | ||||
202 | |||||
203 | my @result = (); | ||||
204 | push( @result, $this ) if $this->{headline} =~ m/$re/i; | ||||
205 | foreach my $child ( @{ $this->{children} } ) { | ||||
206 | push( @result, $child->search($re) ); | ||||
207 | } | ||||
208 | return @result; | ||||
209 | } | ||||
210 | |||||
211 | # Implements Foswiki::Configure::Item | ||||
212 | sub find { | ||||
213 | my $this = shift; | ||||
214 | my %search = @_; | ||||
215 | |||||
216 | my $match = $this->_matches(%search); | ||||
217 | |||||
218 | # Return without searching the subtree if this node matches | ||||
219 | if ($match) { | ||||
220 | return ($this); | ||||
221 | } | ||||
222 | |||||
223 | return () unless $this->{children}; | ||||
224 | |||||
225 | # Search children | ||||
226 | my @result = (); | ||||
227 | foreach my $child ( @{ $this->{children} } ) { | ||||
228 | push( @result, $child->find(@_) ); | ||||
229 | } | ||||
230 | |||||
231 | return @result; | ||||
232 | } | ||||
233 | |||||
234 | # Implements Foswiki::Configure::Item | ||||
235 | sub find_also_dependencies { | ||||
236 | my ( $this, $root ) = @_; | ||||
237 | |||||
238 | $root ||= $this; | ||||
239 | |||||
240 | foreach my $kid ( @{ $this->{children} } ) { | ||||
241 | $kid->find_also_dependencies($root); | ||||
242 | } | ||||
243 | } | ||||
244 | |||||
245 | 1 | 3µs | 1; | ||
246 | __END__ |