line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Stream::Table::LineBreak; |
2
|
102
|
|
|
102
|
|
647
|
use strict; |
|
102
|
|
|
|
|
111
|
|
|
102
|
|
|
|
|
2345
|
|
3
|
102
|
|
|
102
|
|
292
|
use warnings; |
|
102
|
|
|
|
|
108
|
|
|
102
|
|
|
|
|
1922
|
|
4
|
|
|
|
|
|
|
|
5
|
102
|
|
|
102
|
|
288
|
use Carp qw/croak/; |
|
102
|
|
|
|
|
109
|
|
|
102
|
|
|
|
|
3668
|
|
6
|
102
|
|
|
102
|
|
462
|
use Scalar::Util qw/blessed/; |
|
102
|
|
|
|
|
122
|
|
|
102
|
|
|
|
|
5520
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Optional. |
9
|
|
|
|
|
|
|
eval { require Unicode::GCString; 1 }; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Test::Stream::HashBase( |
12
|
102
|
|
|
|
|
723
|
accessors => [qw/string gcstring lbreak _parts idx/], |
13
|
102
|
|
|
102
|
|
369
|
); |
|
102
|
|
|
|
|
116
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub init { |
16
|
1788
|
|
|
1788
|
0
|
1160
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
croak "string is a required attribute" |
19
|
1788
|
50
|
|
|
|
2264
|
unless defined $self->{+STRING}; |
20
|
|
|
|
|
|
|
|
21
|
1788
|
50
|
|
|
|
3003
|
return unless $INC{'Unicode/GCString.pm'}; |
22
|
0
|
|
|
|
|
0
|
$self->{+GCSTRING} = Unicode::GCString->new($self->{+STRING}); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub columns { |
26
|
1601
|
|
|
1601
|
0
|
1107
|
my $self = shift; |
27
|
1601
|
50
|
|
|
|
1877
|
return $self->{+GCSTRING}->columns if $self->{+GCSTRING}; |
28
|
1601
|
|
|
|
|
5303
|
return length($self->{+STRING}); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub break { |
32
|
1346
|
|
|
1346
|
0
|
903
|
my $self = shift; |
33
|
1346
|
|
|
|
|
888
|
my ($len) = @_; |
34
|
|
|
|
|
|
|
|
35
|
1346
|
|
|
|
|
1041
|
$self->{+IDX} = 0; |
36
|
1346
|
|
|
|
|
1274
|
my $str = $self->{+STRING} . ""; # Force stringification |
37
|
|
|
|
|
|
|
|
38
|
1346
|
|
|
|
|
2219
|
binmode(STDOUT, ':utf8'); |
39
|
1346
|
|
|
|
|
819
|
my @parts; |
40
|
1346
|
|
|
|
|
2010
|
my @chars = split //, $str; |
41
|
1346
|
|
|
|
|
1798
|
while (@chars) { |
42
|
1307
|
|
|
|
|
891
|
my $size = 0; |
43
|
1307
|
|
|
|
|
898
|
my $part = ''; |
44
|
1307
|
|
|
|
|
1630
|
until ($size == $len) { |
45
|
7340
|
|
|
|
|
4860
|
my $char = shift @chars; |
46
|
7340
|
100
|
|
|
|
8203
|
$char = '' unless defined $char; |
47
|
7340
|
50
|
|
|
|
6793
|
my $l = $INC{'Unicode/GCString.pm'} ? Unicode::GCString->new("$char")->columns : length($char); |
48
|
7340
|
100
|
|
|
|
7802
|
last unless $l; |
49
|
6728
|
50
|
|
|
|
7325
|
if ($size + $l > $len) { |
50
|
0
|
|
|
|
|
0
|
unshift @chars => $char; |
51
|
0
|
|
|
|
|
0
|
last; |
52
|
|
|
|
|
|
|
} |
53
|
6728
|
|
|
|
|
3782
|
$size += $l; |
54
|
6728
|
|
|
|
|
8014
|
$part .= $char; |
55
|
|
|
|
|
|
|
} |
56
|
1307
|
|
|
|
|
1602
|
until ($size == $len) { |
57
|
4025
|
|
|
|
|
2325
|
$part .= ' '; |
58
|
4025
|
|
|
|
|
4415
|
$size += 1; |
59
|
|
|
|
|
|
|
} |
60
|
1307
|
|
|
|
|
2139
|
push @parts => $part; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
1346
|
|
|
|
|
2830
|
$self->{+_PARTS} = \@parts; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub next { |
67
|
2393
|
|
|
2393
|
0
|
1536
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
croak "String has not yet been broken" |
70
|
2393
|
50
|
|
|
|
2834
|
unless $self->{+_PARTS}; |
71
|
|
|
|
|
|
|
|
72
|
2393
|
|
|
|
|
1589
|
my $idx = $self->{+IDX}++; |
73
|
2393
|
|
|
|
|
1563
|
my $parts = $self->{+_PARTS}; |
74
|
|
|
|
|
|
|
|
75
|
2393
|
100
|
|
|
|
3513
|
return undef if $idx >= @$parts; |
76
|
1307
|
|
|
|
|
2254
|
return $parts->[$idx]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |