← 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/TablePlugin.pm
StatementsExecuted 335 statements in 1.93ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
5118.20ms11.6msFoswiki::Plugins::TablePlugin::::preRenderingHandlerFoswiki::Plugins::TablePlugin::preRenderingHandler
10011445µs576µsFoswiki::Plugins::TablePlugin::::afterCommonTagsHandlerFoswiki::Plugins::TablePlugin::afterCommonTagsHandler
10011131µs131µsFoswiki::Plugins::TablePlugin::::_writeStyleToHeadFoswiki::Plugins::TablePlugin::_writeStyleToHead
226260µs60µsFoswiki::Plugins::TablePlugin::::debugFoswiki::Plugins::TablePlugin::debug
11138µs582µsFoswiki::Plugins::TablePlugin::::_readPluginSettingsFoswiki::Plugins::TablePlugin::_readPluginSettings
11128µs50µsFoswiki::Plugins::TablePlugin::::initPluginFoswiki::Plugins::TablePlugin::initPlugin
11113µs27µsFoswiki::Plugins::TablePlugin::::BEGIN@8Foswiki::Plugins::TablePlugin::BEGIN@8
11110µs15µsFoswiki::Plugins::TablePlugin::::BEGIN@9Foswiki::Plugins::TablePlugin::BEGIN@9
1119µs20µsFoswiki::Plugins::TablePlugin::::BEGIN@15Foswiki::Plugins::TablePlugin::BEGIN@15
1119µs20µsFoswiki::Plugins::TablePlugin::::BEGIN@17Foswiki::Plugins::TablePlugin::BEGIN@17
1118µs17µsFoswiki::Plugins::TablePlugin::::BEGIN@12Foswiki::Plugins::TablePlugin::BEGIN@12
2117µs7µsFoswiki::Plugins::TablePlugin::::debugDataFoswiki::Plugins::TablePlugin::debugData
1114µs4µsFoswiki::Plugins::TablePlugin::::BEGIN@10Foswiki::Plugins::TablePlugin::BEGIN@10
0000s0sFoswiki::Plugins::TablePlugin::::addHeadStylesFoswiki::Plugins::TablePlugin::addHeadStyles
0000s0sFoswiki::Plugins::TablePlugin::::initialiseWhenRenderFoswiki::Plugins::TablePlugin::initialiseWhenRender
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
2#
3# Allow sorting of tables, plus setting of background colour for
4# headings and data cells. See %SYSTEMWEB%.TablePlugin for details of use
5
6package Foswiki::Plugins::TablePlugin;
7
8284µs241µs
# spent 27µs (13+14) within Foswiki::Plugins::TablePlugin::BEGIN@8 which was called: # once (13µs+14µs) by Foswiki::Plugin::BEGIN@2.37 at line 8
use strict;
# spent 27µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@8 # spent 14µs making 1 call to strict::import
9225µs220µs
# spent 15µs (10+5) within Foswiki::Plugins::TablePlugin::BEGIN@9 which was called: # once (10µs+5µs) by Foswiki::Plugin::BEGIN@2.37 at line 9
use warnings;
# spent 15µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@9 # spent 5µs making 1 call to warnings::import
10238µs14µs
# spent 4µs within Foswiki::Plugins::TablePlugin::BEGIN@10 which was called: # once (4µs+0s) by Foswiki::Plugin::BEGIN@2.37 at line 10
use Foswiki::Request ();
# spent 4µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@10
11
12
# spent 17µs (8+10) within Foswiki::Plugins::TablePlugin::BEGIN@12 which was called: # once (8µs+10µs) by Foswiki::Plugin::BEGIN@2.37 at line 19
BEGIN {
13 # Backwards compatibility for Foswiki 1.1.x
1415µs110µs unless ( Foswiki::Request->can('multi_param') ) {
# spent 10µs making 1 call to CGI::can
15238µs230µs
# spent 20µs (9+10) within Foswiki::Plugins::TablePlugin::BEGIN@15 which was called: # once (9µs+10µs) by Foswiki::Plugin::BEGIN@2.37 at line 15
no warnings 'redefine';
# spent 20µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@15 # spent 10µs making 1 call to warnings::unimport
16 *Foswiki::Request::multi_param = \&Foswiki::Request::param;
17224µs232µs
# spent 20µs (9+12) within Foswiki::Plugins::TablePlugin::BEGIN@17 which was called: # once (9µs+12µs) by Foswiki::Plugin::BEGIN@2.37 at line 17
use warnings 'redefine';
# spent 20µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@17 # spent 12µs making 1 call to warnings::import
18 }
191886µs117µs}
# spent 17µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@12
20
21# Simple decimal version, use parse method, no leading "v"
221600nsour $VERSION = '1.142';
231100nsour $RELEASE = '1.142';
241400nsour $SHORTDESCRIPTION =
25 'Control attributes of tables and sorting of table columns';
261200nsour $NO_PREFS_IN_TOPIC = 1;
271300nsour %pluginAttributes;
28
291100nsour $DEBUG_FROM_UNIT_TEST = 0;
3010sour $topic;
3110sour $web;
321100nsour $user;
331100nsour $installWeb;
3410sour $initialised;
351500nsmy $DEFAULT_TABLE_SETTINGS =
36'tableborder="1" valign="top" headercolor="#000000" headerbg="#d6d3cf" headerbgsorted="#c4c1ba" databg="#ffffff,#edf4f9" databgsorted="#f1f7fc,#ddebf6" tablerules="rows" headerrules="cols"';
371600nsmy $styles = {}; # hash to keep track of web->topic
381100nsmy $readyForHandler;
391100nsour $writtenToHead = 0;
40
41
# spent 50µs (28+21) within Foswiki::Plugins::TablePlugin::initPlugin which was called: # once (28µs+21µ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 {
4212µs ( $topic, $web, $user, $installWeb ) = @_;
43
4414µs15µs debug( 'TablePlugin', "initPlugin:$web.$topic" );
# spent 5µs making 1 call to Foswiki::Plugins::TablePlugin::debug
45
46 # check for Plugins.pm versions
47114µs18µs if ( $Foswiki::Plugins::VERSION < 1.026 ) {
# spent 8µs making 1 call to version::vxs::VCMP
48 Foswiki::Func::writeWarning(
49 'Version mismatch between TablePlugin and Plugins.pm');
50 return 0;
51 }
52
5312µs16µs my $cgi = Foswiki::Func::getCgiQuery();
# spent 6µs making 1 call to Foswiki::Func::getCgiQuery
541600ns return 0 unless $cgi;
55
561600ns $initialised = 0;
571200ns $readyForHandler = 0;
581400ns $writtenToHead = 0;
591900ns %pluginAttributes = ();
60
6111µs12µs debug( 'TablePlugin', "inited" );
# spent 2µs making 1 call to Foswiki::Plugins::TablePlugin::debug
62
6314µs return 1;
64}
65
66
# spent 11.6ms (8.20+3.36) within Foswiki::Plugins::TablePlugin::preRenderingHandler which was called 5 times, avg 2.31ms/call: # 5 times (8.20ms+3.36ms) by Foswiki::Plugin::invoke at line 310 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm, avg 2.31ms/call
sub preRenderingHandler {
67 ### my ( $text, $removed ) = @_;
68510µs524µs debug( 'TablePlugin', 'preRenderingHandler' );
# spent 24µs making 5 calls to Foswiki::Plugins::TablePlugin::debug, avg 5µs/call
69514µs5132µs my $sort = Foswiki::Func::getPreferencesValue('TABLEPLUGIN_SORT')
# spent 132µs making 5 calls to Foswiki::Func::getPreferencesValue, avg 26µs/call
70 || 'all';
71 return
72514µs unless ( $sort && $sort =~ m/^(all|attachments)$/ )
73 || $_[0] =~ m/%TABLE\{.*?\}%/;
74
75514µs1582µs _readPluginSettings() if !%pluginAttributes;
# spent 582µs making 1 call to Foswiki::Plugins::TablePlugin::_readPluginSettings
76
77 # on-demand inclusion
78575µs require Foswiki::Plugins::TablePlugin::Core;
7952µs if ( !$readyForHandler ) {
8012µs1821µs Foswiki::Plugins::TablePlugin::Core::_init();
# spent 821µs making 1 call to Foswiki::Plugins::TablePlugin::Core::_init
811700ns $readyForHandler = 1;
82 }
83525µs51.54ms Foswiki::Plugins::TablePlugin::Core::handler(@_);
# spent 1.54ms making 5 calls to Foswiki::Plugins::TablePlugin::Core::handler, avg 308µs/call
84}
85
86=begin TML
87---++ StaticMethod initialiseWhenRender() -> 1
88
89Official API call for TablePlugin. Other plugins can reinitialise the plugin
90which will reset all table counters etc next time the preRenderingHandler
91is run. The preRenderingHandler is called again when a plugin uses the
92Foswiki::Func::renderText method.
93A plugin like !CompareRevisionsAddOn uses initialiseWhenRender between the
94rendering of two revisions of the same topic to avoid table numbers to
95continue counting up when rendering the topic the second time.
96
97Example of use in a plugin taking care to check for TablePlugin being
98installed and being of a version that contains this method.
99Otherwise using a "mother of hacks" to get to the same result.
100
101 if ( defined &Foswiki::Plugins::TablePlugin::initPlugin ) {
102 if ( defined &Foswiki::Plugins::TablePlugin::initialiseWhenRender ) {
103 Foswiki::Plugins::TablePlugin::initialiseWhenRender();
104 }
105 else {
106 # If TablePlugin does not have the reinitialise API
107 # we use try a shameless hack instead
108 if ( defined $Foswiki::Plugins::TablePlugin::initialised ) {
109 $Foswiki::Plugins::TablePlugin::initialised = 0;
110 }
111 }
112 }
113
114=cut
115
116sub initialiseWhenRender {
117
118 $initialised = 0;
119
120 return 1;
121}
122
123=pod
124
125Read in plugin settings from TABLEPLUGIN_TABLEATTRIBUTES
126TABLEATTRIBUTES are no longer supported (NO_PREFS_IN_TOPIC).
127If no settings are found, use the default settings from configure.
128And if these cannot be read, use the default values defined here in this plugin.
129
130Settings are applied by the principle of 'filling in the gaps'
131=cut
132
133
# spent 582µs (38+544) within Foswiki::Plugins::TablePlugin::_readPluginSettings which was called: # once (38µs+544µs) by Foswiki::Plugins::TablePlugin::preRenderingHandler at line 75
sub _readPluginSettings {
13411µs12µs debug( 'TablePlugin', '_readPluginSettings' );
# spent 2µs making 1 call to Foswiki::Plugins::TablePlugin::debug
13512µs my $configureAttrStr =
136 $Foswiki::cfg{Plugins}{TablePlugin}{DefaultAttributes};
13711µs120µs my $pluginAttrStr =
# spent 20µs making 1 call to Foswiki::Func::getPreferencesValue
138 Foswiki::Func::getPreferencesValue('TABLEPLUGIN_TABLEATTRIBUTES');
139
14012µs12µs debug( 'TablePlugin', "\t configureAttrStr=$configureAttrStr" )
# spent 2µs making 1 call to Foswiki::Plugins::TablePlugin::debug
141 if defined $configureAttrStr;
1421400ns debug( 'TablePlugin', "\t pluginAttrStr=$pluginAttrStr" )
143 if defined $pluginAttrStr;
1441600ns debug( 'TablePlugin',
145 "\t no settings from configure could be read; using default values" )
146 unless defined $configureAttrStr;
147
1481200ns $configureAttrStr = $DEFAULT_TABLE_SETTINGS
149 unless defined $configureAttrStr;
150
15112µs1448µs $configureAttrStr = Foswiki::Func::expandCommonVariables( $configureAttrStr,
# spent 448µs making 1 call to Foswiki::Func::expandCommonVariables
152 $topic, $web, undef )
153 if defined $configureAttrStr;
154
1551700ns $pluginAttrStr = Foswiki::Func::expandCommonVariables( $pluginAttrStr,
156 $topic, $web, undef )
157 if defined $pluginAttrStr;
158
15917µs162µs my %configureParams = Foswiki::Func::extractParameters($configureAttrStr);
# spent 62µs making 1 call to Foswiki::Func::extractParameters
16013µs19µs my %pluginParams = Foswiki::Func::extractParameters($pluginAttrStr);
# spent 9µs making 1 call to Foswiki::Func::extractParameters
161
16219µs %pluginAttributes = ( %configureParams, %pluginParams );
163}
164
165
# spent 576µs (445+131) within Foswiki::Plugins::TablePlugin::afterCommonTagsHandler which was called 100 times, avg 6µs/call: # 100 times (445µs+131µs) by Foswiki::Plugin::invoke at line 310 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm, avg 6µs/call
sub afterCommonTagsHandler {
166
167 #debug( '', 'afterCommonTagsHandler' );
168100237µs100131µs _writeStyleToHead();
# spent 131µs making 100 calls to Foswiki::Plugins::TablePlugin::_writeStyleToHead, avg 1µs/call
169}
170
171=pod
172
173addHeadStyles( $id, \@styles )
174
175Store list of CSS lines to be written.
176
177=cut
178
179sub addHeadStyles {
180 my ( $inId, $inStyles ) = @_;
181
182 $styles->{$web}->{$topic}->{$inId} = $inStyles;
183}
184
185
# spent 131µs within Foswiki::Plugins::TablePlugin::_writeStyleToHead which was called 100 times, avg 1µs/call: # 100 times (131µs+0s) by Foswiki::Plugins::TablePlugin::afterCommonTagsHandler at line 168, avg 1µs/call
sub _writeStyleToHead {
186
187100253µs return if !$styles->{$web}->{$topic};
188
189 my @allStyles = ();
190 foreach my $id ( sort keys %{ $styles->{$web}->{$topic} } ) {
191 push @allStyles, @{ $styles->{$web}->{$topic}->{$id} };
192 }
193 my $styleText = join( "\n", @allStyles );
194 debug( 'TablePlugin', "_writeStyleToHead; styleText=$styleText" );
195
196 my $header = <<EOS;
197<style type="text/css" media="all">
198$styleText
199</style>
200EOS
201 Foswiki::Func::addToZone( "head", "TABLEPLUGIN_${web}_${topic}", $header );
202}
203
204=pod
205
206Shorthand debugging call.
207
208=cut
209
210
# spent 60µs within Foswiki::Plugins::TablePlugin::debug which was called 22 times, avg 3µs/call: # 13 times (26µs+0s) by Foswiki::Plugins::TablePlugin::Core::_debug at line 2026 of /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin/Core.pm, avg 2µs/call # 5 times (24µs+0s) by Foswiki::Plugins::TablePlugin::preRenderingHandler at line 68, avg 5µs/call # once (5µs+0s) by Foswiki::Plugins::TablePlugin::initPlugin at line 44 # once (2µs+0s) by Foswiki::Plugins::TablePlugin::_readPluginSettings at line 140 # once (2µs+0s) by Foswiki::Plugins::TablePlugin::_readPluginSettings at line 134 # once (2µs+0s) by Foswiki::Plugins::TablePlugin::initPlugin at line 61
sub debug {
2112220µs my ( $origin, $text ) = @_;
2122281µs return if !$Foswiki::cfg{Plugins}{TablePlugin}{Debug};
213 return if !$text;
214
215 $origin ||= 'TablePlugin';
216 $text = "$origin: $text";
217
218 print STDERR $text . "\n" if $DEBUG_FROM_UNIT_TEST;
219 Foswiki::Func::writeDebug("$text");
220}
221
222
# spent 7µs within Foswiki::Plugins::TablePlugin::debugData which was called 2 times, avg 3µs/call: # 2 times (7µs+0s) by Foswiki::Plugins::TablePlugin::Core::_debugData at line 2030 of /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin/Core.pm, avg 3µs/call
sub debugData {
22322µs my ( $origin, $text, $data ) = @_;
224
22528µs return if !$Foswiki::cfg{Plugins}{TablePlugin}{Debug};
226 $origin ||= 'TablePlugin';
227 Foswiki::Func::writeDebug("$origin: $text:");
228 print STDERR "$origin: $text:" . "\n" if $DEBUG_FROM_UNIT_TEST;
229 if ($data) {
230 eval
231'use Data::Dumper; local $Data::Dumper::Terse = 1; local $Data::Dumper::Indent = 1; Foswiki::Func::writeDebug(Dumper($data));';
232 print STDERR Dumper($data) . "\n" if $DEBUG_FROM_UNIT_TEST;
233 }
234}
235
23615µs1;
237__END__