Plisco/EPD.pm

filter: Statementstmt 90.7% 49 / 54 Branchbran 78.5% 11 / 14 Conditioncond 41.1% 7 / 17 MC/DCmcdc 9.0% 1 / 11 Subroutinesub 87.5% 7 / 8 Podpod 100% 2 / 2 totaltotal 72.6% 77 / 106 CC 15 SCAR 25.6
CC
15
Cov
79%
new
18.5
__readFromFileHandle
2.0
BEGIN
1.0
CRAP 13.0
« Plisco/Tablebase/Syzygy.pm ↑ Summary Plisco/Macro.pm »
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
BranchTrueFalseTotal
if (@args == 1 and "HASH" eq ref $args[0]) 0 10 10
Condition33%1/3
@args == 1 and "HASH" eq ref $args[0]
!ll&&!rl&&r
1000
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]
ABresult
0X0
100
111
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) || ''
l!l
37
MC/DC100%1/1
builtin::reftype($arg) || ''
builtin::reftype($arg)
Truth table100%2/2
A
A= builtin::reftype($arg)
Aresult
11
00
33 10 my @lines;
34 10 ▶ if ('SCALAR' eq $reftype) {
Branch: 3 branches
BranchTrueFalseTotal
if ('SCALAR' eq $reftype) { } 1 9 10
elsif ('ARRAY' eq $reftype) { } 1 8 9
elsif ('GLOB' eq $reftype) { } 1 7 8
35 1 @lines = split /\n/, $$arg;
36 1 ▶ $filename //= __"[in-memory string]";
Condition33%1/3
$filename //= &__("[in-memory string]")
l!l&&r!l&&!r
010
MC/DC0%0/2
$filename //= &__("[in-memory string]")
$filename &__("[in-memory string]")
Truth table33%1/3
A //= B
A= $filenameB= &__("[in-memory string]")
ABresult
1X1
011
000
37 } elsif ('ARRAY' eq $reftype) {
38 1 @lines = @$arg;
39 1 ▶ $filename //= __"[in-memory array]";
Condition33%1/3
$filename //= &__("[in-memory array]")
l!l&&r!l&&!r
010
MC/DC0%0/2
$filename //= &__("[in-memory array]")
$filename &__("[in-memory array]")
Truth table33%1/3
A //= B
A= $filenameB= &__("[in-memory array]")
ABresult
1X1
011
000
40 } elsif ('GLOB' eq $reftype) {
41 1 @lines = <$arg>;
42 1 ▶ $filename //= __"[file-handle]";
Condition33%1/3
$filename //= &__("[file-handle]")
l!l&&r!l&&!r
010
MC/DC0%0/2
$filename //= &__("[file-handle]")
$filename &__("[file-handle]")
Truth table33%1/3
A //= B
A= $filenameB= &__("[file-handle]")
ABresult
1X1
011
000
43 } else {
44 7 ▶ open my $fh, '<', $arg
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $arg or die &__x("cannot open '{filename}' for reading: {error}!\n", "filename", $arg, "error", $!) 6 1 7
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
l!l&&r!l&&!r
060
MC/DC0%0/2
$filename //= $arg
$filename $arg
Truth table33%1/3
A //= B
A= $filenameB= $arg
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless length $line 0 70240 70240
60  
61 70240 my $record = eval { Chess::Plisco::EPD::Record->new($line, $pseudo_legal) };
62 70240 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 70240 70240
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;
« Plisco/Tablebase/Syzygy.pm ↑ Summary Plisco/Macro.pm »