← 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/Plugins/JQueryPlugin/Plugins.pm
StatementsExecuted 822 statements in 3.03ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1411589µs4.37msFoswiki::Plugins::JQueryPlugin::Plugins::::loadFoswiki::Plugins::JQueryPlugin::Plugins::load
6422450µs504µsFoswiki::Plugins::JQueryPlugin::Plugins::::registerPluginFoswiki::Plugins::JQueryPlugin::Plugins::registerPlugin
111296µs2.63msFoswiki::Plugins::JQueryPlugin::Plugins::::initFoswiki::Plugins::JQueryPlugin::Plugins::init
911204µs425µsFoswiki::Plugins::JQueryPlugin::Plugins::::getIconUrlPathFoswiki::Plugins::JQueryPlugin::Plugins::getIconUrlPath
111157µs157µsFoswiki::Plugins::JQueryPlugin::Plugins::::finishFoswiki::Plugins::JQueryPlugin::Plugins::finish
1443141µs5.68msFoswiki::Plugins::JQueryPlugin::Plugins::::createPluginFoswiki::Plugins::JQueryPlugin::Plugins::createPlugin (recurses: max depth 2, inclusive time 2.85ms)
61123µs23µsFoswiki::Plugins::JQueryPlugin::Plugins::::registerThemeFoswiki::Plugins::JQueryPlugin::Plugins::registerTheme
11115µs27µsFoswiki::Plugins::JQueryPlugin::Plugins::::BEGIN@4Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@4
11112µs37µsFoswiki::Plugins::JQueryPlugin::Plugins::::createThemeFoswiki::Plugins::JQueryPlugin::Plugins::createTheme
1119µs13µsFoswiki::Plugins::JQueryPlugin::Plugins::::BEGIN@5Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@5
1114µs4µsFoswiki::Plugins::JQueryPlugin::Plugins::::BEGIN@6Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@6
0000s0sFoswiki::Plugins::JQueryPlugin::Plugins::::expandVariablesFoswiki::Plugins::JQueryPlugin::Plugins::expandVariables
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µs239µs
# spent 27µs (15+12) within Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@4 which was called: # once (15µs+12µs) by Foswiki::Plugins::JEditableContribPlugin::BEGIN@6 at line 4
use strict;
# spent 27µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@4 # spent 12µs making 1 call to strict::import
5223µs217µs
# spent 13µs (9+4) within Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@5 which was called: # once (9µs+4µs) by Foswiki::Plugins::JEditableContribPlugin::BEGIN@6 at line 5
use warnings;
# spent 13µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@5 # spent 4µs making 1 call to warnings::import
621.25ms14µs
# spent 4µs within Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@6 which was called: # once (4µs+0s) by Foswiki::Plugins::JEditableContribPlugin::BEGIN@6 at line 6
use Foswiki::Func();
# spent 4µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@6
7
81300nsmy @iconSearchPath;
91200nsmy %iconCache;
101100nsmy %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 2.63ms (296µs+2.33) within Foswiki::Plugins::JQueryPlugin::Plugins::init which was called: # once (296µs+2.33ms) by Foswiki::Plugins::JQueryPlugin::initPlugin at line 68 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin.pm
sub init {
32
3312µs $debug = $Foswiki::cfg{JQueryPlugin}{Debug} || 0;
34
35 # get all plugins
36133µs foreach
37 my $pluginName ( sort keys %{ $Foswiki::cfg{JQueryPlugin}{Plugins} } )
38 {
3968122µs58445µs registerPlugin($pluginName)
# spent 445µs making 58 calls to Foswiki::Plugins::JQueryPlugin::Plugins::registerPlugin, avg 8µs/call
40 if $Foswiki::cfg{JQueryPlugin}{Plugins}{$pluginName}{Enabled};
41 }
42
43 # get all themes
4416µs foreach my $themeName ( sort keys %{ $Foswiki::cfg{JQueryPlugin}{Themes} } )
45 {
46613µs623µs registerTheme($themeName)
# spent 23µs making 6 calls to Foswiki::Plugins::JQueryPlugin::Plugins::registerTheme, avg 4µs/call
47 if $Foswiki::cfg{JQueryPlugin}{Themes}{$themeName}{Enabled};
48 }
491800ns $currentTheme = $Foswiki::cfg{JQueryPlugin}{JQueryTheme};
50
51 # load jquery
521600ns my $jQuery = $Foswiki::cfg{JQueryPlugin}{JQueryVersion}
53 || "jquery-2.1.0";
54
55 # test for the jquery library to be present
56118µs unless ( -e $Foswiki::cfg{PubDir} . '/'
57 . $Foswiki::cfg{SystemWebName}
58 . '/JQueryPlugin/'
59 . $jQuery
60 . '.js' )
61 {
62 Foswiki::Func::writeWarning(
63"CAUTION: jQuery $jQuery not found. please fix the {JQueryPlugin}{JQueryVersion} settings."
64 );
65 $jQuery = "jquery-2.1.3";
66 }
67
681300ns $jQuery .= ".uncompressed" if $debug;
69
7011µs my $jQueryIE = $Foswiki::cfg{JQueryPlugin}{JQueryVersionForOldIEs};
711300ns $jQueryIE = "jquery-1.11.2" unless defined $jQueryIE;
72
731400ns my $code;
741700ns if ($jQueryIE) {
75
76 # test for the jquery library to be present
7716µs unless ( -e $Foswiki::cfg{PubDir} . '/'
78 . $Foswiki::cfg{SystemWebName}
79 . '/JQueryPlugin/'
80 . $jQueryIE
81 . '.js' )
82 {
83 Foswiki::Func::writeWarning(
84"CAUTION: jQuery $jQueryIE not found. please fix the {JQueryPlugin}{JQueryVersionForOldIEs} settings."
85 );
86 $jQuery = "jquery-1.11.2";
87 }
88
891300ns $jQueryIE .= ".uncompressed" if $debug;
90
9112µs $code = <<"HERE";
92<literal><!--[if lte IE 9]>
93<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/$jQueryIE.js'></script>
94<![endif]-->
95<!--[if gt IE 9]><!-->
96<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/$jQuery.js'></script>
97<!--<![endif]-->
98</literal>
99HERE
100 }
101 else {
102 $code = <<"HERE";
103<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/$jQuery.js'></script>
104HERE
105 }
106
107 # switch on noconflict mode
10811µs if ( $Foswiki::cfg{JQueryPlugin}{NoConflict} ) {
109 my $noConflict = 'noconflict';
110 $noConflict .= ".uncompressed" if $debug;
111
112 $code .= <<"HERE";
113<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/$noConflict.js'></script>
114HERE
115 }
116
11712µs133µs Foswiki::Func::addToZone( 'script', 'JQUERYPLUGIN', $code );
# spent 33µs making 1 call to Foswiki::Func::addToZone
118
119 # initial plugins
12011µs11.41ms createPlugin('Foswiki'); # this one is needed anyway
121
12212µs my $defaultPlugins = $Foswiki::cfg{JQueryPlugin}{DefaultPlugins};
1231300ns if ($defaultPlugins) {
124 foreach my $pluginName ( split( /\s*,\s*/, $defaultPlugins ) ) {
125 createPlugin($pluginName);
126 }
127 }
128
129 # enable migrate for jQuery > 1.9.x as long as we still have 3rd party plugins
130 # making use of deprecated and removed features
13114µs unless ( $defaultPlugins && $defaultPlugins =~ /\bmigrate\b/i ) {
13213µs if ( $jQuery =~ /^jquery-(\d+)\.(\d+)\.(\d+)/ ) {
13314µs my $jqVersion = $1 * 10000 + $2 * 100 + $3;
13412µs1421µs if ( $jqVersion > 10900 ) {
135 createPlugin("Migrate");
136 }
137 }
138 }
139}
140
141=begin TML
142
143---++ ObjectMethod createPlugin( $pluginName, ... ) -> $plugin
144
145Helper method to establish plugin dependencies. See =load()=.
146
147=cut
148
149
# spent 5.68ms (141µs+5.54) within Foswiki::Plugins::JQueryPlugin::Plugins::createPlugin which was called 14 times, avg 406µs/call: # 6 times (66µs+3.79ms) by Foswiki::Plugins::JQueryPlugin::createPlugin at line 109 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin.pm, avg 642µs/call # 6 times (51µs+-51µs) by Foswiki::Plugins::JQueryPlugin::Plugin::init at line 124 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin/Plugin.pm, avg 0s/call # once (10µs+1.40ms) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 120 # once (14µs+407µs) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 134
sub createPlugin {
1501422µs144.37ms my $plugin = load(@_);
# spent 4.37ms making 14 calls to Foswiki::Plugins::JQueryPlugin::Plugins::load, avg 312µs/call
1511464µs143.80ms $plugin->init() if $plugin;
# spent 2.23ms making 11 calls to Foswiki::Plugins::JQueryPlugin::Plugin::init, avg 202µs/call, recursion: max depth 2, sum of overlapping time 226µs # spent 1.03ms making 1 call to Foswiki::Plugins::JQueryPlugin::UI::init # spent 771µs making 2 calls to Foswiki::Plugins::JQueryPlugin::FOSWIKI::init, avg 385µs/call
1521435µs return $plugin;
153}
154
155=begin TML
156
157---++ ObjectMethd createTheme ($themeName, $url) -> $boolean
158
159Helper method to switch on a theme. Returns true
160if =$themeName= has been loaded successfully. Note that a previously
161loaded theme will be replaced with the new one as there can only
162be one theme per html page. The $url parameter optionally specifies
163from where to load the theme. It defaults to the url registered
164in =configure= for the named theme.
165
166=cut
167
168
# spent 37µs (12+25) within Foswiki::Plugins::JQueryPlugin::Plugins::createTheme which was called: # once (12µs+25µs) by Foswiki::Plugins::JQueryPlugin::createTheme at line 122 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin.pm
sub createTheme {
1691900ns my ( $themeName, $url ) = @_;
170
1711800ns $themeName ||= $currentTheme;
1721200ns return 0 unless $themeName;
173
1741700ns my $normalizedName = lc($themeName);
175
1761600ns unless ($url) {
17711µs my $themeDesc = $themes{$normalizedName};
1781100ns return 0 unless defined $themeDesc;
17911µs $url = $themeDesc->{url};
180 }
181
182 # remember last choice
1831200ns $currentTheme = $themeName;
184
18512µs125µs Foswiki::Func::addToZone( "head", "JQUERYPLUGIN::THEME",
# spent 25µs making 1 call to Foswiki::Func::addToZone
186 <<HERE, "JQUERYPLUGIN::FOSWIKI, JQUERYPLUGIN::UI" );
187<link rel="stylesheet" href="$url" type="text/css" media="all" />
188HERE
189
19013µs return 1;
191}
192
193=begin TML
194
195---++ ObjectMethod registerPlugin( $pluginName, $class ) -> $descriptor
196
197Helper method to register a plugin.
198
199=cut
200
201
# spent 504µs (450+55) within Foswiki::Plugins::JQueryPlugin::Plugins::registerPlugin which was called 64 times, avg 8µs/call: # 58 times (398µs+47µs) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 39, avg 8µs/call # 6 times (52µs+7µs) by Foswiki::Plugins::JQueryPlugin::registerPlugin at line 140 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin.pm, avg 10µs/call
sub registerPlugin {
2026427µs my ( $pluginName, $class ) = @_;
203
2046446µs $class ||= $Foswiki::cfg{JQueryPlugin}{Plugins}{$pluginName}{Module}
205 || 'Foswiki::Plugins::JQueryPlugin::' . uc($pluginName);
206
2076418µs my $contextID = $pluginName . 'Registered';
2086433µs $contextID =~ s/\W//g;
2096493µs6455µs Foswiki::Func::getContext()->{$contextID} = 1;
# spent 55µs making 64 calls to Foswiki::Func::getContext, avg 855ns/call
210
21164226µs return $plugins{ lc($pluginName) } = {
212 'class' => $class,
213 'name' => $pluginName,
214 'instance' => undef,
215 };
216}
217
218=begin TML
219
220---++ ObjectMethod registerTheme( $themeName, $url ) -> $descriptor
221
222Helper method to register a theme.
223
224=cut
225
226
# spent 23µs within Foswiki::Plugins::JQueryPlugin::Plugins::registerTheme which was called 6 times, avg 4µs/call: # 6 times (23µs+0s) by Foswiki::Plugins::JQueryPlugin::Plugins::init at line 46, avg 4µs/call
sub registerTheme {
22763µs my ( $themeName, $url ) = @_;
228
22962µs my $normalizedName = lc($themeName);
230
23165µs $url ||= $Foswiki::cfg{JQueryPlugin}{Themes}{$themeName}{Url}
232 || '%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/themes/'
233 . $normalizedName
234 . '/jquery-ui.css';
235
236620µs return $themes{$normalizedName} = {
237 'url' => $url,
238 'name' => $themeName,
239 };
240}
241
242=begin TML
243
244finalizer
245
246=cut
247
248
# spent 157µs within Foswiki::Plugins::JQueryPlugin::Plugins::finish which was called: # once (157µs+0s) by Foswiki::Plugins::JQueryPlugin::finishPlugin at line 96 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin.pm
sub finish {
249
2501145µs undef %plugins;
25116µs undef %themes;
25212µs undef @iconSearchPath;
25312µs undef %iconCache;
25417µs undef $currentTheme;
255}
256
257=begin TML
258
259---++ ObjectMethod load ( $pluginName ) -> $plugin
260
261Loads a plugin and runs its initializer.
262
263parameters
264 * =$pluginName=: name of plugin
265
266returns
267 * =$plugin=: returns the plugin object or false if instantiating
268 the plugin failed
269
270=cut
271
272
# spent 4.37ms (589µs+3.78) within Foswiki::Plugins::JQueryPlugin::Plugins::load which was called 14 times, avg 312µs/call: # 14 times (589µs+3.78ms) by Foswiki::Plugins::JQueryPlugin::Plugins::createPlugin at line 150, avg 312µs/call
sub load {
273146µs my $pluginName = shift;
274
275145µs my $normalizedName = lc($pluginName);
2761411µs my $pluginDesc = $plugins{$normalizedName};
277
278143µs return unless $pluginDesc;
279
280149µs unless ( defined $pluginDesc->{instance} ) {
281
28211412µs eval "use $pluginDesc->{class};";
# spent 94µs executing statements in string eval
# includes 238µs spent executing 1 call to 1 sub defined therein. # spent 89µs executing statements in string eval
# includes 222µs spent executing 1 call to 1 sub defined therein. # spent 88µs executing statements in string eval
# includes 478µs spent executing 1 call to 1 sub defined therein. # spent 88µs executing statements in string eval
# includes 446µs spent executing 1 call to 1 sub defined therein. # spent 87µs executing statements in string eval
# includes 209µs spent executing 1 call to 1 sub defined therein. # spent 85µs executing statements in string eval
# includes 218µs spent executing 1 call to 1 sub defined therein. # spent 85µs executing statements in string eval
# includes 214µs spent executing 1 call to 1 sub defined therein. # spent 84µs executing statements in string eval
# includes 343µs spent executing 1 call to 1 sub defined therein. # spent 83µs executing statements in string eval
# includes 206µs spent executing 1 call to 1 sub defined therein. # spent 78µs executing statements in string eval
# includes 200µs spent executing 1 call to 1 sub defined therein. # spent 20µs executing statements in string eval
# includes 15µs spent executing 1 call to 1 sub defined therein.
283
284117µs if ($@) {
285 Foswiki::Func::writeDebug(
286 "ERROR: can't load jQuery plugin $pluginName: $@");
287 $pluginDesc->{instance} = 0;
288 }
289 else {
2901147µs11508µs $pluginDesc->{instance} = $pluginDesc->{class}->new();
# spent 63µs making 1 call to Foswiki::Plugins::SubscribePlugin::JQuery::new # spent 55µs making 1 call to Foswiki::Contrib::JEditableContrib::JEDITABLE::new # spent 55µs making 1 call to Foswiki::Plugins::CommentPlugin::JQuery::new # spent 48µs making 1 call to Foswiki::Plugins::JQueryPlugin::RENDER::new # spent 45µs making 1 call to Foswiki::Plugins::JQueryPlugin::FOSWIKI::new # spent 43µs making 1 call to Foswiki::Plugins::JQueryPlugin::COOKIE::new # spent 42µs making 1 call to Foswiki::Plugins::JQueryPlugin::LIVEQUERY::new # spent 41µs making 1 call to Foswiki::Plugins::JQueryPlugin::UI::new # spent 40µs making 1 call to Foswiki::Plugins::JQueryPlugin::METADATA::new # spent 39µs making 1 call to Foswiki::Plugins::JQueryPlugin::MIGRATE::new # spent 39µs making 1 call to Foswiki::Plugins::JQueryPlugin::EASING::new
291 }
292 }
293
2941441µs return $pluginDesc->{instance};
295}
296
297=begin TML
298
299---++ ObjectMethod expandVariables( $format, %params) -> $string
300
301Helper function to expand standard escape sequences =$percnt=, =$nop=,
302=$n= and =$dollar=.
303
304 * =$format=: format string to be expaneded
305 * =%params=: optional hash array containing further key-value pairs to be
306 expanded as well, that is all occurences of =$key= will
307 be replaced by its =value= as defined in %params
308 * =$string=: returns the resulting text
309
310=cut
311
312sub expandVariables {
313 my ( $format, %params ) = @_;
314
315 return '' unless $format;
316
317 foreach my $key ( keys %params ) {
318 my $val = $params{$key};
319 $val = '' unless defined $val;
320 $format =~ s/\$$key\b/$val/g;
321 }
322 $format = Foswiki::Func::decodeFormatTokens($format);
323
324 return $format;
325}
326
327=begin TML
328
329---++ ObjectMethod getIconUrlPath ( $iconName ) -> $pubUrlPath
330
331Returns the path to the named icon searching along a given icon search path.
332This path can be in =$Foswiki::cfg{JQueryPlugin}{IconSearchPath}= or will fall
333back to =FamFamFamSilkIcons=, =FamFamFamSilkCompanion1Icons=,
334=FamFamFamFlagIcons=, =FamFamFamMiniIcons=, =FamFamFamMintIcons= As you see
335installing Foswiki:Extensions/FamFamFamContrib would be nice to have.
336
337 = =$iconName=: name of icon; you will have to know the icon name by heart as listed in your
338 favorite icon set, meaning there's no mapping between something like "semantic" and "physical" icons
339 = =$pubUrlPath=: the path to the icon as it is attached somewhere in your wiki or the empty
340 string if the icon was not found
341
342=cut
343
344
# spent 425µs (204+221) within Foswiki::Plugins::JQueryPlugin::Plugins::getIconUrlPath which was called 9 times, avg 47µs/call: # 9 times (204µs+221µs) by Foswiki::Plugins::JQueryPlugin::handleJQueryIcon at line 379 of /var/www/foswikidev/core/lib/Foswiki/Plugins/JQueryPlugin.pm, avg 47µs/call
sub getIconUrlPath {
34594µs my ($iconName) = @_;
346
34791µs return '' unless $iconName;
348
34994µs unless (@iconSearchPath) {
35012µs my $iconSearchPath = $Foswiki::cfg{JQueryPlugin}{IconSearchPath}
351 || 'FamFamFamSilkIcons, FamFamFamSilkCompanion1Icons, FamFamFamSilkCompanion2Icons, FamFamFamSilkGeoSilkIcons, FamFamFamFlagIcons, FamFamFamMiniIcons, FamFamFamMintIcons';
352110µs @iconSearchPath = split( /\s*,\s*/, $iconSearchPath );
353 }
354
35598µs $iconName =~ s/^.*\.(.*?)$/$1/; # strip file extension
356
35795µs my $iconPath = $iconCache{$iconName};
358
35993µs unless ($iconPath) {
36085µs foreach my $item (@iconSearchPath) {
361817µs874µs my ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName(
# spent 74µs making 8 calls to Foswiki::Func::normalizeWebTopicName, avg 9µs/call
362 $Foswiki::cfg{SystemWebName}, $item );
363
364 # SMELL: store violation assumes the we have got file-level access
365 # better use store api
366817µs my $iconDir =
367 $Foswiki::cfg{PubDir} . '/'
368 . $web . '/'
369 . $topic . '/'
370 . $iconName . '.png';
371859µs if ( -f $iconDir ) {
372823µs8146µs $iconPath =
# spent 146µs making 8 calls to Foswiki::Func::getPubUrlPath, avg 18µs/call
373 Foswiki::Func::getPubUrlPath() . '/'
374 . $web . '/'
375 . $topic . '/'
376 . $iconName . '.png';
37786µs last; # first come first serve
378 }
379 }
380
38181µs $iconPath ||= '';
382813µs $iconCache{$iconName} = $iconPath;
383 }
384
385922µs return $iconPath;
386}
387
388=begin TML
389
390---++ ClassMethod getPlugins () -> @plugins
391
392returns a list of all known plugins
393
394=cut
395
396sub getPlugins {
397 my ($include) = @_;
398
399 my @plugins = ();
400 foreach my $key ( sort keys %plugins ) {
401 next if $key eq 'empty';
402 next if $include && $key !~ /^($include)$/;
403 my $pluginDesc = $plugins{$key};
404 my $plugin = load( $pluginDesc->{name} );
405 push @plugins, $plugin if $plugin;
406 }
407
408 return @plugins;
409}
410
411=begin TML
412
413---++ ClassMethod getRandom () -> $integer
414
415returns a random positive integer between 1 and 10000.
416this can be used to
417generate html element IDs which are not
418allowed to clash within the same html page,
419even not when it got extended via ajax.
420
421=cut
422
423sub getRandom {
424 return int( rand(10000) ) + 1;
425}
426
42713µs1;
428__END__