Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/JQueryPlugin/Plugins.pm |
Statements | Executed 443 statements in 5.69ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
55 | 2 | 2 | 1.58ms | 2.68ms | registerPlugin | Foswiki::Plugins::JQueryPlugin::Plugins::
1 | 1 | 1 | 994µs | 8.27ms | init | Foswiki::Plugins::JQueryPlugin::Plugins::
9 | 1 | 1 | 528µs | 5.71ms | load | Foswiki::Plugins::JQueryPlugin::Plugins::
1 | 1 | 1 | 211µs | 211µs | finish | Foswiki::Plugins::JQueryPlugin::Plugins::
9 | 3 | 3 | 197µs | 8.06ms | createPlugin (recurses: max depth 2, inclusive time 4.31ms) | Foswiki::Plugins::JQueryPlugin::Plugins::
6 | 1 | 1 | 83µs | 83µs | registerTheme | Foswiki::Plugins::JQueryPlugin::Plugins::
2 | 2 | 1 | 54µs | 54µs | CORE:sort (opcode) | Foswiki::Plugins::JQueryPlugin::Plugins::
1 | 1 | 1 | 33µs | 99µs | createTheme | Foswiki::Plugins::JQueryPlugin::Plugins::
1 | 1 | 1 | 30µs | 37µs | BEGIN@4 | Foswiki::Plugins::JQueryPlugin::Plugins::
1 | 1 | 1 | 26µs | 26µs | BEGIN@6 | Foswiki::Plugins::JQueryPlugin::Plugins::
1 | 1 | 1 | 22µs | 39µs | BEGIN@5 | Foswiki::Plugins::JQueryPlugin::Plugins::
0 | 0 | 0 | 0s | 0s | expandVariables | Foswiki::Plugins::JQueryPlugin::Plugins::
0 | 0 | 0 | 0s | 0s | getIconUrlPath | Foswiki::Plugins::JQueryPlugin::Plugins::
0 | 0 | 0 | 0s | 0s | getPlugins | Foswiki::Plugins::JQueryPlugin::Plugins::
0 | 0 | 0 | 0s | 0s | getRandom | Foswiki::Plugins::JQueryPlugin::Plugins::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | package Foswiki::Plugins::JQueryPlugin::Plugins; | ||||
3 | |||||
4 | 2 | 47µs | 2 | 44µ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 # spent 37µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@4
# spent 7µs making 1 call to strict::import |
5 | 2 | 46µs | 2 | 57µ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 # spent 39µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@5
# spent 17µs making 1 call to warnings::import |
6 | 2 | 2.02ms | 1 | 26µ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 # spent 26µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::BEGIN@6 |
7 | |||||
8 | 1 | 2µs | our @iconSearchPath; | ||
9 | 1 | 1µs | our %iconCache; | ||
10 | 1 | 800ns | our %plugins; | ||
11 | 1 | 900ns | our %themes; | ||
12 | 1 | 1µs | our $debug; | ||
13 | |||||
14 | =begin TML | ||||
15 | |||||
16 | ---+ package Foswiki::Plugins::JQueryPlugin | ||||
17 | |||||
18 | Container for jQuery and plugins | ||||
19 | |||||
20 | =cut | ||||
21 | |||||
22 | =begin TML | ||||
23 | |||||
24 | ---++ init() | ||||
25 | |||||
26 | initialize 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 | ||||
31 | |||||
32 | 11 | 227µs | $debug = $Foswiki::cfg{JQueryPlugin}{Debug} || 0; | ||
33 | |||||
34 | # get all plugins | ||||
35 | 1 | 7µs | 1 | 48µs | foreach # spent 48µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::CORE:sort |
36 | my $pluginName ( sort keys %{ $Foswiki::cfg{JQueryPlugin}{Plugins} } ) | ||||
37 | { | ||||
38 | 58 | 593µs | 54 | 2.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 | ||||
43 | 1 | 2µs | 1 | 7µs | foreach my $themeName ( sort keys %{ $Foswiki::cfg{JQueryPlugin}{Themes} } ) # spent 7µs making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::CORE:sort |
44 | { | ||||
45 | 6 | 47µs | 6 | 83µ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 | |||||
60 | 1 | 95µs | Foswiki::Func::addToZone( 'script', 'JQUERYPLUGIN', $code ); # spent 95µs making 1 call to Foswiki::Func::addToZone | ||
61 | |||||
62 | # initial plugins | ||||
63 | 1 | 4.44ms | createPlugin('Foswiki'); # this one is needed anyway # spent 4.44ms making 1 call to Foswiki::Plugins::JQueryPlugin::Plugins::createPlugin | ||
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 | |||||
78 | Helper 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 | ||||
83 | 27 | 180µs | 9 | 5.71ms | my $plugin = load(@_); # spent 5.71ms making 9 calls to Foswiki::Plugins::JQueryPlugin::Plugins::load, avg 635µs/call |
84 | 9 | 5.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 | |||||
92 | Helper method to switch on a theme. Returns true | ||||
93 | if =$themeName= has been loaded successfully. Note that a previously | ||||
94 | loaded theme will be replaced with the new one as there can only | ||||
95 | be one theme per html page. The $url parameter optionally specifies | ||||
96 | from where to load the theme. It defaults to the url registered | ||||
97 | in =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 | ||||
102 | 7 | 25µs | my ( $themeName, $url ) = @_; | ||
103 | |||||
104 | $themeName ||= $Foswiki::cfg{JQueryPlugin}{JQueryTheme}; | ||||
105 | return 0 unless $themeName; | ||||
106 | |||||
107 | my $normalizedName = lc($themeName); | ||||
108 | |||||
109 | 3 | 6µs | unless ($url) { | ||
110 | my $themeDesc = $themes{$normalizedName}; | ||||
111 | return 0 unless defined $themeDesc; | ||||
112 | $url = $themeDesc->{url}; | ||||
113 | } | ||||
114 | |||||
115 | 1 | 66µ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" /> | ||||
118 | HERE | ||||
119 | |||||
120 | return 1; | ||||
121 | } | ||||
122 | |||||
123 | =begin TML | ||||
124 | |||||
125 | ---++ ObjectMethod registerPlugin( $pluginName, $class ) -> $descriptor | ||||
126 | |||||
127 | Helper 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 | ||||
132 | 220 | 1.66ms | my ( $pluginName, $class ) = @_; | ||
133 | |||||
134 | $class ||= $Foswiki::cfg{JQueryPlugin}{Plugins}{$pluginName}{Module} | ||||
135 | || 'Foswiki::Plugins::JQueryPlugin::' . uc($pluginName); | ||||
136 | |||||
137 | 55 | 1.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 | |||||
150 | Helper 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 | ||||
155 | 24 | 95µ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 | |||||
172 | finalizer | ||||
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 | ||||
177 | |||||
178 | 4 | 216µs | undef %plugins; | ||
179 | undef %themes; | ||||
180 | undef @iconSearchPath; | ||||
181 | undef %iconCache; | ||||
182 | } | ||||
183 | |||||
184 | =begin TML | ||||
185 | |||||
186 | ---++ ObjectMethod load ( $pluginName ) -> $plugin | ||||
187 | |||||
188 | Loads a plugin and runs its initializer. | ||||
189 | |||||
190 | parameters | ||||
191 | * =$pluginName=: name of plugin | ||||
192 | |||||
193 | returns | ||||
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 | ||||
200 | 54 | 142µs | my $pluginName = shift; | ||
201 | |||||
202 | my $normalizedName = lc($pluginName); | ||||
203 | my $pluginDesc = $plugins{$normalizedName}; | ||||
204 | |||||
205 | return undef unless $pluginDesc; | ||||
206 | |||||
207 | 10 | 329µ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 | |||||
211 | 5 | 40µs | if ($@) { | ||
212 | print STDERR "ERROR: can't load jQuery plugin $pluginName: $@\n"; | ||||
213 | $pluginDesc->{instance} = 0; | ||||
214 | } | ||||
215 | else { | ||||
216 | 5 | 519µ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 | |||||
227 | Helper 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 | |||||
238 | sub 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 | |||||
257 | Returns the path to the named icon searching along a given icon search path. | ||||
258 | This path can be in =$Foswiki::cfg{JQueryPlugin}{IconSearchPath}= or will fall | ||||
259 | back to =FamFamFamSilkIcons=, =FamFamFamSilkCompanion1Icons=, | ||||
260 | =FamFamFamFlagIcons=, =FamFamFamMiniIcons=, =FamFamFamMintIcons= As you see | ||||
261 | installing 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 | |||||
270 | sub 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 | |||||
322 | returns a list of all known plugins | ||||
323 | |||||
324 | =cut | ||||
325 | |||||
326 | sub 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 | |||||
345 | returns a random positive integer between 1 and 10000. | ||||
346 | this can be used to | ||||
347 | generate html element IDs which are not | ||||
348 | allowed to clash within the same html page, | ||||
349 | even not when it got extended via ajax. | ||||
350 | |||||
351 | =cut | ||||
352 | |||||
353 | sub getRandom { | ||||
354 | return int( rand(10000) ) + 1; | ||||
355 | } | ||||
356 | |||||
357 | 1 | 6µs | 1; | ||
358 | __END__ | ||||
sub Foswiki::Plugins::JQueryPlugin::Plugins::CORE:sort; # opcode |