← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 19:05:14 2015
Reported on Fri Jul 31 19:08:10 2015

Filename/var/www/foswiki11/lib/Foswiki/Plugins/JQueryPlugin/Plugins.pm
StatementsExecuted 392 statements in 2.30ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
5622468µs698µsFoswiki::Plugins::JQueryPlugin::Plugins::::registerPluginFoswiki::Plugins::JQueryPlugin::Plugins::registerPlugin
111345µs4.06msFoswiki::Plugins::JQueryPlugin::Plugins::::initFoswiki::Plugins::JQueryPlugin::Plugins::init
211141µs2.51msFoswiki::Plugins::JQueryPlugin::Plugins::::loadFoswiki::Plugins::JQueryPlugin::Plugins::load
111128µs128µsFoswiki::Plugins::JQueryPlugin::Plugins::::finishFoswiki::Plugins::JQueryPlugin::Plugins::finish
71138µs38µsFoswiki::Plugins::JQueryPlugin::Plugins::::registerThemeFoswiki::Plugins::JQueryPlugin::Plugins::registerTheme
22230µs2.97msFoswiki::Plugins::JQueryPlugin::Plugins::::createPluginFoswiki::Plugins::JQueryPlugin::Plugins::createPlugin (recurses: max depth 1, inclusive time 577µs)
11122µs65µsFoswiki::Plugins::JQueryPlugin::Plugins::::createThemeFoswiki::Plugins::JQueryPlugin::Plugins::createTheme
11113µs25µsFoswiki::Plugins::JQueryPlugin::Plugins::::BEGIN@4Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@4
1119µs14µsFoswiki::Plugins::JQueryPlugin::Plugins::::BEGIN@5Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@5
1116µs6µsFoswiki::Plugins::JQueryPlugin::Plugins::::BEGIN@6Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@6
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
4226µs237µs
# spent 25µs (13+12) within Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@4 which was called: # once (13µs+12µs) by Foswiki::Plugins::JQueryPlugin::BEGIN@15 at line 4
use strict;
# spent 25µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@4 # spent 12µs making 1 call to strict::import
5226µs219µs
# spent 14µs (9+5) within Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@5 which was called: # once (9µs+5µs) by Foswiki::Plugins::JQueryPlugin::BEGIN@15 at line 5
use warnings;
# spent 14µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@5 # spent 5µs making 1 call to warnings::import
621.15ms16µs
# spent 6µs within Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@6 which was called: # once (6µs+0s) by Foswiki::Plugins::JQueryPlugin::BEGIN@15 at line 6
use Foswiki::Func;
# spent 6µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@6
7
81200nsmy @iconSearchPath;
91100nsmy %iconCache;
1010smy %plugins;
111100nsmy %themes;
121100nsmy $debug;
1310smy $currentTheme;
14
15=begin TML
16
17---+ package Foswiki::Plugins::JQueryPlugin
18
19Container for jQuery and plugins
20
21=cut
22
23=begin TML
24
25---++ init()
26
27initialize plugin container
28
29=cut
30
31
# spent 4.06ms (345µs+3.71) within Foswiki::Plugins::JQueryPlugin::Plugins::init which was called: # once (345µs+3.71ms) by Foswiki::Plugins::JQueryPlugin::initPlugin at line 57 of /var/www/foswiki11/lib/Foswiki/Plugins/JQueryPlugin.pm
sub init {
32
3312µs $debug = $Foswiki::cfg{JQueryPlugin}{Debug} || 0;
34
35 # get all plugins
36148µs foreach
37 my $pluginName ( sort keys %{ $Foswiki::cfg{JQueryPlugin}{Plugins} } )
38 {
3960145µs55686µs registerPlugin($pluginName)
# spent 686µs making 55 calls to Foswiki::Plugins::JQueryPlugin::Plugins::registerPlugin, avg 12µs/call
40 if $Foswiki::cfg{JQueryPlugin}{Plugins}{$pluginName}{Enabled};
41 }
42
43 # get all themes
44110µs foreach my $themeName ( sort keys %{ $Foswiki::cfg{JQueryPlugin}{Themes} } )
45 {
46720µs738µs registerTheme($themeName)
# spent 38µs making 7 calls to Foswiki::Plugins::JQueryPlugin::Plugins::registerTheme, avg 5µs/call
47 if $Foswiki::cfg{JQueryPlugin}{Themes}{$themeName}{Enabled};
48 }
4912µs $currentTheme = $Foswiki::cfg{JQueryPlugin}{JQueryTheme};
50
51 # load jquery
521900ns my $jQuery = $Foswiki::cfg{JQueryPlugin}{JQueryVersion} || "jquery-1.8.3";
531200ns $jQuery .= ".uncompressed" if $debug;
5411µs my $jQueryIE = $Foswiki::cfg{JQueryPlugin}{JQueryVersionForOldIEs} || "";
551200ns $jQueryIE .= ".uncompressed" if $debug;
56
571200ns my $code;
58
591700ns if ($jQueryIE) {
60 $code = <<"HERE";
61<literal><!--[if lte IE 9]>
62<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/$jQueryIE.js'></script>
63<![endif]-->
64<!--[if gt IE 9]><!-->
65<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/$jQuery.js'></script>
66<!--<![endif]-->
67</literal>
68HERE
69 }
70 else {
7112µs $code = <<"HERE";
72<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/$jQuery.js'></script>
73HERE
74 }
75
76 # switch on noconflict mode
771800ns $code .=
78 "<script type='text/javascript'>var \$j = jQuery.noConflict();</script>"
79 if $Foswiki::cfg{JQueryPlugin}{NoConflict};
80
8111µs122µs Foswiki::Func::addToZone( 'script', 'JQUERYPLUGIN', $code );
# spent 22µs making 1 call to Foswiki::Func::addToZone
82
83 # initial plugins
8413µs12.97ms createPlugin('Foswiki'); # this one is needed anyway
85
8611µs my $defaultPlugins = $Foswiki::cfg{JQueryPlugin}{DefaultPlugins};
871400ns if ($defaultPlugins) {
88 foreach my $pluginName ( split( /\s*,\s*/, $defaultPlugins ) ) {
89 createPlugin($pluginName);
90 }
91 }
92
93 # enable migrate for jQuery > 1.9.x as long as we still have 3rd party plugins
94 # making use of deprecated and removed features
95112µs unless ( $defaultPlugins =~ /\bmigrate\b/i ) {
9615µs if ( $jQuery =~ /^jquery-(\d+)\.(\d+)\.(\d+)/ ) {
9716µs my $jqVersion = $1 * 10000 + $2 * 100 + $3;
9811µs if ( $jqVersion > 10900 ) {
99 createPlugin("Migrate");
100 }
101 }
102 }
103}
104
105=begin TML
106
107---++ ObjectMethod createPlugin( $pluginName, ... ) -> $plugin
108
109Helper method to establish plugin dependencies. See =load()=.
110
111=cut
112
113
# spent 2.97ms (30µs+2.94) within Foswiki::Plugins::JQueryPlugin::Plugins::createPlugin which was called 2 times, avg 1.48ms/call: # once (14µs+2.95ms) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 84 # once (16µs+-16µs) by Foswiki::Plugins::JQueryPlugin::Plugin::init at line 119 of /var/www/foswiki11/lib/Foswiki/Plugins/JQueryPlugin/Plugin.pm
sub createPlugin {
11425µs22.51ms my $plugin = load(@_);
# spent 2.51ms making 2 calls to Foswiki::Plugins::JQueryPlugin::Plugins::load, avg 1.26ms/call
115211µs2916µs $plugin->init() if $plugin;
# spent 916µs making 1 call to Foswiki::Plugins::JQueryPlugin::FOSWIKI::init # spent 86µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugin::init, recursion: max depth 1, sum of overlapping time 86µs
11628µs return $plugin;
117}
118
119=begin TML
120
121---++ ObjectMethd createTheme ($themeName, $url) -> $boolean
122
123Helper method to switch on a theme. Returns true
124if =$themeName= has been loaded successfully. Note that a previously
125loaded theme will be replaced with the new one as there can only
126be one theme per html page. The $url parameter optionally specifies
127from where to load the theme. It defaults to the url registered
128in =configure= for the named theme.
129
130=cut
131
132
# spent 65µs (22+44) within Foswiki::Plugins::JQueryPlugin::Plugins::createTheme which was called: # once (22µs+44µs) by Foswiki::Plugins::JQueryPlugin::createTheme at line 101 of /var/www/foswiki11/lib/Foswiki/Plugins/JQueryPlugin.pm
sub createTheme {
13311µs my ( $themeName, $url ) = @_;
134
1351300ns $themeName ||= $currentTheme;
1361200ns return 0 unless $themeName;
137
1381800ns my $normalizedName = lc($themeName);
139
1401500ns unless ($url) {
14112µs my $themeDesc = $themes{$normalizedName};
1421300ns return 0 unless defined $themeDesc;
14312µs $url = $themeDesc->{url};
144 }
145
146 # remember last choice
14713µs $currentTheme = $themeName;
148
14918µs144µs Foswiki::Func::addToZone( "head", "JQUERYPLUGIN::THEME",
# spent 44µs making 1 call to Foswiki::Func::addToZone
150 <<HERE, "JQUERYPLUGIN::FOSWIKI, JQUERYPLUGIN::UI" );
151<link rel="stylesheet" href="$url" type="text/css" media="all" />
152HERE
153
15416µs return 1;
155}
156
157=begin TML
158
159---++ ObjectMethod registerPlugin( $pluginName, $class ) -> $descriptor
160
161Helper method to register a plugin.
162
163=cut
164
165
# spent 698µs (468+230) within Foswiki::Plugins::JQueryPlugin::Plugins::registerPlugin which was called 56 times, avg 12µs/call: # 55 times (460µs+225µs) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 39, avg 12µs/call # once (8µs+5µs) by Foswiki::Plugins::JQueryPlugin::registerPlugin at line 119 of /var/www/foswiki11/lib/Foswiki/Plugins/JQueryPlugin.pm
sub registerPlugin {
1665629µs my ( $pluginName, $class ) = @_;
167
1685656µs $class ||= $Foswiki::cfg{JQueryPlugin}{Plugins}{$pluginName}{Module}
169 || 'Foswiki::Plugins::JQueryPlugin::' . uc($pluginName);
170
17156122µs56230µs Foswiki::Func::getContext()->{ $pluginName . 'Enabled' } = 1;
# spent 230µs making 56 calls to Foswiki::Func::getContext, avg 4µs/call
172
17356268µs return $plugins{ lc($pluginName) } = {
174 'class' => $class,
175 'name' => $pluginName,
176 'instance' => undef,
177 };
178}
179
180=begin TML
181
182---++ ObjectMethod registerTheme( $themeName, $url ) -> $descriptor
183
184Helper method to register a theme.
185
186=cut
187
188
# spent 38µs within Foswiki::Plugins::JQueryPlugin::Plugins::registerTheme which was called 7 times, avg 5µs/call: # 7 times (38µs+0s) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 46, avg 5µs/call
sub registerTheme {
18974µs my ( $themeName, $url ) = @_;
190
19173µs my $normalizedName = lc($themeName);
192
19378µs $url ||= $Foswiki::cfg{JQueryPlugin}{Themes}{$themeName}{Url}
194 || '%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/themes/'
195 . $normalizedName
196 . '/jquery-ui.css';
197
198734µs return $themes{$normalizedName} = {
199 'url' => $url,
200 'name' => $themeName,
201 };
202}
203
204=begin TML
205
206finalizer
207
208=cut
209
210
# spent 128µs within Foswiki::Plugins::JQueryPlugin::Plugins::finish which was called: # once (128µs+0s) by Foswiki::Plugins::JQueryPlugin::finishPlugin at line 75 of /var/www/foswiki11/lib/Foswiki/Plugins/JQueryPlugin.pm
sub finish {
211
2121110µs undef %plugins;
213112µs undef %themes;
21412µs undef @iconSearchPath;
2151400ns undef %iconCache;
21617µs undef $currentTheme;
217}
218
219=begin TML
220
221---++ ObjectMethod load ( $pluginName ) -> $plugin
222
223Loads a plugin and runs its initializer.
224
225parameters
226 * =$pluginName=: name of plugin
227
228returns
229 * =$plugin=: returns the plugin object or false if instantiating
230 the plugin failed
231
232=cut
233
234
# spent 2.51ms (141µs+2.37) within Foswiki::Plugins::JQueryPlugin::Plugins::load which was called 2 times, avg 1.26ms/call: # 2 times (141µs+2.37ms) by Foswiki::Plugins::JQueryPlugin::Plugins::createPlugin at line 114, avg 1.26ms/call
sub load {
23521µs my $pluginName = shift;
236
23721µs my $normalizedName = lc($pluginName);
23821µs my $pluginDesc = $plugins{$normalizedName};
239
2402500ns return undef unless $pluginDesc;
241
24222µs unless ( defined $pluginDesc->{instance} ) {
243
2442103µs eval "use $pluginDesc->{class};";
# spent 126µs executing statements in string eval
# includes 579µs spent executing 1 call to 1 sub defined therein. # spent 113µs executing statements in string eval
# includes 283µs spent executing 1 call to 1 sub defined therein.
245
24622µs if ($@) {
247 print STDERR "ERROR: can't load jQuery plugin $pluginName: $@\n";
248 $pluginDesc->{instance} = 0;
249 }
250 else {
251212µs2117µs $pluginDesc->{instance} = $pluginDesc->{class}->new();
# spent 62µs making 1 call to Foswiki::Plugins::JQueryPlugin::FOSWIKI::new # spent 55µs making 1 call to Foswiki::Plugins::JQueryPlugin::LIVEQUERY::new
252 }
253 }
254
25529µs return $pluginDesc->{instance};
256}
257
258=begin TML
259
260---++ ObjectMethod expandVariables( $format, %params) -> $string
261
262Helper function to expand standard escape sequences =$percnt=, =$nop=,
263=$n= and =$dollar=.
264
265 * =$format=: format string to be expaneded
266 * =%params=: optional hash array containing further key-value pairs to be
267 expanded as well, that is all occurences of =$key= will
268 be replaced by its =value= as defined in %params
269 * =$string=: returns the resulting text
270
271=cut
272
273sub expandVariables {
274 my ( $format, %params ) = @_;
275
276 return '' unless $format;
277
278 foreach my $key ( keys %params ) {
279 my $val = $params{$key};
280 $val = '' unless defined $val;
281 $format =~ s/\$$key\b/$val/g;
282 }
283 $format = Foswiki::Func::decodeFormatTokens($format);
284
285 return $format;
286}
287
288=begin TML
289
290---++ ObjectMethod getIconUrlPath ( $iconName ) -> $pubUrlPath
291
292Returns the path to the named icon searching along a given icon search path.
293This path can be in =$Foswiki::cfg{JQueryPlugin}{IconSearchPath}= or will fall
294back to =FamFamFamSilkIcons=, =FamFamFamSilkCompanion1Icons=,
295=FamFamFamFlagIcons=, =FamFamFamMiniIcons=, =FamFamFamMintIcons= As you see
296installing Foswiki:Extensions/FamFamFamContrib would be nice to have.
297
298 = =$iconName=: name of icon; you will have to know the icon name by heart as listed in your
299 favorite icon set, meaning there's no mapping between something like "semantic" and "physical" icons
300 = =$pubUrlPath=: the path to the icon as it is attached somewhere in your wiki or the empty
301 string if the icon was not found
302
303=cut
304
305sub getIconUrlPath {
306 my ($iconName) = @_;
307
308 return '' unless $iconName;
309
310 unless (@iconSearchPath) {
311 my $iconSearchPath = $Foswiki::cfg{JQueryPlugin}{IconSearchPath}
312 || 'FamFamFamSilkIcons, FamFamFamSilkCompanion1Icons, FamFamFamSilkCompanion2Icons, FamFamFamSilkGeoSilkIcons, FamFamFamFlagIcons, FamFamFamMiniIcons, FamFamFamMintIcons';
313 @iconSearchPath = split( /\s*,\s*/, $iconSearchPath );
314 }
315
316 $iconName =~ s/^.*\.(.*?)$/$1/; # strip file extension
317
318 my $iconPath = $iconCache{$iconName};
319
320 unless ($iconPath) {
321 my $iconWeb = $Foswiki::cfg{SystemWebName};
322 my $pubSystemDir =
323 $Foswiki::cfg{PubDir} . '/' . $Foswiki::cfg{SystemWebName};
324
325 foreach my $item (@iconSearchPath) {
326 my ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName(
327 $Foswiki::cfg{SystemWebName}, $item );
328
329 # SMELL: store violation assumes the we have got file-level access
330 # better use store api
331 my $iconDir =
332 $Foswiki::cfg{PubDir} . '/'
333 . $web . '/'
334 . $topic . '/'
335 . $iconName . '.png';
336 if ( -f $iconDir ) {
337 $iconPath =
338 Foswiki::Func::getPubUrlPath() . '/'
339 . $web . '/'
340 . $topic . '/'
341 . $iconName . '.png';
342 last; # first come first serve
343 }
344 }
345
346 $iconPath ||= '';
347 $iconCache{$iconName} = $iconPath;
348 }
349
350 return $iconPath;
351}
352
353=begin TML
354
355---++ ClassMethod getPlugins () -> @plugins
356
357returns a list of all known plugins
358
359=cut
360
361sub getPlugins {
362 my ($include) = @_;
363
364 my @plugins = ();
365 foreach my $key ( sort keys %plugins ) {
366 next if $key eq 'empty'; # skip this one
367 next if $include && $key !~ /^($include)$/;
368 my $pluginDesc = $plugins{$key};
369 my $plugin = load( $pluginDesc->{name} );
370 push @plugins, $plugin if $plugin;
371 }
372
373 return @plugins;
374}
375
376=begin TML
377
378---++ ClassMethod getRandom () -> $integer
379
380returns a random positive integer between 1 and 10000.
381this can be used to
382generate html element IDs which are not
383allowed to clash within the same html page,
384even not when it got extended via ajax.
385
386=cut
387
388sub getRandom {
389 return int( rand(10000) ) + 1;
390}
391
39213µs1;
393__END__