line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Text::Table - Organize Data in Tables |
2
|
|
|
|
|
|
|
package Text::Table; |
3
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
291040
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
178
|
|
5
|
6
|
|
|
6
|
|
33
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
200
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
136
|
use 5.008; |
|
6
|
|
|
|
|
20
|
|
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
37
|
use List::Util qw(sum max); |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
538
|
|
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
1791
|
use Text::Aligner qw(align); |
|
6
|
|
|
|
|
65615
|
|
|
6
|
|
|
|
|
696
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.133'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use overload ( |
16
|
|
|
|
|
|
|
# Don't stringify when only doing boolean tests, since stringification can |
17
|
|
|
|
|
|
|
# be expensive for large tables: |
18
|
1
|
|
|
1
|
|
414
|
bool => sub { return 1; }, |
19
|
|
|
|
|
|
|
# Stringify when Table instances are used in most other scalar cases: |
20
|
6
|
|
|
|
|
56
|
'""' => 'stringify', |
21
|
6
|
|
|
6
|
|
5899
|
); |
|
6
|
|
|
|
|
4609
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
### User interface: How to specify columns and column separators |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _is_sep { |
26
|
107
|
|
|
107
|
|
154
|
my $datum = shift; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return |
29
|
|
|
|
|
|
|
( |
30
|
|
|
|
|
|
|
defined($datum) |
31
|
|
|
|
|
|
|
and |
32
|
|
|
|
|
|
|
( |
33
|
|
|
|
|
|
|
(ref($datum) eq 'SCALAR') |
34
|
|
|
|
|
|
|
or |
35
|
|
|
|
|
|
|
(ref($datum) eq 'HASH' and $datum->{is_sep}) |
36
|
107
|
|
33
|
|
|
571
|
) |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _get_sep_title_body |
41
|
|
|
|
|
|
|
{ |
42
|
16
|
|
|
16
|
|
25
|
my $sep = shift; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return |
45
|
|
|
|
|
|
|
+( ref($sep) eq 'HASH' ) |
46
|
7
|
|
|
|
|
39
|
? @{ $sep }{qw(title body)} |
47
|
16
|
100
|
|
|
|
42
|
: split( /\n/, ${$sep}, -1 ) ; |
|
9
|
|
|
|
|
33
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _parse_sep { |
51
|
16
|
|
|
16
|
|
29
|
my $sep = shift; |
52
|
|
|
|
|
|
|
|
53
|
16
|
50
|
|
|
|
38
|
if (!defined($sep)) |
54
|
|
|
|
|
|
|
{ |
55
|
0
|
|
|
|
|
0
|
$sep = ''; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
16
|
|
|
|
|
37
|
my ($title, $body) = _get_sep_title_body($sep); |
59
|
|
|
|
|
|
|
|
60
|
16
|
100
|
|
|
|
47
|
if (!defined($body)) |
61
|
|
|
|
|
|
|
{ |
62
|
8
|
|
|
|
|
15
|
$body = $title; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
16
|
|
|
|
|
55
|
($title, $body) = align( 'left', $title, $body); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return |
68
|
|
|
|
|
|
|
{ |
69
|
16
|
|
|
|
|
5704
|
is_sep => 1, |
70
|
|
|
|
|
|
|
title => $title, |
71
|
|
|
|
|
|
|
body => $body, |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _default_if_empty |
76
|
|
|
|
|
|
|
{ |
77
|
286
|
|
|
286
|
|
440
|
my ($ref, $default) = @_; |
78
|
|
|
|
|
|
|
|
79
|
286
|
100
|
100
|
|
|
681
|
if (! (defined($$ref) && length($$ref))) |
80
|
|
|
|
|
|
|
{ |
81
|
223
|
|
|
|
|
278
|
$$ref = $default; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
286
|
|
|
|
|
391
|
return; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _is_align |
88
|
|
|
|
|
|
|
{ |
89
|
184
|
|
|
184
|
|
248
|
my $align = shift; |
90
|
|
|
|
|
|
|
|
91
|
184
|
|
|
|
|
556
|
return $align =~ /\A(?:left|center|right)/; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub _parse_spec { |
95
|
92
|
|
|
92
|
|
30616
|
my $spec = shift; |
96
|
|
|
|
|
|
|
|
97
|
92
|
100
|
|
|
|
197
|
if (!defined($spec)) |
98
|
|
|
|
|
|
|
{ |
99
|
2
|
|
|
|
|
4
|
$spec = ''; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
92
|
|
|
|
|
271
|
my $alispec = qr/^ *(?:left|center|right|num|point|auto)/; |
103
|
92
|
|
|
|
|
149
|
my ( $title, $align, $align_title, $align_title_lines, $sample); |
104
|
92
|
100
|
|
|
|
187
|
if ( ref ($spec) eq 'HASH' ) { |
105
|
|
|
|
|
|
|
( $title, $align, $align_title, $align_title_lines, $sample) = |
106
|
34
|
|
|
|
|
52
|
@{$spec}{qw( title align align_title align_title_lines sample )}; |
|
34
|
|
|
|
|
88
|
|
107
|
|
|
|
|
|
|
} else { |
108
|
58
|
|
|
|
|
127
|
my $alispec = qr/&(.*)/; |
109
|
58
|
100
|
|
|
|
277
|
if ( $spec =~ $alispec ) { |
110
|
21
|
|
|
|
|
136
|
($title, $align, $sample) = ($spec =~ /(.*)^$alispec\n?(.*)/sm); |
111
|
|
|
|
|
|
|
} else { |
112
|
37
|
|
|
|
|
62
|
$title = $spec; |
113
|
|
|
|
|
|
|
} |
114
|
58
|
|
|
|
|
103
|
for my $s ($title, $sample) |
115
|
|
|
|
|
|
|
{ |
116
|
116
|
100
|
|
|
|
238
|
if (defined($s)) |
117
|
|
|
|
|
|
|
{ |
118
|
79
|
|
|
|
|
137
|
chomp($s); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Assign default values. |
124
|
92
|
|
|
|
|
178
|
foreach my $x ($title, $sample) |
125
|
|
|
|
|
|
|
{ |
126
|
184
|
100
|
|
|
|
407
|
if (!defined($x)) |
|
|
100
|
|
|
|
|
|
127
|
|
|
|
|
|
|
{ |
128
|
60
|
|
|
|
|
102
|
$x = []; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
elsif (ref($x) ne 'ARRAY') |
131
|
|
|
|
|
|
|
{ |
132
|
104
|
|
|
|
|
352
|
$x = [ split /\n/, $x, -1]; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
92
|
|
|
|
|
224
|
_default_if_empty(\$align, 'auto'); |
137
|
|
|
|
|
|
|
|
138
|
92
|
50
|
66
|
|
|
481
|
unless ( |
139
|
|
|
|
|
|
|
ref $align eq 'Regexp' or |
140
|
|
|
|
|
|
|
$align =~ /^(?:left|center|right|num\(?|point\(?|auto)/ |
141
|
|
|
|
|
|
|
) { |
142
|
0
|
|
|
|
|
0
|
_warn( "Invalid align specification: '$align', using 'auto'"); |
143
|
0
|
|
|
|
|
0
|
$align = 'auto'; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
92
|
|
|
|
|
214
|
_default_if_empty(\$align_title, 'left'); |
147
|
|
|
|
|
|
|
|
148
|
92
|
50
|
|
|
|
180
|
if ( ! _is_align($align_title) ) { |
149
|
0
|
|
|
|
|
0
|
_warn( "Invalid align_title specification: " . |
150
|
|
|
|
|
|
|
"'$align_title', using 'left'", |
151
|
|
|
|
|
|
|
); |
152
|
0
|
|
|
|
|
0
|
$align_title = 'left'; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
92
|
|
|
|
|
242
|
_default_if_empty(\$align_title_lines, $align_title); |
156
|
|
|
|
|
|
|
|
157
|
92
|
50
|
|
|
|
157
|
if ( ! _is_align($align_title_lines) ) { |
158
|
0
|
|
|
|
|
0
|
_warn( "Invalid align_title_lines specification: " . |
159
|
|
|
|
|
|
|
"'$align_title_lines', using 'left'", |
160
|
|
|
|
|
|
|
); |
161
|
0
|
|
|
|
|
0
|
$align_title_lines = 'left'; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
return |
165
|
|
|
|
|
|
|
{ |
166
|
92
|
|
|
|
|
467
|
title => $title, |
167
|
|
|
|
|
|
|
align => $align, |
168
|
|
|
|
|
|
|
align_title => $align_title, |
169
|
|
|
|
|
|
|
align_title_lines => $align_title_lines, |
170
|
|
|
|
|
|
|
sample => $sample, |
171
|
|
|
|
|
|
|
}; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
### table creation |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub new |
177
|
|
|
|
|
|
|
{ |
178
|
35
|
|
|
35
|
1
|
12641
|
my $tb = bless {}, shift; |
179
|
|
|
|
|
|
|
|
180
|
35
|
|
|
|
|
119
|
return $tb->_entitle( [ @_ ] ); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub _blank |
184
|
|
|
|
|
|
|
{ |
185
|
217
|
|
|
217
|
|
273
|
my $self = shift; |
186
|
|
|
|
|
|
|
|
187
|
217
|
100
|
|
|
|
364
|
if (@_) |
188
|
|
|
|
|
|
|
{ |
189
|
189
|
|
|
|
|
274
|
$self->{blank} = shift; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
217
|
|
|
|
|
365
|
return $self->{blank}; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub _cols |
196
|
|
|
|
|
|
|
{ |
197
|
349
|
|
|
349
|
|
436
|
my $self = shift; |
198
|
|
|
|
|
|
|
|
199
|
349
|
100
|
|
|
|
592
|
if (@_) |
200
|
|
|
|
|
|
|
{ |
201
|
39
|
|
|
|
|
83
|
$self->{cols} = shift; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
349
|
|
|
|
|
880
|
return $self->{cols}; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub _forms |
208
|
|
|
|
|
|
|
{ |
209
|
180
|
|
|
180
|
|
217
|
my $self = shift; |
210
|
|
|
|
|
|
|
|
211
|
180
|
100
|
|
|
|
357
|
if (@_) |
212
|
|
|
|
|
|
|
{ |
213
|
39
|
|
|
|
|
67
|
$self->{forms} = shift; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
180
|
|
|
|
|
319
|
return $self->{forms}; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub _lines |
220
|
|
|
|
|
|
|
{ |
221
|
415
|
|
|
415
|
|
483
|
my $self = shift; |
222
|
|
|
|
|
|
|
|
223
|
415
|
100
|
|
|
|
640
|
if (@_) |
224
|
|
|
|
|
|
|
{ |
225
|
189
|
|
|
|
|
262
|
$self->{lines} = shift; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
415
|
|
|
|
|
707
|
return $self->{lines}; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub _spec |
232
|
|
|
|
|
|
|
{ |
233
|
259
|
|
|
259
|
|
357
|
my $self = shift; |
234
|
|
|
|
|
|
|
|
235
|
259
|
100
|
|
|
|
451
|
if (@_) |
236
|
|
|
|
|
|
|
{ |
237
|
39
|
|
|
|
|
278
|
$self->{spec} = shift; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
259
|
|
|
|
|
542
|
return $self->{spec}; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub _titles |
244
|
|
|
|
|
|
|
{ |
245
|
330
|
|
|
330
|
|
418
|
my $self = shift; |
246
|
|
|
|
|
|
|
|
247
|
330
|
100
|
|
|
|
550
|
if (@_) |
248
|
|
|
|
|
|
|
{ |
249
|
39
|
|
|
|
|
60
|
$self->{titles} = shift; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
330
|
|
|
|
|
737
|
return $self->{titles}; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub _entitle { |
256
|
39
|
|
|
39
|
|
77
|
my ($tb, $sep_list) = @_; # will be completely overwritten |
257
|
|
|
|
|
|
|
# find active separators and, well separate them from col specs. |
258
|
|
|
|
|
|
|
# n+1 separators for n cols |
259
|
39
|
|
|
|
|
97
|
my ( @seps, @spec); # separators and column specifications |
260
|
39
|
|
|
|
|
0
|
my $sep; |
261
|
39
|
|
|
|
|
60
|
foreach my $sep_item ( @{$sep_list} ) { |
|
39
|
|
|
|
|
76
|
|
262
|
82
|
100
|
|
|
|
176
|
if ( _is_sep ($sep_item) ) { |
263
|
16
|
|
|
|
|
42
|
$sep = _parse_sep($sep_item); |
264
|
|
|
|
|
|
|
} else { |
265
|
66
|
|
|
|
|
122
|
push @seps, $sep; |
266
|
66
|
|
|
|
|
131
|
push @spec, _parse_spec($sep_item); |
267
|
66
|
|
|
|
|
153
|
undef $sep; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
} |
270
|
39
|
|
|
|
|
69
|
push @seps, $sep; |
271
|
|
|
|
|
|
|
# build sprintf formats from separators |
272
|
39
|
|
|
|
|
100
|
my $title_form = _compile_field_format('title', \@seps); |
273
|
39
|
|
|
|
|
95
|
my $body_form = _compile_field_format('body', \@seps); |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
# pre_align titles |
276
|
39
|
|
|
|
|
80
|
my @titles = map { [ @{ $_->{title} } ] } @spec; |
|
66
|
|
|
|
|
113
|
|
|
66
|
|
|
|
|
170
|
|
277
|
|
|
|
|
|
|
|
278
|
39
|
|
|
|
|
82
|
my $title_height = max(0, map { scalar(@$_) } @titles); |
|
66
|
|
|
|
|
154
|
|
279
|
|
|
|
|
|
|
|
280
|
39
|
|
|
|
|
76
|
foreach my $title (@titles) |
281
|
|
|
|
|
|
|
{ |
282
|
66
|
|
|
|
|
114
|
push @{$title}, ( '') x ( $title_height - @{$title}); |
|
66
|
|
|
|
|
95
|
|
|
66
|
|
|
|
|
129
|
|
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
|
285
|
39
|
|
|
|
|
73
|
foreach my $t_idx (0 .. $#titles) |
286
|
|
|
|
|
|
|
{ |
287
|
66
|
|
|
|
|
5809
|
align($spec[$t_idx]->{align_title_lines}, @{$titles[$t_idx]}); |
|
66
|
|
|
|
|
176
|
|
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
# build data structure |
291
|
39
|
|
|
|
|
5039
|
$tb->_spec(\@spec); |
292
|
39
|
|
|
|
|
181
|
$tb->_cols([ map [], 1 .. @spec]); |
293
|
39
|
|
|
|
|
122
|
$tb->_forms([ $title_form, $body_form]); # separators condensed |
294
|
39
|
|
|
|
|
97
|
$tb->_titles(\@titles); |
295
|
|
|
|
|
|
|
|
296
|
39
|
|
|
|
|
96
|
$tb->_clear_cache; |
297
|
|
|
|
|
|
|
|
298
|
39
|
|
|
|
|
130
|
return $tb; |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
# sprintf-format for line assembly, using separators |
302
|
|
|
|
|
|
|
sub _compile_format { |
303
|
78
|
|
|
78
|
|
113
|
my $seps = shift; # mix of strings and undef (for default) |
304
|
|
|
|
|
|
|
|
305
|
78
|
|
|
|
|
172
|
for my $idx (0 .. $#$seps) |
306
|
|
|
|
|
|
|
{ |
307
|
210
|
100
|
|
|
|
338
|
if (!defined($seps->[$idx])) |
308
|
|
|
|
|
|
|
{ |
309
|
180
|
100
|
100
|
|
|
516
|
$seps->[$idx] = ($idx == 0 or $idx == $#$seps) ? '' : q{ }; |
310
|
|
|
|
|
|
|
} |
311
|
|
|
|
|
|
|
else |
312
|
|
|
|
|
|
|
{ |
313
|
|
|
|
|
|
|
# protect against sprintf |
314
|
30
|
|
|
|
|
67
|
$seps->[$idx] =~ s/%/%%/g; |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
} |
317
|
78
|
|
|
|
|
258
|
return join '%s', @$seps; |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
sub _compile_field_format |
321
|
|
|
|
|
|
|
{ |
322
|
78
|
|
|
78
|
|
135
|
my ($field, $seps) = @_; |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
return _compile_format( |
325
|
78
|
100
|
|
|
|
128
|
[map { defined($_) ? $_->{$field} : undef } @$seps] |
|
210
|
|
|
|
|
472
|
|
326
|
|
|
|
|
|
|
); |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
# reverse format compilation (used by colrange()) |
330
|
|
|
|
|
|
|
sub _recover_separators { |
331
|
16
|
|
|
16
|
|
22
|
my $format = shift; |
332
|
16
|
|
|
|
|
88
|
my @seps = split /(?
|
333
|
16
|
|
|
|
|
29
|
for my $s (@seps) |
334
|
|
|
|
|
|
|
{ |
335
|
48
|
|
|
|
|
58
|
$s =~ s/%%/%/g; |
336
|
|
|
|
|
|
|
} |
337
|
16
|
|
|
|
|
26
|
return \@seps; |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
# select some columns, (optionally if in [...]), and add new separators |
341
|
|
|
|
|
|
|
# (the other table creator) |
342
|
|
|
|
|
|
|
sub select { |
343
|
6
|
|
|
6
|
1
|
13
|
my $tb = shift; |
344
|
6
|
|
|
|
|
16
|
my @args = map $tb->_select_group( $_), @_; |
345
|
|
|
|
|
|
|
# get column selection, checking indices (some have been checked by |
346
|
|
|
|
|
|
|
# _select_group, but not all) |
347
|
6
|
|
|
|
|
13
|
my @sel = map $tb->_check_index( $_), grep !_is_sep( $_), @args; |
348
|
|
|
|
|
|
|
# replace indices with column spec to create subtable |
349
|
6
|
|
|
|
|
9
|
for my $arg (@args) |
350
|
|
|
|
|
|
|
{ |
351
|
10
|
50
|
|
|
|
14
|
if (! _is_sep($arg)) |
352
|
|
|
|
|
|
|
{ |
353
|
10
|
|
|
|
|
17
|
$arg = $tb->_spec->[ $arg]; |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
} |
356
|
6
|
|
|
|
|
13
|
my $sub = ref( $tb)->new( @args); |
357
|
|
|
|
|
|
|
# sneak in data columns |
358
|
6
|
|
|
|
|
11
|
@{ $sub->{ cols}} = map { [ @$_ ] } @{ $tb->_cols}[ @sel]; |
|
6
|
|
|
|
|
12
|
|
|
10
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
10
|
|
359
|
6
|
|
|
|
|
27
|
$sub; |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
# the first non-separator column in the group is tested if it has any data |
363
|
|
|
|
|
|
|
# if so, the group is returned, else nothing |
364
|
|
|
|
|
|
|
sub _select_group { |
365
|
13
|
|
|
13
|
|
18
|
my ( $tb, $group) = @_; |
366
|
13
|
100
|
|
|
|
33
|
return $group unless ref $group eq 'ARRAY'; |
367
|
|
|
|
|
|
|
GROUP_LOOP: |
368
|
5
|
|
|
|
|
8
|
for my $g ( @$group ) { |
369
|
5
|
50
|
|
|
|
9
|
if (_is_sep($g)) |
370
|
|
|
|
|
|
|
{ |
371
|
0
|
|
|
|
|
0
|
next GROUP_LOOP; |
372
|
|
|
|
|
|
|
} |
373
|
5
|
|
|
|
|
12
|
$tb->_check_index($g); |
374
|
|
|
|
|
|
|
|
375
|
5
|
100
|
|
|
|
7
|
if (grep { $_} @{ $tb->_cols->[$g] }) |
|
15
|
|
|
|
|
26
|
|
|
5
|
|
|
|
|
7
|
|
376
|
|
|
|
|
|
|
{ |
377
|
2
|
|
|
|
|
5
|
return @$group; |
378
|
|
|
|
|
|
|
} |
379
|
3
|
|
|
|
|
7
|
return; # no more tries after non-sep was found |
380
|
|
|
|
|
|
|
} |
381
|
0
|
|
|
|
|
0
|
return; # no column index in group, no select |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
# check index for validity, return arg if returns at all |
385
|
|
|
|
|
|
|
sub _check_index { |
386
|
15
|
|
|
15
|
|
19
|
my $tb = shift; |
387
|
15
|
|
|
|
|
18
|
my ( $i) = @_; |
388
|
15
|
|
|
|
|
23
|
my $n = $tb->n_cols; |
389
|
15
|
|
|
|
|
19
|
my $ok = eval { |
390
|
6
|
|
|
6
|
|
11977
|
use warnings FATAL => 'numeric'; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
2984
|
|
391
|
15
|
50
|
|
|
|
46
|
-$n <= $i and $i < $n; # in range of column array? |
392
|
|
|
|
|
|
|
}; |
393
|
15
|
50
|
33
|
|
|
35
|
_warn( "Invalid column index '$_'") if $@ or not $ok; |
394
|
15
|
|
|
|
|
26
|
shift; |
395
|
|
|
|
|
|
|
} |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
### data entry |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
sub _clear_cache { |
400
|
157
|
|
|
157
|
|
221
|
my ($tb) = @_; |
401
|
|
|
|
|
|
|
|
402
|
157
|
|
|
|
|
307
|
$tb->_blank(undef()); |
403
|
157
|
|
|
|
|
289
|
$tb->_lines(undef()); |
404
|
|
|
|
|
|
|
|
405
|
157
|
|
|
|
|
199
|
return; |
406
|
|
|
|
|
|
|
} |
407
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
# add one data line or split the line into follow-up lines |
409
|
|
|
|
|
|
|
sub add { |
410
|
57
|
|
|
57
|
1
|
96
|
my $tb = shift; |
411
|
|
|
|
|
|
|
|
412
|
57
|
100
|
|
|
|
95
|
if (! $tb->n_cols) { |
413
|
4
|
|
|
|
|
16
|
$tb->_entitle( [ ('') x @_] ); |
414
|
|
|
|
|
|
|
} |
415
|
|
|
|
|
|
|
|
416
|
57
|
|
|
|
|
98
|
foreach my $row ( |
417
|
|
|
|
|
|
|
_transpose( |
418
|
|
|
|
|
|
|
[ |
419
|
143
|
100
|
|
|
|
461
|
map { [ defined() ? split( /\n/ ) : '' ] } @_ |
420
|
|
|
|
|
|
|
] |
421
|
|
|
|
|
|
|
) |
422
|
|
|
|
|
|
|
) |
423
|
|
|
|
|
|
|
{ |
424
|
59
|
|
|
|
|
110
|
$tb->_add(@$row); |
425
|
|
|
|
|
|
|
} |
426
|
57
|
|
|
|
|
165
|
$tb->_clear_cache; |
427
|
|
|
|
|
|
|
|
428
|
57
|
|
|
|
|
88
|
return $tb; |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
# add one data line |
432
|
|
|
|
|
|
|
sub _add { |
433
|
59
|
|
|
59
|
|
75
|
my $tb = shift; |
434
|
|
|
|
|
|
|
|
435
|
59
|
|
|
|
|
72
|
foreach my $col ( @{ $tb->_cols} ) { |
|
59
|
|
|
|
|
95
|
|
436
|
165
|
|
|
|
|
206
|
push @{$col}, shift(@_); |
|
165
|
|
|
|
|
291
|
|
437
|
|
|
|
|
|
|
} |
438
|
|
|
|
|
|
|
|
439
|
59
|
|
|
|
|
124
|
$tb->_clear_cache; |
440
|
|
|
|
|
|
|
|
441
|
59
|
|
|
|
|
88
|
return $tb; |
442
|
|
|
|
|
|
|
} |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
# add one or more data lines |
445
|
|
|
|
|
|
|
sub load { |
446
|
21
|
|
|
21
|
1
|
1400
|
my $tb = shift; |
447
|
21
|
|
|
|
|
51
|
foreach my $row ( @_ ) { |
448
|
49
|
50
|
|
|
|
95
|
if (!defined($row)) { |
449
|
0
|
|
|
|
|
0
|
$row = ''; |
450
|
|
|
|
|
|
|
} |
451
|
|
|
|
|
|
|
$tb->add( |
452
|
49
|
100
|
|
|
|
153
|
(ref($row) eq 'ARRAY') ? (@$row) : (split ' ',$row) |
453
|
|
|
|
|
|
|
) |
454
|
|
|
|
|
|
|
} |
455
|
21
|
|
|
|
|
62
|
$tb; |
456
|
|
|
|
|
|
|
} |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
sub clear { |
459
|
2
|
|
|
2
|
1
|
5
|
my $tb = shift; |
460
|
|
|
|
|
|
|
|
461
|
2
|
|
|
|
|
2
|
foreach my $col (@{ $tb->_cols} ) |
|
2
|
|
|
|
|
5
|
|
462
|
|
|
|
|
|
|
{ |
463
|
5
|
|
|
|
|
10
|
$col = []; |
464
|
|
|
|
|
|
|
} |
465
|
|
|
|
|
|
|
|
466
|
2
|
|
|
|
|
5
|
$tb->_clear_cache; |
467
|
|
|
|
|
|
|
|
468
|
2
|
|
|
|
|
4
|
return $tb; |
469
|
|
|
|
|
|
|
} |
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
### access to output area |
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
## sizes |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
# number of table columns |
476
|
540
|
|
|
540
|
1
|
1065
|
sub n_cols { scalar @{ $_[0]->{ spec}} } |
|
540
|
|
|
|
|
1333
|
|
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
# number of title lines |
479
|
225
|
100
|
|
225
|
1
|
365
|
sub title_height { $_[ 0]->n_cols and scalar @{ $_[ 0]->_titles->[ 0]} } |
|
221
|
|
|
|
|
351
|
|
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
# number of data lines |
482
|
|
|
|
|
|
|
sub body_height |
483
|
|
|
|
|
|
|
{ |
484
|
209
|
|
|
209
|
1
|
301
|
my ($tb) = @_; |
485
|
|
|
|
|
|
|
|
486
|
209
|
|
100
|
|
|
317
|
return ($tb->n_cols && scalar @{ $tb->_cols->[0] }); |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
# total height |
490
|
|
|
|
|
|
|
sub table_height |
491
|
|
|
|
|
|
|
{ |
492
|
130
|
|
|
130
|
1
|
173
|
my $tb = shift; |
493
|
130
|
|
|
|
|
231
|
return $tb->title_height + $tb->body_height; |
494
|
|
|
|
|
|
|
} |
495
|
|
|
|
|
|
|
|
496
|
6
|
|
|
6
|
|
9129
|
BEGIN { *height = \&table_height; } # alias |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
# number of characters in each table line. need to build the table to know |
499
|
|
|
|
|
|
|
sub width |
500
|
|
|
|
|
|
|
{ |
501
|
38
|
|
|
38
|
1
|
59
|
my ($tb) = @_; |
502
|
|
|
|
|
|
|
|
503
|
38
|
|
66
|
|
|
68
|
return $tb->height && (length( ($tb->table(0))[0] ) - 1); |
504
|
|
|
|
|
|
|
} |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
sub _normalize_col_index |
507
|
|
|
|
|
|
|
{ |
508
|
16
|
|
|
16
|
|
22
|
my ($tb, $col_index) = @_; |
509
|
|
|
|
|
|
|
|
510
|
16
|
|
100
|
|
|
37
|
$col_index ||= 0; |
511
|
|
|
|
|
|
|
|
512
|
16
|
100
|
|
|
|
31
|
if ($col_index < 0) |
513
|
|
|
|
|
|
|
{ |
514
|
2
|
|
|
|
|
5
|
$col_index += $tb->n_cols; |
515
|
|
|
|
|
|
|
} |
516
|
|
|
|
|
|
|
|
517
|
16
|
50
|
|
|
|
37
|
if ($col_index < 0) |
|
|
100
|
|
|
|
|
|
518
|
|
|
|
|
|
|
{ |
519
|
0
|
|
|
|
|
0
|
$col_index = 0; |
520
|
|
|
|
|
|
|
} |
521
|
|
|
|
|
|
|
elsif ($col_index > $tb->n_cols) |
522
|
|
|
|
|
|
|
{ |
523
|
2
|
|
|
|
|
4
|
$col_index = $tb->n_cols; |
524
|
|
|
|
|
|
|
} |
525
|
|
|
|
|
|
|
|
526
|
16
|
|
|
|
|
26
|
return $col_index; |
527
|
|
|
|
|
|
|
} |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
# start and width of each column |
530
|
|
|
|
|
|
|
sub colrange { |
531
|
16
|
|
|
16
|
1
|
32
|
my ( $tb, $proto_col_index) = @_; |
532
|
|
|
|
|
|
|
|
533
|
16
|
|
|
|
|
31
|
my $col_index = $tb->_normalize_col_index($proto_col_index); |
534
|
|
|
|
|
|
|
|
535
|
16
|
50
|
|
|
|
26
|
return ( 0, 0) unless $tb->width; # width called, $tb->_blank() exists now |
536
|
16
|
|
|
|
|
26
|
my @widths = map { length } @{ $tb->_blank}, ''; |
|
48
|
|
|
|
|
80
|
|
|
16
|
|
|
|
|
31
|
|
537
|
16
|
|
|
|
|
39
|
@widths = @widths[ 0 .. $col_index]; |
538
|
|
|
|
|
|
|
|
539
|
16
|
|
|
|
|
20
|
my $width = pop @widths; |
540
|
16
|
|
100
|
|
|
55
|
my $pos = sum(@widths) || 0; |
541
|
|
|
|
|
|
|
|
542
|
16
|
|
|
|
|
25
|
my $seps_aref = _recover_separators( $tb->_forms->[ 0]); |
543
|
|
|
|
|
|
|
|
544
|
16
|
|
|
|
|
22
|
my $sep_sum = 0; |
545
|
16
|
|
|
|
|
27
|
foreach my $sep (@$seps_aref[ 0 .. $col_index]) |
546
|
|
|
|
|
|
|
{ |
547
|
34
|
|
|
|
|
41
|
$sep_sum += length($sep); |
548
|
|
|
|
|
|
|
} |
549
|
|
|
|
|
|
|
|
550
|
16
|
|
|
|
|
77
|
return ( $pos+$sep_sum, $width ) ; |
551
|
|
|
|
|
|
|
} |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
## printable output |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
# whole table |
556
|
|
|
|
|
|
|
sub table { |
557
|
49
|
|
|
49
|
1
|
73
|
my $tb = shift; |
558
|
|
|
|
|
|
|
|
559
|
49
|
|
|
|
|
84
|
return $tb->_table_portion( $tb->height, 0, @_); |
560
|
|
|
|
|
|
|
} |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
# only titles |
563
|
|
|
|
|
|
|
sub title { |
564
|
14
|
|
|
14
|
1
|
57
|
my $tb = shift; |
565
|
|
|
|
|
|
|
|
566
|
14
|
|
|
|
|
31
|
return $tb->_table_portion( $tb->title_height, 0, @_); |
567
|
|
|
|
|
|
|
} |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
# only body |
570
|
|
|
|
|
|
|
sub body { |
571
|
9
|
|
|
9
|
1
|
34
|
my $tb = shift; |
572
|
|
|
|
|
|
|
|
573
|
9
|
|
|
|
|
30
|
return $tb->_table_portion( $tb->body_height, $tb->title_height, @_); |
574
|
|
|
|
|
|
|
} |
575
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
sub stringify |
577
|
|
|
|
|
|
|
{ |
578
|
12
|
|
|
12
|
1
|
32
|
my ($tb) = @_; |
579
|
|
|
|
|
|
|
|
580
|
12
|
|
|
|
|
28
|
return (scalar ( $tb->table() )); |
581
|
|
|
|
|
|
|
} |
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
### common internals |
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
# common representation of table(), title() and body() |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
sub _table_portion_as_aref |
588
|
|
|
|
|
|
|
{ |
589
|
72
|
|
|
72
|
|
95
|
my $tb = shift; |
590
|
|
|
|
|
|
|
|
591
|
72
|
|
|
|
|
90
|
my $total = shift; |
592
|
72
|
|
|
|
|
83
|
my $offset = shift; |
593
|
|
|
|
|
|
|
|
594
|
72
|
|
|
|
|
111
|
my ( $from, $n) = ( 0, $total); # if no parameters |
595
|
|
|
|
|
|
|
|
596
|
72
|
100
|
|
|
|
133
|
if ( @_ ) { |
597
|
51
|
|
|
|
|
67
|
$from = shift; |
598
|
51
|
50
|
|
|
|
103
|
$n = @_ ? shift : 1; # one line if not given |
599
|
|
|
|
|
|
|
} |
600
|
|
|
|
|
|
|
|
601
|
72
|
|
|
|
|
124
|
( $from, $n) = _limit_range( $total, $from, $n); |
602
|
|
|
|
|
|
|
|
603
|
72
|
|
|
|
|
132
|
my $limit = $tb->title_height; # title format below |
604
|
72
|
|
|
|
|
108
|
$from += $offset; |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
return |
607
|
|
|
|
|
|
|
[ |
608
|
72
|
|
|
|
|
214
|
map $tb->_assemble_line( $_ >= $limit, $tb->_table_line( $_), 0), |
609
|
|
|
|
|
|
|
$from .. $from + $n - 1 |
610
|
|
|
|
|
|
|
]; |
611
|
|
|
|
|
|
|
} |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
sub _table_portion |
614
|
|
|
|
|
|
|
{ |
615
|
72
|
|
|
72
|
|
106
|
my $tb = shift; |
616
|
|
|
|
|
|
|
|
617
|
72
|
|
|
|
|
143
|
my $lines_aref = $tb->_table_portion_as_aref(@_); |
618
|
|
|
|
|
|
|
|
619
|
72
|
100
|
|
|
|
484
|
return (wantarray ? @$lines_aref : join('', @$lines_aref)); |
620
|
|
|
|
|
|
|
} |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
sub _limit_range |
623
|
|
|
|
|
|
|
{ |
624
|
72
|
|
|
72
|
|
128
|
my ( $total, $from, $n) = @_; |
625
|
|
|
|
|
|
|
|
626
|
72
|
|
100
|
|
|
243
|
$from ||= 0; |
627
|
72
|
100
|
|
|
|
130
|
$from += $total if $from < 0; |
628
|
72
|
50
|
|
|
|
153
|
$n = $total unless defined $n; |
629
|
|
|
|
|
|
|
|
630
|
72
|
100
|
66
|
|
|
247
|
return ( 0, 0) if $from + $n < 0 or $from >= $total; |
631
|
|
|
|
|
|
|
|
632
|
69
|
50
|
|
|
|
137
|
$from = 0 if $from < 0; |
633
|
69
|
50
|
|
|
|
139
|
$n = $total - $from if $n > $total - $from; |
634
|
|
|
|
|
|
|
|
635
|
69
|
|
|
|
|
136
|
return( $from, $n); |
636
|
|
|
|
|
|
|
} |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
# get table line (formatted, including titles). fill cache if needed |
639
|
|
|
|
|
|
|
sub _table_line { |
640
|
113
|
|
|
113
|
|
190
|
my ($tb, $idx) = @_; |
641
|
|
|
|
|
|
|
|
642
|
113
|
100
|
|
|
|
215
|
if (! $tb->_lines) |
643
|
|
|
|
|
|
|
{ |
644
|
32
|
|
|
|
|
84
|
$tb->_lines([ $tb->_build_table_lines ]); |
645
|
|
|
|
|
|
|
} |
646
|
|
|
|
|
|
|
|
647
|
113
|
|
|
|
|
207
|
return $tb->_lines->[$idx]; |
648
|
|
|
|
|
|
|
} |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
# build array of lines of justified data items |
651
|
|
|
|
|
|
|
sub _build_table_lines { |
652
|
32
|
|
|
32
|
|
45
|
my $tb = shift; |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
# copy data columns, replacing undef with '' |
655
|
|
|
|
|
|
|
my @cols = |
656
|
|
|
|
|
|
|
map |
657
|
70
|
100
|
|
|
|
127
|
{ [ map { defined($_) ? $_ : '' } @$_ ] } |
|
159
|
|
|
|
|
354
|
|
658
|
32
|
|
|
|
|
46
|
@{ $tb->_cols() } ; |
|
32
|
|
|
|
|
59
|
|
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
# add set of empty strings for blank line (needed to build horizontal rules) |
661
|
32
|
|
|
|
|
63
|
foreach my $col (@cols) |
662
|
|
|
|
|
|
|
{ |
663
|
70
|
|
|
|
|
131
|
push @$col, ''; |
664
|
|
|
|
|
|
|
} |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
# add samples for minimum alignment |
667
|
32
|
|
|
|
|
75
|
foreach my $col_idx (0 .. $#cols) |
668
|
|
|
|
|
|
|
{ |
669
|
70
|
|
|
|
|
85
|
push @{$cols[$col_idx]}, @{$tb->_spec->[$col_idx]->{sample}}; |
|
70
|
|
|
|
|
103
|
|
|
70
|
|
|
|
|
95
|
|
670
|
|
|
|
|
|
|
} |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
# align to style |
673
|
32
|
|
|
|
|
68
|
foreach my $col_idx (0 .. $#cols) |
674
|
|
|
|
|
|
|
{ |
675
|
70
|
|
|
|
|
48337
|
align($tb->_spec->[$col_idx]->{align}, @{$cols[$col_idx]}); |
|
70
|
|
|
|
|
194
|
|
676
|
|
|
|
|
|
|
} |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
# trim off samples, but leave blank line |
679
|
32
|
|
|
|
|
32685
|
foreach my $col (@cols) |
680
|
|
|
|
|
|
|
{ |
681
|
70
|
|
|
|
|
105
|
splice( @{$col}, 1 + $tb->body_height ); |
|
70
|
|
|
|
|
142
|
|
682
|
|
|
|
|
|
|
} |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
# include titles |
685
|
32
|
|
|
|
|
82
|
foreach my $col_idx (0 .. $#cols) |
686
|
|
|
|
|
|
|
{ |
687
|
70
|
|
|
|
|
86
|
unshift @{$cols[$col_idx]}, @{$tb->_titles->[$col_idx]}; |
|
70
|
|
|
|
|
93
|
|
|
70
|
|
|
|
|
106
|
|
688
|
|
|
|
|
|
|
} |
689
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
# align title and body portions of columns |
691
|
|
|
|
|
|
|
# blank line will be there even with no data |
692
|
32
|
|
|
|
|
74
|
foreach my $col_idx (0 .. $#cols) |
693
|
|
|
|
|
|
|
{ |
694
|
70
|
|
|
|
|
21475
|
align($tb->_spec->[$col_idx]->{align_title}, @{$cols[$col_idx]}); |
|
70
|
|
|
|
|
160
|
|
695
|
|
|
|
|
|
|
} |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
# deposit a blank line, pulling it off the columns. |
698
|
|
|
|
|
|
|
# *_rule() knows this is done |
699
|
32
|
|
|
|
|
13717
|
my @blank; |
700
|
|
|
|
|
|
|
|
701
|
32
|
|
|
|
|
58
|
foreach my $col (@cols) |
702
|
|
|
|
|
|
|
{ |
703
|
70
|
|
|
|
|
135
|
push @blank, pop(@$col); |
704
|
|
|
|
|
|
|
} |
705
|
|
|
|
|
|
|
|
706
|
32
|
|
|
|
|
94
|
$tb->_blank(\@blank); |
707
|
|
|
|
|
|
|
|
708
|
32
|
|
|
|
|
68
|
return _transpose_n( $tb->height, \@cols); # bye-bye, @cols |
709
|
|
|
|
|
|
|
} |
710
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
# destructively transpose a number of lines/cols from an array of arrayrefs |
712
|
|
|
|
|
|
|
sub _transpose_n { |
713
|
89
|
|
|
89
|
|
145
|
my ($n, $cols) = @_; |
714
|
|
|
|
|
|
|
|
715
|
89
|
|
|
|
|
164
|
return map { [ map { shift @$_ } @$cols] } 1 .. $n; |
|
151
|
|
|
|
|
200
|
|
|
401
|
|
|
|
|
824
|
|
716
|
|
|
|
|
|
|
} |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
# like _transpose_n, but find the number to transpose from max of given |
719
|
|
|
|
|
|
|
sub _transpose |
720
|
|
|
|
|
|
|
{ |
721
|
57
|
|
|
57
|
|
101
|
my ($cols) = @_; |
722
|
|
|
|
|
|
|
|
723
|
57
|
|
|
|
|
86
|
my $m = max ( map { scalar(@$_) } @$cols, []); |
|
200
|
|
|
|
|
319
|
|
724
|
|
|
|
|
|
|
|
725
|
57
|
|
|
|
|
117
|
return _transpose_n( $m, $cols); |
726
|
|
|
|
|
|
|
} |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
# make a line from a number of formatted data elements |
729
|
|
|
|
|
|
|
sub _assemble_line { |
730
|
125
|
|
|
125
|
|
219
|
my ($tb, $in_body, $line_aref, $replace_spaces) = @_; |
731
|
|
|
|
|
|
|
|
732
|
125
|
|
|
|
|
170
|
my $format = $tb->_forms->[ !!$in_body]; |
733
|
|
|
|
|
|
|
|
734
|
125
|
100
|
|
|
|
234
|
if ($replace_spaces) |
735
|
|
|
|
|
|
|
{ |
736
|
2
|
|
|
|
|
15
|
$format =~ s/\s/=/g; |
737
|
|
|
|
|
|
|
} |
738
|
|
|
|
|
|
|
|
739
|
125
|
|
|
|
|
630
|
return sprintf($format, @$line_aref) . "\n"; |
740
|
|
|
|
|
|
|
} |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
sub _text_rule |
743
|
|
|
|
|
|
|
{ |
744
|
10
|
|
|
10
|
|
18
|
my ($tb, $rule, $char, $alt) = @_; |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
# replace blanks with $char. If $alt is given, replace nonblanks |
747
|
|
|
|
|
|
|
# with $alt |
748
|
10
|
100
|
|
|
|
25
|
if ( defined $alt ) |
749
|
|
|
|
|
|
|
{ |
750
|
4
|
100
|
|
|
|
19
|
$rule =~ s/(.)/$1 eq ' ' ? $char : $alt/ge; |
|
99
|
|
|
|
|
228
|
|
751
|
|
|
|
|
|
|
} |
752
|
|
|
|
|
|
|
else |
753
|
|
|
|
|
|
|
{ |
754
|
6
|
100
|
|
|
|
16
|
$rule =~ s/ /$char/g if $char ne ' '; |
755
|
|
|
|
|
|
|
} |
756
|
|
|
|
|
|
|
|
757
|
10
|
|
|
|
|
53
|
return $rule; |
758
|
|
|
|
|
|
|
} |
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
# build a rule line |
761
|
|
|
|
|
|
|
sub _rule { |
762
|
12
|
|
|
12
|
|
20
|
my $tb = shift; |
763
|
|
|
|
|
|
|
|
764
|
12
|
50
|
|
|
|
29
|
return + (!$tb->width) ? '' : $tb->_positive_width_rule(@_); |
765
|
|
|
|
|
|
|
} |
766
|
|
|
|
|
|
|
|
767
|
|
|
|
|
|
|
sub _positive_width_rule |
768
|
|
|
|
|
|
|
{ |
769
|
12
|
|
|
12
|
|
30
|
my ($tb, $in_body, $char, $alt) = @_; |
770
|
|
|
|
|
|
|
|
771
|
12
|
100
|
|
|
|
27
|
my $rule = $tb->_assemble_line( $in_body, $tb->_blank, |
772
|
|
|
|
|
|
|
((ref($char) eq "CODE") ? 1 : 0), |
773
|
|
|
|
|
|
|
); |
774
|
|
|
|
|
|
|
|
775
|
12
|
|
|
|
|
34
|
return $tb->_render_rule($rule, $char, $alt); |
776
|
|
|
|
|
|
|
} |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
sub _render_rule |
779
|
|
|
|
|
|
|
{ |
780
|
12
|
|
|
12
|
|
28
|
my ($tb, $rule, $char, $alt) = @_; |
781
|
|
|
|
|
|
|
|
782
|
12
|
100
|
|
|
|
29
|
if (ref($char) eq "CODE") |
783
|
|
|
|
|
|
|
{ |
784
|
2
|
|
|
|
|
19
|
return $tb->_render_rule_with_callbacks($rule, $char, $alt); |
785
|
|
|
|
|
|
|
} |
786
|
|
|
|
|
|
|
else |
787
|
|
|
|
|
|
|
{ |
788
|
10
|
|
|
|
|
24
|
_default_if_empty(\$char, ' '); |
789
|
|
|
|
|
|
|
|
790
|
10
|
|
|
|
|
22
|
return $tb->_text_rule($rule, $char, $alt); |
791
|
|
|
|
|
|
|
} |
792
|
|
|
|
|
|
|
} |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
sub _get_fixed_len_string |
795
|
|
|
|
|
|
|
{ |
796
|
14
|
|
|
14
|
|
103
|
my ($s, $len) = @_; |
797
|
|
|
|
|
|
|
|
798
|
14
|
|
|
|
|
28
|
$s = substr($s, 0, $len); |
799
|
14
|
|
|
|
|
33
|
$s .= ' ' x ($len - length($s)); |
800
|
|
|
|
|
|
|
|
801
|
14
|
|
|
|
|
74
|
return $s; |
802
|
|
|
|
|
|
|
} |
803
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
sub _render_rule_with_callbacks |
805
|
|
|
|
|
|
|
{ |
806
|
2
|
|
|
2
|
|
8
|
my ($tb, $rule, $char, $alt) = @_; |
807
|
|
|
|
|
|
|
|
808
|
2
|
|
|
|
|
23
|
my %callbacks = |
809
|
|
|
|
|
|
|
( |
810
|
|
|
|
|
|
|
'char' => { cb => $char, idx => 0, }, |
811
|
|
|
|
|
|
|
'alt' => { cb => $alt, idx => 0, }, |
812
|
|
|
|
|
|
|
); |
813
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
my $calc_substitution = sub { |
815
|
14
|
|
|
14
|
|
36
|
my $s = shift; |
816
|
|
|
|
|
|
|
|
817
|
14
|
|
|
|
|
25
|
my $len = length($s); |
818
|
|
|
|
|
|
|
|
819
|
14
|
100
|
|
|
|
52
|
my $which = (($s =~ /\A /) ? 'char' : 'alt'); |
820
|
14
|
|
|
|
|
31
|
my $rec = $callbacks{$which}; |
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
return _get_fixed_len_string( |
823
|
14
|
|
|
|
|
49
|
scalar ($rec->{cb}->($rec->{idx}++, $len)), |
824
|
|
|
|
|
|
|
$len, |
825
|
|
|
|
|
|
|
); |
826
|
2
|
|
|
|
|
15
|
}; |
827
|
|
|
|
|
|
|
|
828
|
2
|
|
|
|
|
43
|
$rule =~ s/((.)\2*)/$calc_substitution->($1)/ge; |
|
14
|
|
|
|
|
37
|
|
829
|
|
|
|
|
|
|
|
830
|
2
|
|
|
|
|
30
|
return $rule; |
831
|
|
|
|
|
|
|
} |
832
|
|
|
|
|
|
|
|
833
|
|
|
|
|
|
|
sub rule { |
834
|
11
|
|
|
11
|
1
|
68
|
my $tb = shift; |
835
|
11
|
|
|
|
|
30
|
return $tb->_rule( 0, @_); |
836
|
|
|
|
|
|
|
} |
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
sub body_rule { |
839
|
1
|
|
|
1
|
1
|
2
|
my $tb = shift; |
840
|
1
|
|
|
|
|
3
|
return $tb->_rule( 1, @_); |
841
|
|
|
|
|
|
|
} |
842
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
### warning behavior |
844
|
6
|
|
|
6
|
|
53
|
use Carp; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
1884
|
|
845
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
{ |
847
|
|
|
|
|
|
|
my ( $warn, $fatal) = ( 0, 0); |
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
sub warnings |
850
|
|
|
|
|
|
|
{ |
851
|
|
|
|
|
|
|
# Ignore the class/object. |
852
|
0
|
|
|
0
|
1
|
|
my (undef, $toggle) = @_; |
853
|
|
|
|
|
|
|
|
854
|
0
|
|
0
|
|
|
|
$toggle ||= 'on'; |
855
|
0
|
0
|
|
|
|
|
if ( $toggle eq 'off' ) |
|
|
0
|
|
|
|
|
|
856
|
|
|
|
|
|
|
{ |
857
|
0
|
|
|
|
|
|
($warn, $fatal) = (0, 0); |
858
|
|
|
|
|
|
|
} |
859
|
|
|
|
|
|
|
elsif ( $toggle eq 'fatal' ) |
860
|
|
|
|
|
|
|
{ |
861
|
0
|
|
|
|
|
|
($warn, $fatal) = (1, 1); |
862
|
|
|
|
|
|
|
} |
863
|
|
|
|
|
|
|
else |
864
|
|
|
|
|
|
|
{ |
865
|
0
|
|
|
|
|
|
($warn, $fatal) = (1, 0); |
866
|
|
|
|
|
|
|
} |
867
|
0
|
0
|
|
|
|
|
return $fatal ? 'fatal' : $warn ? 'on' : 'off'; |
|
|
0
|
|
|
|
|
|
868
|
|
|
|
|
|
|
} |
869
|
|
|
|
|
|
|
|
870
|
|
|
|
|
|
|
sub _warn |
871
|
|
|
|
|
|
|
{ |
872
|
0
|
|
|
0
|
|
|
my $msg = shift; |
873
|
|
|
|
|
|
|
|
874
|
0
|
0
|
|
|
|
|
return unless $warn; |
875
|
|
|
|
|
|
|
|
876
|
0
|
0
|
|
|
|
|
if ($fatal) |
877
|
|
|
|
|
|
|
{ |
878
|
0
|
|
|
|
|
|
croak( $msg) |
879
|
|
|
|
|
|
|
} |
880
|
|
|
|
|
|
|
|
881
|
0
|
|
|
|
|
|
carp( $msg); |
882
|
|
|
|
|
|
|
|
883
|
0
|
|
|
|
|
|
return; |
884
|
|
|
|
|
|
|
} |
885
|
|
|
|
|
|
|
} |
886
|
|
|
|
|
|
|
|
887
|
|
|
|
|
|
|
=pod |
888
|
|
|
|
|
|
|
|
889
|
|
|
|
|
|
|
=encoding UTF-8 |
890
|
|
|
|
|
|
|
|
891
|
|
|
|
|
|
|
=head1 NAME |
892
|
|
|
|
|
|
|
|
893
|
|
|
|
|
|
|
Text::Table - Organize Data in Tables |
894
|
|
|
|
|
|
|
|
895
|
|
|
|
|
|
|
=head1 VERSION |
896
|
|
|
|
|
|
|
|
897
|
|
|
|
|
|
|
version 1.133 |
898
|
|
|
|
|
|
|
|
899
|
|
|
|
|
|
|
=head1 SYNOPSIS |
900
|
|
|
|
|
|
|
|
901
|
|
|
|
|
|
|
use Text::Table; |
902
|
|
|
|
|
|
|
my $tb = Text::Table->new( |
903
|
|
|
|
|
|
|
"Planet", "Radius\nkm", "Density\ng/cm^3" |
904
|
|
|
|
|
|
|
); |
905
|
|
|
|
|
|
|
$tb->load( |
906
|
|
|
|
|
|
|
[ "Mercury", 2360, 3.7 ], |
907
|
|
|
|
|
|
|
[ "Venus", 6110, 5.1 ], |
908
|
|
|
|
|
|
|
[ "Earth", 6378, 5.52 ], |
909
|
|
|
|
|
|
|
[ "Jupiter", 71030, 1.3 ], |
910
|
|
|
|
|
|
|
); |
911
|
|
|
|
|
|
|
print $tb; |
912
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
This prints a table from the given title and data like this: |
914
|
|
|
|
|
|
|
|
915
|
|
|
|
|
|
|
Planet Radius Density |
916
|
|
|
|
|
|
|
km g/cm^3 |
917
|
|
|
|
|
|
|
Mercury 2360 3.7 |
918
|
|
|
|
|
|
|
Venus 6110 5.1 |
919
|
|
|
|
|
|
|
Earth 6378 5.52 |
920
|
|
|
|
|
|
|
Jupiter 71030 1.3 |
921
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
Note that two-line titles work, and that the planet names are aligned |
923
|
|
|
|
|
|
|
differently than the numbers. |
924
|
|
|
|
|
|
|
|
925
|
|
|
|
|
|
|
=head1 DESCRIPTION |
926
|
|
|
|
|
|
|
|
927
|
|
|
|
|
|
|
Organization of data in table form is a time-honored and useful |
928
|
|
|
|
|
|
|
method of data representation. While columns of data are trivially |
929
|
|
|
|
|
|
|
generated by computer through formatted output, even simple tasks |
930
|
|
|
|
|
|
|
like keeping titles aligned with the data columns are not trivial, |
931
|
|
|
|
|
|
|
and the one-shot solutions one comes up with tend to be particularly |
932
|
|
|
|
|
|
|
hard to maintain. Text::Table allows you to create and maintain |
933
|
|
|
|
|
|
|
tables that adapt to alignment requirements as you use them. |
934
|
|
|
|
|
|
|
|
935
|
|
|
|
|
|
|
=head2 Overview |
936
|
|
|
|
|
|
|
|
937
|
|
|
|
|
|
|
The process is simple: you create a table (a Text::Table object) by |
938
|
|
|
|
|
|
|
describing the columns the table is going to have. Then you load |
939
|
|
|
|
|
|
|
lines of data into the table, and finally print the resulting output |
940
|
|
|
|
|
|
|
lines. Alignment of data and column titles is handled dynamically |
941
|
|
|
|
|
|
|
in dependence on the data present. |
942
|
|
|
|
|
|
|
|
943
|
|
|
|
|
|
|
=head2 Table Creation |
944
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
In the simplest case, if all you want is a number of (untitled) columns, |
946
|
|
|
|
|
|
|
you create an unspecified table and start adding data to it. The number |
947
|
|
|
|
|
|
|
of columns is taken from the first line of data. |
948
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
To specify a table you specify its columns. A column description |
950
|
|
|
|
|
|
|
can contain a title and alignment requirements for the data, both |
951
|
|
|
|
|
|
|
optional. Additionally, you can specify how the title is aligned with |
952
|
|
|
|
|
|
|
the body of a column, and how the lines of a multiline title are |
953
|
|
|
|
|
|
|
aligned among themselves. |
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
The columns are collected in the table in the |
956
|
|
|
|
|
|
|
order they are given. On data entry, each column corresponds to |
957
|
|
|
|
|
|
|
one data item, and in column selection columns are indexed left to |
958
|
|
|
|
|
|
|
right, starting from 0. |
959
|
|
|
|
|
|
|
|
960
|
|
|
|
|
|
|
Each title can be a multiline string which will be blank-filled to |
961
|
|
|
|
|
|
|
the length of the longest partial line. The largest number of title |
962
|
|
|
|
|
|
|
lines in a column determines how many title lines the table has as a |
963
|
|
|
|
|
|
|
whole, including the case that no column has any titles. |
964
|
|
|
|
|
|
|
|
965
|
|
|
|
|
|
|
On output, columns are separated by a single blank. You can control |
966
|
|
|
|
|
|
|
what goes between columns by specifying separators between (or before, |
967
|
|
|
|
|
|
|
or after) columns. Separators don't contain any data and don't count |
968
|
|
|
|
|
|
|
in column indexing. They also don't accumulate: in a sequence of only |
969
|
|
|
|
|
|
|
separators and no columns, only the last one counts. |
970
|
|
|
|
|
|
|
|
971
|
|
|
|
|
|
|
=head2 Status Information |
972
|
|
|
|
|
|
|
|
973
|
|
|
|
|
|
|
The width (in characters), height (in lines), number of columns, and |
974
|
|
|
|
|
|
|
similar data about the table is available. |
975
|
|
|
|
|
|
|
|
976
|
|
|
|
|
|
|
=head2 Data Loading |
977
|
|
|
|
|
|
|
|
978
|
|
|
|
|
|
|
Table data is entered line-wise, each time specifying data entries |
979
|
|
|
|
|
|
|
for all table columns. A bulk loader for many lines at once is also |
980
|
|
|
|
|
|
|
available. You can clear the data from the table for re-use (though |
981
|
|
|
|
|
|
|
you will more likely just create another table). |
982
|
|
|
|
|
|
|
|
983
|
|
|
|
|
|
|
Data can contain colorizing escape sequences (as provided by |
984
|
|
|
|
|
|
|
C) without upsetting the alignment. |
985
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
=head2 Table Output |
987
|
|
|
|
|
|
|
|
988
|
|
|
|
|
|
|
The output area of a table is divided in the title and the body. |
989
|
|
|
|
|
|
|
|
990
|
|
|
|
|
|
|
The title contains the combined titles from the table columns, if |
991
|
|
|
|
|
|
|
any. Its content never changes with a given table, but it may be |
992
|
|
|
|
|
|
|
spread out differently on the page through alignment with the data. |
993
|
|
|
|
|
|
|
|
994
|
|
|
|
|
|
|
The body contains the data lines, aligned column-wise as specified, |
995
|
|
|
|
|
|
|
and left-aligned with the column title. |
996
|
|
|
|
|
|
|
|
997
|
|
|
|
|
|
|
Each of these is arranged like a Perl array (counting from 0) and can |
998
|
|
|
|
|
|
|
be accessed in portions by specifying a first line and the number |
999
|
|
|
|
|
|
|
of following lines. Also like an array, giving a negative first line |
1000
|
|
|
|
|
|
|
counts from the end of the area. The whole table, the title followed |
1001
|
|
|
|
|
|
|
by the body, can also be accessed in this manner. |
1002
|
|
|
|
|
|
|
|
1003
|
|
|
|
|
|
|
The subdivisions are there so you can repeat the title (or parts of |
1004
|
|
|
|
|
|
|
it) along with parts of the body on output, whether for screen paging |
1005
|
|
|
|
|
|
|
or printout. |
1006
|
|
|
|
|
|
|
|
1007
|
|
|
|
|
|
|
A rule line is also available, which is the horizontal counterpart to |
1008
|
|
|
|
|
|
|
the separator columns you specify with the table. |
1009
|
|
|
|
|
|
|
It is basically a table line as it would appear if all data entries |
1010
|
|
|
|
|
|
|
in the line were empty, that is, a blank line except for where the |
1011
|
|
|
|
|
|
|
column separators have non-blank entries. If you print it between |
1012
|
|
|
|
|
|
|
data lines, it will not disrupt the vertical separator structure |
1013
|
|
|
|
|
|
|
as a plain blank line would. You can also request a solid rule |
1014
|
|
|
|
|
|
|
consisting of any character, and even one with the non-blank column |
1015
|
|
|
|
|
|
|
separators replaced by a character of your choice. This way you can |
1016
|
|
|
|
|
|
|
get the popular representation of line-crossings like so: |
1017
|
|
|
|
|
|
|
|
1018
|
|
|
|
|
|
|
| |
1019
|
|
|
|
|
|
|
----+--- |
1020
|
|
|
|
|
|
|
| |
1021
|
|
|
|
|
|
|
|
1022
|
|
|
|
|
|
|
=head2 Warning Control |
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
On table creation, some parameters are checked and warnings issued |
1025
|
|
|
|
|
|
|
if you allow warnings. You can also turn warnings into fatal errors. |
1026
|
|
|
|
|
|
|
|
1027
|
|
|
|
|
|
|
=head1 SPECIFICATIONS |
1028
|
|
|
|
|
|
|
|
1029
|
|
|
|
|
|
|
=head2 Column Specification |
1030
|
|
|
|
|
|
|
|
1031
|
|
|
|
|
|
|
Each column specification is a single scalar. Columns can be either proper |
1032
|
|
|
|
|
|
|
data columns or column separators. Both can be specified either as |
1033
|
|
|
|
|
|
|
(possibly multi-line) strings, or in a more explicit form as hash-refs. |
1034
|
|
|
|
|
|
|
In the string form, proper columns are given as plain strings, and |
1035
|
|
|
|
|
|
|
separators are given as scalar references to strings. In hash form, |
1036
|
|
|
|
|
|
|
separators have a true value in the field C while proper columns |
1037
|
|
|
|
|
|
|
don't have this field. |
1038
|
|
|
|
|
|
|
|
1039
|
|
|
|
|
|
|
=over 4 |
1040
|
|
|
|
|
|
|
|
1041
|
|
|
|
|
|
|
=item Columns as strings |
1042
|
|
|
|
|
|
|
|
1043
|
|
|
|
|
|
|
A column is given as a column title (any number of lines), |
1044
|
|
|
|
|
|
|
optionally followed by alignment requirements. Alignment requirements |
1045
|
|
|
|
|
|
|
start with a line that begins with an ampersand "&". However, only the |
1046
|
|
|
|
|
|
|
last such line counts as such, so if you have title lines that begin |
1047
|
|
|
|
|
|
|
with "&", just append an ampersand on a line by itself as a dummy |
1048
|
|
|
|
|
|
|
alignment section if you don't have one anyway. |
1049
|
|
|
|
|
|
|
|
1050
|
|
|
|
|
|
|
What follows the ampersand on its line is the alignment style (like |
1051
|
|
|
|
|
|
|
I, I, ... as described in L<"Alignment">), you want for |
1052
|
|
|
|
|
|
|
the data in this column. If nothing follows, the general default I |
1053
|
|
|
|
|
|
|
is used. If you specify an invalid alignment style, it falls back to |
1054
|
|
|
|
|
|
|
left alignment. |
1055
|
|
|
|
|
|
|
|
1056
|
|
|
|
|
|
|
The lines that follow can contain sample data for this column. These |
1057
|
|
|
|
|
|
|
are considered for alignment in the column, but never actually appear |
1058
|
|
|
|
|
|
|
in the output. The effect is to guarantee a minimum width for the |
1059
|
|
|
|
|
|
|
column even if the current data doesn't require it. This helps dampen |
1060
|
|
|
|
|
|
|
the oscillations in the appearance of dynamically aligned tables. |
1061
|
|
|
|
|
|
|
|
1062
|
|
|
|
|
|
|
=item Columns as Hashes |
1063
|
|
|
|
|
|
|
|
1064
|
|
|
|
|
|
|
The format is |
1065
|
|
|
|
|
|
|
|
1066
|
|
|
|
|
|
|
{ |
1067
|
|
|
|
|
|
|
title => $title, |
1068
|
|
|
|
|
|
|
align => $align, |
1069
|
|
|
|
|
|
|
sample => $sample, |
1070
|
|
|
|
|
|
|
align_title => $align_title, |
1071
|
|
|
|
|
|
|
align_title_lines => $align_title_lines, |
1072
|
|
|
|
|
|
|
} |
1073
|
|
|
|
|
|
|
|
1074
|
|
|
|
|
|
|
$title contains the title lines and $sample the sample data. Both can |
1075
|
|
|
|
|
|
|
be given as a string or as an array-ref to the list of lines. $align contains |
1076
|
|
|
|
|
|
|
the alignment style (without a leading ampersand), usually as a string. |
1077
|
|
|
|
|
|
|
You can also give a regular expression here, which specifies regex alignment. |
1078
|
|
|
|
|
|
|
A regex can only be specified in the hash form of a column specification. |
1079
|
|
|
|
|
|
|
|
1080
|
|
|
|
|
|
|
In hash form you can also specify how the title of a column is aligned |
1081
|
|
|
|
|
|
|
with its body. To do this, you specify the keyword C with |
1082
|
|
|
|
|
|
|
C, C or C. Other alignment specifications are not |
1083
|
|
|
|
|
|
|
valid here. The default is C. |
1084
|
|
|
|
|
|
|
|
1085
|
|
|
|
|
|
|
C also specifies how the lines of a multiline title are |
1086
|
|
|
|
|
|
|
aligned among themselves. If you want a different alignment, you |
1087
|
|
|
|
|
|
|
can specify it with the key C. Again, only C, |
1088
|
|
|
|
|
|
|
C or C are allowed. |
1089
|
|
|
|
|
|
|
|
1090
|
|
|
|
|
|
|
Do not put other keys than those mentioned above (I, I, |
1091
|
|
|
|
|
|
|
I, I, and I) into a hash that |
1092
|
|
|
|
|
|
|
specifies a column. Most would be ignored, but some would confuse the |
1093
|
|
|
|
|
|
|
interpreter (in particular, I has to be avoided). |
1094
|
|
|
|
|
|
|
|
1095
|
|
|
|
|
|
|
=item Separators as strings |
1096
|
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
|
A separator must be given as a reference to a string (often a literal, |
1098
|
|
|
|
|
|
|
like C<\' | '>), any string that is given directly describes a column. |
1099
|
|
|
|
|
|
|
|
1100
|
|
|
|
|
|
|
It is usually just a (short) string that will be printed between |
1101
|
|
|
|
|
|
|
table columns on all table lines instead of the default single |
1102
|
|
|
|
|
|
|
blank. If you specify two separators (on two lines), the first one |
1103
|
|
|
|
|
|
|
will be used in the title and the other in the body of the table. |
1104
|
|
|
|
|
|
|
|
1105
|
|
|
|
|
|
|
=item Separators as Hashes |
1106
|
|
|
|
|
|
|
|
1107
|
|
|
|
|
|
|
The hash representation of a separator has the format |
1108
|
|
|
|
|
|
|
|
1109
|
|
|
|
|
|
|
{ |
1110
|
|
|
|
|
|
|
is_sep => 1, |
1111
|
|
|
|
|
|
|
title => $title, |
1112
|
|
|
|
|
|
|
body => $body, |
1113
|
|
|
|
|
|
|
} |
1114
|
|
|
|
|
|
|
|
1115
|
|
|
|
|
|
|
$title is the separator to be used in the title area and $body |
1116
|
|
|
|
|
|
|
the one for the body. If only one is given, it will be used for |
1117
|
|
|
|
|
|
|
both. If none is given, a blank is used. If one is shorter than |
1118
|
|
|
|
|
|
|
the other, it is blank filled on the right. |
1119
|
|
|
|
|
|
|
|
1120
|
|
|
|
|
|
|
The value of C must be set to a true value, this is the |
1121
|
|
|
|
|
|
|
distinguishing feature of a separator. |
1122
|
|
|
|
|
|
|
|
1123
|
|
|
|
|
|
|
=back |
1124
|
|
|
|
|
|
|
|
1125
|
|
|
|
|
|
|
=head2 Alignment |
1126
|
|
|
|
|
|
|
|
1127
|
|
|
|
|
|
|
The original documentation to L contains all the details |
1128
|
|
|
|
|
|
|
on alignment specification, but here is the rundown: |
1129
|
|
|
|
|
|
|
|
1130
|
|
|
|
|
|
|
The possible alignment specifications are I, I, I, |
1131
|
|
|
|
|
|
|
I and I (which are synonyms), and I. The first |
1132
|
|
|
|
|
|
|
three explain themselves. |
1133
|
|
|
|
|
|
|
|
1134
|
|
|
|
|
|
|
I (and I) align the decimal point in the data, which is |
1135
|
|
|
|
|
|
|
assumed to the right if none is present. Strings that aren't |
1136
|
|
|
|
|
|
|
numbers are treated the same way, that is, they appear aligned |
1137
|
|
|
|
|
|
|
with the integers unless they contain a ".". Instead of the |
1138
|
|
|
|
|
|
|
decimal point ".", you can also specify any other string in |
1139
|
|
|
|
|
|
|
the form I, for instance. The string in parentheses |
1140
|
|
|
|
|
|
|
is aligned in the data. The synonym I for I may be |
1141
|
|
|
|
|
|
|
more appropriate in contexts that deal with arbitrary |
1142
|
|
|
|
|
|
|
strings, as in I)> (which might be used to align certain |
1143
|
|
|
|
|
|
|
bits of Perl code). |
1144
|
|
|
|
|
|
|
|
1145
|
|
|
|
|
|
|
I is a more sophisticated form of point alignment. |
1146
|
|
|
|
|
|
|
If you specify a regular expression, as delivered by C, the start |
1147
|
|
|
|
|
|
|
of the match is used as the alignment point. If the regex contains |
1148
|
|
|
|
|
|
|
capturing parentheses, the last submatch counts. [The usefulness of |
1149
|
|
|
|
|
|
|
this feature is under consideration.] |
1150
|
|
|
|
|
|
|
|
1151
|
|
|
|
|
|
|
I alignment combines numeric alignment with left alignment. |
1152
|
|
|
|
|
|
|
Data items that look like numbers, and those that don't, form two |
1153
|
|
|
|
|
|
|
virtual columns and are aligned accordingly: C for numbers and |
1154
|
|
|
|
|
|
|
C for other strings. These columns are left-aligned with |
1155
|
|
|
|
|
|
|
each other (i.e. the narrower one is blank-filled) to form the |
1156
|
|
|
|
|
|
|
final alignment. |
1157
|
|
|
|
|
|
|
|
1158
|
|
|
|
|
|
|
This way, a column that happens to have only numbers in the data gets |
1159
|
|
|
|
|
|
|
I alignment, a column with no numbers appears I-aligned, |
1160
|
|
|
|
|
|
|
and mixed data is presented in a reasonable way. |
1161
|
|
|
|
|
|
|
|
1162
|
|
|
|
|
|
|
=head2 Column Selection |
1163
|
|
|
|
|
|
|
|
1164
|
|
|
|
|
|
|
Besides creating tables from scratch, they can be created by |
1165
|
|
|
|
|
|
|
selecting columns from an existing table. Tables created this |
1166
|
|
|
|
|
|
|
way contain the data from the columns they were built from. |
1167
|
|
|
|
|
|
|
|
1168
|
|
|
|
|
|
|
This is done by specifying the columns to select by their index |
1169
|
|
|
|
|
|
|
(where negative indices count backward from the last column). |
1170
|
|
|
|
|
|
|
The same column can be selected more than once and the sequence |
1171
|
|
|
|
|
|
|
of columns can be arbitrarily changed. Separators don't travel |
1172
|
|
|
|
|
|
|
with columns, but can be specified between the columns at selection |
1173
|
|
|
|
|
|
|
time. |
1174
|
|
|
|
|
|
|
|
1175
|
|
|
|
|
|
|
You can make the selection of one or more columns dependent on |
1176
|
|
|
|
|
|
|
the data content of one of them. If you specify some of the columns |
1177
|
|
|
|
|
|
|
in angle brackets [...], the whole group is only included in the |
1178
|
|
|
|
|
|
|
selection if the first column in the group contains any data that |
1179
|
|
|
|
|
|
|
evaluates to boolean true. That way you can de-select parts of a |
1180
|
|
|
|
|
|
|
table if it contains no interesting data. Any column separators |
1181
|
|
|
|
|
|
|
given in brackets are selected or deselected along with the rest |
1182
|
|
|
|
|
|
|
of it. |
1183
|
|
|
|
|
|
|
|
1184
|
|
|
|
|
|
|
=head1 PUBLIC METHODS |
1185
|
|
|
|
|
|
|
|
1186
|
|
|
|
|
|
|
=head2 Table Creation |
1187
|
|
|
|
|
|
|
|
1188
|
|
|
|
|
|
|
=over 4 |
1189
|
|
|
|
|
|
|
|
1190
|
|
|
|
|
|
|
=item new() |
1191
|
|
|
|
|
|
|
|
1192
|
|
|
|
|
|
|
my $tb = Text::Table->new( $column, ... ); |
1193
|
|
|
|
|
|
|
|
1194
|
|
|
|
|
|
|
creates a table with the columns specified. A column can be proper column |
1195
|
|
|
|
|
|
|
which contains and displays data, or a separator which tells how to fill |
1196
|
|
|
|
|
|
|
the space between columns. The format of the parameters is described under |
1197
|
|
|
|
|
|
|
L<"Column Specification">. Specifying an invalid alignment for a column |
1198
|
|
|
|
|
|
|
results in a warning if these are allowed. |
1199
|
|
|
|
|
|
|
|
1200
|
|
|
|
|
|
|
If no columns are specified, the number of columns is taken from the first |
1201
|
|
|
|
|
|
|
line of data added to the table. The effect is as if you had specified |
1202
|
|
|
|
|
|
|
Cnew( ( '') x $n)>, where C<$n> is the number of |
1203
|
|
|
|
|
|
|
columns. |
1204
|
|
|
|
|
|
|
|
1205
|
|
|
|
|
|
|
=item select() |
1206
|
|
|
|
|
|
|
|
1207
|
|
|
|
|
|
|
my $sub = $tb->select( $column, ...); |
1208
|
|
|
|
|
|
|
|
1209
|
|
|
|
|
|
|
creates a table from the listed columns of the table $tb, including |
1210
|
|
|
|
|
|
|
the data. Columns are specified as integer indices which refer to |
1211
|
|
|
|
|
|
|
the data columns of $tb. Columns can be repeated and specified in any |
1212
|
|
|
|
|
|
|
order. Negative indices count from the last column. If an invalid |
1213
|
|
|
|
|
|
|
index is specified, a warning is issued, if allowed. |
1214
|
|
|
|
|
|
|
|
1215
|
|
|
|
|
|
|
As with L<"new()">, separators can be interspersed among the column |
1216
|
|
|
|
|
|
|
indices and will be used between the columns of the new table. |
1217
|
|
|
|
|
|
|
|
1218
|
|
|
|
|
|
|
If you enclose some of the arguments (column indices or separators) in |
1219
|
|
|
|
|
|
|
angle brackets C<[...]> (technically, you specify them inside an |
1220
|
|
|
|
|
|
|
arrayref), they form a group for conditional selection. The group is |
1221
|
|
|
|
|
|
|
only included in the resulting table if the first actual column inside |
1222
|
|
|
|
|
|
|
the group contains any data that evaluate to a boolean true. This way |
1223
|
|
|
|
|
|
|
you can exclude groups of columns that wouldn't contribute anything |
1224
|
|
|
|
|
|
|
interesting. Note that separators are selected and de-selected with |
1225
|
|
|
|
|
|
|
their group. That way, more than one separator can appear between |
1226
|
|
|
|
|
|
|
adjacent columns. They don't add up, but only the rightmost separator |
1227
|
|
|
|
|
|
|
is used. A group that contains only separators is never selected. |
1228
|
|
|
|
|
|
|
[Another feature whose usefulness is under consideration.] |
1229
|
|
|
|
|
|
|
|
1230
|
|
|
|
|
|
|
=back |
1231
|
|
|
|
|
|
|
|
1232
|
|
|
|
|
|
|
=head2 Status Information |
1233
|
|
|
|
|
|
|
|
1234
|
|
|
|
|
|
|
=over 4 |
1235
|
|
|
|
|
|
|
|
1236
|
|
|
|
|
|
|
=item n_cols() |
1237
|
|
|
|
|
|
|
|
1238
|
|
|
|
|
|
|
$tb->n_cols |
1239
|
|
|
|
|
|
|
|
1240
|
|
|
|
|
|
|
returns the number of columns in the table. |
1241
|
|
|
|
|
|
|
|
1242
|
|
|
|
|
|
|
=item width() |
1243
|
|
|
|
|
|
|
|
1244
|
|
|
|
|
|
|
$tb->width |
1245
|
|
|
|
|
|
|
|
1246
|
|
|
|
|
|
|
returns the width (in characters) of the table. All table lines have |
1247
|
|
|
|
|
|
|
this length (not counting a final "\n" in the line), as well as the |
1248
|
|
|
|
|
|
|
separator lines returned by $tb->rule() and $b->body_rule(). |
1249
|
|
|
|
|
|
|
The width of a table can potentially be influenced by any data item |
1250
|
|
|
|
|
|
|
in it. |
1251
|
|
|
|
|
|
|
|
1252
|
|
|
|
|
|
|
=item height() |
1253
|
|
|
|
|
|
|
|
1254
|
|
|
|
|
|
|
$tb->height |
1255
|
|
|
|
|
|
|
|
1256
|
|
|
|
|
|
|
returns the total number of lines in a table, including title lines |
1257
|
|
|
|
|
|
|
and body lines. For orthogonality, the synonym table_height() also |
1258
|
|
|
|
|
|
|
exists. |
1259
|
|
|
|
|
|
|
|
1260
|
|
|
|
|
|
|
=item table_height() |
1261
|
|
|
|
|
|
|
|
1262
|
|
|
|
|
|
|
Same as C<< $table->height() >>. |
1263
|
|
|
|
|
|
|
|
1264
|
|
|
|
|
|
|
=item title_height() |
1265
|
|
|
|
|
|
|
|
1266
|
|
|
|
|
|
|
$tb->title_height |
1267
|
|
|
|
|
|
|
|
1268
|
|
|
|
|
|
|
returns the number of title lines in a table. |
1269
|
|
|
|
|
|
|
|
1270
|
|
|
|
|
|
|
=item body_height() |
1271
|
|
|
|
|
|
|
|
1272
|
|
|
|
|
|
|
$tb->body_height |
1273
|
|
|
|
|
|
|
|
1274
|
|
|
|
|
|
|
returns the number of lines in the table body. |
1275
|
|
|
|
|
|
|
|
1276
|
|
|
|
|
|
|
=item colrange() |
1277
|
|
|
|
|
|
|
|
1278
|
|
|
|
|
|
|
$tb->colrange( $i) |
1279
|
|
|
|
|
|
|
|
1280
|
|
|
|
|
|
|
returns the start position and width of the $i-th column (counting from 0) |
1281
|
|
|
|
|
|
|
of the table. If $i is negative, counts from the end of the table. If $i |
1282
|
|
|
|
|
|
|
is larger than the greatest column index, an imaginary column of width 0 |
1283
|
|
|
|
|
|
|
is assumed right of the table. |
1284
|
|
|
|
|
|
|
|
1285
|
|
|
|
|
|
|
=back |
1286
|
|
|
|
|
|
|
|
1287
|
|
|
|
|
|
|
=head2 Data Loading |
1288
|
|
|
|
|
|
|
|
1289
|
|
|
|
|
|
|
=over 4 |
1290
|
|
|
|
|
|
|
|
1291
|
|
|
|
|
|
|
=item add() |
1292
|
|
|
|
|
|
|
|
1293
|
|
|
|
|
|
|
$tb->add( $col1, ..., $colN) |
1294
|
|
|
|
|
|
|
|
1295
|
|
|
|
|
|
|
adds a data line to the table, returns the table. |
1296
|
|
|
|
|
|
|
|
1297
|
|
|
|
|
|
|
C<$col1>, ..., C<$colN> are scalars that |
1298
|
|
|
|
|
|
|
correspond to the table columns. Undefined entries are converted to '', |
1299
|
|
|
|
|
|
|
and extra data beyond the number of table columns is ignored. |
1300
|
|
|
|
|
|
|
|
1301
|
|
|
|
|
|
|
Data entries can be multi-line strings. The partial strings all go into |
1302
|
|
|
|
|
|
|
the same column. The corresponding fields of other columns remain empty |
1303
|
|
|
|
|
|
|
unless there is another multi-line entry in that column that fills the |
1304
|
|
|
|
|
|
|
fields. Adding a line with multi-line entries is equivalent to adding |
1305
|
|
|
|
|
|
|
multiple lines. |
1306
|
|
|
|
|
|
|
|
1307
|
|
|
|
|
|
|
Every call to C increases the body height of the table by the |
1308
|
|
|
|
|
|
|
number of effective lines, one in the absence of multiline entries. |
1309
|
|
|
|
|
|
|
|
1310
|
|
|
|
|
|
|
=item load() |
1311
|
|
|
|
|
|
|
|
1312
|
|
|
|
|
|
|
$tb->load( $line, ...) |
1313
|
|
|
|
|
|
|
|
1314
|
|
|
|
|
|
|
loads the data lines given into the table, returns the table. |
1315
|
|
|
|
|
|
|
|
1316
|
|
|
|
|
|
|
Every argument to C represents a data line to be added to the |
1317
|
|
|
|
|
|
|
table. The line can be given as an array(ref) containing the data |
1318
|
|
|
|
|
|
|
items, or as a string, which is split on whitespace to retrieve the |
1319
|
|
|
|
|
|
|
data. If an undefined argument is given, it is treated as an |
1320
|
|
|
|
|
|
|
empty line. |
1321
|
|
|
|
|
|
|
|
1322
|
|
|
|
|
|
|
=item clear() |
1323
|
|
|
|
|
|
|
|
1324
|
|
|
|
|
|
|
$tb->clear; |
1325
|
|
|
|
|
|
|
|
1326
|
|
|
|
|
|
|
deletes all data from the table and resets it to the state after |
1327
|
|
|
|
|
|
|
creation. Returns the table. The body height of a table is 0 after |
1328
|
|
|
|
|
|
|
C. |
1329
|
|
|
|
|
|
|
|
1330
|
|
|
|
|
|
|
=back |
1331
|
|
|
|
|
|
|
|
1332
|
|
|
|
|
|
|
=head2 Table Output |
1333
|
|
|
|
|
|
|
|
1334
|
|
|
|
|
|
|
The three methods C, C, and C are very similar.
1335
|
|
|
|
|
|
|
They access different parts of the printable output lines of a table with |
1336
|
|
|
|
|
|
|
similar methods. The details are described with the C method.
1337
|
|
|
|
|
|
|
|
1338
|
|
|
|
|
|
|
=over 4 |
1339
|
|
|
|
|
|
|
|
1340
|
|
|
|
|
|
|
=item table() |
1341
|
|
|
|
|
|
|
|
1342
|
|
|
|
|
|
|
The C method returns lines from the entire table, starting
1343
|
|
|
|
|
|
|
with the first title line and ending with the last body line. |
1344
|
|
|
|
|
|
|
|
1345
|
|
|
|
|
|
|
In array context, the lines are returned separately, in scalar context |
1346
|
|
|
|
|
|
|
they are joined together in a single string. |
1347
|
|
|
|
|
|
|
|
1348
|
|
|
|
|
|
|
my @lines = $tb->table; |
1349
|
|
|
|
|
|
|
my $line = $tb->table( $line_number); |
1350
|
|
|
|
|
|
|
my @lines = $tb->table( $line_number, $n); |
1351
|
|
|
|
|
|
|
|
1352
|
|
|
|
|
|
|
The first call returns all the lines in the table. The second call |
1353
|
|
|
|
|
|
|
returns one line given by $line_number. The third call returns $n |
1354
|
|
|
|
|
|
|
lines, starting with $line_number. If $line_number is negative, it |
1355
|
|
|
|
|
|
|
counts from the end of the array. Unlike the C |
1356
|
|
|
|
|
|
|
C (and its sister methods C and C) is
1357
|
|
|
|
|
|
|
protected against large negative line numbers, it truncates the |
1358
|
|
|
|
|
|
|
range described by $line_number and $n to the existing lines. If |
1359
|
|
|
|
|
|
|
$n is 0 or negative, no lines are returned (an empty string in scalar |
1360
|
|
|
|
|
|
|
context). |
1361
|
|
|
|
|
|
|
|
1362
|
|
|
|
|
|
|
=item stringify() |
1363
|
|
|
|
|
|
|
|
1364
|
|
|
|
|
|
|
Returns a string representation of the table. This method is called for |
1365
|
|
|
|
|
|
|
stringification by overload. |
1366
|
|
|
|
|
|
|
|
1367
|
|
|
|
|
|
|
my @table_strings = map { $_->stringify() } @tables; |
1368
|
|
|
|
|
|
|
|
1369
|
|
|
|
|
|
|
=item title() |
1370
|
|
|
|
|
|
|
|
1371
|
|
|
|
|
|
|
Returns lines from the title area of a table, where the column titles |
1372
|
|
|
|
|
|
|
are rendered. Parameters and response to context are as with C,
1373
|
|
|
|
|
|
|
but no lines are returned from outside the title area. |
1374
|
|
|
|
|
|
|
|
1375
|
|
|
|
|
|
|
=item body() |
1376
|
|
|
|
|
|
|
|
1377
|
|
|
|
|
|
|
Returns lines from the body area of a table, that is the part where |
1378
|
|
|
|
|
|
|
the data content is rendered, so that $tb->body( 0) is the first data |
1379
|
|
|
|
|
|
|
line. Parameters and response to context are as with C.
1380
|
|
|
|
|
|
|
|
1381
|
|
|
|
|
|
|
=item rule() |
1382
|
|
|
|
|
|
|
|
1383
|
|
|
|
|
|
|
$tb->rule; |
1384
|
|
|
|
|
|
|
$tb->rule( $char); |
1385
|
|
|
|
|
|
|
$tb->rule( $char, $char1); |
1386
|
|
|
|
|
|
|
$tb->rule( sub { my ($index, $len) = @_; }, |
1387
|
|
|
|
|
|
|
sub { my ($index, $len) = @_; }, |
1388
|
|
|
|
|
|
|
); |
1389
|
|
|
|
|
|
|
|
1390
|
|
|
|
|
|
|
Returns a rule for the table. |
1391
|
|
|
|
|
|
|
|
1392
|
|
|
|
|
|
|
A rule is a line of table width that can be used between table lines |
1393
|
|
|
|
|
|
|
to provide visual horizontal divisions, much like column separators |
1394
|
|
|
|
|
|
|
provide vertical visual divisions. In its basic form (returned by the |
1395
|
|
|
|
|
|
|
first call) it looks like a table line with no data, hence a blank |
1396
|
|
|
|
|
|
|
line except for the non-blank parts of any column-separators. If |
1397
|
|
|
|
|
|
|
one character is specified (the second call), it replaces the blanks |
1398
|
|
|
|
|
|
|
in the first form, but non-blank column separators are retained. If |
1399
|
|
|
|
|
|
|
a second character is specified, it replaces the non-blank parts of |
1400
|
|
|
|
|
|
|
the separators. So specifying the same character twice gives a solid |
1401
|
|
|
|
|
|
|
line of table width. Another useful combo is C<$tb-Erule( '-', '+')>, |
1402
|
|
|
|
|
|
|
together with separators that contain a single nonblank "|", for a |
1403
|
|
|
|
|
|
|
popular representation of line crossings. |
1404
|
|
|
|
|
|
|
|
1405
|
|
|
|
|
|
|
C uses the column separators for the title section if there |
1406
|
|
|
|
|
|
|
is a difference. |
1407
|
|
|
|
|
|
|
|
1408
|
|
|
|
|
|
|
If callbacks are specified instead of the characters, then they receive the |
1409
|
|
|
|
|
|
|
index of the section of the rule they need to render and its desired length in |
1410
|
|
|
|
|
|
|
characters, and should return the string to put there. The indexes given |
1411
|
|
|
|
|
|
|
are 0 based (where 0 is either the left column separator or the leftmost |
1412
|
|
|
|
|
|
|
cell) and the strings will be trimmed or extended in the replacement. |
1413
|
|
|
|
|
|
|
|
1414
|
|
|
|
|
|
|
=item body_rule() |
1415
|
|
|
|
|
|
|
|
1416
|
|
|
|
|
|
|
C works like , except the rule is generated using |
1417
|
|
|
|
|
|
|
the column separators for the table body. |
1418
|
|
|
|
|
|
|
|
1419
|
|
|
|
|
|
|
=back |
1420
|
|
|
|
|
|
|
|
1421
|
|
|
|
|
|
|
=head2 Warning Control |
1422
|
|
|
|
|
|
|
|
1423
|
|
|
|
|
|
|
=over 4 |
1424
|
|
|
|
|
|
|
|
1425
|
|
|
|
|
|
|
=item warnings() |
1426
|
|
|
|
|
|
|
|
1427
|
|
|
|
|
|
|
Text::Table->warnings(); |
1428
|
|
|
|
|
|
|
Text::Table->warnings( 'on'); |
1429
|
|
|
|
|
|
|
Text::Table->warnings( 'off'): |
1430
|
|
|
|
|
|
|
Text::Table->warnings( 'fatal'): |
1431
|
|
|
|
|
|
|
|
1432
|
|
|
|
|
|
|
The C method is used to control the appearance of warning |
1433
|
|
|
|
|
|
|
messages while tables are manipulated. When Text::Table starts, warnings |
1434
|
|
|
|
|
|
|
are disabled. The default action of C is to turn warnings |
1435
|
|
|
|
|
|
|
on. The other possible arguments are self-explanatory. C |
1436
|
|
|
|
|
|
|
can also be called as an object method (C<$tb-Ewarnings( ...)>). |
1437
|
|
|
|
|
|
|
|
1438
|
|
|
|
|
|
|
=back |
1439
|
|
|
|
|
|
|
|
1440
|
|
|
|
|
|
|
=head1 VERSION |
1441
|
|
|
|
|
|
|
|
1442
|
|
|
|
|
|
|
This document pertains to Text::Table version 1.127 |
1443
|
|
|
|
|
|
|
|
1444
|
|
|
|
|
|
|
=head1 BUGS |
1445
|
|
|
|
|
|
|
|
1446
|
|
|
|
|
|
|
=over 4 |
1447
|
|
|
|
|
|
|
|
1448
|
|
|
|
|
|
|
=item o |
1449
|
|
|
|
|
|
|
|
1450
|
|
|
|
|
|
|
I alignment doesn't support alternative characters for the decimal |
1451
|
|
|
|
|
|
|
point. This is actually a bug in the underlying Text::Aligner by the |
1452
|
|
|
|
|
|
|
same author. |
1453
|
|
|
|
|
|
|
|
1454
|
|
|
|
|
|
|
=back |
1455
|
|
|
|
|
|
|
|
1456
|
|
|
|
|
|
|
=head1 AUTHOR |
1457
|
|
|
|
|
|
|
|
1458
|
|
|
|
|
|
|
=head2 MAINTAINER |
1459
|
|
|
|
|
|
|
|
1460
|
|
|
|
|
|
|
Shlomi Fish, L - CPAN ID: "SHLOMIF". |
1461
|
|
|
|
|
|
|
|
1462
|
|
|
|
|
|
|
=head2 ORIGINAL AUTHOR |
1463
|
|
|
|
|
|
|
|
1464
|
|
|
|
|
|
|
Anno Siegel |
1465
|
|
|
|
|
|
|
CPAN ID: ANNO |
1466
|
|
|
|
|
|
|
siegel@zrz.tu-berlin.de |
1467
|
|
|
|
|
|
|
http://www.tu-berlin.de/~siegel |
1468
|
|
|
|
|
|
|
|
1469
|
|
|
|
|
|
|
=head1 COPYRIGHT |
1470
|
|
|
|
|
|
|
|
1471
|
|
|
|
|
|
|
Copyright (c) 2002 Anno Siegel. All rights reserved. |
1472
|
|
|
|
|
|
|
This program is free software; you can redistribute |
1473
|
|
|
|
|
|
|
it and/or modify it under the terms of the ISC license. |
1474
|
|
|
|
|
|
|
|
1475
|
|
|
|
|
|
|
(This program had been licensed under the same terms as Perl itself up to |
1476
|
|
|
|
|
|
|
version 1.118 released on 2011, and was relicensed by permission of its |
1477
|
|
|
|
|
|
|
originator). |
1478
|
|
|
|
|
|
|
|
1479
|
|
|
|
|
|
|
The full text of the license can be found in the |
1480
|
|
|
|
|
|
|
LICENSE file included with this module. |
1481
|
|
|
|
|
|
|
|
1482
|
|
|
|
|
|
|
=head1 SEE ALSO |
1483
|
|
|
|
|
|
|
|
1484
|
|
|
|
|
|
|
L, L . |
1485
|
|
|
|
|
|
|
|
1486
|
|
|
|
|
|
|
=head1 AUTHOR |
1487
|
|
|
|
|
|
|
|
1488
|
|
|
|
|
|
|
Shlomi Fish |
1489
|
|
|
|
|
|
|
|
1490
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
1491
|
|
|
|
|
|
|
|
1492
|
|
|
|
|
|
|
This software is Copyright (c) 2002 by Anno Siegel and others. |
1493
|
|
|
|
|
|
|
|
1494
|
|
|
|
|
|
|
This is free software, licensed under: |
1495
|
|
|
|
|
|
|
|
1496
|
|
|
|
|
|
|
The ISC License |
1497
|
|
|
|
|
|
|
|
1498
|
|
|
|
|
|
|
=head1 BUGS |
1499
|
|
|
|
|
|
|
|
1500
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website |
1501
|
|
|
|
|
|
|
L or by email to |
1502
|
|
|
|
|
|
|
L. |
1503
|
|
|
|
|
|
|
|
1504
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
1505
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
1506
|
|
|
|
|
|
|
feature. |
1507
|
|
|
|
|
|
|
|
1508
|
|
|
|
|
|
|
=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan |
1509
|
|
|
|
|
|
|
|
1510
|
|
|
|
|
|
|
=head1 SUPPORT |
1511
|
|
|
|
|
|
|
|
1512
|
|
|
|
|
|
|
=head2 Perldoc |
1513
|
|
|
|
|
|
|
|
1514
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
1515
|
|
|
|
|
|
|
|
1516
|
|
|
|
|
|
|
perldoc Text::Table |
1517
|
|
|
|
|
|
|
|
1518
|
|
|
|
|
|
|
=head2 Websites |
1519
|
|
|
|
|
|
|
|
1520
|
|
|
|
|
|
|
The following websites have more information about this module, and may be of help to you. As always, |
1521
|
|
|
|
|
|
|
in addition to those websites please use your favorite search engine to discover more resources. |
1522
|
|
|
|
|
|
|
|
1523
|
|
|
|
|
|
|
=over 4 |
1524
|
|
|
|
|
|
|
|
1525
|
|
|
|
|
|
|
=item * |
1526
|
|
|
|
|
|
|
|
1527
|
|
|
|
|
|
|
MetaCPAN |
1528
|
|
|
|
|
|
|
|
1529
|
|
|
|
|
|
|
A modern, open-source CPAN search engine, useful to view POD in HTML format. |
1530
|
|
|
|
|
|
|
|
1531
|
|
|
|
|
|
|
L |
1532
|
|
|
|
|
|
|
|
1533
|
|
|
|
|
|
|
=item * |
1534
|
|
|
|
|
|
|
|
1535
|
|
|
|
|
|
|
Search CPAN |
1536
|
|
|
|
|
|
|
|
1537
|
|
|
|
|
|
|
The default CPAN search engine, useful to view POD in HTML format. |
1538
|
|
|
|
|
|
|
|
1539
|
|
|
|
|
|
|
L |
1540
|
|
|
|
|
|
|
|
1541
|
|
|
|
|
|
|
=item * |
1542
|
|
|
|
|
|
|
|
1543
|
|
|
|
|
|
|
RT: CPAN's Bug Tracker |
1544
|
|
|
|
|
|
|
|
1545
|
|
|
|
|
|
|
The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN. |
1546
|
|
|
|
|
|
|
|
1547
|
|
|
|
|
|
|
L |
1548
|
|
|
|
|
|
|
|
1549
|
|
|
|
|
|
|
=item * |
1550
|
|
|
|
|
|
|
|
1551
|
|
|
|
|
|
|
AnnoCPAN |
1552
|
|
|
|
|
|
|
|
1553
|
|
|
|
|
|
|
The AnnoCPAN is a website that allows community annotations of Perl module documentation. |
1554
|
|
|
|
|
|
|
|
1555
|
|
|
|
|
|
|
L |
1556
|
|
|
|
|
|
|
|
1557
|
|
|
|
|
|
|
=item * |
1558
|
|
|
|
|
|
|
|
1559
|
|
|
|
|
|
|
CPAN Ratings |
1560
|
|
|
|
|
|
|
|
1561
|
|
|
|
|
|
|
The CPAN Ratings is a website that allows community ratings and reviews of Perl modules. |
1562
|
|
|
|
|
|
|
|
1563
|
|
|
|
|
|
|
L |
1564
|
|
|
|
|
|
|
|
1565
|
|
|
|
|
|
|
=item * |
1566
|
|
|
|
|
|
|
|
1567
|
|
|
|
|
|
|
CPAN Forum |
1568
|
|
|
|
|
|
|
|
1569
|
|
|
|
|
|
|
The CPAN Forum is a web forum for discussing Perl modules. |
1570
|
|
|
|
|
|
|
|
1571
|
|
|
|
|
|
|
L |
1572
|
|
|
|
|
|
|
|
1573
|
|
|
|
|
|
|
=item * |
1574
|
|
|
|
|
|
|
|
1575
|
|
|
|
|
|
|
CPANTS |
1576
|
|
|
|
|
|
|
|
1577
|
|
|
|
|
|
|
The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution. |
1578
|
|
|
|
|
|
|
|
1579
|
|
|
|
|
|
|
L |
1580
|
|
|
|
|
|
|
|
1581
|
|
|
|
|
|
|
=item * |
1582
|
|
|
|
|
|
|
|
1583
|
|
|
|
|
|
|
CPAN Testers |
1584
|
|
|
|
|
|
|
|
1585
|
|
|
|
|
|
|
The CPAN Testers is a network of smokers who run automated tests on uploaded CPAN distributions. |
1586
|
|
|
|
|
|
|
|
1587
|
|
|
|
|
|
|
L |
1588
|
|
|
|
|
|
|
|
1589
|
|
|
|
|
|
|
=item * |
1590
|
|
|
|
|
|
|
|
1591
|
|
|
|
|
|
|
CPAN Testers Matrix |
1592
|
|
|
|
|
|
|
|
1593
|
|
|
|
|
|
|
The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms. |
1594
|
|
|
|
|
|
|
|
1595
|
|
|
|
|
|
|
L |
1596
|
|
|
|
|
|
|
|
1597
|
|
|
|
|
|
|
=item * |
1598
|
|
|
|
|
|
|
|
1599
|
|
|
|
|
|
|
CPAN Testers Dependencies |
1600
|
|
|
|
|
|
|
|
1601
|
|
|
|
|
|
|
The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution. |
1602
|
|
|
|
|
|
|
|
1603
|
|
|
|
|
|
|
L |
1604
|
|
|
|
|
|
|
|
1605
|
|
|
|
|
|
|
=back |
1606
|
|
|
|
|
|
|
|
1607
|
|
|
|
|
|
|
=head2 Bugs / Feature Requests |
1608
|
|
|
|
|
|
|
|
1609
|
|
|
|
|
|
|
Please report any bugs or feature requests by email to C, or through |
1610
|
|
|
|
|
|
|
the web interface at L. You will be automatically notified of any |
1611
|
|
|
|
|
|
|
progress on the request by the system. |
1612
|
|
|
|
|
|
|
|
1613
|
|
|
|
|
|
|
=head2 Source Code |
1614
|
|
|
|
|
|
|
|
1615
|
|
|
|
|
|
|
The code is open to the world, and available for you to hack on. Please feel free to browse it and play |
1616
|
|
|
|
|
|
|
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull |
1617
|
|
|
|
|
|
|
from your repository :) |
1618
|
|
|
|
|
|
|
|
1619
|
|
|
|
|
|
|
L |
1620
|
|
|
|
|
|
|
|
1621
|
|
|
|
|
|
|
git clone ssh://git@github.com:shlomif/Text-Table.git |
1622
|
|
|
|
|
|
|
|
1623
|
|
|
|
|
|
|
=cut |
1624
|
|
|
|
|
|
|
|
1625
|
|
|
|
|
|
|
__END__ |
| | | | | |