| 1 | package Skilletor::TOML; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: The reference's TOML writer – what a Codex agent role needs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 401 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 401 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 401 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 401 | ▶ | use JSON::MaybeXS (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 401 | ▶ | use Scalar::Util qw( blessed reftype ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 401 | ▶ | use Skilletor::Error::TOML; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 401 | ▶ | use Skilletor::JSON qw( js_number js_sort_keys js_stringify js_type ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 401 | ▶ | use Skilletor::JSON::OrderedHash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 401 | our $VERSION = '0.008000'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 401 | our @EXPORT_OK = qw( stringify_toml toml_key toml_float is_toml_float ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 401 | my $BARE_KEY = qr/\A[A-Za-z0-9_-]+\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3310 | ▶ | sub toml_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toml_key: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 3310 | my ( $key ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3310 | ▶ | return $key =~ $BARE_KEY ? $key : _basic_string($key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 59 | ▶ | sub toml_float { Skilletor::TOML::Float->new( $_[0] ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toml_float: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 3315 | ▶ | sub is_toml_float { blessed $_[0] && $_[0]->isa('Skilletor::TOML::Float') ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_toml_float: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
Condition100%3/3
builtin::blessed($_[0]) and $_[0]->isa("Skilletor::TOML::Float")
MC/DC100%2/2
builtin::blessed($_[0]) and $_[0]->isa("Skilletor::TOML::Float")
builtin::blessed($_[0])
$_[0]->isa("Skilletor::TOML::Float")
Truth table100%3/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("Skilletor::TOML::Float")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | #### Strings ########################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 401 | my %ESCAPE = ( '\\' => '\\\\', '"' => '\\"', "\n" => '\\n', "\t" => '\\t', "\r" => '\\r' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # What a basic string escapes: `\`, `"` and every control character. The multi-line form | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # keeps LF and tab literal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 401 | my $BASIC_ESCAPED = qr/[\\"\x00-\x1F\x7F]/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 401 | my $MULTILINE_ESCAPED = qr/[\\"\x00-\x08\x0B-\x1F\x7F]/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2592 | ▶ | sub _escape_basic { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_escape_basic: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2592 | my ( $s, $keep_newlines ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 2592 | ▶ | my $re = $keep_newlines ? $MULTILINE_ESCAPED : $BASIC_ESCAPED; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2592 | ▶ | $s =~ s/($re)/ $ESCAPE{$1} \/\/ sprintf( '\\u%04X', ord $1 ) /ge; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ESCAPE{$1} // sprintf("\\u%04X", ord $1)
MC/DC100%1/1
$ESCAPE{$1} // sprintf("\\u%04X", ord $1)
$ESCAPE{$1}
Truth table100%2/2
A
A= $ESCAPE{$1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2592 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1772 | ▶ | sub _basic_string { '"'._escape_basic( $_[0], 0 ).'"' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_basic_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Control characters a literal string cannot hold (tab and LF are fine; CR is refused too, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # CRLF survives exactly). A trailing `'` goes to the basic form, as in the reference. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 401 | my $LITERAL_UNSAFE = qr/[\x00-\x08\x0A-\x1F\x7F]/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1425 | ▶ | sub _multiline_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_multiline_string: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1425 | my ( $s ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1425 | ( my $without_lf = $s ) =~ s/\n//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1425 | ▶ | return "'''\n$s'''" if index( $s, "'''" ) < 0 && $s !~ /'\z/ && $without_lf !~ $LITERAL_UNSAFE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
index($s, "'''") == -1 and not $s =~ /'\z/ and not $without_lf =~ /$LITERAL_UNSAFE/
index($s, "'''") == -1 and not $s =~ /'\z/
MC/DC100%3/3
index($s, "'''") == -1 and not $s =~ /'\z/ and not $without_lf =~ /$LITERAL_UNSAFE/
index($s, "'''") == -1
not $s =~ /'\z/
not $without_lf =~ /$LITERAL_UNSAFE/
Truth table100%4/4
A and not(B) and not(C)
A= index($s, "'''") == -1B= not $s =~ /'\z/C= not $without_lf =~ /$LITERAL_UNSAFE/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 820 | return qq("""\n)._escape_basic( $s, 1 ).'"""'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | #### Values ############################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 30 | ▶ | sub _fail { Skilletor::Error::TOML->throw( $_[0] ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fail: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 401 | my $INF = 9**9**9; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # String(n) for any number, NaN and the infinities included. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 18 | ▶ | sub _number_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_number_text: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 18 | my ( $n ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 18 | ▶ | return 'NaN' if $n != $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 15 | ▶ | return $n > 0 ? 'Infinity' : '-Infinity' if $n == $INF || $n == -$INF; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$n == $INF or $n == -$INF
MC/DC100%2/2
$n == $INF or $n == -$INF
$n == $INF
$n == -$INF
Truth table100%3/3
A or B
A= $n == $INFB= $n == -$INF
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 8 | return js_number($n); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 100 | ▶ | sub _is_finite { $_[0] == $_[0] && $_[0] != $INF && $_[0] != -$INF } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_finite: called CC=3 SCAR=11.0
Branch: 1 branch
Condition100%3/3
$_[0] == $_[0] and $_[0] != $INF
MC/DC100%2/2
$_[0] == $_[0] and $_[0] != $INF
$_[0] == $_[0]
$_[0] != $INF
Truth table100%3/3
A and B
A= $_[0] == $_[0]B= $_[0] != $INF
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 46 | ▶ | sub _is_safe_integer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_safe_integer: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 46 | my ( $n ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 46 | ▶ | return _is_finite($n) && $n == int($n) && abs($n) <= 9007199254740991; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
_is_finite($n) && $n == int $n && abs $n <= 9007199254740991
_is_finite($n) and $n == int $n
MC/DC100%3/3
_is_finite($n) && $n == int $n && abs $n <= 9007199254740991
_is_finite($n)
$n == int $n
abs $n <= 9007199254740991
Truth table100%4/4
A and B && C
A= _is_finite($n)B= $n == int $nC= abs $n <= 9007199254740991
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3286 | ▶ | sub _is_table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_table: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 3286 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3286 | ▶ | return ref $v && ( reftype $v // '' ) eq 'HASH' && !is_toml_float($v) && !JSON::MaybeXS::is_bool($v); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition81%9/11
ref $v && (builtin::reftype($v) // '') eq 'HASH' && !is_toml_float($v) && !JSON::MaybeXS::is_bool($v)
ref $v and (builtin::reftype($v) // "") eq "HASH" and not is_toml_float($v)
ref $v and (builtin::reftype($v) // "") eq "HASH"
builtin::reftype($v) // ""
MC/DC50%2/4
ref $v && (builtin::reftype($v) // '') eq 'HASH' && !is_toml_float($v) && !JSON::MaybeXS::is_bool($v)
ref $v
builtin::reftype($v)
not is_toml_float($v)
!JSON::MaybeXS::is_bool($v)
Truth table60%3/5
A and B and not(C) && not(D)
A= ref $vB= builtin::reftype($v)C= not is_toml_float($v)D= !JSON::MaybeXS::is_bool($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 3194 | ▶ | sub _scalar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scalar: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 3194 | my ( $v, $where, $multiline ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 3194 | ▶ | if ( is_toml_float($v) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 54 | my $x = $v->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 54 | ▶ | _fail( $where.': '._number_text($x).' is not a finite float' ) unless _is_finite($x); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 47 | my $text = js_number($x); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 47 | ▶ | return $text =~ /[.eE]/ ? $text : $text.'.0'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 3140 | my $type = js_type($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 3140 | ▶ | return $multiline ? _multiline_string($v) : _basic_string($v) if $type eq 'string'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 63 | ▶ | return $v ? 'true' : 'false' if $type eq 'boolean'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 50 | ▶ | if ( $type eq 'number' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 46 | ▶ | _fail( $where.': '._number_text($v).' is not an integer (use TomlFloat)' ) unless _is_safe_integer($v); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 35 | return js_number($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # JSON.stringify(v): undefined for what JSON cannot write. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | ▶ | my $json = defined $v ? eval { js_stringify($v) } // 'undefined' : 'null'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
eval {
do {
js_stringify($v)
}
} // "undefined"
MC/DC0%0/1
eval {
do {
js_stringify($v)
}
} // "undefined"
eval {
do {
js_stringify($v)
}
}
Truth table50%1/2
A
A= eval {
do {
js_stringify($v)
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | _fail( $where.': unsupported value '.$json ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 3221 | ▶ | sub _value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 3221 | my ( $v, $where, $multiline ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3221 | ▶ | if ( ref $v && ( reftype $v // '' ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
ref $v and (builtin::reftype($v) // "") eq "ARRAY"
builtin::reftype($v) // ""
MC/DC50%1/2
ref $v and (builtin::reftype($v) // "") eq "ARRAY"
ref $v
builtin::reftype($v)
Truth table66%2/3
A and B
A= ref $vB= builtin::reftype($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 27 | for my $item (@$v) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 61 | ▶ | _fail( $where.': only string arrays are supported' ) unless js_type($item) eq 'string'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 20 | return '['.join( ', ', map { _basic_string($_) } @$v ).']'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3194 | return _scalar( $v, $where, $multiline ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # A JavaScript object's property order: a tied ordered hash keeps it; a plain hash is written | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # as JSON.stringify writes a sorted object – index keys ascending, then the rest sorted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2981 | ▶ | sub _keys { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keys: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 2981 | my ( $h ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2981 | my $tied = tied %$h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2981 | ▶ | return $tied->keys_in_order if blessed $tied && $tied->isa('Skilletor::JSON::OrderedHash'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($tied) and $tied->isa("Skilletor::JSON::OrderedHash")
MC/DC50%1/2
builtin::blessed($tied) and $tied->isa("Skilletor::JSON::OrderedHash")
builtin::blessed($tied)
$tied->isa("Skilletor::JSON::OrderedHash")
Truth table66%2/3
A and B
A= builtin::blessed($tied)B= $tied->isa("Skilletor::JSON::OrderedHash")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | my @keys = keys %$h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my @index = sort { $a <=> $b } grep { Skilletor::JSON::OrderedHash->is_index_key($_) } @keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | return ( @index, js_sort_keys( grep { !Skilletor::JSON::OrderedHash->is_index_key($_) } @keys ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 2918 | ▶ | sub stringify_toml { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify_toml: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2918 | my ( $table, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 2918 | ▶ | my %multiline = map { ( $_ => 1 ) } @{ ( $opts // {} )->{multiline} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
+($opts // {})->{"multiline"} // []
$opts // {}
MC/DC100%1/1
+($opts // {})->{"multiline"} // []
$opts
Truth table100%2/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2918 | my ( @lines, @tables ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2918 | for my $k ( _keys($table) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 3216 | my $v = $table->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 3216 | ▶ | if ( _is_table($v) ) { push @tables, [ $k, $v ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 3152 | else { push @lines, toml_key($k).' = '._value( $v, $k, $multiline{$k} ) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2895 | for my $t (@tables) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 63 | my ( $k, $sub ) = @$t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 63 | push @lines, '', '['.toml_key($k).']'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 63 | for my $sk ( _keys($sub) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 70 | my $sv = $sub->{$sk}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 70 | ▶ | _fail( $k.'.'.$sk.': nested tables are not supported' ) if _is_table($sv); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 69 | push @lines, toml_key($sk).' = '._value( $sv, $k.'.'.$sk, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2888 | return join( "\n", @lines )."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | package # hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | Skilletor::TOML::Float; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # A TOML float: Perl, like JavaScript, cannot tell 1 from 1.0 by the value alone. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 59 | ▶ | sub new { my ( $class, $value ) = @_; return bless { value => $value }, $class } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 55 | ▶ | sub value { $_[0]{value} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | package Skilletor::TOML; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 401 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||