« blib/lib/Term/Fabulous/Chart/Scale/Time.pm
↑ Summary
blib/lib/Term/Fabulous/Widget/Table/Frame.pm »
| 1 | package Term::Fabulous::Chart::Format; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use v5.32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | no warnings 'experimental::signatures'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our @EXPORT_OK = qw(number_formatter time_formatter format_value format_values decimals_of check_number_format check_time_format); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use POSIX qw(floor strftime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | my @SI_PREFIXES = ( [ 1e12, 'T' ], [ 1e9, 'G' ], [ 1e6, 'M' ], [ 1e3, 'k' ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | my %NUMBER_FORMATS = map { $_ => 1 } qw(auto si integer percent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # The decimals a number needs to be written to six significant digits, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # up to 10. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 166 | ▶ | sub decimals_of ($number) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decimals_of: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 166 | foreach my $decimals ( 0 .. 10 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 239 | my $scaled = abs($number) * 10**$decimals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 239 | ▶ | return $decimals if abs( $scaled - int( $scaled + 0.5 ) ) < 1e-6 * ( $scaled || 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$scaled || 1
MC/DC100%1/1
$scaled || 1
$scaled
Truth table100%2/2
A
A= $scaled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | return 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 663 | ▶ | sub _fixed ( $value, $decimals ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fixed: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 663 | my $text = sprintf '%.*f', $decimals, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 663 | $text =~ s/\A-(?=0(?:\.0*)?\z)//; # no "-0" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 663 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # 12000 as "12k": the largest prefix the value reaches. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 52 | ▶ | sub _si ( $value, $decimals_of_unit ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_si: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 52 | my $magnitude = abs $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 52 | foreach my $prefix (@SI_PREFIXES) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 199 | my ( $unit, $symbol ) = @$prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 199 | ▶ | next if $magnitude < $unit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 44 | return _fixed( $value / $unit, $decimals_of_unit->($unit) ) . $symbol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | return _fixed( $value, $decimals_of_unit->(1) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 8 | ▶ | sub check_number_format ( $owner, $name, $format ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_number_format: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | ▶ | return $format if !defined $format || ref $format eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $format or ref $format eq "CODE"
MC/DC50%1/2
not defined $format or ref $format eq "CODE"
not defined $format
ref $format eq "CODE"
Truth table66%2/3
not(A) or B
A= not defined $formatB= ref $format eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | croak "$owner: $name must be auto, si, integer, percent, a sprintf format with one % conversion or a code reference, got " . ( ref $format ? ref($format) . ' reference' : "'$format'" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 7 | ▶ | if ref $format || !( $NUMBER_FORMATS{$format} || $format =~ /%/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
ref $format or not $NUMBER_FORMATS{$format} || $format =~ /%/u
$NUMBER_FORMATS{$format} || $format =~ /%/u
MC/DC100%3/3
ref $format or not $NUMBER_FORMATS{$format} || $format =~ /%/u
ref $format
$NUMBER_FORMATS{$format}
$format =~ /%/u
Truth table100%4/4
A or not(B || C)
A= ref $formatB= $NUMBER_FORMATS{$format}C= $format =~ /%/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 5 | return $format; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # A function that writes the tick labels of a numeric axis whose ticks are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # $step apart and reach $largest (in magnitude): the format of the axis | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # (auto, si, integer, percent, a sprintf format or a code reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # called with the value). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 112 | ▶ | sub number_formatter ( $format, $step, $largest ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
number_formatter: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 112 | ▶ | $format //= 'auto'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$format //= "auto"
MC/DC100%1/1
$format //= "auto"
$format
Truth table100%2/2
A
A= $format
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 112 | ▶ | return $format if ref $format eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | ▶ | return sub ($value) { sprintf $format, $value } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 111 | ▶ | if $format =~ /%/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 106 | ▶ | my $step_decimals = decimals_of( $step || 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$step || 1
MC/DC0%0/1
$step || 1
$step
Truth table50%1/2
A
A= $step
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | return sub ($value) { _fixed( $value, 0 ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 106 | ▶ | if $format eq 'integer'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 20 | ▶ | return sub ($value) { _fixed( $value * 100, decimals_of( ( $step || 1 ) * 100 ) ) . '%' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$step || 1
MC/DC0%0/1
$step || 1
$step
Truth table50%1/2
A
A= $step
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 105 | ▶ | if $format eq 'percent'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 99 | ▶ | my $decimals_of_unit = sub ($unit) { decimals_of( ( $step || 1 ) / $unit ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Condition50%1/2
$step || 1
MC/DC0%0/1
$step || 1
$step
Truth table50%1/2
A
A= $step
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 31 | ▶ | return sub ($value) { _si( $value, $decimals_of_unit ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 99 | ▶ | if $format eq 'si' || abs($largest) >= 1e4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$format eq "si" or abs $largest >= 10000
MC/DC100%2/2
$format eq "si" or abs $largest >= 10000
$format eq "si"
abs $largest >= 10000
Truth table100%3/3
A or B
A= $format eq "si"B= abs $largest >= 10000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 89 | ▶ | return sub ($value) { _fixed( $value, $step_decimals ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # A value shown on its own (a bar's label, a legend entry): as many | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # decimals as it has, at most two (three significant digits below 1), and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # large values with an SI prefix. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 55 | ▶ | sub format_value ( $value, $format = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_value: called CC=19 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 55 | ▶ | return '' unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 54 | ▶ | return $format->($value) if ref $format eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 53 | ▶ | return sprintf $format, $value if defined $format && $format =~ /%/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $format and $format =~ /%/u
MC/DC100%2/2
defined $format and $format =~ /%/u
defined $format
$format =~ /%/u
Truth table100%3/3
A and B
A= defined $formatB= $format =~ /%/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 52 | ▶ | return _fixed( $value * 100, abs( $value * 100 ) < 10 ? 1 : 0 ) . '%' if defined $format && $format eq 'percent'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $format and $format eq "percent"
MC/DC100%2/2
defined $format and $format eq "percent"
defined $format
$format eq "percent"
Truth table100%3/3
A and B
A= defined $formatB= $format eq "percent"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 50 | ▶ | return _fixed( $value, 0 ) if defined $format && $format eq 'integer'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $format and $format eq "integer"
MC/DC100%2/2
defined $format and $format eq "integer"
defined $format
$format eq "integer"
Truth table100%3/3
A and B
A= defined $formatB= $format eq "integer"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 49 | my $magnitude = abs $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 49 | ▶ | if ( $magnitude >= 1e6 || ( defined $format && $format eq 'si' && $magnitude >= 1e3 ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$magnitude >= 1000000 or defined $format and $format eq "si" and $magnitude >= 1000
defined $format and $format eq "si" and $magnitude >= 1000
defined $format and $format eq "si"
MC/DC75%3/4
$magnitude >= 1000000 or defined $format and $format eq "si" and $magnitude >= 1000
$magnitude >= 1000000
defined $format
$format eq "si"
$magnitude >= 1000
Truth table80%4/5
A or B and C and D
A= $magnitude >= 1000000B= defined $formatC= $format eq "si"D= $magnitude >= 1000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 21 | ▶ | my $text = _si( $value, sub ($unit) { $magnitude / $unit >= 100 ? 0 : 1 } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 21 | $text =~ s/\.0(?=[kMGT]\z)//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 21 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 28 | ▶ | my $decimals = $magnitude >= 100 ? 1 : $magnitude >= 1 ? 2 : $magnitude == 0 ? 0 : 2 - floor( log($magnitude) / log(10) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 28 | ▶ | $decimals = 6 if $decimals > 6; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 28 | my $text = _fixed( $value, $decimals ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 28 | $text =~ s/(\.\d*?)0+\z/$1/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 28 | $text =~ s/\.\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 28 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Values shown together (the labels of bars): as format_value writes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # them, but all with the decimals the one with most decimals has. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub format_values ( $values, $format = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_values: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my @texts = map { format_value( $_, $format ) } @$values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return @texts if defined $format || grep { /[^0-9.\-]/ } @texts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $format or grep {/[^0-9.\-]/u;} @texts
MC/DC0%0/2
defined $format or grep {/[^0-9.\-]/u;} @texts
defined $format
grep {/[^0-9.\-]/u;} @texts
Truth table0%0/3
A or B
A= defined $formatB= grep {/[^0-9.\-]/u;} @texts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my $decimals = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | foreach my $text (@texts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | $decimals = length $1 if $text =~ /\.([0-9]+)\z/ && length $1 > $decimals; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$text =~ /\.([0-9]+)\z/u and length $1 > $decimals
MC/DC0%0/2
$text =~ /\.([0-9]+)\z/u and length $1 > $decimals
$text =~ /\.([0-9]+)\z/u
length $1 > $decimals
Truth table0%0/3
A and B
A= $text =~ /\.([0-9]+)\z/uB= length $1 > $decimals
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return map { _fixed( $_, $decimals ) } @$values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | ▶ | sub check_time_format ( $owner, $name, $format ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_time_format: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | ▶ | return $format if !defined $format || ref $format eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $format or ref $format eq "CODE"
MC/DC0%0/2
not defined $format or ref $format eq "CODE"
not defined $format
ref $format eq "CODE"
Truth table33%1/3
not(A) or B
A= not defined $formatB= ref $format eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | ▶ | croak "$owner: $name must be a strftime format or a code reference, got " . ( ref $format ? ref($format) . ' reference' : "'$format'" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
ref $format or not $format =~ /%/u
MC/DC100%2/2
ref $format or not $format =~ /%/u
ref $format
not $format =~ /%/u
Truth table100%3/3
A or not(B)
A= ref $formatB= not $format =~ /%/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | if ref $format || $format !~ /%/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | return $format; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # A function that writes epoch seconds with a strftime format (or calls a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # code reference with the epoch); local time unless $utc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 11 | ▶ | sub time_formatter ( $format, $utc ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
time_formatter: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 11 | ▶ | return $format if ref $format eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 10 | ▶ | return sub ($epoch) { strftime( $format, $utc ? gmtime $epoch : localtime $epoch ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||