Filename | /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin.pm |
Statements | Executed 335 statements in 1.93ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
5 | 1 | 1 | 8.20ms | 11.6ms | preRenderingHandler | Foswiki::Plugins::TablePlugin::
100 | 1 | 1 | 445µs | 576µs | afterCommonTagsHandler | Foswiki::Plugins::TablePlugin::
100 | 1 | 1 | 131µs | 131µs | _writeStyleToHead | Foswiki::Plugins::TablePlugin::
22 | 6 | 2 | 60µs | 60µs | debug | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 38µs | 582µs | _readPluginSettings | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 28µs | 50µs | initPlugin | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 13µs | 27µs | BEGIN@8 | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 10µs | 15µs | BEGIN@9 | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 9µs | 20µs | BEGIN@15 | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 9µs | 20µs | BEGIN@17 | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 8µs | 17µs | BEGIN@12 | Foswiki::Plugins::TablePlugin::
2 | 1 | 1 | 7µs | 7µs | debugData | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@10 | 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 | 84µs | 2 | 41µ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 # spent 27µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@8
# spent 14µs making 1 call to strict::import |
9 | 2 | 25µ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.37 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 | 2 | 38µs | 1 | 4µ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 # 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 | ||||
13 | # Backwards compatibility for Foswiki 1.1.x | ||||
14 | 1 | 5µs | 1 | 10µs | unless ( Foswiki::Request->can('multi_param') ) { # spent 10µs making 1 call to CGI::can |
15 | 2 | 38µs | 2 | 30µ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 # 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; | ||||
17 | 2 | 24µs | 2 | 32µ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 # spent 20µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@17
# spent 12µs making 1 call to warnings::import |
18 | } | ||||
19 | 1 | 886µs | 1 | 17µs | } # spent 17µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@12 |
20 | |||||
21 | # Simple decimal version, use parse method, no leading "v" | ||||
22 | 1 | 600ns | our $VERSION = '1.142'; | ||
23 | 1 | 100ns | our $RELEASE = '1.142'; | ||
24 | 1 | 400ns | our $SHORTDESCRIPTION = | ||
25 | 'Control attributes of tables and sorting of table columns'; | ||||
26 | 1 | 200ns | our $NO_PREFS_IN_TOPIC = 1; | ||
27 | 1 | 300ns | our %pluginAttributes; | ||
28 | |||||
29 | 1 | 100ns | our $DEBUG_FROM_UNIT_TEST = 0; | ||
30 | 1 | 0s | our $topic; | ||
31 | 1 | 0s | our $web; | ||
32 | 1 | 100ns | our $user; | ||
33 | 1 | 100ns | our $installWeb; | ||
34 | 1 | 0s | our $initialised; | ||
35 | 1 | 500ns | my $DEFAULT_TABLE_SETTINGS = | ||
36 | 'tableborder="1" valign="top" headercolor="#000000" headerbg="#d6d3cf" headerbgsorted="#c4c1ba" databg="#ffffff,#edf4f9" databgsorted="#f1f7fc,#ddebf6" tablerules="rows" headerrules="cols"'; | ||||
37 | 1 | 600ns | my $styles = {}; # hash to keep track of web->topic | ||
38 | 1 | 100ns | my $readyForHandler; | ||
39 | 1 | 100ns | our $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 | ||||
42 | 1 | 2µs | ( $topic, $web, $user, $installWeb ) = @_; | ||
43 | |||||
44 | 1 | 4µs | 1 | 5µs | debug( 'TablePlugin', "initPlugin:$web.$topic" ); # spent 5µs making 1 call to Foswiki::Plugins::TablePlugin::debug |
45 | |||||
46 | # check for Plugins.pm versions | ||||
47 | 1 | 14µs | 1 | 8µ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 | |||||
53 | 1 | 2µs | 1 | 6µs | my $cgi = Foswiki::Func::getCgiQuery(); # spent 6µs making 1 call to Foswiki::Func::getCgiQuery |
54 | 1 | 600ns | return 0 unless $cgi; | ||
55 | |||||
56 | 1 | 600ns | $initialised = 0; | ||
57 | 1 | 200ns | $readyForHandler = 0; | ||
58 | 1 | 400ns | $writtenToHead = 0; | ||
59 | 1 | 900ns | %pluginAttributes = (); | ||
60 | |||||
61 | 1 | 1µs | 1 | 2µs | debug( 'TablePlugin', "inited" ); # spent 2µs making 1 call to Foswiki::Plugins::TablePlugin::debug |
62 | |||||
63 | 1 | 4µ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 | ||||
67 | ### my ( $text, $removed ) = @_; | ||||
68 | 5 | 10µs | 5 | 24µs | debug( 'TablePlugin', 'preRenderingHandler' ); # spent 24µs making 5 calls to Foswiki::Plugins::TablePlugin::debug, avg 5µs/call |
69 | 5 | 14µs | 5 | 132µ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 | ||||
72 | 5 | 14µs | unless ( $sort && $sort =~ m/^(all|attachments)$/ ) | ||
73 | || $_[0] =~ m/%TABLE\{.*?\}%/; | ||||
74 | |||||
75 | 5 | 14µs | 1 | 582µs | _readPluginSettings() if !%pluginAttributes; # spent 582µs making 1 call to Foswiki::Plugins::TablePlugin::_readPluginSettings |
76 | |||||
77 | # on-demand inclusion | ||||
78 | 5 | 75µs | require Foswiki::Plugins::TablePlugin::Core; | ||
79 | 5 | 2µs | if ( !$readyForHandler ) { | ||
80 | 1 | 2µs | 1 | 821µs | Foswiki::Plugins::TablePlugin::Core::_init(); # spent 821µs making 1 call to Foswiki::Plugins::TablePlugin::Core::_init |
81 | 1 | 700ns | $readyForHandler = 1; | ||
82 | } | ||||
83 | 5 | 25µs | 5 | 1.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 | |||||
89 | Official API call for TablePlugin. Other plugins can reinitialise the plugin | ||||
90 | which will reset all table counters etc next time the preRenderingHandler | ||||
91 | is run. The preRenderingHandler is called again when a plugin uses the | ||||
92 | Foswiki::Func::renderText method. | ||||
93 | A plugin like !CompareRevisionsAddOn uses initialiseWhenRender between the | ||||
94 | rendering of two revisions of the same topic to avoid table numbers to | ||||
95 | continue counting up when rendering the topic the second time. | ||||
96 | |||||
97 | Example of use in a plugin taking care to check for TablePlugin being | ||||
98 | installed and being of a version that contains this method. | ||||
99 | Otherwise 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 | |||||
116 | sub initialiseWhenRender { | ||||
117 | |||||
118 | $initialised = 0; | ||||
119 | |||||
120 | return 1; | ||||
121 | } | ||||
122 | |||||
123 | =pod | ||||
124 | |||||
125 | Read in plugin settings from TABLEPLUGIN_TABLEATTRIBUTES | ||||
126 | TABLEATTRIBUTES are no longer supported (NO_PREFS_IN_TOPIC). | ||||
127 | If no settings are found, use the default settings from configure. | ||||
128 | And if these cannot be read, use the default values defined here in this plugin. | ||||
129 | |||||
130 | Settings 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 | ||||
134 | 1 | 1µs | 1 | 2µs | debug( 'TablePlugin', '_readPluginSettings' ); # spent 2µs making 1 call to Foswiki::Plugins::TablePlugin::debug |
135 | 1 | 2µs | my $configureAttrStr = | ||
136 | $Foswiki::cfg{Plugins}{TablePlugin}{DefaultAttributes}; | ||||
137 | 1 | 1µs | 1 | 20µs | my $pluginAttrStr = # spent 20µs making 1 call to Foswiki::Func::getPreferencesValue |
138 | Foswiki::Func::getPreferencesValue('TABLEPLUGIN_TABLEATTRIBUTES'); | ||||
139 | |||||
140 | 1 | 2µs | 1 | 2µs | debug( 'TablePlugin', "\t configureAttrStr=$configureAttrStr" ) # spent 2µs making 1 call to Foswiki::Plugins::TablePlugin::debug |
141 | if defined $configureAttrStr; | ||||
142 | 1 | 400ns | debug( 'TablePlugin', "\t pluginAttrStr=$pluginAttrStr" ) | ||
143 | if defined $pluginAttrStr; | ||||
144 | 1 | 600ns | debug( 'TablePlugin', | ||
145 | "\t no settings from configure could be read; using default values" ) | ||||
146 | unless defined $configureAttrStr; | ||||
147 | |||||
148 | 1 | 200ns | $configureAttrStr = $DEFAULT_TABLE_SETTINGS | ||
149 | unless defined $configureAttrStr; | ||||
150 | |||||
151 | 1 | 2µs | 1 | 448µ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 | |||||
155 | 1 | 700ns | $pluginAttrStr = Foswiki::Func::expandCommonVariables( $pluginAttrStr, | ||
156 | $topic, $web, undef ) | ||||
157 | if defined $pluginAttrStr; | ||||
158 | |||||
159 | 1 | 7µs | 1 | 62µs | my %configureParams = Foswiki::Func::extractParameters($configureAttrStr); # spent 62µs making 1 call to Foswiki::Func::extractParameters |
160 | 1 | 3µs | 1 | 9µs | my %pluginParams = Foswiki::Func::extractParameters($pluginAttrStr); # spent 9µs making 1 call to Foswiki::Func::extractParameters |
161 | |||||
162 | 1 | 9µ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 | ||||
166 | |||||
167 | #debug( '', 'afterCommonTagsHandler' ); | ||||
168 | 100 | 237µs | 100 | 131µs | _writeStyleToHead(); # spent 131µs making 100 calls to Foswiki::Plugins::TablePlugin::_writeStyleToHead, avg 1µs/call |
169 | } | ||||
170 | |||||
171 | =pod | ||||
172 | |||||
173 | addHeadStyles( $id, \@styles ) | ||||
174 | |||||
175 | Store list of CSS lines to be written. | ||||
176 | |||||
177 | =cut | ||||
178 | |||||
179 | sub 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 | ||||
186 | |||||
187 | 100 | 253µ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> | ||||
200 | EOS | ||||
201 | Foswiki::Func::addToZone( "head", "TABLEPLUGIN_${web}_${topic}", $header ); | ||||
202 | } | ||||
203 | |||||
204 | =pod | ||||
205 | |||||
206 | Shorthand 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 | ||||
211 | 22 | 20µs | my ( $origin, $text ) = @_; | ||
212 | 22 | 81µ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 | ||||
223 | 2 | 2µs | my ( $origin, $text, $data ) = @_; | ||
224 | |||||
225 | 2 | 8µ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 | |||||
236 | 1 | 5µs | 1; | ||
237 | __END__ |