Filename | /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin.pm |
Statements | Executed 144 statements in 1.40ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
5 | 1 | 1 | 8.29ms | 12.8ms | preRenderingHandler | Foswiki::Plugins::TablePlugin::
23 | 7 | 2 | 72µs | 72µs | debug | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 65µs | 1.48ms | _readPluginSettings | Foswiki::Plugins::TablePlugin::
7 | 1 | 1 | 62µs | 82µs | afterCommonTagsHandler | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 37µs | 63µs | initPlugin | Foswiki::Plugins::TablePlugin::
7 | 1 | 1 | 20µs | 20µs | _writeStyleToHead | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 13µs | 26µs | BEGIN@8 | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 10µs | 15µs | BEGIN@9 | Foswiki::Plugins::TablePlugin::
2 | 1 | 1 | 8µs | 8µs | debugData | Foswiki::Plugins::TablePlugin::
0 | 0 | 0 | 0s | 0s | addHeadStyles | Foswiki::Plugins::TablePlugin::
0 | 0 | 0 | 0s | 0s | initialiseWhenRender | Foswiki::Plugins::TablePlugin::
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 | |||||
6 | package Foswiki::Plugins::TablePlugin; | ||||
7 | |||||
8 | 2 | 27µs | 2 | 39µ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 # spent 26µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@8
# spent 13µs making 1 call to strict::import |
9 | 2 | 898µs | 2 | 20µ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 # 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" | ||||
12 | 1 | 600ns | our $VERSION = '1.142'; | ||
13 | 1 | 300ns | our $RELEASE = '1.142'; | ||
14 | 1 | 400ns | our $SHORTDESCRIPTION = | ||
15 | 'Control attributes of tables and sorting of table columns'; | ||||
16 | 1 | 200ns | our $NO_PREFS_IN_TOPIC = 1; | ||
17 | 1 | 200ns | our %pluginAttributes; | ||
18 | |||||
19 | 1 | 100ns | our $DEBUG_FROM_UNIT_TEST = 0; | ||
20 | 1 | 0s | our $topic; | ||
21 | 1 | 0s | our $web; | ||
22 | 1 | 100ns | our $user; | ||
23 | 1 | 100ns | our $installWeb; | ||
24 | 1 | 0s | our $initialised; | ||
25 | 1 | 600ns | my $DEFAULT_TABLE_SETTINGS = | ||
26 | 'tableborder="1" valign="top" headercolor="#000000" headerbg="#d6d3cf" headerbgsorted="#c4c1ba" databg="#ffffff,#edf4f9" databgsorted="#f1f7fc,#ddebf6" tablerules="rows" headerrules="cols"'; | ||||
27 | 1 | 500ns | my $styles = {}; # hash to keep track of web->topic | ||
28 | 1 | 0s | my $readyForHandler; | ||
29 | 1 | 100ns | our $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 | ||||
32 | 1 | 2µs | ( $topic, $web, $user, $installWeb ) = @_; | ||
33 | |||||
34 | 1 | 5µs | 1 | 5µs | debug( 'TablePlugin', "initPlugin:$web.$topic" ); # spent 5µs making 1 call to Foswiki::Plugins::TablePlugin::debug |
35 | |||||
36 | # check for Plugins.pm versions | ||||
37 | 1 | 16µs | 1 | 10µ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 | |||||
43 | 1 | 2µs | 1 | 8µs | my $cgi = Foswiki::Func::getCgiQuery(); # spent 8µs making 1 call to Foswiki::Func::getCgiQuery |
44 | 1 | 400ns | return 0 unless $cgi; | ||
45 | |||||
46 | 1 | 400ns | $initialised = 0; | ||
47 | 1 | 300ns | $readyForHandler = 0; | ||
48 | 1 | 600ns | $writtenToHead = 0; | ||
49 | 1 | 2µs | %pluginAttributes = (); | ||
50 | |||||
51 | 1 | 2µs | 1 | 3µs | debug( 'TablePlugin', "inited" ); # spent 3µs making 1 call to Foswiki::Plugins::TablePlugin::debug |
52 | |||||
53 | 1 | 6µ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 | ||||
57 | ### my ( $text, $removed ) = @_; | ||||
58 | 5 | 14µs | 5 | 28µs | debug( 'TablePlugin', 'preRenderingHandler' ); # spent 28µs making 5 calls to Foswiki::Plugins::TablePlugin::debug, avg 6µs/call |
59 | 5 | 17µs | 5 | 181µ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 | ||||
62 | 5 | 24µs | unless ( $sort && $sort =~ /^(all|attachments)$/ ) | ||
63 | || $_[0] =~ /%TABLE{.*?}%/; | ||||
64 | |||||
65 | 5 | 19µs | 1 | 1.48ms | _readPluginSettings() if !%pluginAttributes; # spent 1.48ms making 1 call to Foswiki::Plugins::TablePlugin::_readPluginSettings |
66 | |||||
67 | # on-demand inclusion | ||||
68 | 5 | 81µs | require Foswiki::Plugins::TablePlugin::Core; | ||
69 | 5 | 2µs | if ( !$readyForHandler ) { | ||
70 | 1 | 2µs | 1 | 14µs | Foswiki::Plugins::TablePlugin::Core::_init(); # spent 14µs making 1 call to Foswiki::Plugins::TablePlugin::Core::_init |
71 | 1 | 1µs | $readyForHandler = 1; | ||
72 | } | ||||
73 | 5 | 33µs | 5 | 1.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 | |||||
79 | Official API call for TablePlugin. Other plugins can reinitialise the plugin | ||||
80 | which will reset all table counters etc next time the preRenderingHandler | ||||
81 | is run. The preRenderingHandler is called again when a plugin uses the | ||||
82 | Foswiki::Func::renderText method. | ||||
83 | A plugin like !CompareRevisionsAddOn uses initialiseWhenRender between the | ||||
84 | rendering of two revisions of the same topic to avoid table numbers to | ||||
85 | continue counting up when rendering the topic the second time. | ||||
86 | |||||
87 | Example of use in a plugin taking care to check for TablePlugin being | ||||
88 | installed and being of a version that contains this method. | ||||
89 | Otherwise 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 | |||||
106 | sub initialiseWhenRender { | ||||
107 | |||||
108 | $initialised = 0; | ||||
109 | |||||
110 | return 1; | ||||
111 | } | ||||
112 | |||||
113 | =pod | ||||
114 | |||||
115 | Read in plugin settings from TABLEPLUGIN_TABLEATTRIBUTES | ||||
116 | TABLEATTRIBUTES are no longer supported (NO_PREFS_IN_TOPIC). | ||||
117 | If no settings are found, use the default settings from configure. | ||||
118 | And if these cannot be read, use the default values defined here in this plugin. | ||||
119 | |||||
120 | Settings 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 | ||||
124 | 1 | 2µs | 1 | 2µs | debug( 'TablePlugin', '_readPluginSettings' ); # spent 2µs making 1 call to Foswiki::Plugins::TablePlugin::debug |
125 | 1 | 2µs | my $configureAttrStr = | ||
126 | $Foswiki::cfg{Plugins}{TablePlugin}{DefaultAttributes}; | ||||
127 | 1 | 2µs | 1 | 46µs | my $pluginAttrStr = # spent 46µs making 1 call to Foswiki::Func::getPreferencesValue |
128 | Foswiki::Func::getPreferencesValue('TABLEPLUGIN_TABLEATTRIBUTES'); | ||||
129 | |||||
130 | 1 | 3µs | 1 | 2µs | debug( 'TablePlugin', "\t configureAttrStr=$configureAttrStr" ) # spent 2µs making 1 call to Foswiki::Plugins::TablePlugin::debug |
131 | if defined $configureAttrStr; | ||||
132 | 1 | 2µs | 1 | 2µs | debug( 'TablePlugin', "\t pluginAttrStr=$pluginAttrStr" ) # spent 2µs making 1 call to Foswiki::Plugins::TablePlugin::debug |
133 | if defined $pluginAttrStr; | ||||
134 | 1 | 5µs | debug( 'TablePlugin', | ||
135 | "\t no settings from configure could be read; using default values" ) | ||||
136 | unless defined $configureAttrStr; | ||||
137 | |||||
138 | 1 | 500ns | $configureAttrStr = $DEFAULT_TABLE_SETTINGS | ||
139 | unless defined $configureAttrStr; | ||||
140 | |||||
141 | 1 | 4µs | 1 | 650µ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 | |||||
145 | 1 | 3µs | 1 | 560µ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 | |||||
149 | 1 | 7µs | 1 | 86µs | my %configureParams = Foswiki::Func::extractParameters($configureAttrStr); # spent 86µs making 1 call to Foswiki::Func::extractParameters |
150 | 1 | 5µs | 1 | 63µs | my %pluginParams = Foswiki::Func::extractParameters($pluginAttrStr); # spent 63µs making 1 call to Foswiki::Func::extractParameters |
151 | |||||
152 | 1 | 14µ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 | ||||
156 | |||||
157 | #debug( '', 'afterCommonTagsHandler' ); | ||||
158 | 7 | 28µs | 7 | 20µs | _writeStyleToHead(); # spent 20µs making 7 calls to Foswiki::Plugins::TablePlugin::_writeStyleToHead, avg 3µs/call |
159 | } | ||||
160 | |||||
161 | =pod | ||||
162 | |||||
163 | addHeadStyles( $id, \@styles ) | ||||
164 | |||||
165 | Store list of CSS lines to be written. | ||||
166 | |||||
167 | =cut | ||||
168 | |||||
169 | sub 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 | ||||
176 | |||||
177 | 7 | 30µ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> | ||||
190 | EOS | ||||
191 | Foswiki::Func::addToHEAD( "TABLEPLUGIN_${web}_${topic}", $header ); | ||||
192 | } | ||||
193 | |||||
194 | =pod | ||||
195 | |||||
196 | Shorthand 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 | ||||
201 | 23 | 20µs | my ( $origin, $text ) = @_; | ||
202 | 23 | 101µ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 | ||||
213 | 2 | 2µs | my ( $origin, $text, $data ) = @_; | ||
214 | |||||
215 | 2 | 9µ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 | |||||
226 | 1 | 6µs | 1; | ||
227 | __END__ |