Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/TablePlugin.pm |
Statements | Executed 5791 statements in 33.8ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1131 | 1 | 1 | 20.4ms | 32.8ms | afterCommonTagsHandler | Foswiki::Plugins::TablePlugin::
1155 | 8 | 2 | 7.30ms | 7.30ms | debug | Foswiki::Plugins::TablePlugin::
1131 | 1 | 1 | 5.25ms | 5.25ms | _writeStyleToHead | Foswiki::Plugins::TablePlugin::
5 | 1 | 1 | 878µs | 49.3ms | preRenderingHandler | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 116µs | 195µs | initPlugin | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 114µs | 3.74ms | _readPluginSettings | Foswiki::Plugins::TablePlugin::
6 | 1 | 1 | 41µs | 41µs | debugData | Foswiki::Plugins::TablePlugin::
5 | 1 | 1 | 35µs | 35µs | CORE:match (opcode) | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 24µs | 32µs | BEGIN@8 | Foswiki::Plugins::TablePlugin::
1 | 1 | 1 | 17µs | 35µs | BEGIN@9 | 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 | 46µs | 2 | 39µs | # spent 32µs (24+7) within Foswiki::Plugins::TablePlugin::BEGIN@8 which was called:
# once (24µs+7µs) by Foswiki::Plugin::BEGIN@2.17 at line 8 # spent 32µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@8
# spent 7µs making 1 call to strict::import |
9 | 2 | 1.61ms | 2 | 54µs | # spent 35µs (17+19) within Foswiki::Plugins::TablePlugin::BEGIN@9 which was called:
# once (17µs+19µs) by Foswiki::Plugin::BEGIN@2.17 at line 9 # spent 35µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@9
# spent 19µs making 1 call to warnings::import |
10 | |||||
11 | 1 | 2µs | our $VERSION = '$Rev$'; | ||
12 | 1 | 1µs | our $RELEASE = '1.135'; | ||
13 | 1 | 2µs | our $SHORTDESCRIPTION = | ||
14 | 'Control attributes of tables and sorting of table columns'; | ||||
15 | 1 | 1µs | our $NO_PREFS_IN_TOPIC = 1; | ||
16 | 1 | 1µs | our %pluginAttributes; | ||
17 | |||||
18 | 1 | 1µs | our $DEBUG_FROM_UNIT_TEST = 0; | ||
19 | 1 | 1µs | our $topic; | ||
20 | 1 | 800ns | our $web; | ||
21 | 1 | 800ns | our $user; | ||
22 | 1 | 800ns | our $installWeb; | ||
23 | 1 | 700ns | our $initialised; | ||
24 | 1 | 2µs | my $DEFAULT_TABLE_SETTINGS = | ||
25 | 'tableborder="1" valign="top" headercolor="#000000" headerbg="#d6d3cf" headerbgsorted="#c4c1ba" databg="#ffffff,#edf4f9" databgsorted="#f1f7fc,#ddebf6" tablerules="rows" headerrules="cols"'; | ||||
26 | 1 | 2µs | my $styles = {}; # hash to keep track of web->topic | ||
27 | 1 | 1µs | our $writtenToHead = 0; | ||
28 | |||||
29 | # spent 195µs (116+79) within Foswiki::Plugins::TablePlugin::initPlugin which was called:
# once (116µs+79µs) by Foswiki::Plugin::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm:235] at line 228 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm | ||||
30 | 10 | 81µs | ( $topic, $web, $user, $installWeb ) = @_; | ||
31 | |||||
32 | 1 | 19µs | debug( 'TablePlugin', "initPlugin:$web.$topic" ); # spent 19µs making 1 call to Foswiki::Plugins::TablePlugin::debug | ||
33 | |||||
34 | # check for Plugins.pm versions | ||||
35 | if ( $Foswiki::Plugins::VERSION < 1.026 ) { | ||||
36 | Foswiki::Func::writeWarning( | ||||
37 | 'Version mismatch between TablePlugin and Plugins.pm'); | ||||
38 | return 0; | ||||
39 | } | ||||
40 | |||||
41 | 1 | 49µs | my $cgi = Foswiki::Func::getCgiQuery(); # spent 49µs making 1 call to Foswiki::Func::getCgiQuery | ||
42 | return 0 unless $cgi; | ||||
43 | |||||
44 | $initialised = 0; | ||||
45 | $writtenToHead = 0; | ||||
46 | %pluginAttributes = (); | ||||
47 | |||||
48 | 1 | 10µs | debug( 'TablePlugin', "inited" ); # spent 10µs making 1 call to Foswiki::Plugins::TablePlugin::debug | ||
49 | |||||
50 | return 1; | ||||
51 | } | ||||
52 | |||||
53 | # spent 49.3ms (878µs+48.4) within Foswiki::Plugins::TablePlugin::preRenderingHandler which was called 5 times, avg 9.86ms/call:
# 5 times (878µs+48.4ms) by Foswiki::Plugin::invoke at line 287 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm, avg 9.86ms/call | ||||
54 | ### my ( $text, $removed ) = @_; | ||||
55 | 35 | 860µs | 5 | 37µs | debug( 'TablePlugin', 'preRenderingHandler' ); # spent 37µs making 5 calls to Foswiki::Plugins::TablePlugin::debug, avg 7µs/call |
56 | 5 | 526µs | my $sort = Foswiki::Func::getPreferencesValue('TABLEPLUGIN_SORT') # spent 526µs making 5 calls to Foswiki::Func::getPreferencesValue, avg 105µs/call | ||
57 | || 'all'; | ||||
58 | return | ||||
59 | 5 | 35µs | unless ( $sort && $sort =~ /^(all|attachments)$/ ) # spent 35µs making 5 calls to Foswiki::Plugins::TablePlugin::CORE:match, avg 7µs/call | ||
60 | || $_[0] =~ /%TABLE{.*?}%/; | ||||
61 | |||||
62 | 1 | 3.74ms | _readPluginSettings() if !%pluginAttributes; # spent 3.74ms making 1 call to Foswiki::Plugins::TablePlugin::_readPluginSettings | ||
63 | |||||
64 | # on-demand inclusion | ||||
65 | eval "use Foswiki::Plugins::TablePlugin::Core ()"; # spent 294µs executing statements in 5 string evals (merged) # includes 14.6ms spent executing 5 calls to 5 subs defined therein. | ||||
66 | die $@ if $@; | ||||
67 | 5 | 26.7ms | Foswiki::Plugins::TablePlugin::Core::handler(@_); # spent 26.7ms making 5 calls to Foswiki::Plugins::TablePlugin::Core::handler, avg 5.33ms/call | ||
68 | } | ||||
69 | |||||
70 | =begin TML | ||||
71 | ---++ StaticMethod initialiseWhenRender() -> 1 | ||||
72 | |||||
73 | Official API call for TablePlugin. Other plugins can reinitialise the plugin | ||||
74 | which will reset all table counters etc next time the preRenderingHandler | ||||
75 | is run. The preRenderingHandler is called again when a plugin uses the | ||||
76 | Foswiki::Func::renderText method. | ||||
77 | A plugin like !CompareRevisionsAddOn uses initialiseWhenRender between the | ||||
78 | rendering of two revisions of the same topic to avoid table numbers to | ||||
79 | continue counting up when rendering the topic the second time. | ||||
80 | |||||
81 | Example of use in a plugin taking care to check for TablePlugin being | ||||
82 | installed and being of a version that contains this method. | ||||
83 | Otherwise using a "mother of hacks" to get to the same result. | ||||
84 | |||||
85 | if ( defined &Foswiki::Plugins::TablePlugin::initPlugin ) { | ||||
86 | if ( defined &Foswiki::Plugins::TablePlugin::initialiseWhenRender ) { | ||||
87 | Foswiki::Plugins::TablePlugin::initialiseWhenRender(); | ||||
88 | } | ||||
89 | else { | ||||
90 | # If TablePlugin does not have the reinitialise API | ||||
91 | # we use try a shameless hack instead | ||||
92 | if ( defined $Foswiki::Plugins::TablePlugin::initialised ) { | ||||
93 | $Foswiki::Plugins::TablePlugin::initialised = 0; | ||||
94 | } | ||||
95 | } | ||||
96 | } | ||||
97 | |||||
98 | =cut | ||||
99 | |||||
100 | sub initialiseWhenRender { | ||||
101 | |||||
102 | $initialised = 0; | ||||
103 | |||||
104 | return 1; | ||||
105 | } | ||||
106 | |||||
107 | =pod | ||||
108 | |||||
109 | Read in plugin settings from TABLEPLUGIN_TABLEATTRIBUTES | ||||
110 | TABLEATTRIBUTES are no longer supported (NO_PREFS_IN_TOPIC). | ||||
111 | If no settings are found, use the default settings from configure. | ||||
112 | And if these cannot be read, use the default values defined here in this plugin. | ||||
113 | |||||
114 | Settings are applied by the principle of 'filling in the gaps' | ||||
115 | =cut | ||||
116 | |||||
117 | # spent 3.74ms (114µs+3.62) within Foswiki::Plugins::TablePlugin::_readPluginSettings which was called:
# once (114µs+3.62ms) by Foswiki::Plugins::TablePlugin::preRenderingHandler at line 62 | ||||
118 | 12 | 94µs | 1 | 6µs | debug( 'TablePlugin', '_readPluginSettings' ); # spent 6µs making 1 call to Foswiki::Plugins::TablePlugin::debug |
119 | my $configureAttrStr = | ||||
120 | $Foswiki::cfg{Plugins}{TablePlugin}{DefaultAttributes}; | ||||
121 | 1 | 154µs | my $pluginAttrStr = # spent 154µs making 1 call to Foswiki::Func::getPreferencesValue | ||
122 | Foswiki::Func::getPreferencesValue('TABLEPLUGIN_TABLEATTRIBUTES'); | ||||
123 | |||||
124 | 1 | 7µs | debug( 'TablePlugin', "\t configureAttrStr=$configureAttrStr" ) # spent 7µs making 1 call to Foswiki::Plugins::TablePlugin::debug | ||
125 | if $configureAttrStr; | ||||
126 | 1 | 6µs | debug( 'TablePlugin', "\t pluginAttrStr=$pluginAttrStr" ) if $pluginAttrStr; # spent 6µs making 1 call to Foswiki::Plugins::TablePlugin::debug | ||
127 | debug( 'TablePlugin', | ||||
128 | "\t no settings from configure could be read; using default values" ) | ||||
129 | if !$configureAttrStr; | ||||
130 | $configureAttrStr ||= $DEFAULT_TABLE_SETTINGS; | ||||
131 | |||||
132 | 1 | 1.43ms | $configureAttrStr = Foswiki::Func::expandCommonVariables( $configureAttrStr, # spent 1.43ms making 1 call to Foswiki::Func::expandCommonVariables | ||
133 | $topic, $web, undef ) | ||||
134 | if $configureAttrStr; | ||||
135 | 1 | 1.26ms | $pluginAttrStr = Foswiki::Func::expandCommonVariables( $pluginAttrStr, # spent 1.26ms making 1 call to Foswiki::Func::expandCommonVariables | ||
136 | $topic, $web, undef ) | ||||
137 | if $pluginAttrStr; | ||||
138 | |||||
139 | 1 | 410µs | my %configureParams = Foswiki::Func::extractParameters($configureAttrStr); # spent 410µs making 1 call to Foswiki::Func::extractParameters | ||
140 | 1 | 351µs | my %pluginParams = Foswiki::Func::extractParameters($pluginAttrStr); # spent 351µs making 1 call to Foswiki::Func::extractParameters | ||
141 | |||||
142 | %pluginAttributes = ( %configureParams, %pluginParams ); | ||||
143 | } | ||||
144 | |||||
145 | # spent 32.8ms (20.4+12.4) within Foswiki::Plugins::TablePlugin::afterCommonTagsHandler which was called 1131 times, avg 29µs/call:
# 1131 times (20.4ms+12.4ms) by Foswiki::Plugin::invoke at line 287 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm, avg 29µs/call | ||||
146 | |||||
147 | 2262 | 14.6ms | 1131 | 7.11ms | debug( '', 'afterCommonTagsHandler' ); # spent 7.11ms making 1131 calls to Foswiki::Plugins::TablePlugin::debug, avg 6µs/call |
148 | 1131 | 5.25ms | _writeStyleToHead(); # spent 5.25ms making 1131 calls to Foswiki::Plugins::TablePlugin::_writeStyleToHead, avg 5µs/call | ||
149 | } | ||||
150 | |||||
151 | =pod | ||||
152 | |||||
153 | addHeadStyles( $id, \@styles ) | ||||
154 | |||||
155 | Store list of CSS lines to be written. | ||||
156 | |||||
157 | =cut | ||||
158 | |||||
159 | sub addHeadStyles { | ||||
160 | my ( $inId, $inStyles ) = @_; | ||||
161 | |||||
162 | $styles->{$web}->{$topic}->{$inId} = $inStyles; | ||||
163 | } | ||||
164 | |||||
165 | # spent 5.25ms within Foswiki::Plugins::TablePlugin::_writeStyleToHead which was called 1131 times, avg 5µs/call:
# 1131 times (5.25ms+0s) by Foswiki::Plugins::TablePlugin::afterCommonTagsHandler at line 148, avg 5µs/call | ||||
166 | |||||
167 | 1131 | 6.52ms | return if !$styles->{$web}->{$topic}; | ||
168 | |||||
169 | my @allStyles = (); | ||||
170 | foreach my $id ( sort keys %{ $styles->{$web}->{$topic} } ) { | ||||
171 | push @allStyles, @{ $styles->{$web}->{$topic}->{$id} }; | ||||
172 | } | ||||
173 | my $styleText = join( "\n", @allStyles ); | ||||
174 | debug( 'TablePlugin', "_writeStyleToHead; styleText=$styleText" ); | ||||
175 | |||||
176 | my $header = <<EOS; | ||||
177 | <style type="text/css" media="all"> | ||||
178 | $styleText | ||||
179 | </style> | ||||
180 | EOS | ||||
181 | Foswiki::Func::addToHEAD( "TABLEPLUGIN_${web}_${topic}", $header ); | ||||
182 | } | ||||
183 | |||||
184 | =pod | ||||
185 | |||||
186 | Shorthand debugging call. | ||||
187 | |||||
188 | =cut | ||||
189 | |||||
190 | # spent 7.30ms within Foswiki::Plugins::TablePlugin::debug which was called 1155 times, avg 6µs/call:
# 1131 times (7.11ms+0s) by Foswiki::Plugins::TablePlugin::afterCommonTagsHandler at line 147, avg 6µs/call
# 14 times (100µs+0s) by Foswiki::Plugins::TablePlugin::Core::_debug at line 1967 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/TablePlugin/Core.pm, avg 7µs/call
# 5 times (37µs+0s) by Foswiki::Plugins::TablePlugin::preRenderingHandler at line 55, avg 7µs/call
# once (19µs+0s) by Foswiki::Plugins::TablePlugin::initPlugin at line 32
# once (10µs+0s) by Foswiki::Plugins::TablePlugin::initPlugin at line 48
# once (7µs+0s) by Foswiki::Plugins::TablePlugin::_readPluginSettings at line 124
# once (6µs+0s) by Foswiki::Plugins::TablePlugin::_readPluginSettings at line 118
# once (6µs+0s) by Foswiki::Plugins::TablePlugin::_readPluginSettings at line 126 | ||||
191 | 2310 | 9.91ms | my ( $origin, $text ) = @_; | ||
192 | return if !$Foswiki::cfg{Plugins}{TablePlugin}{Debug}; | ||||
193 | return if !$text; | ||||
194 | |||||
195 | $origin ||= 'TablePlugin'; | ||||
196 | $text = "$origin: $text"; | ||||
197 | |||||
198 | print STDERR $text . "\n" if $DEBUG_FROM_UNIT_TEST; | ||||
199 | Foswiki::Func::writeDebug("$text"); | ||||
200 | } | ||||
201 | |||||
202 | # spent 41µs within Foswiki::Plugins::TablePlugin::debugData which was called 6 times, avg 7µs/call:
# 6 times (41µs+0s) by Foswiki::Plugins::TablePlugin::Core::_debugData at line 1971 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/TablePlugin/Core.pm, avg 7µs/call | ||||
203 | 12 | 59µs | my ( $origin, $text, $data ) = @_; | ||
204 | |||||
205 | return if !$Foswiki::cfg{Plugins}{TablePlugin}{Debug}; | ||||
206 | $origin ||= 'TablePlugin'; | ||||
207 | Foswiki::Func::writeDebug("$origin: $text:"); | ||||
208 | print STDERR "$origin: $text:" . "\n" if $DEBUG_FROM_UNIT_TEST; | ||||
209 | if ($data) { | ||||
210 | eval | ||||
211 | 'use Data::Dumper; local $Data::Dumper::Terse = 1; local $Data::Dumper::Indent = 1; Foswiki::Func::writeDebug(Dumper($data));'; | ||||
212 | print STDERR Dumper($data) . "\n" if $DEBUG_FROM_UNIT_TEST; | ||||
213 | } | ||||
214 | } | ||||
215 | |||||
216 | 1 | 10µs | 1; | ||
217 | __END__ | ||||
# spent 35µs within Foswiki::Plugins::TablePlugin::CORE:match which was called 5 times, avg 7µs/call:
# 5 times (35µs+0s) by Foswiki::Plugins::TablePlugin::preRenderingHandler at line 59, avg 7µs/call |