| 1 | package Skilletor::Frontmatter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: The reference's YAML subset – agent frontmatter and bundle files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 469 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 469 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 469 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 469 | ▶ | use JSON::MaybeXS (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 469 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 469 | ▶ | use Skilletor::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 469 | ▶ | use Skilletor::Error::Frontmatter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 469 | ▶ | use Skilletor::JSON qw( js_ordered ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 469 | ▶ | use Skilletor::JSString qw( js_trim js_ws_re ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 469 | our $VERSION = '0.008000'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 469 | our @EXPORT_OK = qw( split_frontmatter parse_yaml_document is_yaml_float ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # JavaScript's `.` (no line terminator) and `\s`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 469 | my $DOT = qr/[^\n\r\x{2028}\x{2029}]/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 469 | my $WS = js_ws_re(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 469 | my $LT = qr/[\n\r\x{2028}\x{2029}]/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 469 | my $OPEN = qr/\A---[ \t]*\r?\n/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # /^---[ \t]*(?:\r?\n|$)/m: JavaScript's multiline ^ and $ sit at any line terminator. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 469 | my $CLOSE = qr/(?:\A|(?<=$LT))---[ \t]*(?:\r?\n|(?=$LT)|\z)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # "key": / 'key': / plain key, then `:` followed by whitespace or the end. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 469 | my $KEY_RE = qr/\A(?:"((?:[^"\\]|\\$DOT)*)"|'((?:[^']|'')*)'|((?!$WS)[^"'#&*!|>\[\]{},?:\-][^:#]*?))[ \t]*:(?:[ \t]+($DOT*))?\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 469 | my %ESCAPES = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | '0' => "\0", a => "\x07", b => "\b", t => "\t", "\t" => "\t", n => "\n", v => "\x0B", f => "\f", r => "\r", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | e => "\x1b", ' ' => ' ', '"' => '"', '/' => '/', '\\' => '\\', N => "\x{85}", _ => "\x{A0}", L => "\x{2028}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | P => "\x{2029}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1888 | ▶ | sub split_frontmatter { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_frontmatter: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1888 | my ( $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1888 | ▶ | return { data => js_ordered(), body => $text } unless $text =~ $OPEN; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 685 | my $start = $+[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 685 | pos($text) = $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 685 | ▶ | Skilletor::Error::Frontmatter->throw('frontmatter: no closing --- line') unless $text =~ /$CLOSE/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 682 | my ( $close, $after ) = ( $-[0], $+[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 682 | my $yaml = substr $text, $start, $close - $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 682 | ( my $body = substr $text, $after ) =~ s/\A(?:[ \t]*\r?\n)+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 682 | return { data => _parse_yaml( $yaml, 2, 'frontmatter line' ), body => $body }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1064 | ▶ | sub parse_yaml_document { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_yaml_document: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1064 | my ( $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1064 | return _parse_yaml( $text, 1, 'line' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3030 | ▶ | sub is_yaml_float { blessed $_[0] && $_[0]->isa('Skilletor::Frontmatter::Float') ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_yaml_float: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
Condition100%3/3
builtin::blessed($_[0]) and $_[0]->isa("Skilletor::Frontmatter::Float")
MC/DC100%2/2
builtin::blessed($_[0]) and $_[0]->isa("Skilletor::Frontmatter::Float")
builtin::blessed($_[0])
$_[0]->isa("Skilletor::Frontmatter::Float")
Truth table100%3/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("Skilletor::Frontmatter::Float")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | #### The parser ######################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 338 | ▶ | sub _fail { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fail: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 338 | my ( $line, $message ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 338 | ▶ | Skilletor::Error::Frontmatter->throw( ( $line ? $line->{label} : 'line' ).' '.( $line ? $line->{no} : '?' ).': '.$message ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 4665 | ▶ | sub _indent_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_indent_of: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4665 | my ( $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 4665 | my ($m) = $line->{raw} =~ /\A([ \t]*)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 4665 | ▶ | _fail( $line, 'tabs are not allowed in indentation' ) if index( $m, "\t" ) >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 4662 | return length $m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 7238 | ▶ | sub _skippable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_skippable: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 7238 | my ( $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 7238 | my $t = js_trim( $line->{raw} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 7238 | ▶ | return ( $t eq '' || substr( $t, 0, 1 ) eq '#' ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$t eq "" or substr($t, 0, 1) eq "#"
MC/DC100%2/2
$t eq "" or substr($t, 0, 1) eq "#"
$t eq ""
substr($t, 0, 1) eq "#"
Truth table100%3/3
A or B
A= $t eq ""B= substr($t, 0, 1) eq "#"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 3304 | ▶ | sub _is_seq_item { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_seq_item: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 3304 | my ( $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 3304 | ▶ | return ( $text eq '-' || substr( $text, 0, 2 ) eq '- ' ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$text eq "-" or substr($text, 0, 2) eq "- "
MC/DC100%2/2
$text eq "-" or substr($text, 0, 2) eq "- "
$text eq "-"
substr($text, 0, 2) eq "- "
Truth table100%3/3
A or B
A= $text eq "-"B= substr($text, 0, 2) eq "- "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1746 | ▶ | sub _parse_yaml { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_yaml: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1746 | my ( $yaml, $first_line, $label ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1746 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1746 | my @lines = map { +{ no => $i++ + $first_line, raw => $_, label => $label } } split /\r?\n/, $yaml, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1746 | my $p = bless { lines => \@lines }, 'Skilletor::Frontmatter::_Parser'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1746 | my ( $value, $pos ) = $p->mapping( 0, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1408 | ▶ | _fail( $lines[$pos], 'unexpected content' ) if $pos < @lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1408 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | package # hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | Skilletor::Frontmatter::_Parser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 7535 | ▶ | sub next_content { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_content: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 7535 | my ( $self, $pos ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 7535 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 7535 | ▶ | $pos++ while $pos < @$lines && Skilletor::Frontmatter::_skippable( $lines->[$pos] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pos < @$lines and Skilletor::Frontmatter::_skippable($lines->[$pos])
MC/DC100%2/2
$pos < @$lines and Skilletor::Frontmatter::_skippable($lines->[$pos])
$pos < @$lines
Skilletor::Frontmatter::_skippable($lines->[$pos])
Truth table100%3/3
A and B
A= $pos < @$linesB= Skilletor::Frontmatter::_skippable($lines->[$pos])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 7535 | return $pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1873 | ▶ | sub mapping { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mapping: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1873 | my ( $self, $start, $indent ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1873 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1873 | my $obj = Skilletor::JSON::js_ordered(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1873 | my $pos = $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1873 | for ( ;; ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 4624 | $pos = $self->next_content($pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 4624 | ▶ | last if $pos >= @$lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3112 | my $line = $lines->[$pos]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3112 | my $ind = Skilletor::Frontmatter::_indent_of($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3112 | ▶ | last if $ind < $indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3089 | ▶ | Skilletor::Frontmatter::_fail( $line, 'unexpected indentation' ) if $ind > $indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 3049 | my $text = substr $line->{raw}, $ind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 3049 | ▶ | Skilletor::Frontmatter::_fail( $line, 'unexpected sequence item' ) if Skilletor::Frontmatter::_is_seq_item($text); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 3042 | ▶ | my @m = $text =~ $KEY_RE or Skilletor::Frontmatter::_fail( $line, 'expected `key: value`' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2813 | ▶ | my $key = defined $m[0] ? Skilletor::Frontmatter::_unescape_double( $m[0], $line ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | : defined $m[1] ? $m[1] =~ s/''/'/gr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | : Skilletor::JSString::js_trim( $m[2] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2813 | ▶ | Skilletor::Frontmatter::_fail( $line, 'duplicate key "'.$key.'"' ) if exists $obj->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2810 | ▶ | my ( $value, $next ) = $self->value( $m[3] // '', $pos + 1, $indent, $line ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$m[3] // ""
MC/DC100%1/1
$m[3] // ""
$m[3]
Truth table100%2/2
A
A= $m[3]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2751 | $obj->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2751 | $pos = $next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1535 | return ( $obj, $pos ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # The value after `key:` on $line; $pos is the line after it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 2810 | ▶ | sub value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2810 | my ( $self, $rest, $pos, $indent, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2810 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 2810 | my $r = Skilletor::JSString::js_trim($rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2810 | ▶ | return $self->block_scalar( $r, $pos, $indent, $line ) if $r =~ /\A[|>]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 2774 | ▶ | if ( $r eq '' || substr( $r, 0, 1 ) eq '#' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$r eq "" or substr($r, 0, 1) eq "#"
MC/DC100%2/2
$r eq "" or substr($r, 0, 1) eq "#"
$r eq ""
substr($r, 0, 1) eq "#"
Truth table100%3/3
A or B
A= $r eq ""B= substr($r, 0, 1) eq "#"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 195 | my $q = $self->next_content($pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 195 | ▶ | return ( undef, $q ) if $q >= @$lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 176 | my $next = $lines->[$q]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 176 | my $ind = Skilletor::Frontmatter::_indent_of($next); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 174 | my $text = substr $next->{raw}, $ind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 174 | ▶ | if ( $ind > $indent ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 169 | ▶ | return Skilletor::Frontmatter::_is_seq_item($text) ? $self->sequence( $q, $ind ) : $self->mapping( $q, $ind ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | ▶ | return $self->sequence( $q, $ind ) if $ind == $indent && Skilletor::Frontmatter::_is_seq_item($text); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ind == $indent and Skilletor::Frontmatter::_is_seq_item($text)
MC/DC50%1/2
$ind == $indent and Skilletor::Frontmatter::_is_seq_item($text)
$ind == $indent
Skilletor::Frontmatter::_is_seq_item($text)
Truth table66%2/3
A and B
A= $ind == $indentB= Skilletor::Frontmatter::_is_seq_item($text)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 3 | return ( undef, $q ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # An inline value, possibly continued on more-indented lines (folded with spaces). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2579 | my @parts = ($r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2579 | my $p = $pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2579 | for ( ;; ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2599 | my $q = $self->next_content($p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 2599 | ▶ | last if $q >= @$lines || Skilletor::Frontmatter::_indent_of( $lines->[$q] ) <= $indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$q >= @$lines or Skilletor::Frontmatter::_indent_of($lines->[$q]) <= $indent
MC/DC100%2/2
$q >= @$lines or Skilletor::Frontmatter::_indent_of($lines->[$q]) <= $indent
$q >= @$lines
Skilletor::Frontmatter::_indent_of($lines->[$q]) <= $indent
Truth table100%3/3
A or B
A= $q >= @$linesB= Skilletor::Frontmatter::_indent_of($lines->[$q]) <= $indent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 20 | push @parts, Skilletor::JSString::js_trim( $lines->[$q]{raw} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 20 | $p = $q + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 2578 | ▶ | return ( Skilletor::Frontmatter::_inline( $r, $line ), $pos ) if @parts == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 17 | ▶ | return ( Skilletor::Frontmatter::_inline( join( ' ', @parts ), $line ), $p ) if $r =~ /\A["'\[{]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 9 | ▶ | Skilletor::Frontmatter::_fail( $line, 'anchors, aliases and tags are not supported' ) if $r =~ /\A[&*!]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 9 | return ( join( ' ', map { Skilletor::Frontmatter::_strip_comment($_) } @parts ), $p ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 44 | ▶ | sub sequence { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sequence: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 44 | my ( $self, $start, $indent ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 44 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 44 | my @arr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 44 | my $pos = $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 44 | for ( ;; ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 117 | $pos = $self->next_content($pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 117 | ▶ | last if $pos >= @$lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 90 | my $line = $lines->[$pos]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 90 | my $ind = Skilletor::Frontmatter::_indent_of($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 90 | ▶ | last if $ind < $indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 83 | ▶ | Skilletor::Frontmatter::_fail( $line, 'unexpected indentation in a sequence' ) if $ind > $indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 81 | my $text = substr $line->{raw}, $ind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 81 | ▶ | last unless Skilletor::Frontmatter::_is_seq_item($text); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 79 | my $item = Skilletor::JSString::js_trim( substr $text, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 79 | ▶ | if ( $item eq '' || substr( $item, 0, 1 ) eq '#' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$item eq "" or substr($item, 0, 1) eq "#"
MC/DC50%1/2
$item eq "" or substr($item, 0, 1) eq "#"
$item eq ""
substr($item, 0, 1) eq "#"
Truth table66%2/3
A or B
A= $item eq ""B= substr($item, 0, 1) eq "#"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 2 | Skilletor::Frontmatter::_fail( $line, 'nested blocks inside sequences are not supported' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 77 | ▶ | Skilletor::Frontmatter::_fail( $line, 'mappings inside sequences are not supported' ) if $item =~ $KEY_RE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 75 | ▶ | Skilletor::Frontmatter::_fail( $line, 'nested collections are not supported' ) if $item =~ /\A[\[{]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 73 | push @arr, Skilletor::Frontmatter::_inline( $item, $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 73 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 36 | return ( \@arr, $pos ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 36 | ▶ | sub block_scalar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
block_scalar: called CC=23 SCAR=31.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 36 | my ( $self, $header, $pos, $indent, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 36 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 36 | ▶ | my @h = $header =~ /\A([|>])([+-]?)([1-9]?)[ \t]*(?:#$DOT*)?\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | or Skilletor::Frontmatter::_fail( $line, 'unsupported block scalar header "'.$header.'"' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 34 | my $folded = $h[0] eq '>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 34 | my $chomp = $h[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 34 | ▶ | my $content_indent = length $h[2] ? $indent + $h[2] : -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 34 | my @collected; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 34 | my $p = $pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 34 | ▶ | while ( $p < @$lines ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 100 | my $l = $lines->[$p]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 100 | ▶ | if ( Skilletor::JSString::js_trim( $l->{raw} ) eq '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 33 | push @collected, $l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 33 | $p++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 33 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 67 | my $ind = Skilletor::Frontmatter::_indent_of($l); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 67 | ▶ | last if $ind <= $indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 50 | ▶ | $content_indent = $ind if $content_indent == -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 50 | ▶ | Skilletor::Frontmatter::_fail( $l, 'block scalar line is less indented than its first line' ) if $ind < $content_indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 48 | push @collected, $l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 48 | $p++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 32 | ▶ | my @texts = map { Skilletor::JSString::js_trim( $_->{raw} ) eq '' ? '' : substr( $_->{raw}, $content_indent ) } @collected; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 32 | my $trailing = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 32 | ▶ | while ( @texts && $texts[-1] eq '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@texts and $texts[-1] eq ""
MC/DC100%2/2
@texts and $texts[-1] eq ""
@texts
$texts[-1] eq ""
Truth table100%3/3
A and B
A= @textsB= $texts[-1] eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 28 | pop @texts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 28 | $trailing++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 32 | my $body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 32 | ▶ | if ( !$folded ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 25 | $body = join "\n", @texts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 7 | $body = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 7 | my ( $pending, $first, $prev_more ) = ( 0, 1, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 7 | for my $t (@texts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 20 | ▶ | if ( $t eq '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 3 | $pending++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 17 | ▶ | my $more = $t =~ /\A[ \t]/ ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 17 | ▶ | if ($first) { $body = $t } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | elsif ( $pending > 0 ) { $body .= ( "\n" x $pending ).$t } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 4 | ▶ | elsif ( $more || $prev_more ) { $body .= "\n".$t } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$more or $prev_more
MC/DC100%2/2
$more or $prev_more
$more
$prev_more
Truth table100%3/3
A or B
A= $moreB= $prev_more
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 5 | else { $body .= ' '.$t } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 17 | $first = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 17 | $pending = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 17 | $prev_more = $more; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 32 | ▶ | return ( $body, $p ) if $chomp eq '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 26 | ▶ | return ( '', $p ) if $body eq '' && $chomp ne '+'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$body eq "" and $chomp ne "+"
MC/DC100%2/2
$body eq "" and $chomp ne "+"
$body eq ""
$chomp ne "+"
Truth table100%3/3
A and B
A= $body eq ""B= $chomp ne "+"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 22 | ▶ | return ( $body."\n".( $chomp eq '+' ? "\n" x $trailing : '' ), $p ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | package Skilletor::Frontmatter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | #### Inline values ##################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1710 | ▶ | sub _strip_comment { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_strip_comment: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1710 | my ( $s ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 1710 | ▶ | return js_trim( $s =~ /(?:\A|[ \t])#/ ? substr( $s, 0, $-[0] ) : $s ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 2427 | ▶ | sub _typed_plain { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_typed_plain: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 2427 | my ( $s ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2427 | ▶ | return undef if $s eq '' || $s eq '~' || $s =~ /\A(?:null|Null|NULL)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$s eq "" or $s eq "~" or $s =~ /\A(?:null|Null|NULL)\z/
$s eq "" or $s eq "~"
MC/DC66%2/3
$s eq "" or $s eq "~" or $s =~ /\A(?:null|Null|NULL)\z/
$s eq ""
$s eq "~"
$s =~ /\A(?:null|Null|NULL)\z/
Truth table75%3/4
A or B or C
A= $s eq ""B= $s eq "~"C= $s =~ /\A(?:null|Null|NULL)\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 2397 | ▶ | return JSON::MaybeXS::true() if $s =~ /\A(?:true|True|TRUE)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 2373 | ▶ | return JSON::MaybeXS::false() if $s =~ /\A(?:false|False|FALSE)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 2366 | ▶ | if ( $s =~ /\A[-+]?([0-9]+)\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 113 | ( my $digits = $1 ) =~ s/\A0+(?=.)//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # Number.isSafeInteger: |n| <= 2**53 - 1, else the text stays a string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 113 | ▶ | my $safe = length($digits) < 16 || ( length($digits) == 16 && $digits le '9007199254740991' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
length $digits < 16 || length $digits == 16 && $digits le '9007199254740991'
length $digits == 16 and $digits le "9007199254740991"
MC/DC100%3/3
length $digits < 16 || length $digits == 16 && $digits le '9007199254740991'
length $digits < 16
length $digits == 16
$digits le "9007199254740991"
Truth table100%4/4
A || B and C
A= length $digits < 16B= length $digits == 16C= $digits le "9007199254740991"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 113 | ▶ | return $safe ? 0 + $s : $s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 2253 | ▶ | if ( $s =~ /\A[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*|[0-9]+(?=[eE]))(?:[eE][-+]?[0-9]+)?\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 469 | ▶ | no warnings 'numeric'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 53 | return Skilletor::Frontmatter::Float->new( 0 + $s ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2200 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 233 | ▶ | sub _unescape_double { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unescape_double: called CC=21 SCAR=30.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 233 | my ( $s, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 233 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 233 | my $n = length $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 233 | ▶ | for ( my $i = 0; $i < $n; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 4593 | my $ch = substr $s, $i, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 4593 | ▶ | if ( $ch ne '\\' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 4486 | $out .= $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 4486 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 107 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 107 | ▶ | _fail( $line, 'dangling backslash in a double-quoted string' ) if $i >= $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 107 | my $e = substr $s, $i, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 107 | ▶ | my $hex_len = $e eq 'x' ? 2 : $e eq 'u' ? 4 : $e eq 'U' ? 8 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 107 | ▶ | if ($hex_len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 61 | my $hex = substr $s, $i + 1, $hex_len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 61 | ▶ | _fail( $line, 'bad \\'.$e.' escape' ) unless $hex =~ /\A[0-9a-fA-F]{$hex_len}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 59 | my $cp = hex $hex; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # Above U+10FFFF the reference refuses the escape like any other bad one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 59 | ▶ | _fail( $line, 'bad \\'.$e.' escape' ) if $cp > 0x10FFFF; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # JavaScript strings are UTF-16: adjoining escapes that make a high and low half are one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # scalar when Node later encodes the string. Keep that character joined in Perl too. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 56 | my $next = $i + $hex_len + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 56 | ▶ | my $next_e = $next < $n ? substr( $s, $next + 1, 1 ) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 56 | ▶ | my $next_len = $next_e eq 'u' ? 4 : $next_e eq 'U' ? 8 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 56 | ▶ | my $next_hex = $next_len ? substr( $s, $next + 2, $next_len ) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 56 | ▶ | if ( $cp >= 0xD800 && $cp <= 0xDBFF && substr( $s, $next, 1 ) eq '\\' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$cp >= 55296 and $cp <= 56319 and substr($s, $next, 1) eq "\\" and $next_hex =~ /\A[0-9a-fA-F]{$next_len}\z/
$cp >= 55296 and $cp <= 56319 and substr($s, $next, 1) eq "\\"
$cp >= 55296 and $cp <= 56319
MC/DC75%3/4
$cp >= 55296 and $cp <= 56319 and substr($s, $next, 1) eq "\\" and $next_hex =~ /\A[0-9a-fA-F]{$next_len}\z/
$cp >= 55296
$cp <= 56319
substr($s, $next, 1) eq "\\"
$next_hex =~ /\A[0-9a-fA-F]{$next_len}\z/
Truth table80%4/5
A and B and C and D
A= $cp >= 55296B= $cp <= 56319C= substr($s, $next, 1) eq "\\"D= $next_hex =~ /\A[0-9a-fA-F]{$next_len}\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | && $next_hex =~ /\A[0-9a-fA-F]{$next_len}\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 13 | my $low = hex $next_hex; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 13 | ▶ | if ( $low >= 0xDC00 && $low <= 0xDFFF ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$low >= 56320 and $low <= 57343
MC/DC50%1/2
$low >= 56320 and $low <= 57343
$low >= 56320
$low <= 57343
Truth table66%2/3
A and B
A= $low >= 56320B= $low <= 57343
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 11 | $out .= chr( 0x10000 + ( ( $cp - 0xD800 ) << 10 ) + ( $low - 0xDC00 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 11 | $i = $next + 1 + $next_len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 11 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 469 | ▶ | no warnings qw( surrogate nonchar non_unicode ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 45 | $out .= chr $cp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 45 | $i += $hex_len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | elsif ( exists $ESCAPES{$e} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 43 | $out .= $ESCAPES{$e}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 3 | _fail( $line, 'unknown escape \\'.$e ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 225 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | # One quoted scalar at substr($s, $i, 1) (a quote): the value and the index after it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 265 | ▶ | sub _quoted { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quoted: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 265 | my ( $s, $i, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 265 | my $q = substr $s, $i, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 265 | my $n = length $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 265 | my $j = $i + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 265 | ▶ | if ( $q eq "'" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 42 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 42 | for ( ;; ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 241 | ▶ | _fail( $line, 'unterminated single-quoted string' ) if $j >= $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 241 | ▶ | if ( substr( $s, $j, 1 ) eq "'" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 48 | ▶ | if ( $j + 1 < $n && substr( $s, $j + 1, 1 ) eq "'" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$j + 1 < $n and substr($s, $j + 1, 1) eq "'"
MC/DC100%2/2
$j + 1 < $n and substr($s, $j + 1, 1) eq "'"
$j + 1 < $n
substr($s, $j + 1, 1) eq "'"
Truth table100%3/3
A and B
A= $j + 1 < $nB= substr($s, $j + 1, 1) eq "'"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 6 | $out .= "'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 6 | $j += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 42 | return ( $out, $j + 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 193 | $out .= substr $s, $j++, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 223 | for ( ;; ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 5137 | ▶ | _fail( $line, 'unterminated double-quoted string' ) if $j >= $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 5133 | my $c = substr $s, $j, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 5133 | ▶ | if ( $c eq '\\' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 117 | $j += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 117 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 5016 | ▶ | return ( _unescape_double( substr( $s, $i + 1, $j - $i - 1 ), $line ), $j + 1 ) if $c eq '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 4797 | $j++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 913 | ▶ | sub _assert_end { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_end: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 913 | my ( $s, $i, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 913 | ▶ | my $rest = js_trim( $i < length $s ? substr( $s, $i ) : '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 913 | ▶ | _fail( $line, 'unexpected text after a value: "'.$rest.'"' ) if $rest ne '' && substr( $rest, 0, 1 ) ne '#'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$rest ne "" and substr($rest, 0, 1) ne "#"
MC/DC100%2/2
$rest ne "" and substr($rest, 0, 1) ne "#"
$rest ne ""
substr($rest, 0, 1) ne "#"
Truth table100%3/3
A and B
A= $rest ne ""B= substr($rest, 0, 1) ne "#"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 45767 | ▶ | sub _char { $_[1] < length $_[0] ? substr( $_[0], $_[1], 1 ) : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_char: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | # A scalar inside a flow collection: quoted, or plain up to `,` or the closing bracket. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 897 | ▶ | sub _flow_scalar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flow_scalar: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 897 | my ( $s, $i, $closer, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 897 | ▶ | $i++ while _char( $s, $i ) eq ' ' || _char( $s, $i ) eq "\t"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
_char($s, $i) eq " " or _char($s, $i) eq "\t"
MC/DC50%1/2
_char($s, $i) eq " " or _char($s, $i) eq "\t"
_char($s, $i) eq " "
_char($s, $i) eq "\t"
Truth table66%2/3
A or B
A= _char($s, $i) eq " "B= _char($s, $i) eq "\t"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 897 | my $c = _char( $s, $i ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 897 | ▶ | return _quoted( $s, $i, $line ) if $c eq '"' || $c eq "'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$c eq "\"" or $c eq "'"
MC/DC100%2/2
$c eq "\"" or $c eq "'"
$c eq "\""
$c eq "'"
Truth table100%3/3
A or B
A= $c eq "\""B= $c eq "'"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 743 | ▶ | _fail( $line, 'nested collections are not supported' ) if $c eq '[' || $c eq '{'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$c eq "[" or $c eq "{"
MC/DC50%1/2
$c eq "[" or $c eq "{"
$c eq "["
$c eq "{"
Truth table66%2/3
A or B
A= $c eq "["B= $c eq "{"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 738 | my $j = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 738 | ▶ | $j++ while $j < length $s && _char( $s, $j ) ne ',' && _char( $s, $j ) ne $closer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$j < length $s and _char($s, $j) ne "," and _char($s, $j) ne $closer
$j < length $s and _char($s, $j) ne ","
MC/DC100%3/3
$j < length $s and _char($s, $j) ne "," and _char($s, $j) ne $closer
$j < length $s
_char($s, $j) ne ","
_char($s, $j) ne $closer
Truth table100%4/4
A and B and C
A= $j < length $sB= _char($s, $j) ne ","C= _char($s, $j) ne $closer
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 738 | return ( _typed_plain( js_trim( substr $s, $i, $j - $i ) ), $j ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 892 | ▶ | sub _flow_separator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flow_separator: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 892 | my ( $s, $j, $closer, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 892 | ▶ | $j++ while _char( $s, $j ) eq ' ' || _char( $s, $j ) eq "\t"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
_char($s, $j) eq " " or _char($s, $j) eq "\t"
MC/DC50%1/2
_char($s, $j) eq " " or _char($s, $j) eq "\t"
_char($s, $j) eq " "
_char($s, $j) eq "\t"
Truth table66%2/3
A or B
A= _char($s, $j) eq " "B= _char($s, $j) eq "\t"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 892 | ▶ | return ( 0, $j + 1 ) if _char( $s, $j ) eq ','; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 804 | ▶ | return ( 1, $j + 1 ) if _char( $s, $j ) eq $closer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 2 | _fail( $line, 'expected "," or "'.$closer.'"' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 2642 | ▶ | sub _inline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inline: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 2642 | my ( $value, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 2642 | my $s = js_trim($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 2642 | ▶ | _fail( $line, 'anchors, aliases and tags are not supported' ) if $s =~ /\A[&*!]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 2625 | my $c = _char( $s, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 2625 | ▶ | if ( $c eq '"' || $c eq "'" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$c eq "\"" or $c eq "'"
MC/DC100%2/2
$c eq "\"" or $c eq "'"
$c eq "\""
$c eq "'"
Truth table100%3/3
A or B
A= $c eq "\""B= $c eq "'"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 111 | my ( $v, $j ) = _quoted( $s, 0, $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 99 | _assert_end( $s, $j, $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 97 | return $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 2514 | ▶ | if ( $c eq '[' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 798 | my @arr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 798 | ▶ | if ( $s =~ /\A\[$WS*\]/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 6 | _assert_end( $s, index( $s, ']' ) + 1, $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 6 | return \@arr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 792 | my $j = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 792 | for ( ;; ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 870 | my ( $v, $k ) = _flow_scalar( $s, $j, ']', $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 866 | push @arr, $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 866 | my ( $done, $n ) = _flow_separator( $s, $k, ']', $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 864 | $j = $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 864 | ▶ | last if $done; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 786 | _assert_end( $s, $j, $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 786 | return \@arr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1716 | ▶ | if ( $c eq '{' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 27 | my $obj = js_ordered(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 27 | ▶ | if ( $s =~ /\A\{$WS*\}/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 6 | _assert_end( $s, index( $s, '}' ) + 1, $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 4 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 21 | my $j = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 21 | for ( ;; ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 31 | ▶ | $j++ while _char( $s, $j ) eq ' '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 31 | my $colon = index $s, ':', $j; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 31 | ▶ | _fail( $line, 'expected `key: value` in a flow mapping' ) if $colon == -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 29 | ( my $key = js_trim( substr $s, $j, $colon - $j ) ) =~ s/\A(["'])($DOT*)\1\z/$2/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 29 | ▶ | _fail( $line, 'bad key in a flow mapping' ) if $key eq '' || $key =~ /[,{}\[\]]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "" or $key =~ /[,{}\[\]]/
MC/DC50%1/2
$key eq "" or $key =~ /[,{}\[\]]/
$key eq ""
$key =~ /[,{}\[\]]/
Truth table66%2/3
A or B
A= $key eq ""B= $key =~ /[,{}\[\]]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 27 | my ( $v, $k ) = _flow_scalar( $s, $colon + 1, '}', $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 26 | $obj->{$key} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 26 | my ( $done, $n ) = _flow_separator( $s, $k, '}', $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 26 | $j = $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 26 | ▶ | last if $done; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 16 | _assert_end( $s, $j, $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 16 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 1689 | return _typed_plain( _strip_comment($s) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | package # hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | Skilletor::Frontmatter::Float; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # A YAML float: JavaScript cannot tell 1 from 1.0, TOML can (Codex agents). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 53 | ▶ | sub new { my ( $class, $value ) = @_; return bless { value => $value }, $class } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 45 | ▶ | sub value { $_[0]{value} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | package Skilletor::Frontmatter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 469 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||