line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::Table::LineBreak; |
2
|
6
|
|
|
6
|
|
74627
|
use strict; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
157
|
|
3
|
6
|
|
|
6
|
|
27
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
231
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.015'; |
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
31
|
use Carp qw/croak/; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
366
|
|
8
|
6
|
|
|
6
|
|
50
|
use Scalar::Util qw/blessed/; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
436
|
|
9
|
6
|
|
|
6
|
|
2300
|
use Term::Table::Util qw/uni_length/; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
69
|
|
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
2826
|
use Term::Table::HashBase qw/string gcstring _len _parts idx/; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
35
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub init { |
14
|
140
|
|
|
140
|
0
|
199
|
my $self = shift; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
croak "string is a required attribute" |
17
|
140
|
50
|
|
|
|
339
|
unless defined $self->{+STRING}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
0
|
0
|
sub columns { uni_length($_[0]->{+STRING}) } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub break { |
23
|
140
|
|
|
140
|
0
|
204
|
my $self = shift; |
24
|
140
|
|
|
|
|
201
|
my ($len) = @_; |
25
|
|
|
|
|
|
|
|
26
|
140
|
|
|
|
|
217
|
$self->{+_LEN} = $len; |
27
|
|
|
|
|
|
|
|
28
|
140
|
|
|
|
|
225
|
$self->{+IDX} = 0; |
29
|
140
|
|
|
|
|
270
|
my $str = $self->{+STRING} . ""; # Force stringification |
30
|
|
|
|
|
|
|
|
31
|
140
|
|
|
|
|
182
|
my @parts; |
32
|
140
|
|
|
|
|
588
|
my @chars = split //, $str; |
33
|
140
|
|
|
|
|
331
|
while (@chars) { |
34
|
264
|
|
|
|
|
352
|
my $size = 0; |
35
|
264
|
|
|
|
|
322
|
my $part = ''; |
36
|
264
|
|
|
|
|
448
|
until ($size == $len) { |
37
|
1826
|
|
|
|
|
2409
|
my $char = shift @chars; |
38
|
1826
|
100
|
|
|
|
2855
|
$char = '' unless defined $char; |
39
|
|
|
|
|
|
|
|
40
|
1826
|
|
|
|
|
3515
|
my $l = uni_length("$char"); |
41
|
1826
|
100
|
|
|
|
20633
|
last unless $l; |
42
|
|
|
|
|
|
|
|
43
|
1757
|
50
|
|
|
|
2998
|
last if $char eq "\n"; |
44
|
|
|
|
|
|
|
|
45
|
1757
|
100
|
|
|
|
2629
|
if ($size + $l > $len) { |
46
|
1
|
|
|
|
|
14
|
unshift @chars => $char; |
47
|
1
|
|
|
|
|
4
|
last; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
1756
|
|
|
|
|
1932
|
$size += $l; |
51
|
1756
|
|
|
|
|
2986
|
$part .= $char; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# If we stopped just before a newline, grab it |
55
|
264
|
100
|
100
|
|
|
849
|
shift @chars if $size == $len && @chars && $chars[0] eq "\n"; |
|
|
|
100
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
264
|
|
|
|
|
478
|
until ($size == $len) { |
58
|
429
|
|
|
|
|
522
|
$part .= ' '; |
59
|
429
|
|
|
|
|
658
|
$size += 1; |
60
|
|
|
|
|
|
|
} |
61
|
264
|
|
|
|
|
613
|
push @parts => $part; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
140
|
|
|
|
|
347
|
$self->{+_PARTS} = \@parts; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub next { |
68
|
495
|
|
|
495
|
0
|
669
|
my $self = shift; |
69
|
|
|
|
|
|
|
|
70
|
495
|
100
|
|
|
|
787
|
if (@_) { |
71
|
476
|
|
|
|
|
726
|
my ($len) = @_; |
72
|
476
|
100
|
66
|
|
|
1380
|
$self->break($len) if !$self->{+_LEN} || $self->{+_LEN} != $len; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
else { |
75
|
|
|
|
|
|
|
croak "String has not yet been broken" |
76
|
19
|
50
|
|
|
|
38
|
unless $self->{+_PARTS}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
495
|
|
|
|
|
704
|
my $idx = $self->{+IDX}++; |
80
|
495
|
|
|
|
|
624
|
my $parts = $self->{+_PARTS}; |
81
|
|
|
|
|
|
|
|
82
|
495
|
100
|
|
|
|
1039
|
return undef if $idx >= @$parts; |
83
|
264
|
|
|
|
|
612
|
return $parts->[$idx]; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |