| 1 | package Getopt::Yath::Term; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '2.000007'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | our @EXPORT = qw/color USE_COLOR term_size fit_to_width/; | |||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Importer Importer => 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Term::Table::Util qw/term_size/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | BEGIN { | ||||||||||||||||||||||||||||
| 13 | 1 | ▶ | if (eval { require Term::ANSIColor; 1 }) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=8.1
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 1 | *USE_COLOR = sub() { 1 }; | |||||||||||||||||||||||||||
| 15 | 1 | *color = \&Term::ANSIColor::color; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | else { | ||||||||||||||||||||||||||||
| 18 | 0 | *USE_COLOR = sub() { 0 }; | |||||||||||||||||||||||||||
| 19 | 0 | ▶ | *color = sub { '' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub fit_to_width { | ||||||||||||||||||||||||||||
| 24 | 31 | ▶ | my ($join, $text, %params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
fit_to_width: called CC=12 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 31 | my $prefix = $params{prefix}; | |||||||||||||||||||||||||||
| 27 | 31 | my $width = $params{width}; | |||||||||||||||||||||||||||
| 28 | 31 | ▶ | unless (defined $width) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 31 | $width = term_size() - 20; | |||||||||||||||||||||||||||
| 30 | 31 | ▶ | $width = 80 unless $width && $width >= 80; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$width and $width >= 80
MC/DC0%0/2
$width and $width >= 80
$width
$width >= 80
Truth table33%1/3
A and B
A= $widthB= $width >= 80
| |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 31 | ▶ | my @parts = ref($text) ? @$text : split /\s+/, $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 31 | my @out; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 31 | my $line = ""; | |||||||||||||||||||||||||||
| 38 | 31 | for my $part (@parts) { | |||||||||||||||||||||||||||
| 39 | 161 | ▶ | my $new = $line ? "$line$join$part" : $part; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 161 | ▶ | if ($line && length($new) > $width) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$line and length $new > $width
MC/DC0%0/2
$line and length $new > $width
$line
length $new > $width
Truth table66%2/3
A and B
A= $lineB= length $new > $width
| |||||||||||||||||||||||||||||
| 42 | 0 | push @out => $line; | |||||||||||||||||||||||||||
| 43 | 0 | $line = $part; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | else { | ||||||||||||||||||||||||||||
| 46 | 161 | $line = $new; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 31 | ▶ | push @out => $line if $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 31 | ▶ | if(defined $prefix) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 31 | $_ =~ s/^/ /gm for @out; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 31 | return join "\n" => @out; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | 1; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||