line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Stream::Table::LineBreak; |
2
|
102
|
|
|
102
|
|
1174
|
use strict; |
|
102
|
|
|
|
|
198
|
|
|
102
|
|
|
|
|
3707
|
|
3
|
102
|
|
|
102
|
|
501
|
use warnings; |
|
102
|
|
|
|
|
195
|
|
|
102
|
|
|
|
|
2799
|
|
4
|
|
|
|
|
|
|
|
5
|
102
|
|
|
102
|
|
500
|
use Carp qw/croak/; |
|
102
|
|
|
|
|
192
|
|
|
102
|
|
|
|
|
5215
|
|
6
|
102
|
|
|
102
|
|
569
|
use Scalar::Util qw/blessed/; |
|
102
|
|
|
|
|
194
|
|
|
102
|
|
|
|
|
8853
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Optional. |
9
|
|
|
|
|
|
|
eval { require Unicode::GCString; 1 }; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Test::Stream::HashBase( |
12
|
102
|
|
|
|
|
1081
|
accessors => [qw/string gcstring lbreak _parts idx/], |
13
|
102
|
|
|
102
|
|
541
|
); |
|
102
|
|
|
|
|
202
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub init { |
16
|
1776
|
|
|
1776
|
0
|
2341
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
croak "string is a required attribute" |
19
|
1776
|
50
|
|
|
|
3757
|
unless defined $self->{+STRING}; |
20
|
|
|
|
|
|
|
|
21
|
1776
|
50
|
|
|
|
5077
|
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
|
1869
|
my $self = shift; |
27
|
1592
|
50
|
|
|
|
3095
|
return $self->{+GCSTRING}->columns if $self->{+GCSTRING}; |
28
|
1592
|
|
|
|
|
9019
|
return length($self->{+STRING}); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub break { |
32
|
1340
|
|
|
1340
|
0
|
1714
|
my $self = shift; |
33
|
1340
|
|
|
|
|
1726
|
my ($len) = @_; |
34
|
|
|
|
|
|
|
|
35
|
1340
|
|
|
|
|
2066
|
$self->{+IDX} = 0; |
36
|
1340
|
|
|
|
|
2191
|
my $str = $self->{+STRING} . ""; # Force stringification |
37
|
|
|
|
|
|
|
|
38
|
1340
|
|
|
|
|
3730
|
binmode(STDOUT, ':utf8'); |
39
|
1340
|
|
|
|
|
1420
|
my @parts; |
40
|
1340
|
|
|
|
|
3431
|
my @chars = split //, $str; |
41
|
1340
|
|
|
|
|
3044
|
while (@chars) { |
42
|
1299
|
|
|
|
|
1539
|
my $size = 0; |
43
|
1299
|
|
|
|
|
1662
|
my $part = ''; |
44
|
1299
|
|
|
|
|
2482
|
until ($size == $len) { |
45
|
7300
|
|
|
|
|
9512
|
my $char = shift @chars; |
46
|
7300
|
100
|
|
|
|
14569
|
$char = '' unless defined $char; |
47
|
7300
|
50
|
|
|
|
12365
|
my $l = $INC{'Unicode/GCString.pm'} ? Unicode::GCString->new("$char")->columns : length($char); |
48
|
7300
|
100
|
|
|
|
12606
|
last unless $l; |
49
|
6692
|
50
|
|
|
|
12184
|
if ($size + $l > $len) { |
50
|
0
|
|
|
|
|
0
|
unshift @chars => $char; |
51
|
0
|
|
|
|
|
0
|
last; |
52
|
|
|
|
|
|
|
} |
53
|
6692
|
|
|
|
|
6684
|
$size += $l; |
54
|
6692
|
|
|
|
|
13761
|
$part .= $char; |
55
|
|
|
|
|
|
|
} |
56
|
1299
|
|
|
|
|
2683
|
until ($size == $len) { |
57
|
3989
|
|
|
|
|
4621
|
$part .= ' '; |
58
|
3989
|
|
|
|
|
7422
|
$size += 1; |
59
|
|
|
|
|
|
|
} |
60
|
1299
|
|
|
|
|
3813
|
push @parts => $part; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
1340
|
|
|
|
|
4686
|
$self->{+_PARTS} = \@parts; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub next { |
67
|
2374
|
|
|
2374
|
0
|
2821
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
croak "String has not yet been broken" |
70
|
2374
|
50
|
|
|
|
4802
|
unless $self->{+_PARTS}; |
71
|
|
|
|
|
|
|
|
72
|
2374
|
|
|
|
|
3174
|
my $idx = $self->{+IDX}++; |
73
|
2374
|
|
|
|
|
3007
|
my $parts = $self->{+_PARTS}; |
74
|
|
|
|
|
|
|
|
75
|
2374
|
100
|
|
|
|
5851
|
return undef if $idx >= @$parts; |
76
|
1299
|
|
|
|
|
3689
|
return $parts->[$idx]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |