← 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/TablePlugin.pm
StatementsExecuted 144 statements in 1.40ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
5118.29ms12.8msFoswiki::Plugins::TablePlugin::::preRenderingHandlerFoswiki::Plugins::TablePlugin::preRenderingHandler
237272µs72µsFoswiki::Plugins::TablePlugin::::debugFoswiki::Plugins::TablePlugin::debug
11165µs1.48msFoswiki::Plugins::TablePlugin::::_readPluginSettingsFoswiki::Plugins::TablePlugin::_readPluginSettings
71162µs82µsFoswiki::Plugins::TablePlugin::::afterCommonTagsHandlerFoswiki::Plugins::TablePlugin::afterCommonTagsHandler
11137µs63µsFoswiki::Plugins::TablePlugin::::initPluginFoswiki::Plugins::TablePlugin::initPlugin
71120µs20µsFoswiki::Plugins::TablePlugin::::_writeStyleToHeadFoswiki::Plugins::TablePlugin::_writeStyleToHead
11113µs26µsFoswiki::Plugins::TablePlugin::::BEGIN@8Foswiki::Plugins::TablePlugin::BEGIN@8
11110µs15µsFoswiki::Plugins::TablePlugin::::BEGIN@9Foswiki::Plugins::TablePlugin::BEGIN@9
2118µs8µsFoswiki::Plugins::TablePlugin::::debugDataFoswiki::Plugins::TablePlugin::debugData
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
8227µs239µs
# spent 26µs (13+13) within Foswiki::Plugins::TablePlugin::BEGIN@8 which was called: # once (13µs+13µs) by Foswiki::Plugin::BEGIN@2.33 at line 8
use strict;
# spent 26µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@8 # spent 13µs making 1 call to strict::import
92898µ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.33 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
10
11# Simple decimal version, no leading "v"
121600nsour $VERSION = '1.142';
131300nsour $RELEASE = '1.142';
141400nsour $SHORTDESCRIPTION =
15 'Control attributes of tables and sorting of table columns';
161200nsour $NO_PREFS_IN_TOPIC = 1;
171200nsour %pluginAttributes;
18
191100nsour $DEBUG_FROM_UNIT_TEST = 0;
2010sour $topic;
2110sour $web;
221100nsour $user;
231100nsour $installWeb;
2410sour $initialised;
251600nsmy $DEFAULT_TABLE_SETTINGS =
26'tableborder="1" valign="top" headercolor="#000000" headerbg="#d6d3cf" headerbgsorted="#c4c1ba" databg="#ffffff,#edf4f9" databgsorted="#f1f7fc,#ddebf6" tablerules="rows" headerrules="cols"';
271500nsmy $styles = {}; # hash to keep track of web->topic
2810smy $readyForHandler;
291100nsour $writtenToHead = 0;
30
31
# spent 63µs (37+26) within Foswiki::Plugins::TablePlugin::initPlugin which was called: # once (37µs+26µ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 {
3212µs ( $topic, $web, $user, $installWeb ) = @_;
33
3415µs15µs debug( 'TablePlugin', "initPlugin:$web.$topic" );
# spent 5µs making 1 call to Foswiki::Plugins::TablePlugin::debug
35
36 # check for Plugins.pm versions
37116µs110µs if ( $Foswiki::Plugins::VERSION < 1.026 ) {
# spent 10µs making 1 call to version::vxs::VCMP
38 Foswiki::Func::writeWarning(
39 'Version mismatch between TablePlugin and Plugins.pm');
40 return 0;
41 }
42
4312µs18µs my $cgi = Foswiki::Func::getCgiQuery();
# spent 8µs making 1 call to Foswiki::Func::getCgiQuery
441400ns return 0 unless $cgi;
45
461400ns $initialised = 0;
471300ns $readyForHandler = 0;
481600ns $writtenToHead = 0;
4912µs %pluginAttributes = ();
50
5112µs13µs debug( 'TablePlugin', "inited" );
# spent 3µs making 1 call to Foswiki::Plugins::TablePlugin::debug
52
5316µs return 1;
54}
55
56
# spent 12.8ms (8.29+4.50) within Foswiki::Plugins::TablePlugin::preRenderingHandler which was called 5 times, avg 2.56ms/call: # 5 times (8.29ms+4.50ms) by Foswiki::Plugin::invoke at line 294 of /var/www/foswiki11/lib/Foswiki/Plugin.pm, avg 2.56ms/call
sub preRenderingHandler {
57 ### my ( $text, $removed ) = @_;
58514µs528µs debug( 'TablePlugin', 'preRenderingHandler' );
# spent 28µs making 5 calls to Foswiki::Plugins::TablePlugin::debug, avg 6µs/call
59517µs5181µs my $sort = Foswiki::Func::getPreferencesValue('TABLEPLUGIN_SORT')
# spent 181µs making 5 calls to Foswiki::Func::getPreferencesValue, avg 36µs/call
60 || 'all';
61 return
62524µs unless ( $sort && $sort =~ /^(all|attachments)$/ )
63 || $_[0] =~ /%TABLE{.*?}%/;
64
65519µs11.48ms _readPluginSettings() if !%pluginAttributes;
66
67 # on-demand inclusion
68581µs require Foswiki::Plugins::TablePlugin::Core;
6952µs if ( !$readyForHandler ) {
7012µs114µs Foswiki::Plugins::TablePlugin::Core::_init();
# spent 14µs making 1 call to Foswiki::Plugins::TablePlugin::Core::_init
7111µs $readyForHandler = 1;
72 }
73533µs51.77ms Foswiki::Plugins::TablePlugin::Core::handler(@_);
# spent 1.77ms making 5 calls to Foswiki::Plugins::TablePlugin::Core::handler, avg 353µs/call
74}
75
76=begin TML
77---++ StaticMethod initialiseWhenRender() -> 1
78
79Official API call for TablePlugin. Other plugins can reinitialise the plugin
80which will reset all table counters etc next time the preRenderingHandler
81is run. The preRenderingHandler is called again when a plugin uses the
82Foswiki::Func::renderText method.
83A plugin like !CompareRevisionsAddOn uses initialiseWhenRender between the
84rendering of two revisions of the same topic to avoid table numbers to
85continue counting up when rendering the topic the second time.
86
87Example of use in a plugin taking care to check for TablePlugin being
88installed and being of a version that contains this method.
89Otherwise using a "mother of hacks" to get to the same result.
90
91 if ( defined &Foswiki::Plugins::TablePlugin::initPlugin ) {
92 if ( defined &Foswiki::Plugins::TablePlugin::initialiseWhenRender ) {
93 Foswiki::Plugins::TablePlugin::initialiseWhenRender();
94 }
95 else {
96 # If TablePlugin does not have the reinitialise API
97 # we use try a shameless hack instead
98 if ( defined $Foswiki::Plugins::TablePlugin::initialised ) {
99 $Foswiki::Plugins::TablePlugin::initialised = 0;
100 }
101 }
102 }
103
104=cut
105
106sub initialiseWhenRender {
107
108 $initialised = 0;
109
110 return 1;
111}
112
113=pod
114
115Read in plugin settings from TABLEPLUGIN_TABLEATTRIBUTES
116TABLEATTRIBUTES are no longer supported (NO_PREFS_IN_TOPIC).
117If no settings are found, use the default settings from configure.
118And if these cannot be read, use the default values defined here in this plugin.
119
120Settings are applied by the principle of 'filling in the gaps'
121=cut
122
123
# spent 1.48ms (65µs+1.41) within Foswiki::Plugins::TablePlugin::_readPluginSettings which was called: # once (65µs+1.41ms) by Foswiki::Plugins::TablePlugin::preRenderingHandler at line 65
sub _readPluginSettings {
12412µs12µs debug( 'TablePlugin', '_readPluginSettings' );
# spent 2µs making 1 call to Foswiki::Plugins::TablePlugin::debug
12512µs my $configureAttrStr =
126 $Foswiki::cfg{Plugins}{TablePlugin}{DefaultAttributes};
12712µs146µs my $pluginAttrStr =
# spent 46µs making 1 call to Foswiki::Func::getPreferencesValue
128 Foswiki::Func::getPreferencesValue('TABLEPLUGIN_TABLEATTRIBUTES');
129
13013µs12µs debug( 'TablePlugin', "\t configureAttrStr=$configureAttrStr" )
# spent 2µs making 1 call to Foswiki::Plugins::TablePlugin::debug
131 if defined $configureAttrStr;
13212µs12µs debug( 'TablePlugin', "\t pluginAttrStr=$pluginAttrStr" )
# spent 2µs making 1 call to Foswiki::Plugins::TablePlugin::debug
133 if defined $pluginAttrStr;
13415µs debug( 'TablePlugin',
135 "\t no settings from configure could be read; using default values" )
136 unless defined $configureAttrStr;
137
1381500ns $configureAttrStr = $DEFAULT_TABLE_SETTINGS
139 unless defined $configureAttrStr;
140
14114µs1650µs $configureAttrStr = Foswiki::Func::expandCommonVariables( $configureAttrStr,
# spent 650µs making 1 call to Foswiki::Func::expandCommonVariables
142 $topic, $web, undef )
143 if defined $configureAttrStr;
144
14513µs1560µs $pluginAttrStr = Foswiki::Func::expandCommonVariables( $pluginAttrStr,
# spent 560µs making 1 call to Foswiki::Func::expandCommonVariables
146 $topic, $web, undef )
147 if defined $pluginAttrStr;
148
14917µs186µs my %configureParams = Foswiki::Func::extractParameters($configureAttrStr);
# spent 86µs making 1 call to Foswiki::Func::extractParameters
15015µs163µs my %pluginParams = Foswiki::Func::extractParameters($pluginAttrStr);
# spent 63µs making 1 call to Foswiki::Func::extractParameters
151
152114µs %pluginAttributes = ( %configureParams, %pluginParams );
153}
154
155
# spent 82µs (62+20) within Foswiki::Plugins::TablePlugin::afterCommonTagsHandler which was called 7 times, avg 12µs/call: # 7 times (62µs+20µs) by Foswiki::Plugin::invoke at line 294 of /var/www/foswiki11/lib/Foswiki/Plugin.pm, avg 12µs/call
sub afterCommonTagsHandler {
156
157 #debug( '', 'afterCommonTagsHandler' );
158728µs720µs _writeStyleToHead();
# spent 20µs making 7 calls to Foswiki::Plugins::TablePlugin::_writeStyleToHead, avg 3µs/call
159}
160
161=pod
162
163addHeadStyles( $id, \@styles )
164
165Store list of CSS lines to be written.
166
167=cut
168
169sub addHeadStyles {
170 my ( $inId, $inStyles ) = @_;
171
172 $styles->{$web}->{$topic}->{$inId} = $inStyles;
173}
174
175
# spent 20µs within Foswiki::Plugins::TablePlugin::_writeStyleToHead which was called 7 times, avg 3µs/call: # 7 times (20µs+0s) by Foswiki::Plugins::TablePlugin::afterCommonTagsHandler at line 158, avg 3µs/call
sub _writeStyleToHead {
176
177730µs return if !$styles->{$web}->{$topic};
178
179 my @allStyles = ();
180 foreach my $id ( sort keys %{ $styles->{$web}->{$topic} } ) {
181 push @allStyles, @{ $styles->{$web}->{$topic}->{$id} };
182 }
183 my $styleText = join( "\n", @allStyles );
184 debug( 'TablePlugin', "_writeStyleToHead; styleText=$styleText" );
185
186 my $header = <<EOS;
187<style type="text/css" media="all">
188$styleText
189</style>
190EOS
191 Foswiki::Func::addToHEAD( "TABLEPLUGIN_${web}_${topic}", $header );
192}
193
194=pod
195
196Shorthand debugging call.
197
198=cut
199
200
# spent 72µs within Foswiki::Plugins::TablePlugin::debug which was called 23 times, avg 3µs/call: # 13 times (31µs+0s) by Foswiki::Plugins::TablePlugin::Core::_debug at line 1992 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm, avg 2µs/call # 5 times (28µs+0s) by Foswiki::Plugins::TablePlugin::preRenderingHandler at line 58, avg 6µs/call # once (5µs+0s) by Foswiki::Plugins::TablePlugin::initPlugin at line 34 # once (3µs+0s) by Foswiki::Plugins::TablePlugin::initPlugin at line 51 # once (2µs+0s) by Foswiki::Plugins::TablePlugin::_readPluginSettings at line 130 # once (2µs+0s) by Foswiki::Plugins::TablePlugin::_readPluginSettings at line 124 # once (2µs+0s) by Foswiki::Plugins::TablePlugin::_readPluginSettings at line 132
sub debug {
2012320µs my ( $origin, $text ) = @_;
20223101µs return if !$Foswiki::cfg{Plugins}{TablePlugin}{Debug};
203 return if !$text;
204
205 $origin ||= 'TablePlugin';
206 $text = "$origin: $text";
207
208 print STDERR $text . "\n" if $DEBUG_FROM_UNIT_TEST;
209 Foswiki::Func::writeDebug("$text");
210}
211
212
# spent 8µs within Foswiki::Plugins::TablePlugin::debugData which was called 2 times, avg 4µs/call: # 2 times (8µs+0s) by Foswiki::Plugins::TablePlugin::Core::_debugData at line 1996 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm, avg 4µs/call
sub debugData {
21322µs my ( $origin, $text, $data ) = @_;
214
21529µs return if !$Foswiki::cfg{Plugins}{TablePlugin}{Debug};
216 $origin ||= 'TablePlugin';
217 Foswiki::Func::writeDebug("$origin: $text:");
218 print STDERR "$origin: $text:" . "\n" if $DEBUG_FROM_UNIT_TEST;
219 if ($data) {
220 eval
221'use Data::Dumper; local $Data::Dumper::Terse = 1; local $Data::Dumper::Indent = 1; Foswiki::Func::writeDebug(Dumper($data));';
222 print STDERR Dumper($data) . "\n" if $DEBUG_FROM_UNIT_TEST;
223 }
224}
225
22616µs1;
227__END__