← 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/DelayMacroPlugin.pm
StatementsExecuted 16 statements in 454µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11134µs114µsFoswiki::Plugins::DelayMacroPlugin::::initPluginFoswiki::Plugins::DelayMacroPlugin::initPlugin
11113µs27µsFoswiki::Plugins::DelayMacroPlugin::::BEGIN@18Foswiki::Plugins::DelayMacroPlugin::BEGIN@18
1114µs4µ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
18229µs241µs
# spent 27µs (13+14) within Foswiki::Plugins::DelayMacroPlugin::BEGIN@18 which was called: # once (13µs+14µs) by Foswiki::Plugin::BEGIN@2.10 at line 18
use strict;
# spent 27µs making 1 call to Foswiki::Plugins::DelayMacroPlugin::BEGIN@18 # spent 14µs making 1 call to strict::import
19
20219µs14µs
# spent 4µs within Foswiki::Plugins::DelayMacroPlugin::BEGIN@20 which was called: # once (4µs+0s) by Foswiki::Plugin::BEGIN@2.10 at line 20
use Foswiki::Func (); # The plugins API
# spent 4µs making 1 call to Foswiki::Plugins::DelayMacroPlugin::BEGIN@20
212354µ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: 6882 (2010-03-24) $ so that Foswiki can determine the checked-in status of the
26# extension.
271600nsour $VERSION = '$Rev: 6882 (2010-03-24) $';
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:
341300nsour $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=.
471200nsour $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 114µs (34+79) within Foswiki::Plugins::DelayMacroPlugin::initPlugin which was called: # once (34µs+79µs) by Foswiki::Plugin::__ANON__[/var/www/foswiki11/lib/Foswiki/Plugin.pm:241] at line 234 of /var/www/foswiki11/lib/Foswiki/Plugin.pm
sub initPlugin {
7612µs my ( $topic, $web, $user, $installWeb ) = @_;
77
78 # check for Plugins.pm versions
79130µs120µs if ( $Foswiki::Plugins::VERSION < 2.0 ) {
# spent 20µ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
8514µs134µs Foswiki::Func::registerTagHandler( 'DELAY', \&_delayMacro );
# spent 34µs making 1 call to Foswiki::Func::registerTagHandler
86
8713µs125µs Foswiki::Func::registerTagHandler( 'DELAYSEARCH', \&_delayMacro );
# spent 25µs making 1 call to Foswiki::Func::registerTagHandler
88
89 # Plugin correctly initialized
9018µ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 # $session - a reference to the Foswiki session object (if you don't know
99 # what this is, just ignore it)
100 # $params= - a reference to a Foswiki::Attrs object containing
101 # parameters.
102 # This can be used as a simple hash that maps parameter names
103 # to values, with _DEFAULT being the name for the default
104 # (unnamed) parameter.
105 # $theTopic - name of the topic in the query
106 # $theWeb - name of the web in the query
107 # Return: the result of processing the macro. This will replace the
108 # macro call in the final text.
109
110 # For example, %EXAMPLETAG{'hamburger' sideorder="onions"}%
111 # $params->{_DEFAULT} will be 'hamburger'
112 # INPUT will be 'onions'
113
114 my $delay = defined $params->{delay} ? $params->{delay} : 1;
115 $delay = 1 unless $delay =~ /\d+/;
116 my $macro = $params->{macro} || 'SEARCH';
117 my $default = defined $params->{_DEFAULT} ? $params->{_DEFAULT} : '';
118 my $result = '';
119
120 if ( $delay-- > 0 ) {
121 $result = "\$percntDELAY{";
122 $result .= "\$quot$default\$quot ";
123 $result .= "delay=\$quot$delay\$quot ";
124
125 foreach my $key ( keys %$params ) {
126 next if ($key eq '_RAW' || $key eq '_DEFAULT' || $key eq 'delay');
127
128 $result .= "$key=\$quot" . $params->{$key} . "\$quot ";
129 }
130 $result .= "}\$percnt";
131 }
132 else {
133 $result = "%" . $macro . "{";
134 $result .= "\"$default\" ";
135
136 foreach my $key ( keys %$params ) {
137 next if ($key eq '_RAW' || $key eq '_DEFAULT' ||
138 $key eq 'macro' || $key eq 'delay' );
139
140 $result .= $key . "=\"" . $params->{$key} . "\" ";
141 }
142
143 $result .= "}%";
144 }
145
146 return $result;
147
148}
149
150
15113µs1;
152__END__