← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 18:42:36 2015
Reported on Fri Jul 31 18:48:14 2015

Filename/var/www/foswikidev/core/lib/Foswiki/Configure/Section.pm
StatementsExecuted 10 statements in 1.02ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.44ms1.52msFoswiki::Configure::Section::::BEGIN@19Foswiki::Configure::Section::BEGIN@19
11115µs27µsFoswiki::Configure::Section::::BEGIN@16Foswiki::Configure::Section::BEGIN@16
11112µs41µsFoswiki::Configure::Section::::BEGIN@23Foswiki::Configure::Section::BEGIN@23
1119µs12µsFoswiki::Configure::Section::::BEGIN@17Foswiki::Configure::Section::BEGIN@17
0000s0sFoswiki::Configure::Section::::_addToVobCacheFoswiki::Configure::Section::_addToVobCache
0000s0sFoswiki::Configure::Section::::addChildFoswiki::Configure::Section::addChild
0000s0sFoswiki::Configure::Section::::findFoswiki::Configure::Section::find
0000s0sFoswiki::Configure::Section::::find_also_dependenciesFoswiki::Configure::Section::find_also_dependencies
0000s0sFoswiki::Configure::Section::::getAllValueKeysFoswiki::Configure::Section::getAllValueKeys
0000s0sFoswiki::Configure::Section::::getPathFoswiki::Configure::Section::getPath
0000s0sFoswiki::Configure::Section::::getSectionObjectFoswiki::Configure::Section::getSectionObject
0000s0sFoswiki::Configure::Section::::getValueObjectFoswiki::Configure::Section::getValueObject
0000s0sFoswiki::Configure::Section::::hasDeepFoswiki::Configure::Section::hasDeep
0000s0sFoswiki::Configure::Section::::newFoswiki::Configure::Section::new
0000s0sFoswiki::Configure::Section::::promoteSettingFoswiki::Configure::Section::promoteSetting
0000s0sFoswiki::Configure::Section::::pruneFoswiki::Configure::Section::prune
0000s0sFoswiki::Configure::Section::::searchFoswiki::Configure::Section::search
0000s0sFoswiki::Configure::Section::::unparentFoswiki::Configure::Section::unparent
0000s0sFoswiki::Configure::Section::::visitFoswiki::Configure::Section::visit
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::Configure::Section;
3
4=begin TML
5
6---+ package Foswiki::Configure::Section
7
8A collection node in a configuration item tree; a collection
9of configuration items and subsections.
10
11IMPORTANT: there are some naming conventions for fields that apply to
12all subclasses of this class. See Foswiki::Configure::Item for details.
13
14=cut
15
16225µs238µ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
use strict;
# spent 27µs making 1 call to Foswiki::Configure::Section::BEGIN@16 # spent 12µs making 1 call to strict::import
17222µs216µ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
use warnings;
# spent 12µs making 1 call to Foswiki::Configure::Section::BEGIN@17 # spent 4µs making 1 call to warnings::import
18
192121µs11.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
use Foswiki::Configure::Item ();
# spent 1.52ms making 1 call to Foswiki::Configure::Section::BEGIN@19
20110µsour @ISA = ('Foswiki::Configure::Item');
21
22# Attributes legal on a section header
2317µs130µ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
use constant ATTRSPEC => {
# spent 30µs making 1 call to constant::import
24 EXPERT => {},
25 SORTED => {}
261830µs141µ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
33Constructor.
34
35=cut
36
37sub 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)
54Add a child node under this node.
55
56=cut
57
58sub 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
72sub _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
87sub 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
97sub 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
109sub 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.
124sub 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
141sub 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.
158sub getValueObject {
159 my ( $this, $keys ) = @_;
160 return $this->{_vobCache}->{$keys};
161}
162
163# Implements Foswiki::Configure::Item
164sub getAllValueKeys {
165 my $this = shift;
166 return keys %{ $this->{_vobCache} };
167}
168
169# Implements Foswiki::Configure::Item
170sub 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
189sub 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
200sub 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
212sub 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
235sub 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
24513µs1;
246__END__