| 1 | package Term::Table::LineBreak; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | our $VERSION = '0.016'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Term::Table::Util qw/uni_length/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Term::Table::HashBase qw/string gcstring _len _parts idx/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | sub init { | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 140 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | croak "string is a required attribute" | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 140 | ▶ | unless defined $self->{+STRING}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub columns { uni_length($_[0]->{+STRING}) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
columns: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | sub break { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 140 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
break: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 140 | my ($len) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 140 | $self->{+_LEN} = $len; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 140 | $self->{+IDX} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 140 | my $str = $self->{+STRING} . ""; # Force stringification | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 140 | my @parts; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 140 | my @chars = split //, $str; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 140 | ▶ | while (@chars) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 264 | my $size = 0; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 264 | my $part = ''; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 264 | ▶ | until ($size == $len) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1826 | my $char = shift @chars; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 1826 | ▶ | $char = '' unless defined $char; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 1826 | my $l = uni_length("$char"); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1826 | ▶ | last unless $l; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1757 | ▶ | last if $char eq "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1757 | ▶ | if ($size + $l > $len) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | unshift @chars => $char; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | last; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1756 | $size += $l; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 1756 | $part .= $char; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # If we stopped just before a newline, grab it | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 264 | ▶ | shift @chars if $size == $len && @chars && $chars[0] eq "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$size == $len and @chars and $chars[0] eq "\n"
$size == $len and @chars
MC/DC100%3/3
$size == $len and @chars and $chars[0] eq "\n"
$size == $len
@chars
$chars[0] eq "\n"
Truth table100%4/4
A and B and C
A= $size == $lenB= @charsC= $chars[0] eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 264 | ▶ | until ($size == $len) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 429 | $part .= ' '; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 429 | $size += 1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 264 | push @parts => $part; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 140 | $self->{+_PARTS} = \@parts; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | sub next { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 495 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 495 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 476 | my ($len) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 476 | ▶ | $self->break($len) if !$self->{+_LEN} || $self->{+_LEN} != $len; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $self->{"_len"} or $self->{"_len"} != $len
MC/DC50%1/2
not $self->{"_len"} or $self->{"_len"} != $len
not $self->{"_len"}
$self->{"_len"} != $len
Truth table66%2/3
not(A) or B
A= not $self->{"_len"}B= $self->{"_len"} != $len
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 75 | croak "String has not yet been broken" | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 19 | ▶ | unless $self->{+_PARTS}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 495 | my $idx = $self->{+IDX}++; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 495 | my $parts = $self->{+_PARTS}; | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 495 | ▶ | return undef if $idx >= @$parts; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 264 | return $parts->[$idx]; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||||||||||||||||