| 1 | #! /bin/false | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Copyright (C) 2021-2026 Guido Flohr <guido.flohr@cantanea.com>, | ||||||||||||||||||||||||||||
| 4 | # all rights reserved. | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # This program is free software. It comes without any warranty, to | ||||||||||||||||||||||||||||
| 7 | # the extent permitted by applicable law. You can redistribute it | ||||||||||||||||||||||||||||
| 8 | # and/or modify it under the terms of the Do What the Fuck You Want | ||||||||||||||||||||||||||||
| 9 | # to Public License, Version 2, as published by Sam Hocevar. See | ||||||||||||||||||||||||||||
| 10 | # http://www.wtfpl.net/ for more details. | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package Chess::Plisco::EPD; | ||||||||||||||||||||||||||||
| 13 | 8 | $Chess::Plisco::EPD::VERSION = 'v1.0.3'; | |||||||||||||||||||||||||||
| 14 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 8 | ▶ | use integer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 8 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 8 | ▶ | use Locale::TextDomain qw('Chess-Plisco'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 8 | ▶ | use Chess::Plisco::EPD::Record; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 10 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=15 SCAR=29.2
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 10 | my ($class, $arg, @args) = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 10 | my %options = @args; | |||||||||||||||||||||||||||
| 26 | 10 | ▶ | if (@args == 1 && 'HASH' eq ref $args[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@args == 1 and "HASH" eq ref $args[0]
MC/DC0%0/2
@args == 1 and "HASH" eq ref $args[0]
@args == 1
"HASH" eq ref $args[0]
Truth table33%1/3
A and B
A= @args == 1B= "HASH" eq ref $args[0]
| |||||||||||||||||||||||||||||
| 27 | 0 | %options = %{$args[0]}; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 10 | my $filename = $options{filename}; | |||||||||||||||||||||||||||
| 30 | 10 | my $pseudo_legal = $options{pseudo_legal}; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 10 | ▶ | my $reftype = (reftype $arg) || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
builtin::reftype($arg) || ''
MC/DC100%1/1
builtin::reftype($arg) || ''
builtin::reftype($arg)
Truth table100%2/2
A
A= builtin::reftype($arg)
| |||||||||||||||||||||||||||||
| 33 | 10 | my @lines; | |||||||||||||||||||||||||||
| 34 | 10 | ▶ | if ('SCALAR' eq $reftype) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 35 | 1 | @lines = split /\n/, $$arg; | |||||||||||||||||||||||||||
| 36 | 1 | ▶ | $filename //= __"[in-memory string]"; | ||||||||||||||||||||||||||
|
Condition33%1/3
$filename //= &__("[in-memory string]")
MC/DC0%0/2
$filename //= &__("[in-memory string]")
$filename
&__("[in-memory string]")
Truth table33%1/3
A //= B
A= $filenameB= &__("[in-memory string]")
| |||||||||||||||||||||||||||||
| 37 | } elsif ('ARRAY' eq $reftype) { | ||||||||||||||||||||||||||||
| 38 | 1 | @lines = @$arg; | |||||||||||||||||||||||||||
| 39 | 1 | ▶ | $filename //= __"[in-memory array]"; | ||||||||||||||||||||||||||
|
Condition33%1/3
$filename //= &__("[in-memory array]")
MC/DC0%0/2
$filename //= &__("[in-memory array]")
$filename
&__("[in-memory array]")
Truth table33%1/3
A //= B
A= $filenameB= &__("[in-memory array]")
| |||||||||||||||||||||||||||||
| 40 | } elsif ('GLOB' eq $reftype) { | ||||||||||||||||||||||||||||
| 41 | 1 | @lines = <$arg>; | |||||||||||||||||||||||||||
| 42 | 1 | ▶ | $filename //= __"[file-handle]"; | ||||||||||||||||||||||||||
|
Condition33%1/3
$filename //= &__("[file-handle]")
MC/DC0%0/2
$filename //= &__("[file-handle]")
$filename
&__("[file-handle]")
Truth table33%1/3
A //= B
A= $filenameB= &__("[file-handle]")
| |||||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||
| 44 | 7 | ▶ | open my $fh, '<', $arg | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | or die __x("cannot open '{filename}' for reading: {error}!\n", | ||||||||||||||||||||||||||||
| 46 | filename => $arg, | ||||||||||||||||||||||||||||
| 47 | error => $!); | ||||||||||||||||||||||||||||
| 48 | 6 | ▶ | $filename //= $arg; | ||||||||||||||||||||||||||
|
Condition33%1/3
$filename //= $arg
MC/DC0%0/2
$filename //= $arg
$filename
$arg
Truth table33%1/3
A //= B
A= $filenameB= $arg
| |||||||||||||||||||||||||||||
| 49 | 6 | @lines = <$fh>; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 9 | my $lineno = 0; | |||||||||||||||||||||||||||
| 53 | 9 | my $ws = "[ \011-\015]"; | |||||||||||||||||||||||||||
| 54 | 9 | my @self; | |||||||||||||||||||||||||||
| 55 | 9 | foreach my $line (@lines) { | |||||||||||||||||||||||||||
| 56 | 70240 | ++$lineno; | |||||||||||||||||||||||||||
| 57 | 70240 | $line =~ s/^$ws+//; | |||||||||||||||||||||||||||
| 58 | 70240 | $line =~ s/ws+$//; | |||||||||||||||||||||||||||
| 59 | 70240 | ▶ | next if !length $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 70240 | my $record = eval { Chess::Plisco::EPD::Record->new($line, $pseudo_legal) }; | |||||||||||||||||||||||||||
| 62 | 70240 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | die "$filename:$lineno: $@"; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 70240 | push @self, $record; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 9 | bless \@self, $class; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub __readFromFileHandle { | ||||||||||||||||||||||||||
|
Subroutine
__readFromFileHandle: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 72 | 0 | my ($class, $filename, $fh) = @_; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | return <$fh>; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 13 | ▶ | sub records { | ||||||||||||||||||||||||||
|
Subroutine
records: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 13 | return @$self; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 8 | 1; | |||||||||||||||||||||||||||