← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/local/src/github.com/foswiki/core/bin/view
  Run on Sun Dec 4 17:17:59 2011
Reported on Sun Dec 4 17:26:48 2011

Filename/usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/JQueryPlugin/Plugins.pm
StatementsExecuted 443 statements in 5.69ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
55221.58ms2.68msFoswiki::Plugins::JQueryPlugin::Plugins::::registerPluginFoswiki::Plugins::JQueryPlugin::Plugins::registerPlugin
111994µs8.27msFoswiki::Plugins::JQueryPlugin::Plugins::::initFoswiki::Plugins::JQueryPlugin::Plugins::init
911528µs5.71msFoswiki::Plugins::JQueryPlugin::Plugins::::loadFoswiki::Plugins::JQueryPlugin::Plugins::load
111211µs211µsFoswiki::Plugins::JQueryPlugin::Plugins::::finishFoswiki::Plugins::JQueryPlugin::Plugins::finish
933197µs8.06msFoswiki::Plugins::JQueryPlugin::Plugins::::createPluginFoswiki::Plugins::JQueryPlugin::Plugins::createPlugin (recurses: max depth 2, inclusive time 4.31ms)
61183µs83µsFoswiki::Plugins::JQueryPlugin::Plugins::::registerThemeFoswiki::Plugins::JQueryPlugin::Plugins::registerTheme
22154µs54µsFoswiki::Plugins::JQueryPlugin::Plugins::::CORE:sortFoswiki::Plugins::JQueryPlugin::Plugins::CORE:sort (opcode)
11133µs99µsFoswiki::Plugins::JQueryPlugin::Plugins::::createThemeFoswiki::Plugins::JQueryPlugin::Plugins::createTheme
11130µs37µsFoswiki::Plugins::JQueryPlugin::Plugins::::BEGIN@4Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@4
11126µs26µsFoswiki::Plugins::JQueryPlugin::Plugins::::BEGIN@6Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@6
11122µs39µsFoswiki::Plugins::JQueryPlugin::Plugins::::BEGIN@5Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@5
0000s0sFoswiki::Plugins::JQueryPlugin::Plugins::::expandVariablesFoswiki::Plugins::JQueryPlugin::Plugins::expandVariables
0000s0sFoswiki::Plugins::JQueryPlugin::Plugins::::getIconUrlPathFoswiki::Plugins::JQueryPlugin::Plugins::getIconUrlPath
0000s0sFoswiki::Plugins::JQueryPlugin::Plugins::::getPluginsFoswiki::Plugins::JQueryPlugin::Plugins::getPlugins
0000s0sFoswiki::Plugins::JQueryPlugin::Plugins::::getRandomFoswiki::Plugins::JQueryPlugin::Plugins::getRandom
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::Plugins::JQueryPlugin::Plugins;
3
4247µs244µs
# spent 37µs (30+7) within Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@4 which was called: # once (30µs+7µs) by Foswiki::Plugins::JQueryPlugin::BEGIN@15 at line 4
use strict;
# spent 37µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@4 # spent 7µs making 1 call to strict::import
5246µs257µs
# spent 39µs (22+17) within Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@5 which was called: # once (22µs+17µs) by Foswiki::Plugins::JQueryPlugin::BEGIN@15 at line 5
use warnings;
# spent 39µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@5 # spent 17µs making 1 call to warnings::import
622.02ms126µs
# spent 26µs within Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@6 which was called: # once (26µs+0s) by Foswiki::Plugins::JQueryPlugin::BEGIN@15 at line 6
use Foswiki::Func;
7
812µsour @iconSearchPath;
911µsour %iconCache;
101800nsour %plugins;
111900nsour %themes;
1211µsour $debug;
13
14=begin TML
15
16---+ package Foswiki::Plugins::JQueryPlugin
17
18Container for jQuery and plugins
19
20=cut
21
22=begin TML
23
24---++ init()
25
26initialize plugin container
27
28=cut
29
30
# spent 8.27ms (994µs+7.28) within Foswiki::Plugins::JQueryPlugin::Plugins::init which was called: # once (994µs+7.28ms) by Foswiki::Plugins::JQueryPlugin::initPlugin at line 62 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/JQueryPlugin.pm
sub init {
31
3211227µs $debug = $Foswiki::cfg{JQueryPlugin}{Debug} || 0;
33
34 # get all plugins
3517µs148µs foreach
36 my $pluginName ( sort keys %{ $Foswiki::cfg{JQueryPlugin}{Plugins} } )
37 {
3858593µs542.60ms registerPlugin($pluginName)
# spent 2.60ms making 54 calls to Foswiki::Plugins::JQueryPlugin::Plugins::registerPlugin, avg 48µs/call
39 if $Foswiki::cfg{JQueryPlugin}{Plugins}{$pluginName}{Enabled};
40 }
41
42 # get all themes
4312µs17µs foreach my $themeName ( sort keys %{ $Foswiki::cfg{JQueryPlugin}{Themes} } )
44 {
45647µs683µs registerTheme($themeName)
# spent 83µs making 6 calls to Foswiki::Plugins::JQueryPlugin::Plugins::registerTheme, avg 14µs/call
46 if $Foswiki::cfg{JQueryPlugin}{Themes}{$themeName}{Enabled};
47 }
48
49 # load jquery
50 my $jQuery = $Foswiki::cfg{JQueryPlugin}{JQueryVersion} || "jquery-1.4.3";
51 $jQuery .= ".uncompressed" if $debug;
52 my $code =
53"<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/$jQuery.js'></script>";
54
55 # switch on noconflict mode
56 $code .=
57 "\n<script type='text/javascript'>var \$j = jQuery.noConflict();</script>"
58 if $Foswiki::cfg{JQueryPlugin}{NoConflict};
59
60195µs Foswiki::Func::addToZone( 'script', 'JQUERYPLUGIN', $code );
# spent 95µs making 1 call to Foswiki::Func::addToZone
61
62 # initial plugins
6314.44ms createPlugin('Foswiki'); # this one is needed anyway
64
65 my $defaultPlugins = $Foswiki::cfg{JQueryPlugin}{DefaultPlugins};
66 if ($defaultPlugins) {
67 foreach my $pluginName ( split( /\s*,\s*/, $defaultPlugins ) ) {
68 createPlugin($pluginName);
69 }
70 }
71
72}
73
74=begin TML
75
76---++ ObjectMethod createPlugin( $pluginName, ... ) -> $plugin
77
78Helper method to establish plugin dependencies. See =load()=.
79
80=cut
81
82
# spent 8.06ms (197µs+7.86) within Foswiki::Plugins::JQueryPlugin::Plugins::createPlugin which was called 9 times, avg 895µs/call: # 6 times (125µs+-125µs) by Foswiki::Plugins::JQueryPlugin::Plugin::init at line 119 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/JQueryPlugin/Plugin.pm, avg 0s/call # 2 times (52µs+3.57ms) by Foswiki::Plugins::JQueryPlugin::createPlugin at line 95 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/JQueryPlugin.pm, avg 1.81ms/call # once (21µs+4.42ms) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 63
sub createPlugin {
8327180µs95.71ms my $plugin = load(@_);
# spent 5.71ms making 9 calls to Foswiki::Plugins::JQueryPlugin::Plugins::load, avg 635µs/call
8495.93ms $plugin->init() if $plugin;
# spent 3.35ms making 7 calls to Foswiki::Plugins::JQueryPlugin::Plugin::init, avg 479µs/call, recursion: max depth 2, sum of overlapping time 527µs # spent 1.64ms making 1 call to Foswiki::Plugins::JQueryPlugin::FOSWIKI::init # spent 1.47ms making 1 call to Foswiki::Plugins::JQueryPlugin::UI::init
85 return $plugin;
86}
87
88=begin TML
89
90---++ ObjectMethd createTheme ($themeName, $url) -> $boolean
91
92Helper method to switch on a theme. Returns true
93if =$themeName= has been loaded successfully. Note that a previously
94loaded theme will be replaced with the new one as there can only
95be one theme per html page. The $url parameter optionally specifies
96from where to load the theme. It defaults to the url registered
97in =configure= for the named theme.
98
99=cut
100
101
# spent 99µs (33+66) within Foswiki::Plugins::JQueryPlugin::Plugins::createTheme which was called: # once (33µs+66µs) by Foswiki::Plugins::JQueryPlugin::createTheme at line 108 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/JQueryPlugin.pm
sub createTheme {
102725µs my ( $themeName, $url ) = @_;
103
104 $themeName ||= $Foswiki::cfg{JQueryPlugin}{JQueryTheme};
105 return 0 unless $themeName;
106
107 my $normalizedName = lc($themeName);
108
10936µs unless ($url) {
110 my $themeDesc = $themes{$normalizedName};
111 return 0 unless defined $themeDesc;
112 $url = $themeDesc->{url};
113 }
114
115166µs Foswiki::Func::addToZone( "head", "JQUERYPLUGIN::THEME",
# spent 66µs making 1 call to Foswiki::Func::addToZone
116 <<HERE, "JQUERYPLUGIN::FOSWIKI, JQUERYPLUGIN::UI" );
117<link rel="stylesheet" href="$url" type="text/css" media="all" />
118HERE
119
120 return 1;
121}
122
123=begin TML
124
125---++ ObjectMethod registerPlugin( $pluginName, $class ) -> $descriptor
126
127Helper method to register a plugin.
128
129=cut
130
131
# spent 2.68ms (1.58+1.10) within Foswiki::Plugins::JQueryPlugin::Plugins::registerPlugin which was called 55 times, avg 49µs/call: # 54 times (1.54ms+1.06ms) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 38, avg 48µs/call # once (40µs+35µs) by Foswiki::Plugins::JQueryPlugin::registerPlugin at line 126 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/JQueryPlugin.pm
sub registerPlugin {
1322201.66ms my ( $pluginName, $class ) = @_;
133
134 $class ||= $Foswiki::cfg{JQueryPlugin}{Plugins}{$pluginName}{Module}
135 || 'Foswiki::Plugins::JQueryPlugin::' . uc($pluginName);
136
137551.10ms Foswiki::Func::getContext()->{ $pluginName . 'Enabled' } = 1;
# spent 1.10ms making 55 calls to Foswiki::Func::getContext, avg 20µs/call
138
139 return $plugins{ lc($pluginName) } = {
140 'class' => $class,
141 'name' => $pluginName,
142 'instance' => undef,
143 };
144}
145
146=begin TML
147
148---++ ObjectMethod registerTheme( $themeName, $url ) -> $descriptor
149
150Helper method to register a theme.
151
152=cut
153
154
# spent 83µs within Foswiki::Plugins::JQueryPlugin::Plugins::registerTheme which was called 6 times, avg 14µs/call: # 6 times (83µs+0s) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 45, avg 14µs/call
sub registerTheme {
1552495µs my ( $themeName, $url ) = @_;
156
157 my $normalizedName = lc($themeName);
158
159 $url ||= $Foswiki::cfg{JQueryPlugin}{Themes}{$themeName}{Url}
160 || '%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/themes/'
161 . $normalizedName
162 . '/jquery-ui.css';
163
164 return $themes{$normalizedName} = {
165 'url' => $url,
166 'name' => $themeName,
167 };
168}
169
170=begin TML
171
172finalizer
173
174=cut
175
176
# spent 211µs within Foswiki::Plugins::JQueryPlugin::Plugins::finish which was called: # once (211µs+0s) by Foswiki::Plugins::JQueryPlugin::modifyHeaderHandler at line 82 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/JQueryPlugin.pm
sub finish {
177
1784216µs undef %plugins;
179 undef %themes;
180 undef @iconSearchPath;
181 undef %iconCache;
182}
183
184=begin TML
185
186---++ ObjectMethod load ( $pluginName ) -> $plugin
187
188Loads a plugin and runs its initializer.
189
190parameters
191 * =$pluginName=: name of plugin
192
193returns
194 * =$plugin=: returns the plugin object or false if instantiating
195 the plugin failed
196
197=cut
198
199
# spent 5.71ms (528µs+5.19) within Foswiki::Plugins::JQueryPlugin::Plugins::load which was called 9 times, avg 635µs/call: # 9 times (528µs+5.19ms) by Foswiki::Plugins::JQueryPlugin::Plugins::createPlugin at line 83, avg 635µs/call
sub load {
20054142µs my $pluginName = shift;
201
202 my $normalizedName = lc($pluginName);
203 my $pluginDesc = $plugins{$normalizedName};
204
205 return undef unless $pluginDesc;
206
20710329µs unless ( defined $pluginDesc->{instance} ) {
208
209 eval "use $pluginDesc->{class};";
# spent 175µs executing statements in string eval
# includes 790µs spent executing 1 call to 1 sub defined therein. # spent 156µs executing statements in string eval
# includes 394µs spent executing 1 call to 1 sub defined therein. # spent 155µs executing statements in string eval
# includes 364µs spent executing 1 call to 1 sub defined therein. # spent 149µs executing statements in string eval
# includes 367µs spent executing 1 call to 1 sub defined therein. # spent 143µs executing statements in string eval
# includes 613µs spent executing 1 call to 1 sub defined therein.
210
211540µs if ($@) {
212 print STDERR "ERROR: can't load jQuery plugin $pluginName: $@\n";
213 $pluginDesc->{instance} = 0;
214 }
215 else {
2165519µs $pluginDesc->{instance} = $pluginDesc->{class}->new();
# spent 134µs making 1 call to Foswiki::Plugins::JQueryPlugin::TEXTBOXLIST::new # spent 108µs making 1 call to Foswiki::Plugins::JQueryPlugin::FOSWIKI::new # spent 96µs making 1 call to Foswiki::Plugins::JQueryPlugin::UI::new # spent 93µs making 1 call to Foswiki::Plugins::JQueryPlugin::METADATA::new # spent 87µs making 1 call to Foswiki::Plugins::JQueryPlugin::LIVEQUERY::new
217 }
218 }
219
220 return $pluginDesc->{instance};
221}
222
223=begin TML
224
225---++ ObjectMethod expandVariables( $format, %params) -> $string
226
227Helper function to expand standard escape sequences =$percnt=, =$nop=,
228=$n= and =$dollar=.
229
230 * =$format=: format string to be expaneded
231 * =%params=: optional hash array containing further key-value pairs to be
232 expanded as well, that is all occurences of =$key= will
233 be replaced by its =value= as defined in %params
234 * =$string=: returns the resulting text
235
236=cut
237
238sub expandVariables {
239 my ( $format, %params ) = @_;
240
241 return '' unless $format;
242
243 foreach my $key ( keys %params ) {
244 my $val = $params{$key};
245 $val = '' unless defined $val;
246 $format =~ s/\$$key\b/$val/g;
247 }
248 $format = Foswiki::Func::decodeFormatTokens($format);
249
250 return $format;
251}
252
253=begin TML
254
255---++ ObjectMethod getIconUrlPath ( $iconName ) -> $pubUrlPath
256
257Returns the path to the named icon searching along a given icon search path.
258This path can be in =$Foswiki::cfg{JQueryPlugin}{IconSearchPath}= or will fall
259back to =FamFamFamSilkIcons=, =FamFamFamSilkCompanion1Icons=,
260=FamFamFamFlagIcons=, =FamFamFamMiniIcons=, =FamFamFamMintIcons= As you see
261installing Foswiki:Extensions/FamFamFamContrib would be nice to have.
262
263 = =$iconName=: name of icon; you will have to know the icon name by heart as listed in your
264 favorite icon set, meaning there's no mapping between something like "semantic" and "physical" icons
265 = =$pubUrlPath=: the path to the icon as it is attached somewhere in your wiki or the empty
266 string if the icon was not found
267
268=cut
269
270sub getIconUrlPath {
271 my ($iconName) = @_;
272
273 return '' unless $iconName;
274
275 unless (@iconSearchPath) {
276 my $iconSearchPath = $Foswiki::cfg{JQueryPlugin}{IconSearchPath}
277 || 'FamFamFamSilkIcons, FamFamFamSilkCompanion1Icons, FamFamFamSilkCompanion2Icons, FamFamFamFlagIcons, FamFamFamMiniIcons, FamFamFamMintIcons';
278 @iconSearchPath = split( /\s*,\s*/, $iconSearchPath );
279 }
280
281 $iconName =~ s/^.*\.(.*?)$/$1/; # strip file extension
282
283 my $iconPath = $iconCache{$iconName};
284
285 unless ($iconPath) {
286 my $iconWeb = $Foswiki::cfg{SystemWebName};
287 my $pubSystemDir =
288 $Foswiki::cfg{PubDir} . '/' . $Foswiki::cfg{SystemWebName};
289
290 foreach my $item (@iconSearchPath) {
291 my ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName(
292 $Foswiki::cfg{SystemWebName}, $item );
293
294 # SMELL: store violation assumes the we have got file-level access
295 # better use store api
296 my $iconDir =
297 $Foswiki::cfg{PubDir} . '/'
298 . $web . '/'
299 . $topic . '/'
300 . $iconName . '.png';
301 if ( -f $iconDir ) {
302 $iconPath =
303 Foswiki::Func::getPubUrlPath() . '/'
304 . $web . '/'
305 . $topic . '/'
306 . $iconName . '.png';
307 last; # first come first serve
308 }
309 }
310
311 $iconPath ||= '';
312 $iconCache{$iconName} = $iconPath;
313 }
314
315 return $iconPath;
316}
317
318=begin TML
319
320---++ ClassMethod getPlugins () -> @plugins
321
322returns a list of all known plugins
323
324=cut
325
326sub getPlugins {
327 my ($include) = @_;
328
329 my @plugins = ();
330 foreach my $key ( sort keys %plugins ) {
331 next if $key eq 'empty'; # skip this one
332 next if $include && $key !~ /^($include)$/;
333 my $pluginDesc = $plugins{$key};
334 my $plugin = load( $pluginDesc->{name} );
335 push @plugins, $plugin if $plugin;
336 }
337
338 return @plugins;
339}
340
341=begin TML
342
343---++ ClassMethod getRandom () -> $integer
344
345returns a random positive integer between 1 and 10000.
346this can be used to
347generate html element IDs which are not
348allowed to clash within the same html page,
349even not when it got extended via ajax.
350
351=cut
352
353sub getRandom {
354 return int( rand(10000) ) + 1;
355}
356
35716µs1;
358__END__
 
# spent 54µs within Foswiki::Plugins::JQueryPlugin::Plugins::CORE:sort which was called 2 times, avg 27µs/call: # once (48µs+0s) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 35 # once (7µs+0s) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 43
sub Foswiki::Plugins::JQueryPlugin::Plugins::CORE:sort; # opcode