| 1 | # perl -w | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ShowTable.pm | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Copyright (C) 1996-2013 Alan K. Stebbens <aks@stebbens.org> | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # the Free Software Foundation; either version 2 of the License, or | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # (at your option) any later version. | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # along with this program; if not, write to the Free Software | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | package Data::ShowTable; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 23 | $VERSION = '4.6'; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | B<ShowTable> - routines to display tabular data in several formats. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 USAGE | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | C<use Data::ShowTable;> | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | B<ShowTable> { I<parameter> => I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | B<ShowTable> I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> [, I<\&fmt_sub> ]; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | B<ShowDatabases> I<\@dbnames>; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | B<ShowDatabases> { I<parameter> => I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | B<ShowTables> I<\@tblnames>; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | B<ShowTables> { I<parameter> => I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | B<ShowColumns> I<\@columns>, I<\@col_types>, I<\@col_lengths>, I<\@col_attrs>; | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | B<ShowColumns> { I<parameter> => I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | B<ShowBoxTable> I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> [, I<\&fmt_sub> ]; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | B<ShowBoxTable> { I<parameter> => I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | B<ShowSimpleTable> I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> [, I<\&fmt_sub>]; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | B<ShowSimpleTable> { I<parameter> => I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | B<ShowHTMLTable> I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> [, I<\&fmt_sub>]; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | B<ShowHTMLTable> { I<parameter> => I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | B<ShowListTable> I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> [, I<\&fmt_sub>]; | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | B<ShowListTable> { I<parameter> => I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | C<package Data::ShowTable>; | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | B<$Show_Mode> = 'I<mode>'; | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | B<$Max_Table_Width> = I<number>; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | B<$Max_List_Width> = I<number>; | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | B<$No_Escape> = I<flag>; | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | B<%URL_Keys> = { "I<$colname>" => "I<$col_URL>", ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | B<@Title_Formats> = ( I<fmt1_html>, <fmt2_html>, ... ); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | B<@Data_Formats> = ( I<fmt1_html>, <fmt2_html>, ... ); | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | B<ShowRow> I<$rewindflag>, I<\$index>, I<$col_array_1> [, I<$col_array_2>, ...;] | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | I<$fmt> = B<ShowTableValue> I<$value>, I<$type>, I<$max_width>, I<$width>, I<$precision>, I<$showmode>; | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | [I<$plaintext> = ] B<PlainText> [I<$htmltext>]; | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | The B<ShowTable> module provides subroutines to display tabular data, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | typially from a database, in nicely formatted columns, in several formats. | ||||||||||||||||||||||||||||||||||||||||||
| 98 | Its arguments can either be given in a fixed order, or, as | ||||||||||||||||||||||||||||||||||||||||||
| 99 | a single, anonymous hash-array. | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | The output format for any one invocation can be one of four possible styles: | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | =over 10 | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | =item Box | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | A tabular format, with the column titles and the entire table surrounded by a | ||||||||||||||||||||||||||||||||||||||||||
| 108 | "box" of "C<+>", "C<->", and "C<|>" characters. See L<"ShowBoxTable"> for details. | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =item Table | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | A simple tabular format, with columns automatically aligned, with column titles. | ||||||||||||||||||||||||||||||||||||||||||
| 113 | See L<"ShowSimpleTable">. | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | =item List | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | A I<list> style, where columns of data are listed as a I<name>:I<value> pair, one | ||||||||||||||||||||||||||||||||||||||||||
| 118 | pair per line, with rows being one or more column values, separated by an empty line. | ||||||||||||||||||||||||||||||||||||||||||
| 119 | See L<"ShowListTable">. | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | =item HTML | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | The data is output as an HTML I<TABLE>, suitable for display through a I<Web>-client. | ||||||||||||||||||||||||||||||||||||||||||
| 124 | See L<"ShowHTMLTable">. Input can either be plain ASCII text, or text | ||||||||||||||||||||||||||||||||||||||||||
| 125 | with embedded HTML elements, depending upon an argument or global parameter. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | The subroutines which perform these displays are listed below. | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =head1 EXPORTED NAMES | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | This module exports the following subroutines: | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | ShowDatabases - show list of databases | ||||||||||||||||||||||||||||||||||||||||||
| 136 | ShowTables - show list of tables | ||||||||||||||||||||||||||||||||||||||||||
| 137 | ShowColumns - show table of column info | ||||||||||||||||||||||||||||||||||||||||||
| 138 | ShowTable - show a table of data | ||||||||||||||||||||||||||||||||||||||||||
| 139 | ShowRow - show a row from one or more columns | ||||||||||||||||||||||||||||||||||||||||||
| 140 | ShowTableValue - show a single column's value | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ShowBoxTable - show a table of data in a box | ||||||||||||||||||||||||||||||||||||||||||
| 142 | ShowListTable - show a table of data in a list | ||||||||||||||||||||||||||||||||||||||||||
| 143 | ShowSimpleTable - show a table of data in a simple table | ||||||||||||||||||||||||||||||||||||||||||
| 144 | ShowHTMLTable - show a table of data using HTML | ||||||||||||||||||||||||||||||||||||||||||
| 145 | PlainText - convert HTML text into plain text | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | All of these subroutines, and others, are described in detail in the | ||||||||||||||||||||||||||||||||||||||||||
| 148 | following sections. | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 23 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 23 | @ISA = qw( Exporter ); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 23 | @EXPORT = qw( ShowDatabases | |||||||||||||||||||||||||||||||||||||||||
| 156 | ShowTables | ||||||||||||||||||||||||||||||||||||||||||
| 157 | ShowColumns | ||||||||||||||||||||||||||||||||||||||||||
| 158 | ShowTable | ||||||||||||||||||||||||||||||||||||||||||
| 159 | ShowRow | ||||||||||||||||||||||||||||||||||||||||||
| 160 | ShowBoxTable | ||||||||||||||||||||||||||||||||||||||||||
| 161 | ShowHTMLTable | ||||||||||||||||||||||||||||||||||||||||||
| 162 | ShowListTable | ||||||||||||||||||||||||||||||||||||||||||
| 163 | ShowSimpleTable | ||||||||||||||||||||||||||||||||||||||||||
| 164 | ShowTableValue | ||||||||||||||||||||||||||||||||||||||||||
| 165 | Show_Mode | ||||||||||||||||||||||||||||||||||||||||||
| 166 | PlainText | ||||||||||||||||||||||||||||||||||||||||||
| 167 | URL_Keys | ||||||||||||||||||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 23 | @EXPORT_OK = qw( Show_Mode | |||||||||||||||||||||||||||||||||||||||||
| 171 | URL_Keys | ||||||||||||||||||||||||||||||||||||||||||
| 172 | Title_Formats | ||||||||||||||||||||||||||||||||||||||||||
| 173 | Data_Formats | ||||||||||||||||||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | # Some control variables -- the user may set these | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 23 | $Show_Mode = 'Box'; # one of: List, Table, Box, or HTML | |||||||||||||||||||||||||||||||||||||||||
| 179 | 23 | $List_Wrap_Margin = 10; # break words up to this long | |||||||||||||||||||||||||||||||||||||||||
| 180 | 23 | $Max_Table_Width = ''; # if defined, scale tables | |||||||||||||||||||||||||||||||||||||||||
| 181 | 23 | ▶ | $Max_List_Width = $ENV{'COLUMNS'} || 80; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'COLUMNS'} || 80
MC/DC0%0/1
$ENV{'COLUMNS'} || 80
$ENV{'COLUMNS'}
Truth table50%1/2
A
A= $ENV{'COLUMNS'}
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 23 | $No_Escape = ''; # escape by default | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 23 | %URL_Keys = (); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 23 | @Title_Formats = (); # formats for HTML formatting | |||||||||||||||||||||||||||||||||||||||||
| 186 | 23 | @Data_Formats = (); | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 23 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 23 | unshift(@INC, '.'); | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | sub ShowDatabases; | ||||||||||||||||||||||||||||||||||||||||||
| 193 | sub ShowTables; | ||||||||||||||||||||||||||||||||||||||||||
| 194 | sub ShowColumns; | ||||||||||||||||||||||||||||||||||||||||||
| 195 | sub ShowTable; | ||||||||||||||||||||||||||||||||||||||||||
| 196 | sub ShowRow; | ||||||||||||||||||||||||||||||||||||||||||
| 197 | sub PlainText; | ||||||||||||||||||||||||||||||||||||||||||
| 198 | sub htmltext; | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | sub get_params; | ||||||||||||||||||||||||||||||||||||||||||
| 201 | sub html_formats; | ||||||||||||||||||||||||||||||||||||||||||
| 202 | sub center; | ||||||||||||||||||||||||||||||||||||||||||
| 203 | sub max_length; | ||||||||||||||||||||||||||||||||||||||||||
| 204 | sub max; | ||||||||||||||||||||||||||||||||||||||||||
| 205 | sub out; | ||||||||||||||||||||||||||||||||||||||||||
| 206 | sub put; | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | =head1 MODULES | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | =head1 ShowTable | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | Format and display the contents of one or more rows of data. | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | S< >B<ShowTable> { I<parameter> => I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | S< >B<ShowTable> I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> | ||||||||||||||||||||||||||||||||||||||||||
| 217 | [, I<\&fmt_sub> [, I<$max_width> ] [, I<$show_mode> ] ]; | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | The B<ShowTable> subroutine displays tabular data aligned in columns, | ||||||||||||||||||||||||||||||||||||||||||
| 220 | with headers. B<ShowTable> supports four I<modes> of display: B<Box>, B<Table>, | ||||||||||||||||||||||||||||||||||||||||||
| 221 | B<List>, and B<HTML>. Each mode is described separately below. | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | The arguments to B<ShowTable> may be given in one of two ways: as a | ||||||||||||||||||||||||||||||||||||||||||
| 224 | hashed-array, or by a combination of fixed order arguments, and some | ||||||||||||||||||||||||||||||||||||||||||
| 225 | package-global variable settings. The hash-array parameters correspond | ||||||||||||||||||||||||||||||||||||||||||
| 226 | to the fixed arguments and the global-parameter settings. | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | In the list below, both the hash-array parameter name and the | ||||||||||||||||||||||||||||||||||||||||||
| 229 | fixed-order argument name is given as the value. In the case where | ||||||||||||||||||||||||||||||||||||||||||
| 230 | there is no fixed-order argument for a given parameter-value pair, then | ||||||||||||||||||||||||||||||||||||||||||
| 231 | the corresponding global variable name is given. | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | =over 10 | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | =item C<titles> => I<\@titles> | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | A reference to an array of column names, or titles. If a particular column name | ||||||||||||||||||||||||||||||||||||||||||
| 238 | is null, then the string C<Field_I<num>> is used by default. To have a column | ||||||||||||||||||||||||||||||||||||||||||
| 239 | have no title, use the empty string. | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | =item C<types> => I<\@types> | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | A reference to an array of types, one for each column. These types are | ||||||||||||||||||||||||||||||||||||||||||
| 244 | passed to the I<fmt_sub> for appropriate formatting. Also, if a column | ||||||||||||||||||||||||||||||||||||||||||
| 245 | type matches the regexp "C</text|char|string/i>", then the column | ||||||||||||||||||||||||||||||||||||||||||
| 246 | alignment will be left-justified, otherwise it will be right-justified. | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | =item C<widths> => I<\@widths> | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | A reference to an array of column widths, which may be given as an integer, or | ||||||||||||||||||||||||||||||||||||||||||
| 251 | as a string of the form: "I<width>.I<precision>". | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | =item C<row_sub> => I<\&row_sub> | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | A reference to a subroutine which successively returns rows of values in an array. | ||||||||||||||||||||||||||||||||||||||||||
| 256 | It is called for two purposes, each described separately: | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | * To fetch successive rows of data: | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | @row = &$row_sub(0); | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | When given a null, zero, or empty argument, the next row is returned. | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | * To initialize or rewind the data traversal. | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | $rewindable = &$row_sub(1); | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | When invoked with a non-null argument, the subroutine should rewind its | ||||||||||||||||||||||||||||||||||||||||||
| 269 | row pointer to start at the first row of data. If the data which | ||||||||||||||||||||||||||||||||||||||||||
| 270 | I<row_sub> is traversing is not rewindable, it must return zero or null. | ||||||||||||||||||||||||||||||||||||||||||
| 271 | If the data is rewindable, a non-null, non-zero value should be returned. | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | The I<row_sub> must expect to be invoked once with a non-null argument, | ||||||||||||||||||||||||||||||||||||||||||
| 274 | in order to discover whether or not the data is rewindable. If the data | ||||||||||||||||||||||||||||||||||||||||||
| 275 | cannot be rewound, I<row_sub> will thereafter only be called with a zero | ||||||||||||||||||||||||||||||||||||||||||
| 276 | argument. | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | Specifically, I<row_sub> subroutine is used in this manner: | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | $rewindable = &$row_sub(1); | ||||||||||||||||||||||||||||||||||||||||||
| 281 | if ($rewindable) { | ||||||||||||||||||||||||||||||||||||||||||
| 282 | while ((@row = &$row_sub(0)), $#row >= 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 283 | # examine lengths for optimal formatting | ||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | &$row_sub(1); # rewind | ||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | while ((@row = &$row_sub(0)), $#row >= 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 288 | # format the data | ||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | The consequence of data that is not rewindable, a reasonably nice table | ||||||||||||||||||||||||||||||||||||||||||
| 292 | will still be formatted, but it may contain fairly large amounts of | ||||||||||||||||||||||||||||||||||||||||||
| 293 | whitespace for wide columns. | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | =item C<fmtsub> => I<\&fmt_sub> | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | A reference to a subroutine which formats a value, according to its | ||||||||||||||||||||||||||||||||||||||||||
| 298 | type, width, precision, and the current column width. It is invoked | ||||||||||||||||||||||||||||||||||||||||||
| 299 | either with a fixed list of arguments, or with a hash-array of parameter | ||||||||||||||||||||||||||||||||||||||||||
| 300 | and value pairs. | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | $string = &fmt_sub { I<parameter> => I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | $string = &fmt_sub($value, $type, $max_width, $width, $precision) | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | If I<\&fmt_sub> is omitted, then a default subroutine, B<ShowTableValue>, | ||||||||||||||||||||||||||||||||||||||||||
| 307 | will be used, which will use Perl's standard string formatting rules. | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | The arguments to I<\&fmt_sub>, either as values passed in a fixed | ||||||||||||||||||||||||||||||||||||||||||
| 310 | order, or as part of the parameter value pair, are described in the | ||||||||||||||||||||||||||||||||||||||||||
| 311 | section on L<"ShowTableValue> below. | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | =item C<max_width> => I<number>, | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | The maximum table width, including the table formatting characters. If | ||||||||||||||||||||||||||||||||||||||||||
| 316 | not given, defaults to the global variable B<$Max_Table_Width>; | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | =item C<show_mode> => 'I<mode>', | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | The display mode of the output. One of five strings: C<'Box'>, | ||||||||||||||||||||||||||||||||||||||||||
| 321 | C<'Table'>, C<'Simple'>, C<'List'>, and C<'HTML'>. | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | ▶ | sub ShowTable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowTable: called CC=5 SCAR=18.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | my @argv = @_; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | local ($_,$titles,$types,$widths,$row_sub,$fmt_sub, | |||||||||||||||||||||||||||||||||||||||||
| 330 | $max_width, $show_mode, $wrap_margin, $url_keys, | ||||||||||||||||||||||||||||||||||||||||||
| 331 | $no_escape, $title_formats, $data_formats); | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 1 | my $args = | |||||||||||||||||||||||||||||||||||||||||
| 333 | get_params \@argv, | ||||||||||||||||||||||||||||||||||||||||||
| 334 | { titles => \$titles, | ||||||||||||||||||||||||||||||||||||||||||
| 335 | types => \$types, | ||||||||||||||||||||||||||||||||||||||||||
| 336 | widths => \$widths, | ||||||||||||||||||||||||||||||||||||||||||
| 337 | row_sub => \$row_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 338 | fmt_sub => \$fmt_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 339 | max_width => \$max_width, | ||||||||||||||||||||||||||||||||||||||||||
| 340 | show_mode => \$show_mode, | ||||||||||||||||||||||||||||||||||||||||||
| 341 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 342 | [qw(titles types widths row_sub fmt_sub max_width show_mode)]; | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | # Default mode is from $Show_Mode global | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | ▶ | $show_mode = $args->{'show_mode'} = $Show_Mode unless $show_mode ne ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 1 | $_ = $show_mode; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if (/List/i) { &ShowListTable($args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | elsif (/HTML/i) { &ShowHTMLTable($args); } | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | elsif (/Table/i) { &ShowSimpleTable($args); } | |||||||||||||||||||||||||||||||||||||||||
| 350 | 1 | else { &ShowBoxTable($args); } | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | =head1 ShowDatabases | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | Show a list of database names. | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | S< >B<ShowDatabases> I<\@dbnames>; | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | S< >B<ShowDatabases> { 'data' => I<\@dbnames>, I<parameter> => | ||||||||||||||||||||||||||||||||||||||||||
| 360 | I<value>, ...}; | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | B<ShowDatabases> is intended to be used to display a list of database | ||||||||||||||||||||||||||||||||||||||||||
| 363 | names, under the column heading of "Databases". It is a special case | ||||||||||||||||||||||||||||||||||||||||||
| 364 | usage of B<ShowTable> (and can thus be passed any parameter suitable | ||||||||||||||||||||||||||||||||||||||||||
| 365 | for B<ShowTable>. | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | The argument, I<\@dbnames>, is a reference to an array of strings, used | ||||||||||||||||||||||||||||||||||||||||||
| 368 | as the values of the single column display. | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | sub ShowDatabases { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowDatabases: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my @argv = @_; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | local $databases; | |||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my $args = get_params \@argv, {data => \$databases}, ['data']; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | $databases ne '' or croak "Missing array of databases.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | $args->{'titles'} = 'Databases' unless exists $args->{'titles'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $args->{'types'} = [ 'char' ]; | |||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $args->{'width'} = max_length $databases; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $args->{'lengths'} = $args->{'width'}; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | local( $current_row ) = 0; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | $args->{'row_sub'} = sub { &ShowRow( $_[0], \$current_row, $databases ); }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ShowTable $args; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | =head1 ShowTables | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | Show an array of table names. | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | S< >B<ShowTables> I<\@tblnames>; | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | S< >B<ShowTables> { 'data' => I<\@tblnames>, I<parameter> => I<value>, ...}; | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | B<ShowTables> is used to display a list of table names, under the column | ||||||||||||||||||||||||||||||||||||||||||
| 396 | heading of "Tables". It is a special case usage of B<ShowTable>, and can | ||||||||||||||||||||||||||||||||||||||||||
| 397 | be passed any L<"ShowTable"> argument parameter. | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | sub ShowTables { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowTables: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my @argv = @_; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | local $tables; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | my $args = get_params \@argv, {data => \$tables}, ['data']; | |||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | $tables ne '' or croak "Missing array of tables.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | $args->{'titles'} = 'Tables' unless exists $args->{'titles'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $args->{'types'} = 'char'; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $args->{'width'} = max_length $tables; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $args->{'lengths'} = $args->{'width'}; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | local( $current_row ) = 0; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | $args->{'row_sub'} = sub { &ShowRow( $_[0], \$current_row, $tables ); }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ShowTable $args; | |||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | =head1 ShowColumns | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | Display a table of column names, types, and attributes. | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | S< >B<ShowColumns> { I<parameter> => I<values>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | S< >B<ShowColumns> I<\@columns>, I<\@col_types>, I<\@col_lengths>, I<\@col_attrs>; | ||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | The B<ShowColumns> subroutine displays a table of column names, types, lengths, | ||||||||||||||||||||||||||||||||||||||||||
| 425 | and other attributes in a nicely formatted table. It is a special case usage | ||||||||||||||||||||||||||||||||||||||||||
| 426 | of B<ShowTable>, and can be passed any argument suitable for L<"ShowTable">; | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | The arguments are: | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | =over 10 | ||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | =item C<columns> = I<\@columns> | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | An array of column names. This provides the value for the first column | ||||||||||||||||||||||||||||||||||||||||||
| 435 | of the output. | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | =item C<col_types> = I<\@col_types> | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | An array of column types names. This provides the value for the second | ||||||||||||||||||||||||||||||||||||||||||
| 440 | column. | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | =item C<col_lengths> = I<\@col_lengths> | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | An array of maximum lengths for corresponding columns. This provides | ||||||||||||||||||||||||||||||||||||||||||
| 445 | the value for the third column of the output. | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | =item C<col_attrs> = I<\@col_attrs> | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | An array of column attributes array references (ie: an array of arrays). | ||||||||||||||||||||||||||||||||||||||||||
| 450 | The attributes array for the first column are at "I<$col_attrs>-\>[0]". | ||||||||||||||||||||||||||||||||||||||||||
| 451 | The first attribute of the second column is "I<$col_attrs>-\>[1][0]". | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | The columns, types, lengths, and attributes are displayed in a table | ||||||||||||||||||||||||||||||||||||||||||
| 456 | with the column headings: "Column", "Type", "Length", and "Attributes". | ||||||||||||||||||||||||||||||||||||||||||
| 457 | This is a special case usage of B<ShowTable>, and can be passed | ||||||||||||||||||||||||||||||||||||||||||
| 458 | additional arguments suitable for L<"ShowTable">. | ||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | sub ShowColumns { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowColumns: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | my @argv = @_; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | local ($col_names, $col_types, $col_lengths, $col_attributes); | |||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my $args = | |||||||||||||||||||||||||||||||||||||||||
| 466 | get_params | ||||||||||||||||||||||||||||||||||||||||||
| 467 | \@argv, | ||||||||||||||||||||||||||||||||||||||||||
| 468 | { col_names => \$col_names, | ||||||||||||||||||||||||||||||||||||||||||
| 469 | col_types => \$col_types, | ||||||||||||||||||||||||||||||||||||||||||
| 470 | col_lengths => \$col_lengths, | ||||||||||||||||||||||||||||||||||||||||||
| 471 | col_attributes => \$col_attributes, | ||||||||||||||||||||||||||||||||||||||||||
| 472 | },[qw(col_names col_types col_lengths col_attributes)]; | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | $col_names ne '' or croak "Missing array of column names.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | $col_types ne '' or croak "Missing array of column types.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | $col_lengths ne '' or croak "Missing array of column lengths.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | $col_attributes ne '' or croak "Missing array of column attributes.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | # setup the descriptor arrays | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | $args->{'titles'} = [ qw(Column Type Length Attributes) ]; | |||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | $args->{'types'} = [ qw(varchar varchar int varchar) ]; | |||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | # Do some data conversions before displaying | ||||||||||||||||||||||||||||||||||||||||||
| 484 | # Convert attribute array to a string of attributes | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | local @col_attrs = (); | |||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | my $i; | |||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | for ($i = 0; $i <= $#{$col_attributes}; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | $col_attrs[$i] = join(', ',@{$col_attributes->[$i]}); | |||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | # count the widths, to setup the Column name column width | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | $args->{'lengths'} = [ (max_length $col_names), (max_length $col_types), | |||||||||||||||||||||||||||||||||||||||||
| 493 | (max_length $col_lengths), (max_length \@col_attrs) ]; | ||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | local($current_row) = 0; | |||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | $args->{'row_sub'} = sub { &ShowRow($_[0], \$current_row, $col_names, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | $col_types, $col_lengths, \@col_attrs); }; | |||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | # Finally, show the darn thing | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ShowTable $args; | |||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | =head1 ShowBoxTable | ||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | Show tabular data in a box. | ||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | S< >B<ShowBoxTable> { I<parameter> = I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | S< >B<ShowBoxTable> I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> | ||||||||||||||||||||||||||||||||||||||||||
| 511 | S< >[, [ I<\&fmt_sub> ] [, I<$max_width> ] ]; | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | The B<ShowBoxTable> displays tabular data in titled columns using a "box" | ||||||||||||||||||||||||||||||||||||||||||
| 514 | of ASCII graphics, looking something like this: | ||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | +------------+----------+-----+----------+ | ||||||||||||||||||||||||||||||||||||||||||
| 518 | | Column1 | Column2 | ... | ColumnN | | ||||||||||||||||||||||||||||||||||||||||||
| 519 | +------------+----------+-----+----------+ | ||||||||||||||||||||||||||||||||||||||||||
| 520 | | Value11 | Value12 | ... | Value 1M | | ||||||||||||||||||||||||||||||||||||||||||
| 521 | | Value21 | Value22 | ... | Value 2M | | ||||||||||||||||||||||||||||||||||||||||||
| 522 | | Value31 | Value32 | ... | Value 3M | | ||||||||||||||||||||||||||||||||||||||||||
| 523 | | ... | ... | ... | ... | | ||||||||||||||||||||||||||||||||||||||||||
| 524 | | ValueN1 | ValueN2 | ... | Value NM | | ||||||||||||||||||||||||||||||||||||||||||
| 525 | +------------+----------+-----+----------+ | ||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | The arguments are the same as with L<"ShowTable">. If the I<@titles> array | ||||||||||||||||||||||||||||||||||||||||||
| 529 | is empty, the header row is omitted. | ||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | 38 | ▶ | sub ShowBoxTable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowBoxTable: called CC=17 SCAR=28.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 38 | my @argv = @_; | |||||||||||||||||||||||||||||||||||||||||
| 535 | 38 | local ($titles, $types, $col_widths, $row_sub, $fmt_sub, $max_width); | |||||||||||||||||||||||||||||||||||||||||
| 536 | 38 | my $args = | |||||||||||||||||||||||||||||||||||||||||
| 537 | get_params | ||||||||||||||||||||||||||||||||||||||||||
| 538 | \@argv, | ||||||||||||||||||||||||||||||||||||||||||
| 539 | { titles => \$titles, | ||||||||||||||||||||||||||||||||||||||||||
| 540 | types => \$types, | ||||||||||||||||||||||||||||||||||||||||||
| 541 | widths => \$col_widths, | ||||||||||||||||||||||||||||||||||||||||||
| 542 | row_sub => \$row_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 543 | fmtsub => \$fmt_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 544 | max_width => \$max_width, | ||||||||||||||||||||||||||||||||||||||||||
| 545 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 546 | [qw(titles types widths row_sub fmtsub max_width)]; | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | 38 | ▶ | $titles ne '' or croak "Missing column names array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 38 | ▶ | $types ne '' or croak "Missing column types array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 38 | ▶ | $col_widths ne '' or croak "Missing column width array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | 38 | ▶ | $row_sub ne '' or croak "Missing row subroutine.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 38 | ▶ | $fmt_sub = \&ShowTableValue if !defined($fmt_sub) || $fmt_sub eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $fmt_sub or $fmt_sub eq ""
MC/DC100%2/2
not defined $fmt_sub or $fmt_sub eq ""
not defined $fmt_sub
$fmt_sub eq ""
Truth table100%3/3
not(A) or B
A= not defined $fmt_subB= $fmt_sub eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | 38 | ▶ | $max_width = $Max_Table_Width if !defined($max_width) || $max_width eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $max_width or $max_width eq ""
MC/DC100%2/2
not defined $max_width or $max_width eq ""
not defined $max_width
$max_width eq ""
Truth table100%3/3
not(A) or B
A= not defined $max_widthB= $max_width eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 38 | my $rewindable = &$row_sub(1); # see if data is rewindable | |||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 38 | my ($num_cols, $widths, $precision, $max_widths) = | |||||||||||||||||||||||||||||||||||||||||
| 558 | &calc_widths($col_widths, $titles, $rewindable, | ||||||||||||||||||||||||||||||||||||||||||
| 559 | $row_sub, $fmt_sub, $types, 'box', $max_width); | ||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | 38 | my $width = 1; | |||||||||||||||||||||||||||||||||||||||||
| 562 | 38 | my $dashes = ' +'; | |||||||||||||||||||||||||||||||||||||||||
| 563 | 38 | my $title_line = ' |'; | |||||||||||||||||||||||||||||||||||||||||
| 564 | 38 | my $title; | |||||||||||||||||||||||||||||||||||||||||
| 565 | 38 | my $fmt = ' |'; # initial format string | |||||||||||||||||||||||||||||||||||||||||
| 566 | 38 | my $c; | |||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | # Compose the box header | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 38 | ▶ | for ($c = 0; $c < $num_cols; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | 173 | $width = $max_widths->[$c]; # get previously calculated max col width | |||||||||||||||||||||||||||||||||||||||||
| 571 | 173 | $width += 2; # account for a blank on either | |||||||||||||||||||||||||||||||||||||||||
| 572 | # side of each value | ||||||||||||||||||||||||||||||||||||||||||
| 573 | 173 | $dashes .= ('-' x $width); | |||||||||||||||||||||||||||||||||||||||||
| 574 | 173 | $dashes .= '+'; | |||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | 173 | ▶ | $title = $#$titles >= 0 && defined($titles->[$c]) ? $titles->[$c] : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$titles->$#* >= 0 and defined $titles->[$c]
MC/DC50%1/2
$titles->$#* >= 0 and defined $titles->[$c]
$titles->$#* >= 0
defined $titles->[$c]
Truth table66%2/3
A and B
A= $titles->$#* >= 0B= defined $titles->[$c]
| |||||||||||||||||||||||||||||||||||||||||||
| 577 | sprintf("Field_%d", $c+1); | ||||||||||||||||||||||||||||||||||||||||||
| 578 | 173 | $title_line .= center $title, $width; | |||||||||||||||||||||||||||||||||||||||||
| 579 | 173 | $title_line .= '|'; | |||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||
| 581 | 38 | out $dashes; | |||||||||||||||||||||||||||||||||||||||||
| 582 | 38 | ▶ | if ($#$titles >= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 583 | 37 | out $title_line; | |||||||||||||||||||||||||||||||||||||||||
| 584 | 37 | out $dashes; | |||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 38 | my @values; | |||||||||||||||||||||||||||||||||||||||||
| 588 | 38 | my @prefix = (" ", "<"); | |||||||||||||||||||||||||||||||||||||||||
| 589 | 38 | my @suffix = (" |", ">|"); | |||||||||||||||||||||||||||||||||||||||||
| 590 | 38 | my @cell; | |||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | # loop over the data, formatting it into cells, one row at a time. | ||||||||||||||||||||||||||||||||||||||||||
| 593 | 38 | ▶ | while ((@values = &$row_sub(0)), $#values >= $[) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | # first pass -- format each value into a string | ||||||||||||||||||||||||||||||||||||||||||
| 595 | 187 | @cell = (); | |||||||||||||||||||||||||||||||||||||||||
| 596 | 187 | ▶ | for ($c = 0; $c <= $#values; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 856 | $cell[$c] = &$fmt_sub($values[$c], $types->[$c], $max_widths->[$c], | |||||||||||||||||||||||||||||||||||||||||
| 598 | $widths->[$c], $precision->[$c], 'box'); | ||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||
| 600 | # second pass -- output each cell, wrapping if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 601 | 187 | my $will_wrap; | |||||||||||||||||||||||||||||||||||||||||
| 602 | 187 | my $wrapped = 0; | |||||||||||||||||||||||||||||||||||||||||
| 603 | 187 | ▶ | do { $will_wrap = 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | 464 | put " |"; # start a line | |||||||||||||||||||||||||||||||||||||||||
| 605 | 464 | ▶ | for ($c = 0; $c <= $#cell; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | 2175 | $will_wrap |= &putcell(\@cell, $c, $max_widths->[$c], | |||||||||||||||||||||||||||||||||||||||||
| 607 | \@prefix, \@suffix, $wrapped); | ||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||
| 609 | 464 | out ""; | |||||||||||||||||||||||||||||||||||||||||
| 610 | 464 | $wrapped++; | |||||||||||||||||||||||||||||||||||||||||
| 611 | } while ($will_wrap); | ||||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||
| 613 | 38 | out $dashes; | |||||||||||||||||||||||||||||||||||||||||
| 614 | 38 | out ""; | |||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | =head1 ShowSimpleTable | ||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | Display a table of data using a simple table format. | ||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | S< >B<ShowSimpleTable> I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> [, I<\&fmt_sub>]; | ||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | S< >B<ShowSimpleTable> { I<parameter> => I<values>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | The B<ShowSimpleTable> subroutine formats data into a simple table of | ||||||||||||||||||||||||||||||||||||||||||
| 627 | aligned columns, in the following example: | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | Column1 Column2 Column3 | ||||||||||||||||||||||||||||||||||||||||||
| 630 | ------- ------- ------- | ||||||||||||||||||||||||||||||||||||||||||
| 631 | Value1 Value2 Value3 | ||||||||||||||||||||||||||||||||||||||||||
| 632 | Value12 Value22 Value32 | ||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||
| 634 | Columns are auto-sized by the data's widths, plus two spaces between columns. | ||||||||||||||||||||||||||||||||||||||||||
| 635 | Values which are too long for the maximum colulmn width are wrapped within | ||||||||||||||||||||||||||||||||||||||||||
| 636 | the column. | ||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||
| 638 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||
| 640 | 37 | ▶ | sub ShowSimpleTable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowSimpleTable: called CC=16 SCAR=27.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 641 | 37 | my @argv = @_; | |||||||||||||||||||||||||||||||||||||||||
| 642 | 37 | local ($titles, $types, $col_widths, $row_sub, $fmt_sub, $max_width); | |||||||||||||||||||||||||||||||||||||||||
| 643 | 37 | my $args = | |||||||||||||||||||||||||||||||||||||||||
| 644 | get_params | ||||||||||||||||||||||||||||||||||||||||||
| 645 | \@argv, | ||||||||||||||||||||||||||||||||||||||||||
| 646 | { titles => \$titles, | ||||||||||||||||||||||||||||||||||||||||||
| 647 | types => \$types, | ||||||||||||||||||||||||||||||||||||||||||
| 648 | widths => \$col_widths, | ||||||||||||||||||||||||||||||||||||||||||
| 649 | row_sub => \$row_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 650 | fmtsub => \$fmt_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 651 | max_width => \$max_width, | ||||||||||||||||||||||||||||||||||||||||||
| 652 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 653 | [qw(titles types widths row_sub fmtsub max_width)]; | ||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||
| 655 | 37 | ▶ | $titles ne '' or croak "Missing column names array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 656 | 37 | ▶ | $types ne '' or croak "Missing column types array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 657 | 37 | ▶ | $col_widths ne '' or croak "Missing column width array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 37 | ▶ | $row_sub ne '' or croak "Missing row sub array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | 37 | ▶ | $fmt_sub = \&ShowTableValue if !defined($fmt_sub) || $fmt_sub eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $fmt_sub or $fmt_sub eq ""
MC/DC100%2/2
not defined $fmt_sub or $fmt_sub eq ""
not defined $fmt_sub
$fmt_sub eq ""
Truth table100%3/3
not(A) or B
A= not defined $fmt_subB= $fmt_sub eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 660 | 37 | ▶ | $max_width = $Max_Table_Width if !defined($max_width) || $max_width eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $max_width or $max_width eq ""
MC/DC100%2/2
not defined $max_width or $max_width eq ""
not defined $max_width
$max_width eq ""
Truth table100%3/3
not(A) or B
A= not defined $max_widthB= $max_width eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | 37 | my $rewindable = &$row_sub(1); # see if data is rewindable | |||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | 37 | my ($num_cols, $widths, $precision, $max_widths) = | |||||||||||||||||||||||||||||||||||||||||
| 665 | &calc_widths($col_widths, $titles, $rewindable, | ||||||||||||||||||||||||||||||||||||||||||
| 666 | $row_sub, $fmt_sub, $types, 'table', $max_width); | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | 37 | my $width = 1; | |||||||||||||||||||||||||||||||||||||||||
| 669 | 37 | my $dashes = ' '; | |||||||||||||||||||||||||||||||||||||||||
| 670 | 37 | my $title_line = ' '; | |||||||||||||||||||||||||||||||||||||||||
| 671 | 37 | my $title ; | |||||||||||||||||||||||||||||||||||||||||
| 672 | 37 | my $postfix = shift; | |||||||||||||||||||||||||||||||||||||||||
| 673 | 37 | my $c ; | |||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||
| 675 | # Calculate the maximum widths | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 37 | ▶ | for ($c = 0; $c < $num_cols; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 677 | 170 | $width = $max_widths->[$c]; | |||||||||||||||||||||||||||||||||||||||||
| 678 | 170 | $dashes .= ('-' x $width); | |||||||||||||||||||||||||||||||||||||||||
| 679 | 170 | $dashes .= ' '; | |||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||
| 681 | 170 | ▶ | next if $#$titles < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 682 | 170 | $title = center $titles->[$c], $width; | |||||||||||||||||||||||||||||||||||||||||
| 683 | 170 | $title_line .= $title; | |||||||||||||||||||||||||||||||||||||||||
| 684 | 170 | $title_line .= ' '; | |||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||||
| 687 | 37 | ▶ | out $title_line if $#$titles >= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 688 | 37 | out $dashes; | |||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | 37 | my @values; | |||||||||||||||||||||||||||||||||||||||||
| 691 | 37 | my @prefix = (" ", "<"); | |||||||||||||||||||||||||||||||||||||||||
| 692 | 37 | my @suffix = (" ", ">"); | |||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | 37 | ▶ | while ((@values = &$row_sub(0)), $#values >= $[) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | # first pass -- format each value into a string | ||||||||||||||||||||||||||||||||||||||||||
| 696 | 185 | my @cell; | |||||||||||||||||||||||||||||||||||||||||
| 697 | 185 | ▶ | for ($c = 0; $c <= $#values; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 698 | 850 | $cell[$c] = &$fmt_sub($values[$c], $types->[$c], $max_widths->[$c], | |||||||||||||||||||||||||||||||||||||||||
| 699 | $widths->[$c], $precision->[$c], 'table'); | ||||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||
| 701 | # second pass -- output each cell, wrapping if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 702 | 185 | my $will_wrap; | |||||||||||||||||||||||||||||||||||||||||
| 703 | 185 | my $wrapped = 0; | |||||||||||||||||||||||||||||||||||||||||
| 704 | 185 | ▶ | do { $will_wrap = 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 705 | 391 | ▶ | for ($c = 0; $c <= $#cell; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 706 | 1814 | $will_wrap |= &putcell(\@cell, $c, $max_widths->[$c], | |||||||||||||||||||||||||||||||||||||||||
| 707 | \@prefix, \@suffix, $wrapped); | ||||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||
| 709 | 391 | out ""; | |||||||||||||||||||||||||||||||||||||||||
| 710 | 391 | $wrapped++; | |||||||||||||||||||||||||||||||||||||||||
| 711 | } while ($will_wrap); | ||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||
| 713 | 37 | out ""; | |||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | =head1 ShowHTMLTable | ||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | Display a table of data nicely using HTML tables. | ||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | S< >B<ShowHTMLTable> { I<parameter> => I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||
| 722 | S< >B<ShowHTMLTable> I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> | ||||||||||||||||||||||||||||||||||||||||||
| 723 | [, I<\&fmt_sub> [, I<$max_width> [, I<\%URL_Keys> [, I<$no_escape> | ||||||||||||||||||||||||||||||||||||||||||
| 724 | [, I<\@title_formats> [, I<\@data_formats> [, I<$table_attrs> ] ] ] ] ] ] ]; | ||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||
| 726 | The B<ShowHTMLTable> displays one or more rows of columns of data using | ||||||||||||||||||||||||||||||||||||||||||
| 727 | the HTML C<\<TABLE\>> feature. In addition to the usual parameter arguments | ||||||||||||||||||||||||||||||||||||||||||
| 728 | of L<"ShowTable">, the following parameter arguments are defined: | ||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||
| 730 | =over 10 | ||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||
| 732 | =item C<url_keys> => I<\%URL_Keys>, | ||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||
| 734 | This is a hash array of column names (titles) and corresponding base | ||||||||||||||||||||||||||||||||||||||||||
| 735 | URLs. The values of any column names or indexes occuring as keys in | ||||||||||||||||||||||||||||||||||||||||||
| 736 | the hash array will be generated as hypertext anchors using the | ||||||||||||||||||||||||||||||||||||||||||
| 737 | associated I<printf>-like string as the base URL. Either the column name | ||||||||||||||||||||||||||||||||||||||||||
| 738 | or the column index (beginning with 1) may be used as the hash key. | ||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||
| 740 | In the string value, these macros can be substituted: | ||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||
| 742 | "C<%K>" is replaced with the column name. | ||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||
| 744 | "C<%V>" is replaced with the column value; | ||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||
| 746 | "C<%I>" is replaced with the column index. | ||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||
| 748 | For example, if we define the array: | ||||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||
| 750 | $base_url = "http://www.$domain/cgi/lookup?col=%K?val=%V"; | ||||||||||||||||||||||||||||||||||||||||||
| 751 | %url_cols = ('Author' => $base_url, | ||||||||||||||||||||||||||||||||||||||||||
| 752 | 'Name' => $base_url); | ||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | Then, the values in the C<Author> column will be generated with the following | ||||||||||||||||||||||||||||||||||||||||||
| 755 | HTML text: | ||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||
| 757 | <A HREF="http://www.$domain/cgi/lookup?col=Author?val=somevalue>somevalue</A> | ||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||
| 759 | and the values in the C<Name> column will be generated with the URL: | ||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | <A HREF="http://www.$domain/cgi/lookup?col=Name?val=othervalue>othervalue</A> | ||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||
| 763 | If this variable is not given, it will default to the global variable | ||||||||||||||||||||||||||||||||||||||||||
| 764 | C<\%URL_Keys>. | ||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | =item C<no_escape> => I<boolean>, | ||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | Unless B<$no_escape> is set, HTML-escaping is performed on the data | ||||||||||||||||||||||||||||||||||||||||||
| 769 | values in order to properly display the special HTML formatting | ||||||||||||||||||||||||||||||||||||||||||
| 770 | characters : '\<', '\>', and '&'. If you wish to display data with | ||||||||||||||||||||||||||||||||||||||||||
| 771 | embedded HTML text, you must set B<$no_escape>. | ||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||
| 773 | Enabling embedded HTML, turns on certain heuristics which enable the | ||||||||||||||||||||||||||||||||||||||||||
| 774 | user to more completely define appearance of the table. For instance, | ||||||||||||||||||||||||||||||||||||||||||
| 775 | any C<\<TR\>> tokens found embedded *anywhere* within a row of data will | ||||||||||||||||||||||||||||||||||||||||||
| 776 | be placed at the front of the row, within the generated C<\<TR\>>. | ||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||
| 778 | Similarly, a row of data containing the C<\<THEAD\>> or C<\<TFOOT\>> | ||||||||||||||||||||||||||||||||||||||||||
| 779 | tokens, and their closing counterparts, will begin and end, respectively | ||||||||||||||||||||||||||||||||||||||||||
| 780 | a table header or footer data. | ||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||
| 782 | =item C<title_formats> => I<\@title_formats>, | ||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | =item C<tformats> => I<\@title_formats>, | ||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | An array of HTML formatting elements for the column titles, one for each | ||||||||||||||||||||||||||||||||||||||||||
| 787 | column. Each array element is a list of one or more HTML elements, | ||||||||||||||||||||||||||||||||||||||||||
| 788 | given as C<\<ELEMENT\>> or plainly, C<ELEMENT>, and separated by a comma | ||||||||||||||||||||||||||||||||||||||||||
| 789 | C<','>, semi-colon C<';'>, or vertical bar C<'|'>. Each given HTML | ||||||||||||||||||||||||||||||||||||||||||
| 790 | element is prepended to the corresponding column title, in the order | ||||||||||||||||||||||||||||||||||||||||||
| 791 | given. The corresponding HTML closing elements are appended in the | ||||||||||||||||||||||||||||||||||||||||||
| 792 | opposite order. | ||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | For example, if I<\@title_formats> contains the two elements: | ||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||
| 796 | [ 'FONT SIZE=+2,BOLD', 'FONT COLOR=red,EM' ] | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | then the text output for the title of the first column would be: | ||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | <FONT SIZE=+2><BOLD>I<column_1_title></BOLD></FONT> | ||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||
| 802 | If C<title_formats> is omitted, the global variable B<@Title_Formats> | ||||||||||||||||||||||||||||||||||||||||||
| 803 | is used by default. | ||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||
| 805 | =item C<data_formats> => I<\@data_formats>, | ||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||
| 807 | =item C<dformats> => I<\@data_formats>, | ||||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||
| 809 | Similar to C<title_formats>, this array provides HTML formatting for | ||||||||||||||||||||||||||||||||||||||||||
| 810 | the columns of each row of data. If C<data_formats> is omitted or | ||||||||||||||||||||||||||||||||||||||||||
| 811 | null, then the global variable B<\@Data_Formats> is used by default. | ||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | =item C<table_attrs> => I<$table_attrs>, | ||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||
| 815 | This variable defines a string of attributes to be inserted within the | ||||||||||||||||||||||||||||||||||||||||||
| 816 | C<\<TABLE\>> token. For example, if the user wishes to have no table | ||||||||||||||||||||||||||||||||||||||||||
| 817 | border: | ||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | ShowHTMLTable { | ||||||||||||||||||||||||||||||||||||||||||
| 820 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 821 | table_attrs => 'BORDER=0', | ||||||||||||||||||||||||||||||||||||||||||
| 822 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 823 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||
| 825 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||
| 827 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | 49 | ▶ | sub ShowHTMLTable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowHTMLTable: called CC=51 SCAR=39.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 830 | 49 | my @argv = @_; | |||||||||||||||||||||||||||||||||||||||||
| 831 | 49 | local ($titles, $types, $col_widths, $row_sub, $fmt_sub, $max_width, | |||||||||||||||||||||||||||||||||||||||||
| 832 | $url_keys, $no_escape, $title_formats, $data_formats, | ||||||||||||||||||||||||||||||||||||||||||
| 833 | $show_mode, $table_attrs); | ||||||||||||||||||||||||||||||||||||||||||
| 834 | 49 | my $args = | |||||||||||||||||||||||||||||||||||||||||
| 835 | get_params | ||||||||||||||||||||||||||||||||||||||||||
| 836 | \@argv, | ||||||||||||||||||||||||||||||||||||||||||
| 837 | { titles => \$titles, | ||||||||||||||||||||||||||||||||||||||||||
| 838 | types => \$types, | ||||||||||||||||||||||||||||||||||||||||||
| 839 | widths => \$col_widths, | ||||||||||||||||||||||||||||||||||||||||||
| 840 | row_sub => \$row_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 841 | fmtsub => \$fmt_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 842 | max_width => \$max_width, | ||||||||||||||||||||||||||||||||||||||||||
| 843 | url_keys => \$url_keys, | ||||||||||||||||||||||||||||||||||||||||||
| 844 | no_escape => \$no_escape, | ||||||||||||||||||||||||||||||||||||||||||
| 845 | tformats => \$title_formats, | ||||||||||||||||||||||||||||||||||||||||||
| 846 | dformats => \$data_formats, | ||||||||||||||||||||||||||||||||||||||||||
| 847 | table_attrs => \$table_attrs, | ||||||||||||||||||||||||||||||||||||||||||
| 848 | data_formats => 'tformats', | ||||||||||||||||||||||||||||||||||||||||||
| 849 | title_formats => 'tformats', | ||||||||||||||||||||||||||||||||||||||||||
| 850 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 851 | [qw(titles types widths row_sub fmtsub max_width | ||||||||||||||||||||||||||||||||||||||||||
| 852 | url_keys no_escape title_formats data_formats | ||||||||||||||||||||||||||||||||||||||||||
| 853 | table_attrs)]; | ||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||
| 855 | 49 | ▶ | $titles ne '' or croak "Missing column names array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 856 | 49 | ▶ | $types ne '' or croak "Missing column types array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 857 | 49 | ▶ | $col_widths ne '' or croak "Missing column width array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 858 | 49 | ▶ | $row_sub ne '' or croak "Missing row sub array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||
| 860 | # Defaults | ||||||||||||||||||||||||||||||||||||||||||
| 861 | 49 | ▶ | $fmt_sub = \&ShowTableValue if !defined($fmt_sub) || $fmt_sub eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $fmt_sub or $fmt_sub eq ""
MC/DC100%2/2
not defined $fmt_sub or $fmt_sub eq ""
not defined $fmt_sub
$fmt_sub eq ""
Truth table100%3/3
not(A) or B
A= not defined $fmt_subB= $fmt_sub eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 862 | 49 | ▶ | $max_width = $Max_Table_Width if !defined($max_width) || $max_width eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $max_width or $max_width eq ""
MC/DC100%2/2
not defined $max_width or $max_width eq ""
not defined $max_width
$max_width eq ""
Truth table100%3/3
not(A) or B
A= not defined $max_widthB= $max_width eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 863 | 49 | ▶ | $url_keys = \%URL_Keys if !defined($url_keys) || $url_keys eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $url_keys or $url_keys eq ""
MC/DC100%2/2
not defined $url_keys or $url_keys eq ""
not defined $url_keys
$url_keys eq ""
Truth table100%3/3
not(A) or B
A= not defined $url_keysB= $url_keys eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 864 | 49 | ▶ | $title_formats = \@Title_Formats if !defined($title_formats) || $title_formats eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $title_formats or $title_formats eq ""
MC/DC100%2/2
not defined $title_formats or $title_formats eq ""
not defined $title_formats
$title_formats eq ""
Truth table100%3/3
not(A) or B
A= not defined $title_formatsB= $title_formats eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 865 | 49 | ▶ | $data_formats = \@Data_Formats if !defined($data_formats) || $data_formats eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $data_formats or $data_formats eq ""
MC/DC50%1/2
not defined $data_formats or $data_formats eq ""
not defined $data_formats
$data_formats eq ""
Truth table66%2/3
not(A) or B
A= not defined $data_formatsB= $data_formats eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 866 | 49 | ▶ | $no_escape = $No_Escape if !defined($no_escape); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | 49 | my $rewindable = &$row_sub(1); # see if rewindable | |||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | 49 | my ($num_cols, $widths, $precision, $max_widths) = | |||||||||||||||||||||||||||||||||||||||||
| 871 | &calc_widths($col_widths, $titles, $rewindable, | ||||||||||||||||||||||||||||||||||||||||||
| 872 | $row_sub, $fmt_sub, $types, 'html', $max_width); | ||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||
| 874 | 49 | my $width = 1; | |||||||||||||||||||||||||||||||||||||||||
| 875 | 49 | my $total_width = 0; | |||||||||||||||||||||||||||||||||||||||||
| 876 | 49 | my $title_line = ''; | |||||||||||||||||||||||||||||||||||||||||
| 877 | 49 | my $title; | |||||||||||||||||||||||||||||||||||||||||
| 878 | 49 | my ($c,$x); | |||||||||||||||||||||||||||||||||||||||||
| 879 | 49 | my ($tprefixes,$tsuffixes,$dprefixes,$dsuffixes); | |||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||
| 881 | # prepare the HTML prefixes and suffixes, if any | ||||||||||||||||||||||||||||||||||||||||||
| 882 | 49 | ▶ | ($tprefixes,$tsuffixes) = html_formats $title_formats | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $title_formats and $title_formats ne ""
MC/DC0%0/2
defined $title_formats and $title_formats ne ""
defined $title_formats
$title_formats ne ""
Truth table33%1/3
A and B
A= defined $title_formatsB= $title_formats ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 883 | if defined($title_formats) && $title_formats ne ''; | ||||||||||||||||||||||||||||||||||||||||||
| 884 | 49 | ▶ | ($dprefixes,$dsuffixes) = html_formats $data_formats | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $data_formats and $data_formats ne ""
MC/DC0%0/2
defined $data_formats and $data_formats ne ""
defined $data_formats
$data_formats ne ""
Truth table33%1/3
A and B
A= defined $data_formatsB= $data_formats ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 885 | if defined($data_formats) && $data_formats ne ''; | ||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||
| 887 | 49 | ▶ | if ($table_attrs) { # any table attributes? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 888 | 4 | local($_) = $table_attrs; | |||||||||||||||||||||||||||||||||||||||||
| 889 | 4 | ▶ | $table_attrs .= ' BORDER=1' unless /\bBORDER=/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 890 | 4 | ▶ | $table_attrs .= ' CELLPADDING=1' unless /\bCELLPADDING=/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 891 | 4 | ▶ | $table_attrs .= ' CELLSPACING=1' unless /\bCELLSPACING=/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 892 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 893 | 45 | $table_attrs = 'BORDER=2 CELLPADDING=1 CELLSPACING=1'; | |||||||||||||||||||||||||||||||||||||||||
| 894 | } | ||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||
| 896 | 49 | out "<TABLE $table_attrs>\n<TR>" ; | |||||||||||||||||||||||||||||||||||||||||
| 897 | 49 | ▶ | map { $total_width += defined($_) ? $_ : 0; } @$max_widths; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 898 | 49 | ▶ | for ($c = 0; $c < $num_cols; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 899 | # If the user specified a width, then use it. | ||||||||||||||||||||||||||||||||||||||||||
| 900 | 230 | ▶ | $width = defined($widths->[$c]) ? $widths->[$c] : $max_widths->[$c]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 901 | 230 | my $pct_width = int(100 * $width/$total_width); | |||||||||||||||||||||||||||||||||||||||||
| 902 | 230 | $title_line .= " <TH ALIGN=CENTER WIDTH=$pct_width%%>"; | |||||||||||||||||||||||||||||||||||||||||
| 903 | 230 | ▶ | if ($#$titles >= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 904 | 230 | ▶ | if (($x = $#$tprefixes) >= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 905 | 10 | ▶ | $title_line .= $tprefixes->[$c > $x ? $x : $c]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||||
| 907 | 230 | ▶ | $title_line .= $no_escape ? $titles->[$c] : &htmltext($titles->[$c]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 908 | 230 | ▶ | if (($x = $#$tsuffixes) >= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 909 | 10 | ▶ | $title_line .= $tsuffixes->[$c > $x ? $x : $c]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 910 | } | ||||||||||||||||||||||||||||||||||||||||||
| 911 | } | ||||||||||||||||||||||||||||||||||||||||||
| 912 | 230 | $title_line .= "</TH>\n"; | |||||||||||||||||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||||||||||||||||
| 914 | 49 | out $title_line; | |||||||||||||||||||||||||||||||||||||||||
| 915 | 49 | out "</TR>"; | |||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||
| 917 | 49 | my ($href, $key, $val, $out); | |||||||||||||||||||||||||||||||||||||||||
| 918 | 49 | ▶ | while ((@values = &$row_sub(0)), $#values >= $[) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 919 | 245 | out "<TR> "; | |||||||||||||||||||||||||||||||||||||||||
| 920 | # Walk through the values | ||||||||||||||||||||||||||||||||||||||||||
| 921 | 245 | ▶ | for ($c = 0; $c <= $#values; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 922 | 1150 | $out = "<TD"; | |||||||||||||||||||||||||||||||||||||||||
| 923 | 1150 | ▶ | if (defined($val = $values[$c])) { # only worry about defined values | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 924 | # In HTML mode, all CHAR, TEXT, SYMBOL, or STRING data should | ||||||||||||||||||||||||||||||||||||||||||
| 925 | # be escaped to protect HTML syntax "<", ">", "\", and "&". | ||||||||||||||||||||||||||||||||||||||||||
| 926 | 1150 | ▶ | if ($types->[$c] =~ /char|text|symbol|string/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 927 | 710 | ▶ | $val = &htmltext($val) unless $no_escape; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 928 | 710 | $out .= " ALIGN=LEFT"; | |||||||||||||||||||||||||||||||||||||||||
| 929 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 930 | 440 | $out .= " ALIGN=RIGHT"; | |||||||||||||||||||||||||||||||||||||||||
| 931 | } | ||||||||||||||||||||||||||||||||||||||||||
| 932 | 1150 | $out .= ">"; | |||||||||||||||||||||||||||||||||||||||||
| 933 | # Discover if either the column name or column index | ||||||||||||||||||||||||||||||||||||||||||
| 934 | # have been mapped to a URL. | ||||||||||||||||||||||||||||||||||||||||||
| 935 | 1150 | $href = ''; | |||||||||||||||||||||||||||||||||||||||||
| 936 | 1150 | ▶ | foreach $key ( $#$titles >= 0 && &PlainText($titles->[$c]), | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$titles->$#* >= 0 && &PlainText($titles->[$c])
MC/DC0%0/2
$titles->$#* >= 0 && &PlainText($titles->[$c])
$titles->$#* >= 0
&PlainText($titles->[$c])
Truth table33%1/3
A && B
A= $titles->$#* >= 0B= &PlainText($titles->[$c])
| |||||||||||||||||||||||||||||||||||||||||||
| 937 | sprintf("%d", $c+1)) { | ||||||||||||||||||||||||||||||||||||||||||
| 938 | 2255 | ▶ | next unless $key ne '' && defined($url_keys->{$key}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key ne "" and defined $url_keys->{$key}
MC/DC50%1/2
$key ne "" and defined $url_keys->{$key}
$key ne ""
defined $url_keys->{$key}
Truth table66%2/3
A and B
A= $key ne ""B= defined $url_keys->{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 939 | 45 | $href = $url_keys->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 940 | 45 | last; | |||||||||||||||||||||||||||||||||||||||||
| 941 | } | ||||||||||||||||||||||||||||||||||||||||||
| 942 | 1150 | ▶ | if ($href ne '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 943 | 45 | ▶ | if ($href =~ /%K/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 944 | 30 | my $s = &htmltext(&PlainText($titles->[$c]), 1); | |||||||||||||||||||||||||||||||||||||||||
| 945 | 30 | $href =~ s/%K/$s/g; | |||||||||||||||||||||||||||||||||||||||||
| 946 | } | ||||||||||||||||||||||||||||||||||||||||||
| 947 | 45 | ▶ | if ($href =~ /%V/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 948 | 45 | my $s = &htmltext($val, 1); | |||||||||||||||||||||||||||||||||||||||||
| 949 | 45 | $href =~ s/%V/$s/g; | |||||||||||||||||||||||||||||||||||||||||
| 950 | } | ||||||||||||||||||||||||||||||||||||||||||
| 951 | 45 | ▶ | if ($href =~ /%I/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 952 | 20 | my $s = sprintf("%d", $c+1); | |||||||||||||||||||||||||||||||||||||||||
| 953 | 20 | $href =~ s/%I/$s/g; | |||||||||||||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||||||||||||
| 955 | 45 | $out .= sprintf("<A HREF=\"%s\">",$href); | |||||||||||||||||||||||||||||||||||||||||
| 956 | } | ||||||||||||||||||||||||||||||||||||||||||
| 957 | 1150 | $val = &$fmt_sub($val, $types->[$c], 0, $widths->[$c], | |||||||||||||||||||||||||||||||||||||||||
| 958 | $precision->[$c], 'html'); | ||||||||||||||||||||||||||||||||||||||||||
| 959 | 1150 | $val =~ s/^\s+//; # don't try to align | |||||||||||||||||||||||||||||||||||||||||
| 960 | 1150 | $val =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||||||
| 962 | 1150 | ▶ | if (($x = $#$dprefixes) >= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 963 | 125 | ▶ | $out .= $dprefixes->[$c > $x ? $x : $c]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||||||||||||
| 965 | 1150 | $out .= $val; | |||||||||||||||||||||||||||||||||||||||||
| 966 | 1150 | ▶ | if (($x = $#$dsuffixes) >= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 967 | 125 | ▶ | $out .= $dsuffixes->[$c > $x ? $x : $c]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 968 | } | ||||||||||||||||||||||||||||||||||||||||||
| 969 | 1150 | ▶ | $out .= "</A>" if $href; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 970 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 971 | 0 | $out .= ">"; | |||||||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||||||
| 973 | 1150 | $out .= "</TD>"; | |||||||||||||||||||||||||||||||||||||||||
| 974 | 1150 | out $out; | |||||||||||||||||||||||||||||||||||||||||
| 975 | } | ||||||||||||||||||||||||||||||||||||||||||
| 976 | 245 | out "</TR>"; | |||||||||||||||||||||||||||||||||||||||||
| 977 | } | ||||||||||||||||||||||||||||||||||||||||||
| 978 | 49 | out "</TABLE>"; | |||||||||||||||||||||||||||||||||||||||||
| 979 | } | ||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||
| 981 | =head1 ShowListTable | ||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||
| 983 | Display a table of data using a list format. | ||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||
| 985 | S< >B<ShowListTable> { I<parameter> => I<value>, ... }; | ||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||
| 987 | S< >B<ShowListTable> I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> | ||||||||||||||||||||||||||||||||||||||||||
| 988 | [, I<\&fmt_sub> [, I<$max_width> [, I<$wrap_margin> ] ] ]; | ||||||||||||||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||||||||||||||
| 990 | The arguments for B<ShowListTable> are the same as for L<"ShowTable">, | ||||||||||||||||||||||||||||||||||||||||||
| 991 | except for those described next. | ||||||||||||||||||||||||||||||||||||||||||
| 992 | |||||||||||||||||||||||||||||||||||||||||||
| 993 | =over 10 | ||||||||||||||||||||||||||||||||||||||||||
| 994 | |||||||||||||||||||||||||||||||||||||||||||
| 995 | =item C<max_width> = I<number>, | ||||||||||||||||||||||||||||||||||||||||||
| 996 | |||||||||||||||||||||||||||||||||||||||||||
| 997 | =item C<wrap_margin> = I<number>, | ||||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||
| 999 | Lines are truncated, and wrapped when their length exceeds | ||||||||||||||||||||||||||||||||||||||||||
| 1000 | I<$max_width>. Wrapping is done on a word-basis, unless the resulting | ||||||||||||||||||||||||||||||||||||||||||
| 1001 | right margin exceeds I<$wrap_margin>, in which case the line is simply | ||||||||||||||||||||||||||||||||||||||||||
| 1002 | truncated at the I<$max_width> limit. | ||||||||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||||||||
| 1004 | The I<$max_width> variable defaults to B<$Max_List_Width>. The | ||||||||||||||||||||||||||||||||||||||||||
| 1005 | I<$wrap_margin> defaults to B<$List_Wrap_Margin>. | ||||||||||||||||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||||||||||||||||
| 1007 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||||||||||||||||
| 1009 | In I<List> mode, columns (called "fields" in List mode) are displayed | ||||||||||||||||||||||||||||||||||||||||||
| 1010 | wth a field name and value pair per line, with records being one or | ||||||||||||||||||||||||||||||||||||||||||
| 1011 | more fields . In other words, the output of a table would | ||||||||||||||||||||||||||||||||||||||||||
| 1012 | look something like this: | ||||||||||||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||||||||||||
| 1014 | Field1_1: Value1_1 | ||||||||||||||||||||||||||||||||||||||||||
| 1015 | Field1_2: Value1_2 | ||||||||||||||||||||||||||||||||||||||||||
| 1016 | Field1_3: Value1_3 | ||||||||||||||||||||||||||||||||||||||||||
| 1017 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 1018 | Field1-N: Value1_M | ||||||||||||||||||||||||||||||||||||||||||
| 1019 | <empty line> | ||||||||||||||||||||||||||||||||||||||||||
| 1020 | Field2_1: Value2_1 | ||||||||||||||||||||||||||||||||||||||||||
| 1021 | Field2_2: Value2_2 | ||||||||||||||||||||||||||||||||||||||||||
| 1022 | Field2_3: Value2_3 | ||||||||||||||||||||||||||||||||||||||||||
| 1023 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 1024 | Field2_N: Value2_N | ||||||||||||||||||||||||||||||||||||||||||
| 1025 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 1026 | FieldM_1: ValueM_1 | ||||||||||||||||||||||||||||||||||||||||||
| 1027 | FieldM_2: ValueM_2 | ||||||||||||||||||||||||||||||||||||||||||
| 1028 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 1029 | FieldM_N: ValueM_N | ||||||||||||||||||||||||||||||||||||||||||
| 1030 | <empty line> | ||||||||||||||||||||||||||||||||||||||||||
| 1031 | <empty line> | ||||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||
| 1033 | Characteristics of I<List> mode: | ||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||
| 1035 | =over 10 | ||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||
| 1037 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||
| 1039 | two empty lines indicate the end of data. | ||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||
| 1041 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||
| 1043 | An empty field (column) may be omitted, or may have a label, but no | ||||||||||||||||||||||||||||||||||||||||||
| 1044 | data. | ||||||||||||||||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||||||||||||||||
| 1046 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||||||||||||||||
| 1048 | A long line can be continue by a null field (column): | ||||||||||||||||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||||||||||||||||
| 1050 | Field2: blah blah blah | ||||||||||||||||||||||||||||||||||||||||||
| 1051 | : blah blah blah | ||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||
| 1053 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||||||||||
| 1055 | On a continuation, the null field is an arbitrary number of leading | ||||||||||||||||||||||||||||||||||||||||||
| 1056 | white space, a colon ':', a single blank or tab, followed by the | ||||||||||||||||||||||||||||||||||||||||||
| 1057 | continued text. | ||||||||||||||||||||||||||||||||||||||||||
| 1058 | |||||||||||||||||||||||||||||||||||||||||||
| 1059 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||||||||||||||||
| 1061 | Embedded newlines are indicated by the escape mechanism "\n". | ||||||||||||||||||||||||||||||||||||||||||
| 1062 | Similarly, embedded tabs are indicated with "\t", returns with "\r". | ||||||||||||||||||||||||||||||||||||||||||
| 1063 | |||||||||||||||||||||||||||||||||||||||||||
| 1064 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 1065 | |||||||||||||||||||||||||||||||||||||||||||
| 1066 | If the I<@titles> array is empty, the field names "C<Field_>I<NN>" are used | ||||||||||||||||||||||||||||||||||||||||||
| 1067 | instead. | ||||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||
| 1069 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||
| 1071 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||
| 1073 | 37 | ▶ | sub ShowListTable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowListTable: called CC=23 SCAR=34.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1074 | 37 | my @argv = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1075 | 37 | local ($titles, $types, $col_widths, $row_sub, $fmt_sub, $max_width, | |||||||||||||||||||||||||||||||||||||||||
| 1076 | $wrap_margin); | ||||||||||||||||||||||||||||||||||||||||||
| 1077 | 37 | my $args = | |||||||||||||||||||||||||||||||||||||||||
| 1078 | get_params | ||||||||||||||||||||||||||||||||||||||||||
| 1079 | \@argv, | ||||||||||||||||||||||||||||||||||||||||||
| 1080 | { titles => \$titles, | ||||||||||||||||||||||||||||||||||||||||||
| 1081 | types => \$types, | ||||||||||||||||||||||||||||||||||||||||||
| 1082 | widths => \$col_widths, | ||||||||||||||||||||||||||||||||||||||||||
| 1083 | row_sub => \$row_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 1084 | fmtsub => \$fmt_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 1085 | max_width => \$max_width, | ||||||||||||||||||||||||||||||||||||||||||
| 1086 | wrap_margin => \$wrap_margin, | ||||||||||||||||||||||||||||||||||||||||||
| 1087 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1088 | [qw(titles types widths row_sub fmt_sub max_width wrap_margin)]; | ||||||||||||||||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||||||||||||||||
| 1090 | 37 | ▶ | defined($titles) && $titles ne '' or croak "Missing column names array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $titles and $titles ne ""
MC/DC0%0/2
defined $titles and $titles ne ""
defined $titles
$titles ne ""
Truth table33%1/3
A and B
A= defined $titlesB= $titles ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1091 | 37 | ▶ | defined($types) && $types ne '' or croak "Missing column types array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $types and $types ne ""
MC/DC0%0/2
defined $types and $types ne ""
defined $types
$types ne ""
Truth table33%1/3
A and B
A= defined $typesB= $types ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1092 | 37 | ▶ | defined($col_widths) && $col_widths ne '' or croak "Missing column width array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $col_widths and $col_widths ne ""
MC/DC0%0/2
defined $col_widths and $col_widths ne ""
defined $col_widths
$col_widths ne ""
Truth table33%1/3
A and B
A= defined $col_widthsB= $col_widths ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1093 | 37 | ▶ | defined($row_sub) && $row_sub ne '' or croak "Missing row sub array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $row_sub and $row_sub ne ""
MC/DC0%0/2
defined $row_sub and $row_sub ne ""
defined $row_sub
$row_sub ne ""
Truth table33%1/3
A and B
A= defined $row_subB= $row_sub ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||||||||||||||||
| 1095 | 37 | ▶ | $fmt_sub = \&ShowTableValue if !defined($fmt_sub) || $fmt_sub eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $fmt_sub or $fmt_sub eq ""
MC/DC0%0/2
not defined $fmt_sub or $fmt_sub eq ""
not defined $fmt_sub
$fmt_sub eq ""
Truth table33%1/3
not(A) or B
A= not defined $fmt_subB= $fmt_sub eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1096 | 37 | ▶ | $max_width = $Max_List_Width if !defined($max_width) || $max_width eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $max_width or $max_width eq ""
MC/DC100%2/2
not defined $max_width or $max_width eq ""
not defined $max_width
$max_width eq ""
Truth table100%3/3
not(A) or B
A= not defined $max_widthB= $max_width eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1097 | 37 | ▶ | $wrap_margin = $List_Wrap_Margin if !defined($wrap_margin) || $wrap_margin eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $wrap_margin or $wrap_margin eq ""
MC/DC0%0/2
not defined $wrap_margin or $wrap_margin eq ""
not defined $wrap_margin
$wrap_margin eq ""
Truth table66%2/3
not(A) or B
A= not defined $wrap_marginB= $wrap_margin eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||
| 1099 | 37 | my $rewindable = &$row_sub(1); # init the row pointer | |||||||||||||||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||||||||||||||||
| 1101 | 37 | my ($num_cols, $widths, $precision, $max_widths) = | |||||||||||||||||||||||||||||||||||||||||
| 1102 | &calc_widths($col_widths, $titles, $rewindable, | ||||||||||||||||||||||||||||||||||||||||||
| 1103 | $row_sub, $fmt_sub, $types, 'list', ''); | ||||||||||||||||||||||||||||||||||||||||||
| 1104 | |||||||||||||||||||||||||||||||||||||||||||
| 1105 | 37 | ▶ | my $fmt = sprintf("%%-%ds : %%s\n", ($#$titles >= 0 ? &max_length($titles) : 8)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1106 | 37 | my @values; | |||||||||||||||||||||||||||||||||||||||||
| 1107 | 37 | my ($value, $c, $cut, $line); | |||||||||||||||||||||||||||||||||||||||||
| 1108 | 37 | my $col_limit = $max_width - 2; | |||||||||||||||||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||||||||||||||||
| 1110 | 37 | ▶ | while ((@values = &$row_sub(0)), $#values >= $[) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1111 | 185 | ▶ | for ($c = 0; $c <= $#values; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1112 | # get this column's title | ||||||||||||||||||||||||||||||||||||||||||
| 1113 | 850 | ▶ | $title = $#$titles >= 0 ? $titles->[$c] : sprintf("Field_%d", $c+1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1114 | 850 | my $type = $types->[$c]; | |||||||||||||||||||||||||||||||||||||||||
| 1115 | 850 | my $width = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1116 | 850 | my $prec = $precision->[$c]; | |||||||||||||||||||||||||||||||||||||||||
| 1117 | 850 | $value = &$fmt_sub($values[$c], $type, 0, $width, $prec, 'list'); | |||||||||||||||||||||||||||||||||||||||||
| 1118 | 850 | ▶ | while (length($value)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1119 | 871 | ▶ | if (length($value) > ($cut = $col_limit)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1120 | 21 | $line = substr($value, 0, $cut); | |||||||||||||||||||||||||||||||||||||||||
| 1121 | 21 | ▶ | if ($line =~ m/([-,;? \t])([^-,;? \t]*)$/ && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line =~ /([-,;? \t])([^-,;? \t]*)$/ and length $2 <= $wrap_margin
MC/DC0%0/2
$line =~ /([-,;? \t])([^-,;? \t]*)$/ and length $2 <= $wrap_margin
$line =~ /([-,;? \t])([^-,;? \t]*)$/
length $2 <= $wrap_margin
Truth table33%1/3
A and B
A= $line =~ /([-,;? \t])([^-,;? \t]*)$/B= length $2 <= $wrap_margin
| |||||||||||||||||||||||||||||||||||||||||||
| 1122 | length($2) <= $wrap_margin) { | ||||||||||||||||||||||||||||||||||||||||||
| 1123 | 21 | $cut = $col_limit - length($2); | |||||||||||||||||||||||||||||||||||||||||
| 1124 | 21 | $line = substr($value, 0, $cut); | |||||||||||||||||||||||||||||||||||||||||
| 1125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1126 | 21 | ($value = substr($value, $cut)) =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 1127 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1128 | 850 | $line = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1129 | 850 | $value = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1131 | 871 | out $fmt, $title, $line; | |||||||||||||||||||||||||||||||||||||||||
| 1132 | 871 | $title = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1135 | 185 | out ""; | |||||||||||||||||||||||||||||||||||||||||
| 1136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||||||||||
| 1139 | =head1 ShowRow | ||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||
| 1141 | Fetch rows successively from one or more columns of data. | ||||||||||||||||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||||||||||||||||
| 1143 | S< >B<ShowRow> I<$rewindflag>, I<\$index>, I<$col_array_1> [, I<$col_array_2>, ...;] | ||||||||||||||||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||||||||||||||||
| 1145 | The B<ShowRow> subroutine returns a row of data from one or more | ||||||||||||||||||||||||||||||||||||||||||
| 1146 | columns of data. It is designed to be used as a I<callback> routine, | ||||||||||||||||||||||||||||||||||||||||||
| 1147 | within the B<ShowTable> routine. It can be used to select elements | ||||||||||||||||||||||||||||||||||||||||||
| 1148 | from one or more array reference arguments. | ||||||||||||||||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||||||||||||||||
| 1150 | If passed two or more array references as arguments, elements of the | ||||||||||||||||||||||||||||||||||||||||||
| 1151 | arrays selected by I<$index> are returned as the "row" of data. | ||||||||||||||||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||||||||||||||||
| 1153 | If a single array argument is passed, and each element of the array is | ||||||||||||||||||||||||||||||||||||||||||
| 1154 | itself an array, the subarray is returned as the "row" of data. | ||||||||||||||||||||||||||||||||||||||||||
| 1155 | |||||||||||||||||||||||||||||||||||||||||||
| 1156 | If the I<$rewindflag> flag is set, then the I<$index> pointer is reset | ||||||||||||||||||||||||||||||||||||||||||
| 1157 | to zero, and "true" is returned (a scalar 1). This indicates that the | ||||||||||||||||||||||||||||||||||||||||||
| 1158 | data is rewindable to the B<ShowTable> routines. | ||||||||||||||||||||||||||||||||||||||||||
| 1159 | |||||||||||||||||||||||||||||||||||||||||||
| 1160 | When the I<$rewindflag> is not set, then the current row of data, as | ||||||||||||||||||||||||||||||||||||||||||
| 1161 | determined by I<$index> is returned, and I<$index> will | ||||||||||||||||||||||||||||||||||||||||||
| 1162 | have been incremented. | ||||||||||||||||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||||||||||||||||
| 1164 | An actual invocation (from B<ShowColumns>) is: | ||||||||||||||||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||||||||||||||||
| 1166 | ShowTable \@titles, \@types, \@lengths, | ||||||||||||||||||||||||||||||||||||||||||
| 1167 | sub { &ShowRow( $_[0], \$current_row, $col_names, $col_types, | ||||||||||||||||||||||||||||||||||||||||||
| 1168 | $col_lengths, \@col_attrs); }; | ||||||||||||||||||||||||||||||||||||||||||
| 1169 | |||||||||||||||||||||||||||||||||||||||||||
| 1170 | In the example above, after each invocation, the I<$current_row> argument | ||||||||||||||||||||||||||||||||||||||||||
| 1171 | will have been incremented. | ||||||||||||||||||||||||||||||||||||||||||
| 1172 | |||||||||||||||||||||||||||||||||||||||||||
| 1173 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||||||||||||||||
| 1175 | 2052 | ▶ | sub ShowRow { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowRow: called CC=7 SCAR=22.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1176 | 2052 | my $rewind_flag = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1177 | 2052 | my $index_ref = shift; # an indirect index | |||||||||||||||||||||||||||||||||||||||||
| 1178 | 2052 | my @columns = @_; # get rest of columns | |||||||||||||||||||||||||||||||||||||||||
| 1179 | 2052 | my @row; # we're selecting a row | |||||||||||||||||||||||||||||||||||||||||
| 1180 | 2052 | ▶ | if ($rewind_flag) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1181 | 294 | $$index_ref = 0; # reset the pointer | |||||||||||||||||||||||||||||||||||||||||
| 1182 | 294 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1184 | 1758 | ▶ | return () if $#{$columns[0]} < $$index_ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1185 | 1464 | ▶ | if ($#columns == 0) { # exactly one array ref argument | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1186 | 1464 | my $data = $columns[0]->[$$index_ref]; # get the current data | |||||||||||||||||||||||||||||||||||||||||
| 1187 | 1464 | ▶ | if (ref($data) eq 'ARRAY') { # if an array.. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1188 | 1464 | @row = @$data; # ..return the array of data | |||||||||||||||||||||||||||||||||||||||||
| 1189 | } elsif (ref($data) eq 'HASH') {# if a hash.. | ||||||||||||||||||||||||||||||||||||||||||
| 1190 | 0 | @row = values %$data; # ..return the values | |||||||||||||||||||||||||||||||||||||||||
| 1191 | } else { # otherwise.. | ||||||||||||||||||||||||||||||||||||||||||
| 1192 | 0 | @row = ($data); # ..return the data element | |||||||||||||||||||||||||||||||||||||||||
| 1193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1194 | } else { # with two or more array refs.. | ||||||||||||||||||||||||||||||||||||||||||
| 1195 | 0 | my $col; # select elements from each | |||||||||||||||||||||||||||||||||||||||||
| 1196 | 0 | ▶ | for ($col = 0; $col <= $#columns; $col++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1197 | 0 | push(@row, ${$columns[$col]}[$$index_ref]); | |||||||||||||||||||||||||||||||||||||||||
| 1198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1200 | 1464 | ${$index_ref}++; # increment the index for the next call | |||||||||||||||||||||||||||||||||||||||||
| 1201 | 1464 | @row; # return this row of data | |||||||||||||||||||||||||||||||||||||||||
| 1202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1203 | |||||||||||||||||||||||||||||||||||||||||||
| 1204 | =head1 ShowTableValue | ||||||||||||||||||||||||||||||||||||||||||
| 1205 | |||||||||||||||||||||||||||||||||||||||||||
| 1206 | Prepare and return a formatted representation of a value. A value | ||||||||||||||||||||||||||||||||||||||||||
| 1207 | argument, using its corresponding type, effective width, and precision | ||||||||||||||||||||||||||||||||||||||||||
| 1208 | is formatted into a field of a given maximum width. | ||||||||||||||||||||||||||||||||||||||||||
| 1209 | |||||||||||||||||||||||||||||||||||||||||||
| 1210 | S< >I<$fmt> = B<ShowTableValue> I<$value>, I<$type>, I<$max_width>, I<$width>, I<$precision>, I<$showmode>; | ||||||||||||||||||||||||||||||||||||||||||
| 1211 | |||||||||||||||||||||||||||||||||||||||||||
| 1212 | =over 10 | ||||||||||||||||||||||||||||||||||||||||||
| 1213 | |||||||||||||||||||||||||||||||||||||||||||
| 1214 | =item C<width> => I<$width> | ||||||||||||||||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||||||||||||||||
| 1216 | =item I<$width> | ||||||||||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||||||||||
| 1218 | The width of the current value. If omittied, I<$max_width> is assumed. | ||||||||||||||||||||||||||||||||||||||||||
| 1219 | |||||||||||||||||||||||||||||||||||||||||||
| 1220 | =item C<precision> => I<$precision> | ||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||
| 1222 | =item I<$precision> | ||||||||||||||||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||||||||||||||||
| 1224 | The number of decimal digits; zero is assumed if omittied. | ||||||||||||||||||||||||||||||||||||||||||
| 1225 | |||||||||||||||||||||||||||||||||||||||||||
| 1226 | =item C<value> => I<$value> | ||||||||||||||||||||||||||||||||||||||||||
| 1227 | |||||||||||||||||||||||||||||||||||||||||||
| 1228 | =item I<$value> | ||||||||||||||||||||||||||||||||||||||||||
| 1229 | |||||||||||||||||||||||||||||||||||||||||||
| 1230 | The value to be formatted. | ||||||||||||||||||||||||||||||||||||||||||
| 1231 | |||||||||||||||||||||||||||||||||||||||||||
| 1232 | =item I<$type> | ||||||||||||||||||||||||||||||||||||||||||
| 1233 | |||||||||||||||||||||||||||||||||||||||||||
| 1234 | The type name of the value; eg: C<char>, C<varchar>, C<int>, etc. | ||||||||||||||||||||||||||||||||||||||||||
| 1235 | |||||||||||||||||||||||||||||||||||||||||||
| 1236 | =item C<maxwidth> => I<$max_width> | ||||||||||||||||||||||||||||||||||||||||||
| 1237 | |||||||||||||||||||||||||||||||||||||||||||
| 1238 | =item I<$max_width> | ||||||||||||||||||||||||||||||||||||||||||
| 1239 | |||||||||||||||||||||||||||||||||||||||||||
| 1240 | The maximum width of any value in the current value's column. If I<$width> | ||||||||||||||||||||||||||||||||||||||||||
| 1241 | is zero or null, I<$max_width> is used by default. I<$max_width> is also | ||||||||||||||||||||||||||||||||||||||||||
| 1242 | used as a I<minimum> width, in case I<$width> is a smaller value. | ||||||||||||||||||||||||||||||||||||||||||
| 1243 | |||||||||||||||||||||||||||||||||||||||||||
| 1244 | =item I<$width> | ||||||||||||||||||||||||||||||||||||||||||
| 1245 | |||||||||||||||||||||||||||||||||||||||||||
| 1246 | The default width of the value, obtained from the width specification of the | ||||||||||||||||||||||||||||||||||||||||||
| 1247 | column in which this value occurs. | ||||||||||||||||||||||||||||||||||||||||||
| 1248 | |||||||||||||||||||||||||||||||||||||||||||
| 1249 | =item I<$precision> | ||||||||||||||||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||||||||||||||||
| 1251 | The precision specification, if any, from the column width specification. | ||||||||||||||||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||||||||||||||||
| 1253 | =item I<$showmode> | ||||||||||||||||||||||||||||||||||||||||||
| 1254 | |||||||||||||||||||||||||||||||||||||||||||
| 1255 | The mode of the output: one of "table", "list", "box", or "html". Currently, | ||||||||||||||||||||||||||||||||||||||||||
| 1256 | only the "html" mode is significant: it is used to avoid using HTML tokens | ||||||||||||||||||||||||||||||||||||||||||
| 1257 | as part of the formatted text and length calculations. | ||||||||||||||||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||||||||||||||||
| 1259 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||||||||||||||||
| 1261 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||||||||||||||||
| 1263 | 6772 | ▶ | sub ShowTableValue { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowTableValue: called CC=17 SCAR=36.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1264 | 6772 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1265 | 6772 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1266 | 6772 | my $max_width = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1267 | 6772 | my $width = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1268 | 6772 | ▶ | my $prec = shift || 2; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 2
MC/DC0%0/1
shift() || 2
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 1269 | 6772 | my $showmode = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1270 | 6772 | ▶ | my $fmt = ($Type2Format{lc($type)} || $Type2Format{'char'}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Type2Format{lc $type} || $Type2Format{'char'}
MC/DC0%0/2
$Type2Format{lc $type} || $Type2Format{'char'}
$Type2Format{lc $type}
$Type2Format{'char'}
Truth table66%2/3
A || B
A= $Type2Format{lc $type}B= $Type2Format{'char'}
| |||||||||||||||||||||||||||||||||||||||||||
| 1271 | 6772 | my $str; | |||||||||||||||||||||||||||||||||||||||||
| 1272 | |||||||||||||||||||||||||||||||||||||||||||
| 1273 | 6772 | ▶ | $max_width = 0 if !defined($max_width) || $max_width eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $max_width or $max_width eq ""
MC/DC0%0/2
not defined $max_width or $max_width eq ""
not defined $max_width
$max_width eq ""
Truth table33%1/3
not(A) or B
A= not defined $max_widthB= $max_width eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1274 | 6772 | ▶ | $width = $max_width if !defined($width) || $width eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $width or $width eq ""
MC/DC0%0/2
not defined $width or $width eq ""
not defined $width
$width eq ""
Truth table33%1/3
not(A) or B
A= not defined $widthB= $width eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1275 | |||||||||||||||||||||||||||||||||||||||||||
| 1276 | 6772 | ▶ | $width = min($width, $max_width) if $max_width > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1277 | 6772 | ▶ | if ($type =~ /money/i) { # money formatting is special | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1278 | 0 | ▶ | if (($str = $value) !~ /[\$,]/) { # not already formatted? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1279 | 0 | my ($d,$c) = split(/\./,$value,2); | |||||||||||||||||||||||||||||||||||||||||
| 1280 | # reverse the digits | ||||||||||||||||||||||||||||||||||||||||||
| 1281 | 0 | $d = join('',reverse(split(//,abs($d)))); | |||||||||||||||||||||||||||||||||||||||||
| 1282 | # do the grouping from the rightmost to the left | ||||||||||||||||||||||||||||||||||||||||||
| 1283 | 0 | $d =~ s/(...)(?=.)/$1,/g; | |||||||||||||||||||||||||||||||||||||||||
| 1284 | # reverse the digits and grouping char | ||||||||||||||||||||||||||||||||||||||||||
| 1285 | 0 | $d = '$'.join('',reverse(split(//,$d))); | |||||||||||||||||||||||||||||||||||||||||
| 1286 | # If there is any precision, add on pennies (allow for > 2 precision) | ||||||||||||||||||||||||||||||||||||||||||
| 1287 | 0 | ▶ | $d .= sprintf($prec > 2 ? "%0${prec}d" : ".%02d",$c) if $prec > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1288 | # Mark as negative with '(xxx)' | ||||||||||||||||||||||||||||||||||||||||||
| 1289 | 0 | ▶ | $d = '-'.$d if $value < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1290 | 0 | $str = $d; | |||||||||||||||||||||||||||||||||||||||||
| 1291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1292 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1293 | 6772 | $fmt = sprintf ($fmt,$width,$prec); | |||||||||||||||||||||||||||||||||||||||||
| 1294 | |||||||||||||||||||||||||||||||||||||||||||
| 1295 | # If we are in HTML mode, and the value has any HTML tokens, | ||||||||||||||||||||||||||||||||||||||||||
| 1296 | # then format it always as a string (even if it might | ||||||||||||||||||||||||||||||||||||||||||
| 1297 | # be a decimal--this is a kluge but seems to work). | ||||||||||||||||||||||||||||||||||||||||||
| 1298 | |||||||||||||||||||||||||||||||||||||||||||
| 1299 | 6772 | ▶ | if ($showmode =~ /html/i && $value =~ /<\/?($HTML_Elements)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$showmode =~ /html/i and $value =~ m[</?($HTML_Elements)]
MC/DC100%2/2
$showmode =~ /html/i and $value =~ m[</?($HTML_Elements)]
$showmode =~ /html/i
$value =~ m[</?($HTML_Elements)]
Truth table100%3/3
A and B
A= $showmode =~ /html/iB= $value =~ m[</?($HTML_Elements)]
| |||||||||||||||||||||||||||||||||||||||||||
| 1300 | 80 | $fmt =~ s/[df]/s/; # convert to string sub | |||||||||||||||||||||||||||||||||||||||||
| 1301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1302 | 6772 | $str = sprintf($fmt,$value); | |||||||||||||||||||||||||||||||||||||||||
| 1303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1304 | 6772 | ▶ | if ($width > length(&PlainText($str))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1305 | # right align the value if any kind of number | ||||||||||||||||||||||||||||||||||||||||||
| 1306 | 40 | ▶ | $str = sprintf("%${width}s", $str) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1307 | if $type =~ /int|float|pct|real|numeric|money/i; | ||||||||||||||||||||||||||||||||||||||||||
| 1308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1309 | 6772 | $str; | |||||||||||||||||||||||||||||||||||||||||
| 1310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1311 | |||||||||||||||||||||||||||||||||||||||||||
| 1312 | 23 | %Type2Format = ( | |||||||||||||||||||||||||||||||||||||||||
| 1313 | 'char' => '%%-%ds', | ||||||||||||||||||||||||||||||||||||||||||
| 1314 | 'varchar' => '%%-%ds', | ||||||||||||||||||||||||||||||||||||||||||
| 1315 | 'symbol' => '%%-%ds', | ||||||||||||||||||||||||||||||||||||||||||
| 1316 | 'tinyint' => '%%%dd', | ||||||||||||||||||||||||||||||||||||||||||
| 1317 | 'shortint' => '%%%dd', | ||||||||||||||||||||||||||||||||||||||||||
| 1318 | 'int' => '%%%dd', | ||||||||||||||||||||||||||||||||||||||||||
| 1319 | 'pct' => '%%%d.%df%%%%', | ||||||||||||||||||||||||||||||||||||||||||
| 1320 | 'real' => '%%%d.%df', | ||||||||||||||||||||||||||||||||||||||||||
| 1321 | 'float' => '%%%d.%df', | ||||||||||||||||||||||||||||||||||||||||||
| 1322 | 'numeric' => '%%%d.%df', | ||||||||||||||||||||||||||||||||||||||||||
| 1323 | 'text' => '%%-%ds', | ||||||||||||||||||||||||||||||||||||||||||
| 1324 | |||||||||||||||||||||||||||||||||||||||||||
| 1325 | # The money types do not actually need to be in this table, since | ||||||||||||||||||||||||||||||||||||||||||
| 1326 | # ShowTableValue handle money formatting explicitly. However, some | ||||||||||||||||||||||||||||||||||||||||||
| 1327 | # one else might use this table, so we treat them like right-aligned | ||||||||||||||||||||||||||||||||||||||||||
| 1328 | # strings. | ||||||||||||||||||||||||||||||||||||||||||
| 1329 | 'money' => '%%%d.%df', | ||||||||||||||||||||||||||||||||||||||||||
| 1330 | 'smallmoney' => '%%%d.%df', | ||||||||||||||||||||||||||||||||||||||||||
| 1331 | |||||||||||||||||||||||||||||||||||||||||||
| 1332 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1333 | |||||||||||||||||||||||||||||||||||||||||||
| 1334 | =head1 PlainText | ||||||||||||||||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||||||||||||||||
| 1336 | S< >I<$plaintext> = B<&PlainText>(I<$htmltext>); | ||||||||||||||||||||||||||||||||||||||||||
| 1337 | |||||||||||||||||||||||||||||||||||||||||||
| 1338 | S< >B<&PlainText> | ||||||||||||||||||||||||||||||||||||||||||
| 1339 | |||||||||||||||||||||||||||||||||||||||||||
| 1340 | This function removes any HTML formatting sequences from the input argument, | ||||||||||||||||||||||||||||||||||||||||||
| 1341 | or from C<$_> if no argument is given. The resulting plain text is returned | ||||||||||||||||||||||||||||||||||||||||||
| 1342 | as the result. | ||||||||||||||||||||||||||||||||||||||||||
| 1343 | |||||||||||||||||||||||||||||||||||||||||||
| 1344 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1345 | |||||||||||||||||||||||||||||||||||||||||||
| 1346 | # $plaintext = &PlainText($htmltext); | ||||||||||||||||||||||||||||||||||||||||||
| 1347 | # or: | ||||||||||||||||||||||||||||||||||||||||||
| 1348 | # &PlainText; | ||||||||||||||||||||||||||||||||||||||||||
| 1349 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1350 | # Convert the argument and return as a string, or convert $_. | ||||||||||||||||||||||||||||||||||||||||||
| 1351 | |||||||||||||||||||||||||||||||||||||||||||
| 1352 | 8165 | ▶ | sub PlainText { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PlainText: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1353 | 8165 | ▶ | local($_) = shift if $#_ >= 0; # set local $_ if there's an argument | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1354 | # skip unless there's a sequence | ||||||||||||||||||||||||||||||||||||||||||
| 1355 | 8165 | ▶ | return $_ unless m=</?($HTML_Elements)=i; # HTML text? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1356 | 80 | s{</?(?:$HTML_Elements)# # match and remove any HTML token.. | |||||||||||||||||||||||||||||||||||||||||
| 1357 | (?:\ \w+# # ..then PARAM or PARAM=VALUE | ||||||||||||||||||||||||||||||||||||||||||
| 1358 | (?:\=(?:"(?:[^"]|\\")*"|# # ...."STRING" or.. | ||||||||||||||||||||||||||||||||||||||||||
| 1359 | [^"> ]+# # ....VALUE | ||||||||||||||||||||||||||||||||||||||||||
| 1360 | )# | ||||||||||||||||||||||||||||||||||||||||||
| 1361 | )?# # ..=VALUE is optional | ||||||||||||||||||||||||||||||||||||||||||
| 1362 | )*# # zero or more PARAM or PARAM=VALUE | ||||||||||||||||||||||||||||||||||||||||||
| 1363 | >}{}igx; # up to the closing '>' | ||||||||||||||||||||||||||||||||||||||||||
| 1364 | 80 | $_; # return the result | |||||||||||||||||||||||||||||||||||||||||
| 1365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1366 | |||||||||||||||||||||||||||||||||||||||||||
| 1367 | 23 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1368 | |||||||||||||||||||||||||||||||||||||||||||
| 1369 | 23 | @HTML_Elements = qw( | |||||||||||||||||||||||||||||||||||||||||
| 1370 | A ABBREV ACRONYM ADDRESS APP APPLET AREA AU B BANNER BASE BASEFONT BDO | ||||||||||||||||||||||||||||||||||||||||||
| 1371 | BGSOUND BIG BLINK BLOCKQUOTE BODY BQ BR CAPTION CENTER CITE CODE COL | ||||||||||||||||||||||||||||||||||||||||||
| 1372 | COLGROUP CREDIT DD DEL DFN DIR DIV DL DT EM EMBED FN FIG FONT FORM FRAME | ||||||||||||||||||||||||||||||||||||||||||
| 1373 | FRAMESET H1 H2 H3 H4 H5 H6 HEAD HP HR HTML I IMG INPUT INS ISINDEX KBD | ||||||||||||||||||||||||||||||||||||||||||
| 1374 | LANG LH LI LINK LISTING MAP MARQUEE MENU META NEXTID NOBR NOEMBED | ||||||||||||||||||||||||||||||||||||||||||
| 1375 | NOFRAMES NOTE OL OPTION OVERLAY P PARAM PERSON PLAINTEXT PRE Q S SAMP | ||||||||||||||||||||||||||||||||||||||||||
| 1376 | SELECT SMALL SPAN STRIKE STRONG SUB SUP TAB TABLE TBODY TD TEXTAREA | ||||||||||||||||||||||||||||||||||||||||||
| 1377 | TFOOT TH THEAD TITLE TR TT U UL VAR WBR XMP | ||||||||||||||||||||||||||||||||||||||||||
| 1378 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1379 | |||||||||||||||||||||||||||||||||||||||||||
| 1380 | 23 | $HTML_Elements = join("|",@HTML_Elements); | |||||||||||||||||||||||||||||||||||||||||
| 1381 | |||||||||||||||||||||||||||||||||||||||||||
| 1382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1383 | |||||||||||||||||||||||||||||||||||||||||||
| 1384 | =head1 VARIABLES | ||||||||||||||||||||||||||||||||||||||||||
| 1385 | |||||||||||||||||||||||||||||||||||||||||||
| 1386 | The following variables may be set by the user to affect the display (with | ||||||||||||||||||||||||||||||||||||||||||
| 1387 | the defaults enclosed in square brackets [..]): | ||||||||||||||||||||||||||||||||||||||||||
| 1388 | |||||||||||||||||||||||||||||||||||||||||||
| 1389 | =over 10 | ||||||||||||||||||||||||||||||||||||||||||
| 1390 | |||||||||||||||||||||||||||||||||||||||||||
| 1391 | =item B<$Show_Mode> [Box] | ||||||||||||||||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||||||||||||||||
| 1393 | This is the default display mode when using B<ShowTable>. The | ||||||||||||||||||||||||||||||||||||||||||
| 1394 | environment variable, C<$ENV{'SHOW_MODE'}>, is used when this variable is | ||||||||||||||||||||||||||||||||||||||||||
| 1395 | null or the empty string. The possible values for this variable are: | ||||||||||||||||||||||||||||||||||||||||||
| 1396 | C<"Box">, C<"List">, C<"Table">, and C<"HTML">. Case is insignificant. | ||||||||||||||||||||||||||||||||||||||||||
| 1397 | |||||||||||||||||||||||||||||||||||||||||||
| 1398 | =item B<$List_Wrap_Margin> [2] | ||||||||||||||||||||||||||||||||||||||||||
| 1399 | |||||||||||||||||||||||||||||||||||||||||||
| 1400 | This variable's value determines how large a margin to keep before wrarpping a | ||||||||||||||||||||||||||||||||||||||||||
| 1401 | long value's display in a column. This value is only used in "List" mode. | ||||||||||||||||||||||||||||||||||||||||||
| 1402 | |||||||||||||||||||||||||||||||||||||||||||
| 1403 | =item B<$Max_List_Width> [80] | ||||||||||||||||||||||||||||||||||||||||||
| 1404 | |||||||||||||||||||||||||||||||||||||||||||
| 1405 | This variable, used in "List" mode, is used to determine how long an output line | ||||||||||||||||||||||||||||||||||||||||||
| 1406 | may be before wrapping it. The environment variable, C<$ENV{'COLUMNS'}>, is | ||||||||||||||||||||||||||||||||||||||||||
| 1407 | used to define this value when it is null. | ||||||||||||||||||||||||||||||||||||||||||
| 1408 | |||||||||||||||||||||||||||||||||||||||||||
| 1409 | =item B<$Max_Table_Width> [''] | ||||||||||||||||||||||||||||||||||||||||||
| 1410 | |||||||||||||||||||||||||||||||||||||||||||
| 1411 | This variable, when set, causes all tables to have their columns scaled | ||||||||||||||||||||||||||||||||||||||||||
| 1412 | such that their total combined width does not exceed this value. When | ||||||||||||||||||||||||||||||||||||||||||
| 1413 | this variable is not set, which is the default case, there is no maximum | ||||||||||||||||||||||||||||||||||||||||||
| 1414 | table width, and no scaling will be done. | ||||||||||||||||||||||||||||||||||||||||||
| 1415 | |||||||||||||||||||||||||||||||||||||||||||
| 1416 | =item B<$No_Escape> [''] | ||||||||||||||||||||||||||||||||||||||||||
| 1417 | |||||||||||||||||||||||||||||||||||||||||||
| 1418 | If set, allows embedded HTML text to be included in the data displayed | ||||||||||||||||||||||||||||||||||||||||||
| 1419 | in an HTML-formatted table. By default, the HTML formatting characters | ||||||||||||||||||||||||||||||||||||||||||
| 1420 | ("<", ">", and "&") occuring in values are escaped. | ||||||||||||||||||||||||||||||||||||||||||
| 1421 | |||||||||||||||||||||||||||||||||||||||||||
| 1422 | =item B<%URL_Keys> | ||||||||||||||||||||||||||||||||||||||||||
| 1423 | |||||||||||||||||||||||||||||||||||||||||||
| 1424 | In HTML mode, this variable is used to recognize which columns are to be | ||||||||||||||||||||||||||||||||||||||||||
| 1425 | displayed with a corresponding hypertext anchor. See L<"ShowHTMLTable"> | ||||||||||||||||||||||||||||||||||||||||||
| 1426 | for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 1427 | |||||||||||||||||||||||||||||||||||||||||||
| 1428 | =item B<@HTML_Elements> | ||||||||||||||||||||||||||||||||||||||||||
| 1429 | |||||||||||||||||||||||||||||||||||||||||||
| 1430 | An array of HTML elements (as of HTML 3.0) used to recognize and strip for | ||||||||||||||||||||||||||||||||||||||||||
| 1431 | width calculations. | ||||||||||||||||||||||||||||||||||||||||||
| 1432 | |||||||||||||||||||||||||||||||||||||||||||
| 1433 | =item B<$HTML_Elements> | ||||||||||||||||||||||||||||||||||||||||||
| 1434 | |||||||||||||||||||||||||||||||||||||||||||
| 1435 | A regular expression string formed from the elements of B<@HTML_Elements>. | ||||||||||||||||||||||||||||||||||||||||||
| 1436 | |||||||||||||||||||||||||||||||||||||||||||
| 1437 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1438 | |||||||||||||||||||||||||||||||||||||||||||
| 1439 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1440 | |||||||||||||||||||||||||||||||||||||||||||
| 1441 | ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 1442 | |||||||||||||||||||||||||||||||||||||||||||
| 1443 | =head1 INTERNAL SUBROUTINES | ||||||||||||||||||||||||||||||||||||||||||
| 1444 | |||||||||||||||||||||||||||||||||||||||||||
| 1445 | =head1 get_params | ||||||||||||||||||||||||||||||||||||||||||
| 1446 | |||||||||||||||||||||||||||||||||||||||||||
| 1447 | S< >my I<$args> = B<&get_params> I<\@argv>, I<\%params>, I<\@arglist>; | ||||||||||||||||||||||||||||||||||||||||||
| 1448 | |||||||||||||||||||||||||||||||||||||||||||
| 1449 | Given the I<@argv> originally passed to the calling sub, and the hash of | ||||||||||||||||||||||||||||||||||||||||||
| 1450 | named parameters as I<%params>, and the array of parameter names in the | ||||||||||||||||||||||||||||||||||||||||||
| 1451 | order expected for a pass-by-value invocation, set the values of each of | ||||||||||||||||||||||||||||||||||||||||||
| 1452 | the variables named in I<@vars>. | ||||||||||||||||||||||||||||||||||||||||||
| 1453 | |||||||||||||||||||||||||||||||||||||||||||
| 1454 | If the only element of the I<@argv> is a hash array, then set the | ||||||||||||||||||||||||||||||||||||||||||
| 1455 | variables to the values of their corresponding parameters used as keys | ||||||||||||||||||||||||||||||||||||||||||
| 1456 | to the hash array. If the parameter is not a key of the I<%params> | ||||||||||||||||||||||||||||||||||||||||||
| 1457 | hash, and is not a key in the global hash B<%ShowTableParams>, then an | ||||||||||||||||||||||||||||||||||||||||||
| 1458 | error is noted. | ||||||||||||||||||||||||||||||||||||||||||
| 1459 | |||||||||||||||||||||||||||||||||||||||||||
| 1460 | When I<@argv> has multiple elements, or is not a hash array, set each | ||||||||||||||||||||||||||||||||||||||||||
| 1461 | variable, in the order given within I<@arglist>, to the values from the | ||||||||||||||||||||||||||||||||||||||||||
| 1462 | I<@argv>, setting the variables named by each value in I<%params>. | ||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||
| 1464 | Variables may given either by name or by reference. | ||||||||||||||||||||||||||||||||||||||||||
| 1465 | |||||||||||||||||||||||||||||||||||||||||||
| 1466 | The result is a HASH array reference, either corresponding directly to | ||||||||||||||||||||||||||||||||||||||||||
| 1467 | the HASH array passed as the single argument, or one created by | ||||||||||||||||||||||||||||||||||||||||||
| 1468 | associating the resulting variable values to the parameter names | ||||||||||||||||||||||||||||||||||||||||||
| 1469 | associated with the variable names. | ||||||||||||||||||||||||||||||||||||||||||
| 1470 | |||||||||||||||||||||||||||||||||||||||||||
| 1471 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1472 | |||||||||||||||||||||||||||||||||||||||||||
| 1473 | 162 | ▶ | sub get_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_params: called CC=24 SCAR=33.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1474 | 162 | ▶ | my $argvref = shift or croak "Missing required argument.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1475 | 162 | ▶ | my $params = shift or croak "Missing required parameters hash.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1476 | 162 | ▶ | my $arglist = shift or croak "Missing required arglist array.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1477 | 162 | my %args; | |||||||||||||||||||||||||||||||||||||||||
| 1478 | 162 | my ($param, $var); | |||||||||||||||||||||||||||||||||||||||||
| 1479 | 162 | ▶ | if ($#$argvref == 0 && ref($argvref->[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$argvref->$#* == 0 and ref $argvref->[0] eq "HASH"
MC/DC50%1/2
$argvref->$#* == 0 and ref $argvref->[0] eq "HASH"
$argvref->$#* == 0
ref $argvref->[0] eq "HASH"
Truth table66%2/3
A and B
A= $argvref->$#* == 0B= ref $argvref->[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 1480 | 145 | my $href = $argvref->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1481 | 145 | %args = %$href; # initialize result with input hash | |||||||||||||||||||||||||||||||||||||||||
| 1482 | 145 | foreach $param (keys %$href) { # for each named argument... | |||||||||||||||||||||||||||||||||||||||||
| 1483 | # Is this a known parameter? | ||||||||||||||||||||||||||||||||||||||||||
| 1484 | 697 | ▶ | if (exists($params->{$param})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1485 | 674 | $var = $params->{$param}; | |||||||||||||||||||||||||||||||||||||||||
| 1486 | 674 | ▶ | while ($var ne '' && ref($var) eq '') { # indirect refs? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$var ne "" and ref $var eq ""
MC/DC0%0/2
$var ne "" and ref $var eq ""
$var ne ""
ref $var eq ""
Truth table33%1/3
A and B
A= $var ne ""B= ref $var eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1487 | 0 | $var = $params->{$param = $var}; | |||||||||||||||||||||||||||||||||||||||||
| 1488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1489 | 674 | ▶ | if ($var ne '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1490 | 674 | $$var = $href->{$param}; # assign the param's variable | |||||||||||||||||||||||||||||||||||||||||
| 1491 | 674 | $args{$param} = $$var; # make sure canonical param gets defined | |||||||||||||||||||||||||||||||||||||||||
| 1492 | 674 | next; # go to the next parameter | |||||||||||||||||||||||||||||||||||||||||
| 1493 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1495 | 23 | ▶ | if (!exists($show_table_params{$param})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1496 | 0 | croak "Unknown parameter: \"$param\"\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1499 | } else { # use args in the order given for variables | ||||||||||||||||||||||||||||||||||||||||||
| 1500 | 17 | my $i; | |||||||||||||||||||||||||||||||||||||||||
| 1501 | 17 | ▶ | for ($i = 0; $i <= $#$arglist; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1502 | 131 | $param = $arglist->[$i]; # get the next argument | |||||||||||||||||||||||||||||||||||||||||
| 1503 | 131 | $var = $params->{$param}; # get it's variable | |||||||||||||||||||||||||||||||||||||||||
| 1504 | 131 | ▶ | next unless defined($var); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1505 | 127 | ▶ | while ($var ne '' && ref($var) eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$var ne "" and ref $var eq ""
MC/DC50%1/2
$var ne "" and ref $var eq ""
$var ne ""
ref $var eq ""
Truth table66%2/3
A and B
A= $var ne ""B= ref $var eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1506 | 10 | $var = $params->{$param = $var}; | |||||||||||||||||||||||||||||||||||||||||
| 1507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1508 | 127 | ▶ | if ($var ne '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1509 | 127 | ▶ | $$var = $i <= $#$argvref ? $argvref->[$i] : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1510 | 127 | $args{$param} = $$var; # assign to the hash | |||||||||||||||||||||||||||||||||||||||||
| 1511 | } elsif (!exists($show_table_params{$param})) { | ||||||||||||||||||||||||||||||||||||||||||
| 1512 | 0 | croak "Unknown parameter: \"$param\" for argument $i.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1516 | # Now, make sure all variables get initialized | ||||||||||||||||||||||||||||||||||||||||||
| 1517 | 162 | foreach $param (keys %$params) { | |||||||||||||||||||||||||||||||||||||||||
| 1518 | 1353 | $var = $params->{$param}; | |||||||||||||||||||||||||||||||||||||||||
| 1519 | 1353 | ▶ | while ($var ne '' && ref($var) eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$var ne "" and ref $var eq ""
MC/DC50%1/2
$var ne "" and ref $var eq ""
$var ne ""
ref $var eq ""
Truth table66%2/3
A and B
A= $var ne ""B= ref $var eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1520 | 98 | $var = $params->{$param = $var}; | |||||||||||||||||||||||||||||||||||||||||
| 1521 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1522 | 1353 | ▶ | if ($var ne '' && !exists($args{$param})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$var ne "" and not exists $args{$param}
MC/DC50%1/2
$var ne "" and not exists $args{$param}
$var ne ""
not exists $args{$param}
Truth table66%2/3
A and not(B)
A= $var ne ""B= not exists $args{$param}
| |||||||||||||||||||||||||||||||||||||||||||
| 1523 | 459 | $$var = $args{$param} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1524 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1525 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1526 | 162 | \%args; # return the HASH ref | |||||||||||||||||||||||||||||||||||||||||
| 1527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1528 | |||||||||||||||||||||||||||||||||||||||||||
| 1529 | 23 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1530 | |||||||||||||||||||||||||||||||||||||||||||
| 1531 | # A table of parameters used by all the external subroutines For | ||||||||||||||||||||||||||||||||||||||||||
| 1532 | # example, in order for parameters applicable to ShowHTMLTable to be | ||||||||||||||||||||||||||||||||||||||||||
| 1533 | # passed through ShowTable, they need to be defined in this table. | ||||||||||||||||||||||||||||||||||||||||||
| 1534 | |||||||||||||||||||||||||||||||||||||||||||
| 1535 | 23 | @show_table_params = qw( | |||||||||||||||||||||||||||||||||||||||||
| 1536 | caption | ||||||||||||||||||||||||||||||||||||||||||
| 1537 | col_attributes | ||||||||||||||||||||||||||||||||||||||||||
| 1538 | col_lengths | ||||||||||||||||||||||||||||||||||||||||||
| 1539 | col_names | ||||||||||||||||||||||||||||||||||||||||||
| 1540 | col_types | ||||||||||||||||||||||||||||||||||||||||||
| 1541 | data | ||||||||||||||||||||||||||||||||||||||||||
| 1542 | data_formats | ||||||||||||||||||||||||||||||||||||||||||
| 1543 | dformats | ||||||||||||||||||||||||||||||||||||||||||
| 1544 | fmt_sub | ||||||||||||||||||||||||||||||||||||||||||
| 1545 | fmtsub | ||||||||||||||||||||||||||||||||||||||||||
| 1546 | max_width | ||||||||||||||||||||||||||||||||||||||||||
| 1547 | no_escape | ||||||||||||||||||||||||||||||||||||||||||
| 1548 | row_sub | ||||||||||||||||||||||||||||||||||||||||||
| 1549 | show_mode | ||||||||||||||||||||||||||||||||||||||||||
| 1550 | table_attrs | ||||||||||||||||||||||||||||||||||||||||||
| 1551 | tformats | ||||||||||||||||||||||||||||||||||||||||||
| 1552 | title_formats | ||||||||||||||||||||||||||||||||||||||||||
| 1553 | titles | ||||||||||||||||||||||||||||||||||||||||||
| 1554 | types | ||||||||||||||||||||||||||||||||||||||||||
| 1555 | url_keys | ||||||||||||||||||||||||||||||||||||||||||
| 1556 | widths | ||||||||||||||||||||||||||||||||||||||||||
| 1557 | wrap_margin | ||||||||||||||||||||||||||||||||||||||||||
| 1558 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1559 | 23 | @show_table_params{@show_table_params} = () x (1 + $#show_table_params); | |||||||||||||||||||||||||||||||||||||||||
| 1560 | 23 | undef @show_table_params; | |||||||||||||||||||||||||||||||||||||||||
| 1561 | |||||||||||||||||||||||||||||||||||||||||||
| 1562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1563 | |||||||||||||||||||||||||||||||||||||||||||
| 1564 | =head1 html_formats | ||||||||||||||||||||||||||||||||||||||||||
| 1565 | |||||||||||||||||||||||||||||||||||||||||||
| 1566 | S< >(I<$prefixes>,I<$suffixes>) = B<html_formats> I<\@html_formats>; | ||||||||||||||||||||||||||||||||||||||||||
| 1567 | |||||||||||||||||||||||||||||||||||||||||||
| 1568 | The B<html_format> function takes an array reference of HTML formatting | ||||||||||||||||||||||||||||||||||||||||||
| 1569 | elements I<\@html_formats>, and builds two arrays of strings: the first: | ||||||||||||||||||||||||||||||||||||||||||
| 1570 | I<$prefixes>, is an array of prefixes containing the corresponding HTML | ||||||||||||||||||||||||||||||||||||||||||
| 1571 | formatting elements from I<\@html_formats>, and the second, | ||||||||||||||||||||||||||||||||||||||||||
| 1572 | I<$suffixes>, containing the appropriate HTML closing elements, in the | ||||||||||||||||||||||||||||||||||||||||||
| 1573 | opposite order. | ||||||||||||||||||||||||||||||||||||||||||
| 1574 | |||||||||||||||||||||||||||||||||||||||||||
| 1575 | The result is designed to be used as prefixes and suffixes for the | ||||||||||||||||||||||||||||||||||||||||||
| 1576 | corresponding titles and column values. | ||||||||||||||||||||||||||||||||||||||||||
| 1577 | |||||||||||||||||||||||||||||||||||||||||||
| 1578 | The array I<\@html_formats> contains lists of HTML formatting elements, | ||||||||||||||||||||||||||||||||||||||||||
| 1579 | one for each column (either title or data). Each array element is a | ||||||||||||||||||||||||||||||||||||||||||
| 1580 | list of one or more HTML elements, either given in HTML syntax, or as a | ||||||||||||||||||||||||||||||||||||||||||
| 1581 | "plain" name (ie: given as C<\<ELEMENT\>> or plainly, C<ELEMENT>). | ||||||||||||||||||||||||||||||||||||||||||
| 1582 | Multiple elements are separated by a comma C<','>. | ||||||||||||||||||||||||||||||||||||||||||
| 1583 | |||||||||||||||||||||||||||||||||||||||||||
| 1584 | The resulting array of I<$prefixes> contains the corresponding opening | ||||||||||||||||||||||||||||||||||||||||||
| 1585 | elements, in the order given, with the proper HTML element syntax. The | ||||||||||||||||||||||||||||||||||||||||||
| 1586 | resulting array of I<$suffixes> contains the closing elements, in the | ||||||||||||||||||||||||||||||||||||||||||
| 1587 | opposite order given, with the proper HTML element syntax. | ||||||||||||||||||||||||||||||||||||||||||
| 1588 | |||||||||||||||||||||||||||||||||||||||||||
| 1589 | For example, if I<\@html_formats> contains the two elements: | ||||||||||||||||||||||||||||||||||||||||||
| 1590 | |||||||||||||||||||||||||||||||||||||||||||
| 1591 | [ 'FONT SIZE=+2,BOLD', 'FONT COLOR=red,EM' ] | ||||||||||||||||||||||||||||||||||||||||||
| 1592 | |||||||||||||||||||||||||||||||||||||||||||
| 1593 | then the resulting two arrays will be returned as: | ||||||||||||||||||||||||||||||||||||||||||
| 1594 | |||||||||||||||||||||||||||||||||||||||||||
| 1595 | [ [ '<FONT SIZE=+2><BOLD>', '<FONT COLOR=red><EM>' ], | ||||||||||||||||||||||||||||||||||||||||||
| 1596 | [ '</FONT></BOLD>', '</FONT></EM>' ] ] | ||||||||||||||||||||||||||||||||||||||||||
| 1597 | |||||||||||||||||||||||||||||||||||||||||||
| 1598 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1599 | |||||||||||||||||||||||||||||||||||||||||||
| 1600 | 98 | ▶ | sub html_formats { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
html_formats: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1601 | 98 | my $html_formats = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||
| 1602 | 98 | my $i; | |||||||||||||||||||||||||||||||||||||||||
| 1603 | 98 | my (@prefixes, @suffixes); | |||||||||||||||||||||||||||||||||||||||||
| 1604 | 98 | my ($html, $elt, $html_list, @html_list); | |||||||||||||||||||||||||||||||||||||||||
| 1605 | 98 | my ($prefixes, $suffixes); | |||||||||||||||||||||||||||||||||||||||||
| 1606 | 98 | local($_); | |||||||||||||||||||||||||||||||||||||||||
| 1607 | |||||||||||||||||||||||||||||||||||||||||||
| 1608 | 98 | foreach $html_list (@$html_formats) { | |||||||||||||||||||||||||||||||||||||||||
| 1609 | 9 | @html_list = split(/,/,$html_list); | |||||||||||||||||||||||||||||||||||||||||
| 1610 | 9 | $prefixes = $suffixes = ''; # initialize the list | |||||||||||||||||||||||||||||||||||||||||
| 1611 | 9 | my %formats; # keep track of formats | |||||||||||||||||||||||||||||||||||||||||
| 1612 | 9 | foreach (@html_list) { | |||||||||||||||||||||||||||||||||||||||||
| 1613 | 9 | ($html, $elt) = (); | |||||||||||||||||||||||||||||||||||||||||
| 1614 | 9 | ▶ | if (($html, $elt) = /^(<)?\s*(\w+)/) {# <KEYWORD or KEYWORD | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1615 | 9 | ▶ | next if $formats{$elt}++ > 0; # only do an element once | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1616 | 9 | ▶ | $html = '<' unless $html; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1617 | 9 | $prefixes .= $html.$elt.$'; | |||||||||||||||||||||||||||||||||||||||||
| 1618 | 9 | ▶ | $prefixes .= '>' unless $prefixes =~ />$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1619 | 9 | $suffixes = $html.'/'.$elt.'>'.$suffixes; | |||||||||||||||||||||||||||||||||||||||||
| 1620 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1621 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1622 | 9 | push(@prefixes, $prefixes); # even push empty items | |||||||||||||||||||||||||||||||||||||||||
| 1623 | 9 | push(@suffixes, $suffixes); | |||||||||||||||||||||||||||||||||||||||||
| 1624 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1625 | 98 | ( \@prefixes, \@suffixes ); | |||||||||||||||||||||||||||||||||||||||||
| 1626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1627 | |||||||||||||||||||||||||||||||||||||||||||
| 1628 | |||||||||||||||||||||||||||||||||||||||||||
| 1629 | =head1 calc_widths | ||||||||||||||||||||||||||||||||||||||||||
| 1630 | |||||||||||||||||||||||||||||||||||||||||||
| 1631 | S< >(I<$num_cols>, I<$widths>, I<$precision>, I<$max_widths>) = | ||||||||||||||||||||||||||||||||||||||||||
| 1632 | S< >B<&calc_widths>( I<$widthspec>, I<$titles>, I<$rewindable>, | ||||||||||||||||||||||||||||||||||||||||||
| 1633 | S< >I<$row_sub>, I<$fmt_sub>, I<$types>, I<$showmode>, | ||||||||||||||||||||||||||||||||||||||||||
| 1634 | S< >I<$max_width>); | ||||||||||||||||||||||||||||||||||||||||||
| 1635 | |||||||||||||||||||||||||||||||||||||||||||
| 1636 | =head2 B<DESCRIPTION> | ||||||||||||||||||||||||||||||||||||||||||
| 1637 | |||||||||||||||||||||||||||||||||||||||||||
| 1638 | B<calc_widths> is a generalized subroutine used by all the B<ShowTable> | ||||||||||||||||||||||||||||||||||||||||||
| 1639 | variant subroutines to setup internal variables prior to formatting for | ||||||||||||||||||||||||||||||||||||||||||
| 1640 | display. B<Calc_widths> handles the column width and precision | ||||||||||||||||||||||||||||||||||||||||||
| 1641 | analysis, including scanning the data (if rewindable) for appropriate | ||||||||||||||||||||||||||||||||||||||||||
| 1642 | default values. | ||||||||||||||||||||||||||||||||||||||||||
| 1643 | |||||||||||||||||||||||||||||||||||||||||||
| 1644 | The number of columns in the data is returned, as well as three arrays: | ||||||||||||||||||||||||||||||||||||||||||
| 1645 | the declared column widths, the column precision values, and the maximum | ||||||||||||||||||||||||||||||||||||||||||
| 1646 | column widths. | ||||||||||||||||||||||||||||||||||||||||||
| 1647 | |||||||||||||||||||||||||||||||||||||||||||
| 1648 | =head2 B<RETURN VALUES> | ||||||||||||||||||||||||||||||||||||||||||
| 1649 | |||||||||||||||||||||||||||||||||||||||||||
| 1650 | =over 10 | ||||||||||||||||||||||||||||||||||||||||||
| 1651 | |||||||||||||||||||||||||||||||||||||||||||
| 1652 | =item I<$num_cols> | ||||||||||||||||||||||||||||||||||||||||||
| 1653 | |||||||||||||||||||||||||||||||||||||||||||
| 1654 | is the number of columns in the data. If the data is not rewindable, | ||||||||||||||||||||||||||||||||||||||||||
| 1655 | this is computed as the maximum of the number of elements in the | ||||||||||||||||||||||||||||||||||||||||||
| 1656 | I<$widthspec> array and the number of elements in the I<$titles> | ||||||||||||||||||||||||||||||||||||||||||
| 1657 | array. When the data is rewindable, this is the maximum of the number | ||||||||||||||||||||||||||||||||||||||||||
| 1658 | of columns of each row of data. | ||||||||||||||||||||||||||||||||||||||||||
| 1659 | |||||||||||||||||||||||||||||||||||||||||||
| 1660 | =item I<$widths> | ||||||||||||||||||||||||||||||||||||||||||
| 1661 | |||||||||||||||||||||||||||||||||||||||||||
| 1662 | is the column widths array ref, without the precision specs (if any). | ||||||||||||||||||||||||||||||||||||||||||
| 1663 | Each column's width value is determined by the original I<$widthspec> | ||||||||||||||||||||||||||||||||||||||||||
| 1664 | value and/or the maximum length of the formatted data for the column. | ||||||||||||||||||||||||||||||||||||||||||
| 1665 | |||||||||||||||||||||||||||||||||||||||||||
| 1666 | =item I<$precision> | ||||||||||||||||||||||||||||||||||||||||||
| 1667 | |||||||||||||||||||||||||||||||||||||||||||
| 1668 | is the precision component (if any) of the original I<$widthspec> | ||||||||||||||||||||||||||||||||||||||||||
| 1669 | array ref. If there was no original precision component from the I<$widthspec>, | ||||||||||||||||||||||||||||||||||||||||||
| 1670 | and the data is rewindable, then the data is examined to determine the | ||||||||||||||||||||||||||||||||||||||||||
| 1671 | maximum default precision. | ||||||||||||||||||||||||||||||||||||||||||
| 1672 | |||||||||||||||||||||||||||||||||||||||||||
| 1673 | =item I<$max_widths> | ||||||||||||||||||||||||||||||||||||||||||
| 1674 | |||||||||||||||||||||||||||||||||||||||||||
| 1675 | is the ref to the array of maximum widths for the given columns. | ||||||||||||||||||||||||||||||||||||||||||
| 1676 | |||||||||||||||||||||||||||||||||||||||||||
| 1677 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1678 | |||||||||||||||||||||||||||||||||||||||||||
| 1679 | =head2 B<ARGUMENTS> | ||||||||||||||||||||||||||||||||||||||||||
| 1680 | |||||||||||||||||||||||||||||||||||||||||||
| 1681 | =over 10 | ||||||||||||||||||||||||||||||||||||||||||
| 1682 | |||||||||||||||||||||||||||||||||||||||||||
| 1683 | =item I<$widthspec> | ||||||||||||||||||||||||||||||||||||||||||
| 1684 | |||||||||||||||||||||||||||||||||||||||||||
| 1685 | A reference to an array of column width (or length) values, each given | ||||||||||||||||||||||||||||||||||||||||||
| 1686 | as an integer, real number, or a string value of | ||||||||||||||||||||||||||||||||||||||||||
| 1687 | "I<width>.I<precision>". If a value is zero or null, the length of the | ||||||||||||||||||||||||||||||||||||||||||
| 1688 | corresponding formatted data (if rewindable) and column title length are | ||||||||||||||||||||||||||||||||||||||||||
| 1689 | used to determine a reasonable default. | ||||||||||||||||||||||||||||||||||||||||||
| 1690 | |||||||||||||||||||||||||||||||||||||||||||
| 1691 | If a column's I<width> portion is a positive, non-zero number, then the | ||||||||||||||||||||||||||||||||||||||||||
| 1692 | column will be this wide, regardless of the values lengths of the data | ||||||||||||||||||||||||||||||||||||||||||
| 1693 | in the column. | ||||||||||||||||||||||||||||||||||||||||||
| 1694 | |||||||||||||||||||||||||||||||||||||||||||
| 1695 | If the column's I<width> portion is given as a negative number, then the | ||||||||||||||||||||||||||||||||||||||||||
| 1696 | positive value is used as a minimum column width, with no limit on the | ||||||||||||||||||||||||||||||||||||||||||
| 1697 | maximum column width. In other words, the column will be at least | ||||||||||||||||||||||||||||||||||||||||||
| 1698 | I<width> characters wide. | ||||||||||||||||||||||||||||||||||||||||||
| 1699 | |||||||||||||||||||||||||||||||||||||||||||
| 1700 | If the data is not rewindable, and a column's width value is null or | ||||||||||||||||||||||||||||||||||||||||||
| 1701 | zero, then the length of the column title is used. This may cause severe | ||||||||||||||||||||||||||||||||||||||||||
| 1702 | wrapping of data in the column, if the column data lengths are much | ||||||||||||||||||||||||||||||||||||||||||
| 1703 | greater than the column title widths. | ||||||||||||||||||||||||||||||||||||||||||
| 1704 | |||||||||||||||||||||||||||||||||||||||||||
| 1705 | =item I<$titles> | ||||||||||||||||||||||||||||||||||||||||||
| 1706 | |||||||||||||||||||||||||||||||||||||||||||
| 1707 | The array ref to the column titles; used to determine the minimum | ||||||||||||||||||||||||||||||||||||||||||
| 1708 | acceptable width, as well as the default number of columns. If the | ||||||||||||||||||||||||||||||||||||||||||
| 1709 | C<$titles> array is empty, then the C<$widthspec> array is used to | ||||||||||||||||||||||||||||||||||||||||||
| 1710 | determine the default number of columns. | ||||||||||||||||||||||||||||||||||||||||||
| 1711 | |||||||||||||||||||||||||||||||||||||||||||
| 1712 | =item I<$rewindable> | ||||||||||||||||||||||||||||||||||||||||||
| 1713 | |||||||||||||||||||||||||||||||||||||||||||
| 1714 | A flag indicating whether or not the data being formatted is rewindable. | ||||||||||||||||||||||||||||||||||||||||||
| 1715 | If this is true, a pass over the data will be done in order to calculate | ||||||||||||||||||||||||||||||||||||||||||
| 1716 | the maximum lengths of the actual formatted data, using I<$fmt_sub> | ||||||||||||||||||||||||||||||||||||||||||
| 1717 | (below), rather than just rely on the declared column lengths. This | ||||||||||||||||||||||||||||||||||||||||||
| 1718 | allows for optimal column width adjustments (ie: the actual column | ||||||||||||||||||||||||||||||||||||||||||
| 1719 | widths may be less than the declared column widths). | ||||||||||||||||||||||||||||||||||||||||||
| 1720 | |||||||||||||||||||||||||||||||||||||||||||
| 1721 | If it is not desired to have the column widths dynamically adjusted, | ||||||||||||||||||||||||||||||||||||||||||
| 1722 | then set the I<$rewindable> argument to 0, even if the data is | ||||||||||||||||||||||||||||||||||||||||||
| 1723 | rewindable. | ||||||||||||||||||||||||||||||||||||||||||
| 1724 | |||||||||||||||||||||||||||||||||||||||||||
| 1725 | =item I<$row_sub> | ||||||||||||||||||||||||||||||||||||||||||
| 1726 | |||||||||||||||||||||||||||||||||||||||||||
| 1727 | The code reference to the subroutine which returns the data; invoked | ||||||||||||||||||||||||||||||||||||||||||
| 1728 | only if I<$rewindable> is non-null. | ||||||||||||||||||||||||||||||||||||||||||
| 1729 | |||||||||||||||||||||||||||||||||||||||||||
| 1730 | =item I<$fmt_sub> | ||||||||||||||||||||||||||||||||||||||||||
| 1731 | |||||||||||||||||||||||||||||||||||||||||||
| 1732 | The subroutine used to determine the length of the data when formatted; | ||||||||||||||||||||||||||||||||||||||||||
| 1733 | if this is omitted or null, the length of the data is used by default. | ||||||||||||||||||||||||||||||||||||||||||
| 1734 | The I<$fmt_sub> is used only when the data is rewindable. | ||||||||||||||||||||||||||||||||||||||||||
| 1735 | |||||||||||||||||||||||||||||||||||||||||||
| 1736 | =item I<$types> | ||||||||||||||||||||||||||||||||||||||||||
| 1737 | |||||||||||||||||||||||||||||||||||||||||||
| 1738 | An array reference to the types of each of the value columns; used only | ||||||||||||||||||||||||||||||||||||||||||
| 1739 | when I<$fmt_sub> is invoked. | ||||||||||||||||||||||||||||||||||||||||||
| 1740 | |||||||||||||||||||||||||||||||||||||||||||
| 1741 | =item I<$showmode> | ||||||||||||||||||||||||||||||||||||||||||
| 1742 | |||||||||||||||||||||||||||||||||||||||||||
| 1743 | A string indicating the mode of the eventual display; one of four strings: | ||||||||||||||||||||||||||||||||||||||||||
| 1744 | "C<box>", "C<table>", "C<list>", and "C<html>". Used to adjust widths | ||||||||||||||||||||||||||||||||||||||||||
| 1745 | for formatting requirements. | ||||||||||||||||||||||||||||||||||||||||||
| 1746 | |||||||||||||||||||||||||||||||||||||||||||
| 1747 | =item I<$max_width> | ||||||||||||||||||||||||||||||||||||||||||
| 1748 | |||||||||||||||||||||||||||||||||||||||||||
| 1749 | The maximum width of the table being formatted. If set, and the total | ||||||||||||||||||||||||||||||||||||||||||
| 1750 | sum of the individual columns exceeds this value, the column widths are | ||||||||||||||||||||||||||||||||||||||||||
| 1751 | scaled down uniformly. If not set (null), no column width scaling is done. | ||||||||||||||||||||||||||||||||||||||||||
| 1752 | |||||||||||||||||||||||||||||||||||||||||||
| 1753 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1754 | |||||||||||||||||||||||||||||||||||||||||||
| 1755 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1756 | |||||||||||||||||||||||||||||||||||||||||||
| 1757 | 161 | ▶ | sub calc_widths { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
calc_widths: called CC=48 SCAR=39.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1758 | 161 | my $widthspec = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1759 | 161 | my $titles = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1760 | 161 | my $rewindable = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1761 | 161 | my $row_sub = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1762 | 161 | my $fmt_sub = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1763 | 161 | my $types = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1764 | 161 | my $showmode = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1765 | 161 | my $max_width = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1766 | |||||||||||||||||||||||||||||||||||||||||||
| 1767 | 161 | my @precision; # array of precision values | |||||||||||||||||||||||||||||||||||||||||
| 1768 | my @setprec; # array of flags to set default precision | ||||||||||||||||||||||||||||||||||||||||||
| 1769 | 161 | my @widths; # array of widths | |||||||||||||||||||||||||||||||||||||||||
| 1770 | 161 | my @max_widths; # array of max widths | |||||||||||||||||||||||||||||||||||||||||
| 1771 | 161 | my @expandable; # flag if widths expandable | |||||||||||||||||||||||||||||||||||||||||
| 1772 | 161 | my $num_cols; | |||||||||||||||||||||||||||||||||||||||||
| 1773 | 161 | my $c; | |||||||||||||||||||||||||||||||||||||||||
| 1774 | |||||||||||||||||||||||||||||||||||||||||||
| 1775 | 161 | ▶ | if ($#$widthspec >= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1776 | 144 | @precision = @$widthspec; | |||||||||||||||||||||||||||||||||||||||||
| 1777 | 144 | ▶ | foreach (@precision) { s/^.*\.(\d+)/$1/ || ($_ = ''); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1778 | |||||||||||||||||||||||||||||||||||||||||||
| 1779 | # The setprec array indicates which columns need a default precision | ||||||||||||||||||||||||||||||||||||||||||
| 1780 | 144 | @setprec = map { !length } @precision; | |||||||||||||||||||||||||||||||||||||||||
| 1781 | |||||||||||||||||||||||||||||||||||||||||||
| 1782 | # Get the integer portions | ||||||||||||||||||||||||||||||||||||||||||
| 1783 | 144 | ▶ | @widths = map { length($_) ? int : 0 } @$widthspec; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1784 | |||||||||||||||||||||||||||||||||||||||||||
| 1785 | # Set @expandable if negative widths | ||||||||||||||||||||||||||||||||||||||||||
| 1786 | 144 | @expandable = map { $_ < 0 } @widths; | |||||||||||||||||||||||||||||||||||||||||
| 1787 | |||||||||||||||||||||||||||||||||||||||||||
| 1788 | # Convert widths to all positive values | ||||||||||||||||||||||||||||||||||||||||||
| 1789 | 144 | @widths = map abs, @widths; | |||||||||||||||||||||||||||||||||||||||||
| 1790 | 144 | @max_widths = (0) x (1 + $#widths); # no maximums yet | |||||||||||||||||||||||||||||||||||||||||
| 1791 | 144 | $num_cols = 1 + $#widths; | |||||||||||||||||||||||||||||||||||||||||
| 1792 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1793 | # No widths given | ||||||||||||||||||||||||||||||||||||||||||
| 1794 | 17 | @expandable = (1) x (1 + $#$titles); | |||||||||||||||||||||||||||||||||||||||||
| 1795 | 17 | @precision = ('') x (1 + $#$titles); | |||||||||||||||||||||||||||||||||||||||||
| 1796 | 17 | @setprec = @expandable; | |||||||||||||||||||||||||||||||||||||||||
| 1797 | 17 | @max_widths = map length, @$titles; # initialize maximums to title widths | |||||||||||||||||||||||||||||||||||||||||
| 1798 | 17 | $num_cols = 1 + $#$titles; | |||||||||||||||||||||||||||||||||||||||||
| 1799 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1800 | |||||||||||||||||||||||||||||||||||||||||||
| 1801 | # If the data is rewindable, scan and accumulate *actual* widths for | ||||||||||||||||||||||||||||||||||||||||||
| 1802 | # each column, using the title lengths as a minimum. | ||||||||||||||||||||||||||||||||||||||||||
| 1803 | 161 | ▶ | if ($rewindable) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1804 | 133 | my @values; | |||||||||||||||||||||||||||||||||||||||||
| 1805 | my @prectype; | ||||||||||||||||||||||||||||||||||||||||||
| 1806 | 133 | ▶ | if (ref($types) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1807 | 133 | @prectype = map {/float|num(eric|ber)|money|dec|real|precision|double/i } @$types; | |||||||||||||||||||||||||||||||||||||||||
| 1808 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1809 | |||||||||||||||||||||||||||||||||||||||||||
| 1810 | # Scan the values | ||||||||||||||||||||||||||||||||||||||||||
| 1811 | 133 | ▶ | while ((@values = &$row_sub(0)), $#values >= $[) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1812 | # If the new row is larger than the number of titles, adjust | ||||||||||||||||||||||||||||||||||||||||||
| 1813 | # the info arrays.. | ||||||||||||||||||||||||||||||||||||||||||
| 1814 | 662 | ▶ | if ($num_cols < 1 + $#values) { # new column? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1815 | 1 | $num_cols = 1 + $#values; # new # of columns | |||||||||||||||||||||||||||||||||||||||||
| 1816 | 1 | ▶ | for ($c = $#expandable + 1; $c <= $#values; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1817 | 3 | $expandable[$c] = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1818 | 3 | $precision[$c] = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1819 | 3 | $setprec[$c] = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1820 | 3 | $max_widths[$c] = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1821 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1822 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1823 | 662 | my $len; | |||||||||||||||||||||||||||||||||||||||||
| 1824 | my $value; | ||||||||||||||||||||||||||||||||||||||||||
| 1825 | 662 | ▶ | for ($c = 0; $c < $num_cols; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1826 | # Does this column's precision need setting? | ||||||||||||||||||||||||||||||||||||||||||
| 1827 | 3066 | ▶ | if ($setprec[$c]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1828 | # Yes, is it a type of value which can use the precision? | ||||||||||||||||||||||||||||||||||||||||||
| 1829 | 615 | ▶ | if ($prectype[$c]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1830 | # yes, how much is the current value's default precision? | ||||||||||||||||||||||||||||||||||||||||||
| 1831 | 0 | ▶ | if ($values[$c] =~ /\.(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1832 | 0 | ▶ | $precision[$c] = length($1) if length($1) > $precision[$c]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1833 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1834 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1835 | # No, this column can't use the precision value -- don't | ||||||||||||||||||||||||||||||||||||||||||
| 1836 | # do this check on this column again | ||||||||||||||||||||||||||||||||||||||||||
| 1837 | 615 | $precision[$c] = $setprec[$c] = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1838 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1839 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1840 | |||||||||||||||||||||||||||||||||||||||||||
| 1841 | # Now, let's get the formatted value so we can guess the best | ||||||||||||||||||||||||||||||||||||||||||
| 1842 | # default widths | ||||||||||||||||||||||||||||||||||||||||||
| 1843 | $value = | ||||||||||||||||||||||||||||||||||||||||||
| 1844 | # If a fmt_sub is available, use it to format the value | ||||||||||||||||||||||||||||||||||||||||||
| 1845 | 3066 | ▶ | $fmt_sub ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1846 | &$fmt_sub($values[$c], $types->[$c], 0, 0, $precision[$c], $showmode) | ||||||||||||||||||||||||||||||||||||||||||
| 1847 | # If no fmt sub, then use Perl stringify | ||||||||||||||||||||||||||||||||||||||||||
| 1848 | : length($showmode eq 'html' ? # in HTML mode? | ||||||||||||||||||||||||||||||||||||||||||
| 1849 | &PlainText($values[$c]) # use plain text | ||||||||||||||||||||||||||||||||||||||||||
| 1850 | : $values[$c]); # else, use raw text | ||||||||||||||||||||||||||||||||||||||||||
| 1851 | 3066 | $len = length($value); | |||||||||||||||||||||||||||||||||||||||||
| 1852 | |||||||||||||||||||||||||||||||||||||||||||
| 1853 | 3066 | ▶ | $max_widths[$c] = $len if | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$c > $#max_widths or $len > $max_widths[$c]
MC/DC50%1/2
$c > $#max_widths or $len > $max_widths[$c]
$c > $#max_widths
$len > $max_widths[$c]
Truth table66%2/3
A or B
A= $c > $#max_widthsB= $len > $max_widths[$c]
| |||||||||||||||||||||||||||||||||||||||||||
| 1854 | $c > $#max_widths || $len > $max_widths[$c]; | ||||||||||||||||||||||||||||||||||||||||||
| 1855 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1856 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1857 | # okay -- maximums scanned. | ||||||||||||||||||||||||||||||||||||||||||
| 1858 | # If the maximum table width set, scale the max_widths | ||||||||||||||||||||||||||||||||||||||||||
| 1859 | 133 | ▶ | $max_width = 0 unless | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $max_width and $max_width ne ""
MC/DC50%1/2
defined $max_width and $max_width ne ""
defined $max_width
$max_width ne ""
Truth table66%2/3
A and B
A= defined $max_widthB= $max_width ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 1860 | defined($max_width) && $max_width ne ''; | ||||||||||||||||||||||||||||||||||||||||||
| 1861 | 133 | ▶ | if ($max_width > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1862 | # Start with the given maximum, but adjust it to account for | ||||||||||||||||||||||||||||||||||||||||||
| 1863 | # the formatting and space characters. | ||||||||||||||||||||||||||||||||||||||||||
| 1864 | 50 | my $max_width = $max_width; | |||||||||||||||||||||||||||||||||||||||||
| 1865 | 50 | ▶ | $max_width -= $num_cols * 3 + 2 if $showmode eq 'box'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1866 | 50 | ▶ | $max_width -= $num_cols * 2 - 1 if $showmode eq 'table'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1867 | 50 | my $total = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1868 | # Calculate the total table width | ||||||||||||||||||||||||||||||||||||||||||
| 1869 | 50 | ▶ | for ($c = 0; $c <= $#max_widths; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1870 | 250 | $total += $max_widths[$c]; | |||||||||||||||||||||||||||||||||||||||||
| 1871 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1872 | 50 | ▶ | if ($max_width < $total) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1873 | # Now scale it to the adjusted maximum table width | ||||||||||||||||||||||||||||||||||||||||||
| 1874 | 44 | ▶ | for ($c = 0; $c <= $#max_widths; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1875 | 220 | $max_widths[$c] = int($max_widths[$c] * | |||||||||||||||||||||||||||||||||||||||||
| 1876 | $max_width / $total); | ||||||||||||||||||||||||||||||||||||||||||
| 1877 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1878 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1879 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1880 | |||||||||||||||||||||||||||||||||||||||||||
| 1881 | # If the column is expandable, allow the width to grow to the max_width. | ||||||||||||||||||||||||||||||||||||||||||
| 1882 | # If the column is not expandable, allow the width to shrink to | ||||||||||||||||||||||||||||||||||||||||||
| 1883 | # the max_width if it is smaller. | ||||||||||||||||||||||||||||||||||||||||||
| 1884 | |||||||||||||||||||||||||||||||||||||||||||
| 1885 | 133 | ▶ | if ($#widths < 0) { # were there any widths? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1886 | 17 | @widths = @max_widths; # nope, set them to the scanned values | |||||||||||||||||||||||||||||||||||||||||
| 1887 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1888 | 116 | ▶ | $num_cols = max($num_cols, 1 + $#widths) if $#widths >= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1889 | 116 | my $len; | |||||||||||||||||||||||||||||||||||||||||
| 1890 | 116 | ▶ | for ($c = 0; $c < $num_cols; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1891 | # provide defaults first | ||||||||||||||||||||||||||||||||||||||||||
| 1892 | 544 | ▶ | $max_widths[$c] = 0 if !defined($max_widths[$c]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1893 | 544 | ▶ | $widths[$c] = $max_widths[$c] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$c > $#widths or not defined $widths[$c]
MC/DC0%0/2
$c > $#widths or not defined $widths[$c]
$c > $#widths
not defined $widths[$c]
Truth table33%1/3
A or not(B)
A= $c > $#widthsB= not defined $widths[$c]
| |||||||||||||||||||||||||||||||||||||||||||
| 1894 | if $c > $#widths || !defined($widths[$c]); | ||||||||||||||||||||||||||||||||||||||||||
| 1895 | # if the column can shrink, let it | ||||||||||||||||||||||||||||||||||||||||||
| 1896 | 544 | ▶ | if ($max_widths[$c] < $widths[$c]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1897 | 348 | $widths[$c] = $max_widths[$c]; | |||||||||||||||||||||||||||||||||||||||||
| 1898 | ▶ | } elsif ($expandable[$c] || !$widths[$c]) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$expandable[$c] or not $widths[$c]
MC/DC100%2/2
$expandable[$c] or not $widths[$c]
$expandable[$c]
not $widths[$c]
Truth table100%3/3
A or not(B)
A= $expandable[$c]B= not $widths[$c]
| |||||||||||||||||||||||||||||||||||||||||||
| 1899 | # allow the width to grow to the maximum width | ||||||||||||||||||||||||||||||||||||||||||
| 1900 | 44 | ▶ | $widths[$c] = $max_widths[$c] if $widths[$c] < $max_widths[$c]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1901 | ▶ | } elsif ($max_widths[$c] > $widths[$c] && $widths[$c] > 0) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$max_widths[$c] > $widths[$c] and $widths[$c] > 0
MC/DC50%1/2
$max_widths[$c] > $widths[$c] and $widths[$c] > 0
$max_widths[$c] > $widths[$c]
$widths[$c] > 0
Truth table66%2/3
A and B
A= $max_widths[$c] > $widths[$c]B= $widths[$c] > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 1902 | # not expandable -- set the max width to the width value | ||||||||||||||||||||||||||||||||||||||||||
| 1903 | 98 | $max_widths[$c] = $widths[$c]; | |||||||||||||||||||||||||||||||||||||||||
| 1904 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1905 | # In either case, however, ensure that the widths are at | ||||||||||||||||||||||||||||||||||||||||||
| 1906 | # least as long as the title length | ||||||||||||||||||||||||||||||||||||||||||
| 1907 | 544 | ▶ | if ($c <= $#$titles) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1908 | 544 | ▶ | if (defined($titles->[$c])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1909 | # If we're in HTML mode, get the length of the plaintext | ||||||||||||||||||||||||||||||||||||||||||
| 1910 | 544 | ▶ | $len = length($showmode eq 'html' ? &PlainText($titles->[$c]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1911 | # else, use raw text. | ||||||||||||||||||||||||||||||||||||||||||
| 1912 | : $titles->[$c]); | ||||||||||||||||||||||||||||||||||||||||||
| 1913 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1914 | 0 | $len = length("Field_$c"); | |||||||||||||||||||||||||||||||||||||||||
| 1915 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1916 | 544 | ▶ | $widths[$c] = $len | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1917 | if $widths[$c] < $len; | ||||||||||||||||||||||||||||||||||||||||||
| 1918 | 544 | ▶ | $max_widths[$c] = $len | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1919 | if $max_widths[$c] < $len; | ||||||||||||||||||||||||||||||||||||||||||
| 1920 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1921 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1922 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1923 | 133 | &$row_sub(1); # reset the pointer for the next scan | |||||||||||||||||||||||||||||||||||||||||
| 1924 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1925 | # Use title width as default if original width is null or zero | ||||||||||||||||||||||||||||||||||||||||||
| 1926 | 28 | my $len; | |||||||||||||||||||||||||||||||||||||||||
| 1927 | 28 | ▶ | for ($c = 0; $c <= $#widths; $c++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1928 | 128 | ▶ | next unless $c <= $#$titles; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1929 | # Get the length of the title (sans HTML text if in that mode) | ||||||||||||||||||||||||||||||||||||||||||
| 1930 | 128 | ▶ | $len = length($showmode eq 'html' ? &PlainText($titles->[$c]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1931 | : $titles->[$c]); | ||||||||||||||||||||||||||||||||||||||||||
| 1932 | 128 | ▶ | $widths[$c] = $len if $widths[$c] < $len; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1933 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1934 | # Can't scan the data, so the maximums can only be set by using the | ||||||||||||||||||||||||||||||||||||||||||
| 1935 | # explicit widths. | ||||||||||||||||||||||||||||||||||||||||||
| 1936 | 28 | @max_widths = @widths; | |||||||||||||||||||||||||||||||||||||||||
| 1937 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1938 | 161 | ($num_cols, \@widths, \@precision, \@max_widths); | |||||||||||||||||||||||||||||||||||||||||
| 1939 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1940 | |||||||||||||||||||||||||||||||||||||||||||
| 1941 | ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 1942 | |||||||||||||||||||||||||||||||||||||||||||
| 1943 | =head1 putcell | ||||||||||||||||||||||||||||||||||||||||||
| 1944 | |||||||||||||||||||||||||||||||||||||||||||
| 1945 | S< >I<$wrapped> = B<&putcell>( I<\@cells>, I<$c>, I<$cell_width>, I<\@prefix>, I<\@suffix>, I<$wrap_flag> ); | ||||||||||||||||||||||||||||||||||||||||||
| 1946 | |||||||||||||||||||||||||||||||||||||||||||
| 1947 | Output the contents of an array cell at I<$cell>[I<$c>], causing text | ||||||||||||||||||||||||||||||||||||||||||
| 1948 | longer than I<$cell_width> to be saved for output on subsequent calls. | ||||||||||||||||||||||||||||||||||||||||||
| 1949 | Prefixing the output of each cell's value is a string from the | ||||||||||||||||||||||||||||||||||||||||||
| 1950 | two-element array I<@prefix>. Suffixing each cell's value is a string | ||||||||||||||||||||||||||||||||||||||||||
| 1951 | from the two-element array I<@suffix>. The first element of either | ||||||||||||||||||||||||||||||||||||||||||
| 1952 | array is selected when I<$wrap_flag> is zero or null, or when there is | ||||||||||||||||||||||||||||||||||||||||||
| 1953 | no more text in the current to be output. The second element | ||||||||||||||||||||||||||||||||||||||||||
| 1954 | is selected when I<$wrap_flag> is non-zero, and when there is more text in | ||||||||||||||||||||||||||||||||||||||||||
| 1955 | the current cell to be output. | ||||||||||||||||||||||||||||||||||||||||||
| 1956 | |||||||||||||||||||||||||||||||||||||||||||
| 1957 | In the case of text longer than I<$cell_width>, a non-zero value is | ||||||||||||||||||||||||||||||||||||||||||
| 1958 | returned. | ||||||||||||||||||||||||||||||||||||||||||
| 1959 | |||||||||||||||||||||||||||||||||||||||||||
| 1960 | Cells with undefined data are not output, nor are the prefix or suffix | ||||||||||||||||||||||||||||||||||||||||||
| 1961 | strings. | ||||||||||||||||||||||||||||||||||||||||||
| 1962 | |||||||||||||||||||||||||||||||||||||||||||
| 1963 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1964 | |||||||||||||||||||||||||||||||||||||||||||
| 1965 | 3989 | ▶ | sub putcell { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
putcell: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1966 | 3989 | my $cells = shift; # ref to cell array | |||||||||||||||||||||||||||||||||||||||||
| 1967 | 3989 | my $c = shift; # index | |||||||||||||||||||||||||||||||||||||||||
| 1968 | 3989 | my $cell_width = shift; # maximum width of the cell | |||||||||||||||||||||||||||||||||||||||||
| 1969 | 3989 | my $prefix = shift; # 2-elt array of prefix strings | |||||||||||||||||||||||||||||||||||||||||
| 1970 | 3989 | my $suffix = shift; # 2-elt array of suffix strings | |||||||||||||||||||||||||||||||||||||||||
| 1971 | 3989 | my $wrap_flag = shift; # non-zero for wrapped lines | |||||||||||||||||||||||||||||||||||||||||
| 1972 | 3989 | my $more; | |||||||||||||||||||||||||||||||||||||||||
| 1973 | |||||||||||||||||||||||||||||||||||||||||||
| 1974 | 3989 | my $v = $cells->[$c]; # get the data | |||||||||||||||||||||||||||||||||||||||||
| 1975 | 3989 | my $px = 0; # prefix index | |||||||||||||||||||||||||||||||||||||||||
| 1976 | 3989 | my $sx = 0; # suffix index | |||||||||||||||||||||||||||||||||||||||||
| 1977 | 3989 | ▶ | if (defined $v) { # not undef data? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1978 | 3989 | my $text = $v; # save the text | |||||||||||||||||||||||||||||||||||||||||
| 1979 | 3989 | ▶ | $cell_width = 1 if !defined($cell_width) || $cell_width == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $cell_width or $cell_width == 0
MC/DC50%1/2
not defined $cell_width or $cell_width == 0
not defined $cell_width
$cell_width == 0
Truth table66%2/3
not(A) or B
A= not defined $cell_widthB= $cell_width == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 1980 | 3989 | ▶ | if ($cell_width <= length($text)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1981 | 2359 | $more = substr($text,$cell_width); | |||||||||||||||||||||||||||||||||||||||||
| 1982 | 2359 | $v = substr($text,0,$cell_width); | |||||||||||||||||||||||||||||||||||||||||
| 1983 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1984 | 1630 | $v = $text; $more = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1985 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1986 | |||||||||||||||||||||||||||||||||||||||||||
| 1987 | # wrapping? | ||||||||||||||||||||||||||||||||||||||||||
| 1988 | 3989 | ▶ | if ($more ne '' && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$more ne "" and $v =~ /([-,;? \t])([^-,;? \t0-9]*)$/ and length $2 <= $List_Wrap_Margin
$more ne "" and $v =~ /([-,;? \t])([^-,;? \t0-9]*)$/
MC/DC66%2/3
$more ne "" and $v =~ /([-,;? \t])([^-,;? \t0-9]*)$/ and length $2 <= $List_Wrap_Margin
$more ne ""
$v =~ /([-,;? \t])([^-,;? \t0-9]*)$/
length $2 <= $List_Wrap_Margin
Truth table75%3/4
A and B and C
A= $more ne ""B= $v =~ /([-,;? \t])([^-,;? \t0-9]*)$/C= length $2 <= $List_Wrap_Margin
| |||||||||||||||||||||||||||||||||||||||||||
| 1989 | |||||||||||||||||||||||||||||||||||||||||||
| 1990 | # See if we can wrap on a word boundary, instead of | ||||||||||||||||||||||||||||||||||||||||||
| 1991 | # arbitrarily splitting one; note that we try to not | ||||||||||||||||||||||||||||||||||||||||||
| 1992 | # split grouped numbers (1,345) or reals (1.234). | ||||||||||||||||||||||||||||||||||||||||||
| 1993 | |||||||||||||||||||||||||||||||||||||||||||
| 1994 | $v =~ /([-,;? \t])([^-,;? \t0-9]*)$/ && | ||||||||||||||||||||||||||||||||||||||||||
| 1995 | |||||||||||||||||||||||||||||||||||||||||||
| 1996 | # but also make sure that it is not too long | ||||||||||||||||||||||||||||||||||||||||||
| 1997 | |||||||||||||||||||||||||||||||||||||||||||
| 1998 | length($2) <= $List_Wrap_Margin ) | ||||||||||||||||||||||||||||||||||||||||||
| 1999 | { | ||||||||||||||||||||||||||||||||||||||||||
| 2000 | |||||||||||||||||||||||||||||||||||||||||||
| 2001 | # Okay, cut on the word boundary, leaving the break char | ||||||||||||||||||||||||||||||||||||||||||
| 2002 | # on the tail end of the current output value | ||||||||||||||||||||||||||||||||||||||||||
| 2003 | |||||||||||||||||||||||||||||||||||||||||||
| 2004 | 548 | my $cut = $cell_width - length($2); | |||||||||||||||||||||||||||||||||||||||||
| 2005 | 548 | $v = substr($text,0,$cut); # get new value | |||||||||||||||||||||||||||||||||||||||||
| 2006 | 548 | $more = substr($text, $cut); # new remainder | |||||||||||||||||||||||||||||||||||||||||
| 2007 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2008 | 3989 | $cells->[$c] = $more; # leave the rest for later | |||||||||||||||||||||||||||||||||||||||||
| 2009 | 3989 | ▶ | $px = $wrap_flag != 0 && length($v) > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$wrap_flag != 0 && length $v > 0
MC/DC100%2/2
$wrap_flag != 0 && length $v > 0
$wrap_flag != 0
length $v > 0
Truth table100%3/3
A && B
A= $wrap_flag != 0B= length $v > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 2010 | 3989 | $sx = length($more) > 0; | |||||||||||||||||||||||||||||||||||||||||
| 2011 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2012 | 3989 | my $fmt = sprintf("%%s%%-%ds%%s",$cell_width); | |||||||||||||||||||||||||||||||||||||||||
| 2013 | 3989 | put $fmt,$prefix->[$px],$v,$suffix->[$sx]; # output something (could be blanks) | |||||||||||||||||||||||||||||||||||||||||
| 2014 | 3989 | $sx; # leave wrapped flag | |||||||||||||||||||||||||||||||||||||||||
| 2015 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2016 | |||||||||||||||||||||||||||||||||||||||||||
| 2017 | ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 2018 | |||||||||||||||||||||||||||||||||||||||||||
| 2019 | =head1 center | ||||||||||||||||||||||||||||||||||||||||||
| 2020 | |||||||||||||||||||||||||||||||||||||||||||
| 2021 | Center a string within a given width. | ||||||||||||||||||||||||||||||||||||||||||
| 2022 | |||||||||||||||||||||||||||||||||||||||||||
| 2023 | S< >I<$field> = B<center> I<$string>, I<$width>; | ||||||||||||||||||||||||||||||||||||||||||
| 2024 | |||||||||||||||||||||||||||||||||||||||||||
| 2025 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2026 | |||||||||||||||||||||||||||||||||||||||||||
| 2027 | 343 | ▶ | sub center { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
center: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2028 | 343 | my($string,$width) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 2029 | 343 | ▶ | $width = 0 if !defined($width); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2030 | 343 | ▶ | return $string if length($string) >= $width; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2031 | 281 | my($pad) = int(($width - length($string))/2); # pad left half | |||||||||||||||||||||||||||||||||||||||||
| 2032 | 281 | my($center) = (' ' x $pad) . $string; | |||||||||||||||||||||||||||||||||||||||||
| 2033 | 281 | $pad = $width - length($center); | |||||||||||||||||||||||||||||||||||||||||
| 2034 | 281 | $center .= ' ' x $pad; # pad right half | |||||||||||||||||||||||||||||||||||||||||
| 2035 | 281 | $center; # return with the centered string | |||||||||||||||||||||||||||||||||||||||||
| 2036 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2037 | |||||||||||||||||||||||||||||||||||||||||||
| 2038 | ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 2039 | |||||||||||||||||||||||||||||||||||||||||||
| 2040 | =head1 max | ||||||||||||||||||||||||||||||||||||||||||
| 2041 | |||||||||||||||||||||||||||||||||||||||||||
| 2042 | Compute the maximum value from a list of values. | ||||||||||||||||||||||||||||||||||||||||||
| 2043 | |||||||||||||||||||||||||||||||||||||||||||
| 2044 | S< >I<$max> = B<&max>( I<@values> ); | ||||||||||||||||||||||||||||||||||||||||||
| 2045 | |||||||||||||||||||||||||||||||||||||||||||
| 2046 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2047 | |||||||||||||||||||||||||||||||||||||||||||
| 2048 | 153 | ▶ | sub max { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2049 | 153 | my ($max) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2050 | 153 | ▶ | foreach (@_) { $max = $_ if $max < $_; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2051 | 153 | $max; | |||||||||||||||||||||||||||||||||||||||||
| 2052 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2053 | |||||||||||||||||||||||||||||||||||||||||||
| 2054 | ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 2055 | |||||||||||||||||||||||||||||||||||||||||||
| 2056 | =head1 min | ||||||||||||||||||||||||||||||||||||||||||
| 2057 | |||||||||||||||||||||||||||||||||||||||||||
| 2058 | Compute the minum value from a list of values. | ||||||||||||||||||||||||||||||||||||||||||
| 2059 | |||||||||||||||||||||||||||||||||||||||||||
| 2060 | S< >I<$min> = B<&min>( I<@values> ); | ||||||||||||||||||||||||||||||||||||||||||
| 2061 | |||||||||||||||||||||||||||||||||||||||||||
| 2062 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2063 | |||||||||||||||||||||||||||||||||||||||||||
| 2064 | 1696 | ▶ | sub min { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2065 | 1696 | my ($min) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2066 | 1696 | ▶ | foreach (@_) { $min = $_ if $min > $_; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2067 | 1696 | $min; | |||||||||||||||||||||||||||||||||||||||||
| 2068 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2069 | |||||||||||||||||||||||||||||||||||||||||||
| 2070 | ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 2071 | |||||||||||||||||||||||||||||||||||||||||||
| 2072 | =head1 max_length | ||||||||||||||||||||||||||||||||||||||||||
| 2073 | |||||||||||||||||||||||||||||||||||||||||||
| 2074 | Compute the maximum length of a set of strings in an array reference. | ||||||||||||||||||||||||||||||||||||||||||
| 2075 | |||||||||||||||||||||||||||||||||||||||||||
| 2076 | S< >I<$maxlength> = B<&max_length>( I<\@array_ref> ); | ||||||||||||||||||||||||||||||||||||||||||
| 2077 | |||||||||||||||||||||||||||||||||||||||||||
| 2078 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2079 | |||||||||||||||||||||||||||||||||||||||||||
| 2080 | 37 | ▶ | sub max_length { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_length: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2081 | 37 | my($aref) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2082 | 37 | my(@lens) = map { length } @$aref; | |||||||||||||||||||||||||||||||||||||||||
| 2083 | 37 | my($maxlen) = max( @lens ); | |||||||||||||||||||||||||||||||||||||||||
| 2084 | 37 | $maxlen; | |||||||||||||||||||||||||||||||||||||||||
| 2085 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2086 | |||||||||||||||||||||||||||||||||||||||||||
| 2087 | ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 2088 | |||||||||||||||||||||||||||||||||||||||||||
| 2089 | =head1 htmltext | ||||||||||||||||||||||||||||||||||||||||||
| 2090 | |||||||||||||||||||||||||||||||||||||||||||
| 2091 | Translate regular text for output into an HTML document. This means | ||||||||||||||||||||||||||||||||||||||||||
| 2092 | certain characters, such as "&", ">", and "<" must be escaped. | ||||||||||||||||||||||||||||||||||||||||||
| 2093 | |||||||||||||||||||||||||||||||||||||||||||
| 2094 | S< >I<$output> = B<&htmltext>( I<$input> [, I<$allflag> ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 2095 | |||||||||||||||||||||||||||||||||||||||||||
| 2096 | If I<$allflag> is non-zero, then all characters are escaped. Normally, | ||||||||||||||||||||||||||||||||||||||||||
| 2097 | only the four HTML syntactic break characters are escaped. | ||||||||||||||||||||||||||||||||||||||||||
| 2098 | |||||||||||||||||||||||||||||||||||||||||||
| 2099 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2100 | |||||||||||||||||||||||||||||||||||||||||||
| 2101 | # htmltext -- translate special text into HTML esacpes | ||||||||||||||||||||||||||||||||||||||||||
| 2102 | 935 | ▶ | sub htmltext { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
htmltext: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2103 | 935 | local($_) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2104 | 935 | my $all = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2105 | 935 | ▶ | return undef unless defined($_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2106 | 935 | s/&(?!(?:amp|quot|gt|lt|#\d+);)/&/g; | |||||||||||||||||||||||||||||||||||||||||
| 2107 | 935 | s/\"/"/g; | |||||||||||||||||||||||||||||||||||||||||
| 2108 | 935 | s/>/>/g; | |||||||||||||||||||||||||||||||||||||||||
| 2109 | 935 | s/</\</g; | |||||||||||||||||||||||||||||||||||||||||
| 2110 | 935 | ▶ | if ($all) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2111 | 75 | s/ /\ /g; | |||||||||||||||||||||||||||||||||||||||||
| 2112 | 75 | s/\t/\	/g; | |||||||||||||||||||||||||||||||||||||||||
| 2113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2114 | 935 | $_; | |||||||||||||||||||||||||||||||||||||||||
| 2115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2116 | |||||||||||||||||||||||||||||||||||||||||||
| 2117 | ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 2118 | |||||||||||||||||||||||||||||||||||||||||||
| 2119 | =head1 out | ||||||||||||||||||||||||||||||||||||||||||
| 2120 | |||||||||||||||||||||||||||||||||||||||||||
| 2121 | Print text followed by a newline. | ||||||||||||||||||||||||||||||||||||||||||
| 2122 | |||||||||||||||||||||||||||||||||||||||||||
| 2123 | S< >B<out> I<$fmt> [, I<@text> ]; | ||||||||||||||||||||||||||||||||||||||||||
| 2124 | |||||||||||||||||||||||||||||||||||||||||||
| 2125 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2126 | |||||||||||||||||||||||||||||||||||||||||||
| 2127 | 4046 | ▶ | sub out { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
out: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2128 | 4046 | my $fmt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2129 | 4046 | ▶ | $fmt .= "\n" unless $fmt =~ /\n$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2130 | 4046 | printf STDOUT $fmt, @_; | |||||||||||||||||||||||||||||||||||||||||
| 2131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2132 | |||||||||||||||||||||||||||||||||||||||||||
| 2133 | ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 2134 | |||||||||||||||||||||||||||||||||||||||||||
| 2135 | =head1 put | ||||||||||||||||||||||||||||||||||||||||||
| 2136 | |||||||||||||||||||||||||||||||||||||||||||
| 2137 | Print text (without a trailing newline). | ||||||||||||||||||||||||||||||||||||||||||
| 2138 | |||||||||||||||||||||||||||||||||||||||||||
| 2139 | S< >B<out> I<$fmt> [, I<@text> ]; | ||||||||||||||||||||||||||||||||||||||||||
| 2140 | |||||||||||||||||||||||||||||||||||||||||||
| 2141 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2142 | |||||||||||||||||||||||||||||||||||||||||||
| 2143 | 4453 | ▶ | sub put { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2144 | 4453 | printf STDOUT @_; | |||||||||||||||||||||||||||||||||||||||||
| 2145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2146 | |||||||||||||||||||||||||||||||||||||||||||
| 2147 | ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 2148 | |||||||||||||||||||||||||||||||||||||||||||
| 2149 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 2150 | |||||||||||||||||||||||||||||||||||||||||||
| 2151 | Alan K. Stebbens <aks@stebbens.org> | ||||||||||||||||||||||||||||||||||||||||||
| 2152 | |||||||||||||||||||||||||||||||||||||||||||
| 2153 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2154 | |||||||||||||||||||||||||||||||||||||||||||
| 2155 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 2156 | |||||||||||||||||||||||||||||||||||||||||||
| 2157 | =over 10 | ||||||||||||||||||||||||||||||||||||||||||
| 2158 | |||||||||||||||||||||||||||||||||||||||||||
| 2159 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 2160 | |||||||||||||||||||||||||||||||||||||||||||
| 2161 | Embedded HTML is how the user can insert formatting overrides. However, | ||||||||||||||||||||||||||||||||||||||||||
| 2162 | the HTML formatting techniques have not been given much consideration -- | ||||||||||||||||||||||||||||||||||||||||||
| 2163 | feel free to provide constructive feedback. | ||||||||||||||||||||||||||||||||||||||||||
| 2164 | |||||||||||||||||||||||||||||||||||||||||||
| 2165 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 2166 | |||||||||||||||||||||||||||||||||||||||||||
| 2167 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2168 | |||||||||||||||||||||||||||||||||||||||||||
| 2169 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2170 | 23 | 1; | |||||||||||||||||||||||||||||||||||||||||