| 1 | package LibTmux::Schema; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use v5.44; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use JSON::PP (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use File::Basename qw(dirname); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Scalar::Util qw(blessed reftype); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Encode qw(encode decode FB_CROAK LEAVE_SRC); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use LibTmux::X; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | my ($catalog, %adapters); | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 760 | ▶ | sub catalog ($class) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
catalog: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 760 | ▶ | unless ($catalog) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | open my $in, '<:raw', dirname(__FILE__) . '/schema.json' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | or die "Read schema: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | $catalog = JSON::PP->new->utf8->decode(<$in>); | |||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 760 | return $catalog; | |||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 158 | ▶ | sub _version_at_least ($class, $version, $minimum) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_version_at_least: called CC=5 SCAR=17.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 158 | my @got = $version =~ /(\d+)\.(\d+)([a-z]?)/; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 158 | my @want = $minimum =~ /(\d+)\.(\d+)([a-z]?)/; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 158 | ▶ | return false unless @got == 3 && @want == 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@got == 3 and @want == 3
MC/DC0%0/2
@got == 3 and @want == 3
@got == 3
@want == 3
Truth table33%1/3
A and B
A= @got == 3B= @want == 3
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 158 | ▶ | return $got[0] > $want[0] if $got[0] != $want[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 158 | ▶ | return $got[1] > $want[1] if $got[1] != $want[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | return $got[2] ge $want[2]; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 723 | ▶ | sub entity ($class, $kind) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
entity: called CC=4 SCAR=15.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 723 | ▶ | LibTmux::X::InvalidFilter->throw( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $kind and not ref $kind
MC/DC0%0/2
defined $kind and not ref $kind
defined $kind
not ref $kind
Truth table33%1/3
A and not(B)
A= defined $kindB= not ref $kind
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | message => 'entity kind must be a defined string') | ||||||||||||||||||||||||||||||||||||||||||
| 32 | unless defined($kind) && !ref($kind); | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 723 | my $spec = $class->catalog->{entities}{$kind}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 723 | ▶ | LibTmux::X::InvalidFilter->throw( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | message => 'unknown entity', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | entity => $kind | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ) unless $spec; | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 723 | return $spec; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 656 | ▶ | sub field ($class, $kind, $field) { $class->entity($kind)->{fields}{$field} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 330 | ▶ | sub class_for ($class, $kind) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class_for: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 330 | 'LibTmux::' . join('', map { ucfirst } split /_/, $kind); | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 86 | ▶ | sub selection_for ($class, $kind) { $class->class_for($kind) . 'Selection' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
selection_for: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | ▶ | sub type_name ($class, $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type_name: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | ▶ | defined($value) ? blessed($value) // reftype($value) // 'scalar' : 'undef'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
(builtin::blessed($value) // builtin::reftype($value)) // "scalar"
builtin::blessed($value) // builtin::reftype($value)
MC/DC100%2/2
(builtin::blessed($value) // builtin::reftype($value)) // "scalar"
builtin::blessed($value)
builtin::reftype($value)
Truth table100%3/3
A // B
A= builtin::blessed($value)B= builtin::reftype($value)
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 9 | ▶ | sub invalid ($class, $path, $expected, $value, $type = 'InvalidFilter') { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
invalid: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 9 | my $error = "LibTmux::X::$type"; | |||||||||||||||||||||||||||||||||||||||||
| 53 | $error->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 54 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | entity => do { | |||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | my ($kind) = split /\./, $path; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 9 | ▶ | exists($class->catalog->{entities}{$kind}) ? $kind : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | expected => $expected, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | received => $class->type_name($value), | ||||||||||||||||||||||||||||||||||||||||||
| 61 | message => "expected $expected" | ||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 201 | ▶ | sub normalize ($class, $field, $value, $path, $error = 'InvalidFilter') { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize: called CC=19 SCAR=32.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 201 | ▶ | if (!defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 8 | ▶ | return undef if $field->{nullable}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $class->invalid($path, 'defined ' . $field->{type}, $value, $error); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 193 | ▶ | $class->invalid($path, $field->{type}, $value, $error) if ref $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 193 | my $type = $field->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 193 | ▶ | if ($type eq 'integer') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 39 | my $text = "$value"; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 39 | ▶ | $class->invalid($path, 'safe decimal integer', $value, $error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | unless $text =~ /\A[+-]?[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 37 | my $negative = $text =~ s/^-//; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 37 | $text =~ s/^\+//; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 37 | $text =~ s/^0+(?=[0-9])//; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 37 | ▶ | $class->invalid($path, 'integer within +/-9007199254740991', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
length $text > 16 or length $text == 16 and $text gt "9007199254740991"
length $text == 16 and $text gt "9007199254740991"
MC/DC0%0/3
length $text > 16 or length $text == 16 and $text gt "9007199254740991"
length $text > 16
length $text == 16
$text gt "9007199254740991"
Truth table25%1/4
A or B and C
A= length $text > 16B= length $text == 16C= $text gt "9007199254740991"
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | $value, $error) | ||||||||||||||||||||||||||||||||||||||||||
| 81 | if length($text) > 16 | ||||||||||||||||||||||||||||||||||||||||||
| 82 | || (length($text) == 16 && $text gt '9007199254740991'); | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 37 | ▶ | return 0 + ($negative ? "-$text" : $text); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 154 | ▶ | if ($type eq 'boolean') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 51 | ▶ | $class->invalid($path, 'Boolean or 0/1', $value, $error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
JSON::PP::is_bool($value) or "$value" eq 0 or "$value" eq 1
JSON::PP::is_bool($value) or "$value" eq 0
MC/DC0%0/3
JSON::PP::is_bool($value) or "$value" eq 0 or "$value" eq 1
JSON::PP::is_bool($value)
"$value" eq 0
"$value" eq 1
Truth table25%1/4
A or B or C
A= JSON::PP::is_bool($value)B= "$value" eq 0C= "$value" eq 1
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | unless JSON::PP::is_bool($value) | ||||||||||||||||||||||||||||||||||||||||||
| 88 | || "$value" eq '0' | ||||||||||||||||||||||||||||||||||||||||||
| 89 | || "$value" eq '1'; | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 51 | ▶ | return $value ? true : false; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 103 | my $text = "$value"; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 103 | ▶ | if ($type eq 'bytes') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 11 | ▶ | return utf8::is_utf8($text) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | ? encode('UTF-8', $text, FB_CROAK | LEAVE_SRC) | ||||||||||||||||||||||||||||||||||||||||||
| 96 | : $text; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 92 | ▶ | if (!utf8::is_utf8($text)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 92 | try { $text = decode('UTF-8', $text, FB_CROAK | LEAVE_SRC) } | |||||||||||||||||||||||||||||||||||||||||
| 100 | catch ($e) { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $class->invalid($path, 'valid UTF-8 text', $value, $error) | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 92 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 5 | ▶ | sub wire_scalar ($class, $field, $value, $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wire_scalar: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | ▶ | return $value unless defined $value && $field->{type} eq 'bytes'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $value and $field->{"type"} eq "bytes"
MC/DC50%1/2
defined $value and $field->{"type"} eq "bytes"
defined $value
$field->{"type"} eq "bytes"
Truth table66%2/3
A and B
A= defined $valueB= $field->{"type"} eq "bytes"
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | my $text; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | try { $text = decode('UTF-8', $value, FB_CROAK | LEAVE_SRC) } | |||||||||||||||||||||||||||||||||||||||||
| 111 | catch ($e) { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | LibTmux::X::UnsupportedValue->throw( | |||||||||||||||||||||||||||||||||||||||||
| 113 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | message => | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 'non-UTF-8 octets have no string representation in libtmux.where/v1' | ||||||||||||||||||||||||||||||||||||||||||
| 116 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub register_adapter ($class, %args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_adapter: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $class->entity($args{entity}); | |||||||||||||||||||||||||||||||||||||||||
| 123 | $class->invalid('adapter.class', 'class name', $args{class}) | ||||||||||||||||||||||||||||||||||||||||||
| 124 | unless defined $args{class} | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | && $args{class} =~ /\A[A-Za-z_][A-Za-z0-9_:]*\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $args{"class"} and $args{"class"} =~ /\A[A-Za-z_][A-Za-z0-9_:]*\z/u
MC/DC0%0/2
defined $args{"class"} and $args{"class"} =~ /\A[A-Za-z_][A-Za-z0-9_:]*\z/u
defined $args{"class"}
$args{"class"} =~ /\A[A-Za-z_][A-Za-z0-9_:]*\z/u
Truth table0%0/3
A and B
A= defined $args{"class"}B= $args{"class"} =~ /\A[A-Za-z_][A-Za-z0-9_:]*\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | $class->invalid('adapter.readers', 'unblessed hash reference', | ||||||||||||||||||||||||||||||||||||||||||
| 127 | $args{readers}) | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | unless ref($args{readers}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | for my $field (keys $args{readers}->%*) { | |||||||||||||||||||||||||||||||||||||||||
| 130 | $class->invalid( | ||||||||||||||||||||||||||||||||||||||||||
| 131 | "adapter.$field", | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 'registered field reader', | ||||||||||||||||||||||||||||||||||||||||||
| 133 | $args{readers}{$field} | ||||||||||||||||||||||||||||||||||||||||||
| 134 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 135 | unless $class->field($args{entity}, $field) | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | && ref($args{readers}{$field}) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$class->field($args{"entity"}, $field) and ref $args{"readers"}{$field} eq "CODE"
MC/DC0%0/2
$class->field($args{"entity"}, $field) and ref $args{"readers"}{$field} eq "CODE"
$class->field($args{"entity"}, $field)
ref $args{"readers"}{$field} eq "CODE"
Truth table0%0/3
A and B
A= $class->field($args{"entity"}, $field)B= ref $args{"readers"}{$field} eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | $adapters{$args{class}} = | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | {entity => $args{entity}, readers => {%{$args{readers}}}}; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 306 | ▶ | sub assert_record ($class, $kind, $record, $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assert_record: called CC=8 SCAR=29.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 306 | ▶ | if (blessed($record) && $record->isa('LibTmux::Entity')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($record) and $record->isa("LibTmux::Entity")
MC/DC50%1/2
builtin::blessed($record) and $record->isa("LibTmux::Entity")
builtin::blessed($record)
$record->isa("LibTmux::Entity")
Truth table66%2/3
A and B
A= builtin::blessed($record)B= $record->isa("LibTmux::Entity")
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 301 | ▶ | $class->invalid($path, "$kind entity", $record) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | unless $record->kind eq $kind; | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 301 | return; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 5 | ▶ | return if ref($record) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my $adapter = blessed($record) ? $adapters{ref $record} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | return if $adapter && $adapter->{entity} eq $kind; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$adapter and $adapter->{"entity"} eq $kind
MC/DC0%0/2
$adapter and $adapter->{"entity"} eq $kind
$adapter
$adapter->{"entity"} eq $kind
Truth table0%0/3
A and B
A= $adapterB= $adapter->{"entity"} eq $kind
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $class->invalid($path, "$kind record or registered adapter", $record); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 144 | ▶ | sub read ($class, $kind, $record, $field, $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=7 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 144 | $class->assert_record($kind, $record, $path); | |||||||||||||||||||||||||||||||||||||||||
| 156 | 144 | my $spec = $class->field($kind, $field); | |||||||||||||||||||||||||||||||||||||||||
| 157 | 144 | ▶ | return $record->_read($field) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($record) and $record->isa("LibTmux::Entity")
MC/DC50%1/2
builtin::blessed($record) and $record->isa("LibTmux::Entity")
builtin::blessed($record)
$record->isa("LibTmux::Entity")
Truth table66%2/3
A and B
A= builtin::blessed($record)B= $record->isa("LibTmux::Entity")
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | if blessed($record) && $record->isa('LibTmux::Entity'); | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 3 | my $value; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 3 | ▶ | if (ref($record) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | LibTmux::X::Unloaded->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 162 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||
| 163 | entity => $kind, | ||||||||||||||||||||||||||||||||||||||||||
| 164 | message => 'field or relation was not loaded' | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 3 | ▶ | ) unless exists $record->{$field}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 3 | $value = $record->{$field}; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my $reader = $adapters{ref $record}{readers}{$field}; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | LibTmux::X::Unloaded->throw( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||
| 172 | entity => $kind, | ||||||||||||||||||||||||||||||||||||||||||
| 173 | message => 'adapter has no reader for field' | ||||||||||||||||||||||||||||||||||||||||||
| 174 | ) unless $reader; | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $value = $reader->($record); | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | ▶ | return $value if $spec->{type} eq 'relation'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 3 | return $class->normalize($spec, $value, $path, 'Unloaded'); | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | LibTmux::Schema - Catalog and explicit record adapters | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | =head2 register_adapter | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | C<register_adapter(class =E<gt> ..., entity =E<gt> ..., readers =E<gt> {...})> | ||||||||||||||||||||||||||||||||||||||||||
| 190 | registers trusted callbacks for declared fields. Unknown criteria keys never | ||||||||||||||||||||||||||||||||||||||||||
| 191 | become method names. Missing fields throw; nullable undef is known null. | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | =cut | ||||||||||||||||||||||||||||||||||||||||||