← 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/DelayMacroPlugin.pm
StatementsExecuted 16 statements in 437µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11121µs61µsFoswiki::Plugins::DelayMacroPlugin::::initPluginFoswiki::Plugins::DelayMacroPlugin::initPlugin
11118µs32µsFoswiki::Plugins::DelayMacroPlugin::::BEGIN@18Foswiki::Plugins::DelayMacroPlugin::BEGIN@18
1115µs5µsFoswiki::Plugins::DelayMacroPlugin::::BEGIN@20Foswiki::Plugins::DelayMacroPlugin::BEGIN@20
1113µs3µsFoswiki::Plugins::DelayMacroPlugin::::BEGIN@21Foswiki::Plugins::DelayMacroPlugin::BEGIN@21
0000s0sFoswiki::Plugins::DelayMacroPlugin::::_delayMacroFoswiki::Plugins::DelayMacroPlugin::_delayMacro
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 default license and copyright information
2
3=begin TML
4
5---+ package DelayMacroPlugin
6
7This is a simple plugin that can delay the expansion of macros.
8You use this when you have a macro inside another macro and that supports
9tokens $percnt and $quot such as SEARCH and you want this macro to expand
10after the SEARCH is complete.
11
12=cut
13
14# change the package name!!!
15package Foswiki::Plugins::DelayMacroPlugin;
16
17# Always use strict to enforce variable scoping
18230µs245µs
# spent 32µs (18+13) within Foswiki::Plugins::DelayMacroPlugin::BEGIN@18 which was called: # once (18µs+13µs) by Foswiki::Plugin::BEGIN@2.10 at line 18
use strict;
# spent 32µs making 1 call to Foswiki::Plugins::DelayMacroPlugin::BEGIN@18 # spent 13µs making 1 call to strict::import
19
20220µs15µs
# spent 5µs within Foswiki::Plugins::DelayMacroPlugin::BEGIN@20 which was called: # once (5µs+0s) by Foswiki::Plugin::BEGIN@2.10 at line 20
use Foswiki::Func (); # The plugins API
# spent 5µs making 1 call to Foswiki::Plugins::DelayMacroPlugin::BEGIN@20
212357µs13µs
# spent 3µs within Foswiki::Plugins::DelayMacroPlugin::BEGIN@21 which was called: # once (3µs+0s) by Foswiki::Plugin::BEGIN@2.10 at line 21
use Foswiki::Plugins (); # For the API version
# spent 3µs making 1 call to Foswiki::Plugins::DelayMacroPlugin::BEGIN@21
22
23# $VERSION is referred to by Foswiki, and is the only global variable that
24# *must* exist in this package. This should always be in the format
25# $Rev: 5771 $ so that Foswiki can determine the checked-in status of the
26# extension.
271600nsour $VERSION = '$Rev: 5771 $';
28
29# $RELEASE is used in the "Find More Extensions" automation in configure.
301200nsour $RELEASE = '1.1';
31
32# Short description of this plugin
33# One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic:
341200nsour $SHORTDESCRIPTION = 'Plugin delays expansion of Foswiki macros';
35
36# You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use
37# preferences set in the plugin topic. This is required for compatibility
38# with older plugins, but imposes a significant performance penalty, and
39# is not recommended. Instead, leave $NO_PREFS_IN_TOPIC at 1 and use
40# =$Foswiki::cfg= entries, or if you want the users
41# to be able to change settings, then use standard Foswiki preferences that
42# can be defined in your %USERSWEB%.SitePreferences and overridden at the web
43# and topic level.
44#
45# %SYSTEMWEB%.DevelopingPlugins has details of how to define =$Foswiki::cfg=
46# entries so they can be used with =configure=.
471100nsour $NO_PREFS_IN_TOPIC = 1;
48
49=begin TML
50
51---++ initPlugin($topic, $web, $user) -> $boolean
52 * =$topic= - the name of the topic in the current CGI query
53 * =$web= - the name of the web in the current CGI query
54 * =$user= - the login name of the user
55 * =$installWeb= - the name of the web the plugin topic is in
56 (usually the same as =$Foswiki::cfg{SystemWebName}=)
57
58*REQUIRED*
59
60Called to initialise the plugin. If everything is OK, should return
61a non-zero value. On non-fatal failure, should write a message
62using =Foswiki::Func::writeWarning= and return 0. In this case
63%<nop>FAILEDPLUGINS% will indicate which plugins failed.
64
65In the case of a catastrophic failure that will prevent the whole
66installation from working safely, this handler may use 'die', which
67will be trapped and reported in the browser.
68
69__Note:__ Please align macro names with the Plugin name, e.g. if
70your Plugin is called !FooBarPlugin, name macros FOOBAR and/or
71FOOBARSOMETHING. This avoids namespace issues.
72
73=cut
74
75
# spent 61µs (21+39) within Foswiki::Plugins::DelayMacroPlugin::initPlugin which was called: # once (21µs+39µs) by Foswiki::Plugin::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Plugin.pm:257] at line 250 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm
sub initPlugin {
7612µs my ( $topic, $web, $user, $installWeb ) = @_;
77
78 # check for Plugins.pm versions
79115µs19µs if ( $Foswiki::Plugins::VERSION < 2.0 ) {
# spent 9µs making 1 call to version::vxs::VCMP
80 Foswiki::Func::writeWarning( 'Version mismatch between ',
81 __PACKAGE__, ' and Plugins.pm' );
82 return 0;
83 }
84
8513µs118µs Foswiki::Func::registerTagHandler( 'DELAY', \&_delayMacro );
# spent 18µs making 1 call to Foswiki::Func::registerTagHandler
86
8712µs113µs Foswiki::Func::registerTagHandler( 'DELAYSEARCH', \&_delayMacro );
# spent 13µs making 1 call to Foswiki::Func::registerTagHandler
88
89 # Plugin correctly initialized
9015µs return 1;
91}
92
93# delayMacro expands %DELAY.. and returns
94# DELAY hidden by $percnt and $quot if delay > 0
95# The macro specified by macro parameter if delay = 0
96sub _delayMacro {
97 my ( $session, $params, $theTopic, $theWeb ) = @_;
98
99 # $session - a reference to the Foswiki session object (if you don't know
100 # what this is, just ignore it)
101 # $params= - a reference to a Foswiki::Attrs object containing
102 # parameters.
103 # This can be used as a simple hash that maps parameter names
104 # to values, with _DEFAULT being the name for the default
105 # (unnamed) parameter.
106 # $theTopic - name of the topic in the query
107 # $theWeb - name of the web in the query
108 # Return: the result of processing the macro. This will replace the
109 # macro call in the final text.
110
111 # For example, %EXAMPLETAG{'hamburger' sideorder="onions"}%
112 # $params->{_DEFAULT} will be 'hamburger'
113 # INPUT will be 'onions'
114
115 my $delay = defined $params->{delay} ? $params->{delay} : 1;
116 $delay = 1 unless $delay =~ /\d+/;
117 my $macro = $params->{macro} || 'SEARCH';
118 my $default = defined $params->{_DEFAULT} ? $params->{_DEFAULT} : '';
119 my $result = '';
120
121 if ( $delay-- > 0 ) {
122 $result = "\$percntDELAY{";
123 $result .= "\$quot$default\$quot ";
124 $result .= "delay=\$quot$delay\$quot ";
125
126 foreach my $key ( keys %$params ) {
127 next if ( $key eq '_RAW' || $key eq '_DEFAULT' || $key eq 'delay' );
128
129 $result .= "$key=\$quot" . $params->{$key} . "\$quot ";
130 }
131 $result .= "}\$percnt";
132 }
133 else {
134 $result = "%" . $macro . "{";
135 $result .= "\"$default\" ";
136
137 foreach my $key ( keys %$params ) {
138 next
139 if ( $key eq '_RAW'
140 || $key eq '_DEFAULT'
141 || $key eq 'macro'
142 || $key eq 'delay' );
143
144 $result .= $key . "=\"" . $params->{$key} . "\" ";
145 }
146
147 $result .= "}%";
148 }
149
150 return $result;
151
152}
153
15413µs1;
155__END__