line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Stream::Table::LineBreak; |
2
|
102
|
|
|
102
|
|
1028
|
use strict; |
|
102
|
|
|
|
|
216
|
|
|
102
|
|
|
|
|
3629
|
|
3
|
102
|
|
|
102
|
|
508
|
use warnings; |
|
102
|
|
|
|
|
191
|
|
|
102
|
|
|
|
|
2661
|
|
4
|
|
|
|
|
|
|
|
5
|
102
|
|
|
102
|
|
544
|
use Carp qw/croak/; |
|
102
|
|
|
|
|
192
|
|
|
102
|
|
|
|
|
5196
|
|
6
|
102
|
|
|
102
|
|
541
|
use Scalar::Util qw/blessed/; |
|
102
|
|
|
|
|
203
|
|
|
102
|
|
|
|
|
9169
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Optional. |
9
|
|
|
|
|
|
|
eval { require Unicode::GCString; 1 }; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Test::Stream::HashBase( |
12
|
102
|
|
|
|
|
1040
|
accessors => [qw/string gcstring lbreak _parts idx/], |
13
|
102
|
|
|
102
|
|
602
|
); |
|
102
|
|
|
|
|
205
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub init { |
16
|
1776
|
|
|
1776
|
0
|
2337
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
croak "string is a required attribute" |
19
|
1776
|
50
|
|
|
|
3921
|
unless defined $self->{+STRING}; |
20
|
|
|
|
|
|
|
|
21
|
1776
|
50
|
|
|
|
5538
|
return unless $INC{'Unicode/GCString.pm'}; |
22
|
0
|
|
|
|
|
0
|
$self->{+GCSTRING} = Unicode::GCString->new($self->{+STRING}); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub columns { |
26
|
1592
|
|
|
1592
|
0
|
2004
|
my $self = shift; |
27
|
1592
|
50
|
|
|
|
3280
|
return $self->{+GCSTRING}->columns if $self->{+GCSTRING}; |
28
|
1592
|
|
|
|
|
9487
|
return length($self->{+STRING}); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub break { |
32
|
1340
|
|
|
1340
|
0
|
1805
|
my $self = shift; |
33
|
1340
|
|
|
|
|
1782
|
my ($len) = @_; |
34
|
|
|
|
|
|
|
|
35
|
1340
|
|
|
|
|
2070
|
$self->{+IDX} = 0; |
36
|
1340
|
|
|
|
|
2243
|
my $str = $self->{+STRING} . ""; # Force stringification |
37
|
|
|
|
|
|
|
|
38
|
1340
|
|
|
|
|
3990
|
binmode(STDOUT, ':utf8'); |
39
|
1340
|
|
|
|
|
1599
|
my @parts; |
40
|
1340
|
|
|
|
|
3430
|
my @chars = split //, $str; |
41
|
1340
|
|
|
|
|
3078
|
while (@chars) { |
42
|
1299
|
|
|
|
|
1707
|
my $size = 0; |
43
|
1299
|
|
|
|
|
1644
|
my $part = ''; |
44
|
1299
|
|
|
|
|
2641
|
until ($size == $len) { |
45
|
7300
|
|
|
|
|
9552
|
my $char = shift @chars; |
46
|
7300
|
100
|
|
|
|
13590
|
$char = '' unless defined $char; |
47
|
7300
|
50
|
|
|
|
12763
|
my $l = $INC{'Unicode/GCString.pm'} ? Unicode::GCString->new("$char")->columns : length($char); |
48
|
7300
|
100
|
|
|
|
13071
|
last unless $l; |
49
|
6692
|
50
|
|
|
|
14116
|
if ($size + $l > $len) { |
50
|
0
|
|
|
|
|
0
|
unshift @chars => $char; |
51
|
0
|
|
|
|
|
0
|
last; |
52
|
|
|
|
|
|
|
} |
53
|
6692
|
|
|
|
|
7320
|
$size += $l; |
54
|
6692
|
|
|
|
|
14820
|
$part .= $char; |
55
|
|
|
|
|
|
|
} |
56
|
1299
|
|
|
|
|
2667
|
until ($size == $len) { |
57
|
3989
|
|
|
|
|
4440
|
$part .= ' '; |
58
|
3989
|
|
|
|
|
7692
|
$size += 1; |
59
|
|
|
|
|
|
|
} |
60
|
1299
|
|
|
|
|
3873
|
push @parts => $part; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
1340
|
|
|
|
|
4939
|
$self->{+_PARTS} = \@parts; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub next { |
67
|
2374
|
|
|
2374
|
0
|
2860
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
croak "String has not yet been broken" |
70
|
2374
|
50
|
|
|
|
5076
|
unless $self->{+_PARTS}; |
71
|
|
|
|
|
|
|
|
72
|
2374
|
|
|
|
|
3242
|
my $idx = $self->{+IDX}++; |
73
|
2374
|
|
|
|
|
3237
|
my $parts = $self->{+_PARTS}; |
74
|
|
|
|
|
|
|
|
75
|
2374
|
100
|
|
|
|
6120
|
return undef if $idx >= @$parts; |
76
|
1299
|
|
|
|
|
3893
|
return $parts->[$idx]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |