| 1 | package Term::Fabulous::Widget::Table::Mutator; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use v5.32; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | no warnings 'experimental::signatures'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our @EXPORT_OK = qw(datetime date number percent bytes duration boolean lookup truncate sprintf_format chain); | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | our %EXPORT_TAGS = ( all => \@EXPORT_OK ); | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Term::Fabulous::Widget::Table::Value qw(is_blank number_of date_epoch); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Term::Fabulous::Unicode qw(ELLIPSIS fit_columns string_columns); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 26 | ▶ | sub _options ( $function, $known, %options ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_options: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 26 | my @unknown = grep { !exists $known->{$_} } sort keys %options; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 26 | ▶ | croak "Term::Fabulous::Widget::Table::Mutator: $function does not accept @unknown (known: " . join( ', ', sort keys %$known ) . ")" if @unknown; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 25 | return { %$known, %options }; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 16 | ▶ | sub _non_negative_integer ( $function, $name, $value ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_non_negative_integer: called CC=5 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 16 | ▶ | croak "Term::Fabulous::Widget::Table::Mutator: $function $name must be a non-negative integer, got " . ( defined $value ? "'$value'" : 'undef' ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
defined $value and not ref $value and $value =~ /\A[0-9]+\z/u
defined $value and not ref $value
MC/DC0%0/3
defined $value and not ref $value and $value =~ /\A[0-9]+\z/u
defined $value
not ref $value
$value =~ /\A[0-9]+\z/u
Truth table25%1/4
A and not(B) and C
A= defined $valueB= not ref $valueC= $value =~ /\A[0-9]+\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | unless defined $value && !ref $value && $value =~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 16 | return $value + 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # A number with a fixed number of decimals and a separator between groups | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # of three digits. | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | ▶ | sub _format_number ( $number, $decimals, $separator, $point ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_number: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 5 | my $text = sprintf "%.${decimals}f", $number; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | my ( $sign, $whole, $fraction ) = $text =~ /\A(-?)([0-9]+)(?:\.([0-9]+))?\z/; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | ▶ | $sign = '' if $text =~ /\A-0(?:\.0*)?\z/; # no "-0.00" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | ▶ | 1 while length $separator && $whole =~ s/\A([0-9]+)([0-9]{3})/$1$separator$2/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $separator and $whole =~ s/\A([0-9]+)([0-9]{3})/$1$separator$2/u
MC/DC50%1/2
length $separator and $whole =~ s/\A([0-9]+)([0-9]{3})/$1$separator$2/u
length $separator
$whole =~ s/\A([0-9]+)([0-9]{3})/$1$separator$2/u
Truth table66%2/3
A and B
A= length $separatorB= $whole =~ s/\A([0-9]+)([0-9]{3})/$1$separator$2/u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | return $sign . $whole . ( defined $fraction ? $point . $fraction : '' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | sub datetime ( $format = '%Y-%m-%d %H:%M', %options ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
datetime: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | my $settings = _options( datetime => { utc => 0 }, %options ); | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | ▶ | croak "Term::Fabulous::Widget::Table::Mutator: datetime needs a strftime format string" if ref $format || !length $format; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $format or not length $format
MC/DC0%0/2
ref $format or not length $format
ref $format
not length $format
Truth table33%1/3
A or not(B)
A= ref $formatB= not length $format
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | ▶ | return sub ( $value, $row = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | ▶ | my $epoch = date_epoch($value) // return is_blank($value) ? '' : "$value"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
date_epoch($value) // (return is_blank($value) ? "" : "$value")
MC/DC100%1/1
date_epoch($value) // (return is_blank($value) ? "" : "$value")
date_epoch($value)
Truth table100%2/2
A
A= date_epoch($value)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | ▶ | return POSIX::strftime( $format, $settings->{utc} ? gmtime $epoch : localtime $epoch ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub date ( $format = '%Y-%m-%d', %options ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
date: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | return datetime( $format, %options ); | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | ▶ | sub number (%options) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
number: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | my $settings = _options( number => { decimals => undef, separator => ',', point => '.', prefix => '', suffix => '' }, %options ); | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | ▶ | $settings->{decimals} = _non_negative_integer( number => decimals => $settings->{decimals} ) if defined $settings->{decimals}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | ▶ | return sub ( $value, $row = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | ▶ | my $number = number_of($value) // return is_blank($value) ? '' : "$value"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
number_of($value) // (return is_blank($value) ? "" : "$value")
MC/DC100%1/1
number_of($value) // (return is_blank($value) ? "" : "$value")
number_of($value)
Truth table100%2/2
A
A= number_of($value)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | ▶ | my $decimals = $settings->{decimals} // ( "$number" =~ /\.([0-9]+)\z/ ? length $1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$settings->{"decimals"} // ("$number" =~ /\.([0-9]+)\z/u ? length $1 : 0)
MC/DC0%0/2
$settings->{"decimals"} // ("$number" =~ /\.([0-9]+)\z/u ? length $1 : 0)
$settings->{"decimals"}
("$number" =~ /\.([0-9]+)\z/u ? length $1 : 0)
Truth table66%2/3
A // B
A= $settings->{"decimals"}B= ("$number" =~ /\.([0-9]+)\z/u ? length $1 : 0)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | return $settings->{prefix} . _format_number( $number, $decimals, $settings->{separator}, $settings->{point} ) . $settings->{suffix}; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | sub percent (%options) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
percent: called CC=2 SCAR=7.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | my $settings = _options( percent => { decimals => 0, scale => 100, separator => ',', point => '.' }, %options ); | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | $settings->{decimals} = _non_negative_integer( percent => decimals => $settings->{decimals} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | croak "Term::Fabulous::Widget::Table::Mutator: percent scale must be a number" unless defined number_of( $settings->{scale} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | return sub ( $value, $row = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=16.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | my $number = number_of($value) // return is_blank($value) ? '' : "$value"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
number_of($value) // (return is_blank($value) ? "" : "$value")
MC/DC0%0/1
number_of($value) // (return is_blank($value) ? "" : "$value")
number_of($value)
Truth table50%1/2
A
A= number_of($value)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | return _format_number( $number * $settings->{scale}, $settings->{decimals}, $settings->{separator}, $settings->{point} ) . '%'; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | ▶ | sub bytes (%options) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bytes: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | my $settings = _options( bytes => { decimals => 1, binary => 1 }, %options ); | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | $settings->{decimals} = _non_negative_integer( bytes => decimals => $settings->{decimals} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | ▶ | my ( $step, @units ) = $settings->{binary} ? ( 1024, qw(B KiB MiB GiB TiB PiB EiB) ) : ( 1000, qw(B kB MB GB TB PB EB) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | ▶ | return sub ( $value, $row = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 4 | ▶ | my $number = number_of($value) // return is_blank($value) ? '' : "$value"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
number_of($value) // (return is_blank($value) ? "" : "$value")
MC/DC100%1/1
number_of($value) // (return is_blank($value) ? "" : "$value")
number_of($value)
Truth table100%2/2
A
A= number_of($value)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | my ( $size, $unit ) = ( abs $number, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | while ( $size >= $step && $unit < $#units ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$size >= $step and $unit < $#units
MC/DC50%1/2
$size >= $step and $unit < $#units
$size >= $step
$unit < $#units
Truth table66%2/3
A and B
A= $size >= $stepB= $unit < $#units
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | $size /= $step; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | $unit++; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | my $sign = $number < 0 ? '-' : ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | ▶ | return $unit == 0 ? "$sign$size $units[0]" : sprintf( "%s%.$settings->{decimals}f %s", $sign, $size, $units[$unit] ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | sub duration (%options) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
duration: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | my $settings = _options( duration => { parts => 2 }, %options ); | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | my $parts = _non_negative_integer( duration => parts => $settings->{parts} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | ▶ | croak "Term::Fabulous::Widget::Table::Mutator: duration parts must be at least 1" unless $parts >= 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | my @units = ( [ d => 86400 ], [ h => 3600 ], [ m => 60 ], [ s => 1 ] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 3 | ▶ | return sub ( $value, $row = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 3 | ▶ | my $number = number_of($value) // return is_blank($value) ? '' : "$value"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
number_of($value) // (return is_blank($value) ? "" : "$value")
MC/DC100%1/1
number_of($value) // (return is_blank($value) ? "" : "$value")
number_of($value)
Truth table100%2/2
A
A= number_of($value)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | my $left = int abs $number; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | my @shown; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | foreach my $unit (@units) { | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | my ( $name, $seconds ) = @$unit; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | my $count = int( $left / $seconds ); | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | $left -= $count * $seconds; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | ▶ | push @shown, ( @shown ? sprintf( '%02d', $count ) : $count ) . $name if $count || @shown; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$count or @shown
MC/DC50%1/2
$count or @shown
$count
@shown
Truth table66%2/3
A or B
A= $countB= @shown
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | ▶ | last if @shown == $parts; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | @shown = ('0s') unless @shown; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | ▶ | return ( $number < 0 ? '-' : '' ) . join ' ', @shown; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | ▶ | sub boolean ( $true_text = 'yes', $false_text = 'no' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
boolean: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | ▶ | croak "Term::Fabulous::Widget::Table::Mutator: boolean takes two strings" if ref $true_text || ref $false_text; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $true_text or ref $false_text
MC/DC0%0/2
ref $true_text or ref $false_text
ref $true_text
ref $false_text
Truth table33%1/3
A or B
A= ref $true_textB= ref $false_text
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | return sub ( $value, $row = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | ▶ | return '' unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | ▶ | return $value ? $true_text : $false_text; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | ▶ | sub lookup ( $table, %options ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lookup: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | ▶ | croak "Term::Fabulous::Widget::Table::Mutator: lookup needs a hash reference" unless ref $table eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | my $settings = _options( lookup => { default => undef }, %options ); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | my %text_of = %$table; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | ▶ | return sub ( $value, $row = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | ▶ | return '' unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | ▶ | return $text_of{$value} if exists $text_of{$value}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | ▶ | return $settings->{default} // "$value"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$settings->{"default"} // "$value"
MC/DC100%1/1
$settings->{"default"} // "$value"
$settings->{"default"}
Truth table100%2/2
A
A= $settings->{"default"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 5 | ▶ | sub truncate ( $columns, %options ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
truncate: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 5 | $columns = _non_negative_integer( truncate => columns => $columns ); | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | my $settings = _options( truncate => { ellipsis => ELLIPSIS }, %options ); | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 5 | my $ellipsis = $settings->{ellipsis}; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 5 | ▶ | croak "Term::Fabulous::Widget::Table::Mutator: truncate needs more columns than the ellipsis takes" if string_columns($ellipsis) > $columns; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 4 | ▶ | return sub ( $value, $row = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 4 | ▶ | return '' unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | return fit_columns( "$value", $columns, mark => $ellipsis ); | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | ▶ | sub sprintf_format ($format) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sprintf_format: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | ▶ | croak "Term::Fabulous::Widget::Table::Mutator: sprintf_format needs a format string" if ref $format || !defined $format; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $format or not defined $format
MC/DC0%0/2
ref $format or not defined $format
ref $format
not defined $format
Truth table33%1/3
A or not(B)
A= ref $formatB= not defined $format
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | ▶ | return sub ( $value, $row = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | return is_blank($value) ? '' : sprintf( $format, $value ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | ▶ | sub chain (@mutators) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
chain: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | foreach my $mutator (@mutators) { | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | ▶ | croak "Term::Fabulous::Widget::Table::Mutator: chain takes code references" unless ref $mutator eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | ▶ | return sub ( $value, $row = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | $value = $_->( $value, $row ) foreach @mutators; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||