blib/lib/Langertha/Holmgang/Loader.pm

filter: Statementstmt 77.8% 376 / 483 Branchbran 69.9% 137 / 196 Conditioncond 58.4% 73 / 125 MC/DCmcdc 30.0% 21 / 70 Subroutinesub 83.8% 52 / 62 Podpod 100% 8 / 8 totaltotal 70.6% 667 / 944 CC 287 SCAR 24.8
CC
287
Cov
73%
assemble
38.5
assemble
38.5
_y_differs
26.1
CRAP 11.9
« blib/lib/Langertha/Holmgang/Simulators.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/IOS.pm »
1 package Langertha::Holmgang::Loader;
2 # ABSTRACT: Loads suite format 2 from search directories, lints every case
3  
4 35 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 35 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 35 ▶use B ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 35 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 35 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 35 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 35 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 35 ▶use YAML::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 35 ▶use Langertha::Holmgang::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 35 ▶use Langertha::Holmgang::Grader;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 35 ▶use Langertha::Holmgang::Haystack;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 35 ▶use Langertha::Holmgang::Lint;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 35 ▶use Langertha::Holmgang::Runner;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 35 ▶use Langertha::Holmgang::Simulators;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 35 ▶use Langertha::Holmgang::Structure;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 35 ▶use Langertha::Holmgang::Suite;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 35 our $VERSION = '0.001';
24  
25  
26 35 has simulators => (
27 is => 'ro',
28 lazy => 1,
29 builder => '_build_simulators',
30 );
31 72 ▶sub _build_simulators { Langertha::Holmgang::Simulators->new }
Subroutine _build_simulators: called CC=1 SCAR=0.0
32  
33  
34 35 has haystack => (
35 is => 'ro',
36 lazy => 1,
37 builder => '_build_haystack',
38 );
39 74 ▶sub _build_haystack { Langertha::Holmgang::Haystack->new }
Subroutine _build_haystack: called CC=1 SCAR=0.0
40  
41  
42 35 has structure => (
43 is => 'ro',
44 lazy => 1,
45 builder => '_build_structure',
46 );
47 74 ▶sub _build_structure {
Subroutine _build_structure: called CC=1 SCAR=1.2
48 0 ▶ my ( $self ) = @_;
Subroutine _build_structure: not called CC=1 SCAR=1.2
49 0 return Langertha::Holmgang::Structure->new( simulators => $self->simulators, haystack => $self->haystack );
50 }
51  
52  
53 35 has lint => (
54 is => 'ro',
55 lazy => 1,
56 builder => '_build_lint',
57 );
58 53 ▶sub _build_lint {
Subroutine _build_lint: called CC=1 SCAR=1.2
59 0 ▶ my ( $self ) = @_;
Subroutine _build_lint: not called CC=1 SCAR=1.2
60 0 return Langertha::Holmgang::Lint->new(
61 grader => Langertha::Holmgang::Grader->new( simulators => $self->simulators ),
62 mock_runs => Langertha::Holmgang::Runner->lint_mock_runs,
63 );
64 }
65  
66  
67 has seeds => (
68 is => 'ro',
69 74 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
70 35 );
71  
72  
73 18 ▶sub _refuse {
Subroutine _refuse: called CC=1 SCAR=1.2
74 0 ▶ my ( $self, $field, $reason ) = @_;
Subroutine _refuse: not called CC=1 SCAR=1.2
75 0 Langertha::Holmgang::Error->throw( $field, $reason );
76 }
77  
78 557 ▶sub _read_yaml {
Subroutine _read_yaml: called CC=4 SCAR=18.5
79 0 ▶ my ( $self, $file, $field ) = @_;
Subroutine _read_yaml: not called CC=4 SCAR=18.5
80 0 my $bytes = eval { path($file)->slurp_raw };
81 0 ▶ $self->_refuse( $field, 'not readable: '.( $@ =~ s/\s+\z//r ) ) unless defined $bytes;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $bytes 1 556 557
unless defined $bytes 0 0 0
82 0 my $data = eval { YAML::XS::Load($bytes) };
83 0 ▶ if ( my $err = $@ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $err = $@) 2 554 556
if (my $err = $@) 0 0 0
84 0 $err =~ s/\s+\z//;
85 0 $self->_refuse( $field, 'not valid YAML: '.$err );
86 }
87 0 ▶ $self->_refuse( $field, 'not a hash' ) unless ref $data eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 554 554
unless ref $data eq "HASH" 0 0 0
88 0 return ( $data, $bytes );
89 }
90  
91 310 ▶sub load {
Subroutine load: called CC=8 SCAR=28.8
Pod documented
92 0 ▶ my ( $self, $dir ) = @_;
Subroutine load: not called CC=8 SCAR=28.8
Pod documented
93 0 $dir =~ s{/+\z}{};
94 0 my $dirname = path($dir)->basename;
95 0 my ( $yaml, $pl ) = map { -f $dir.'/'.$_ } qw( suite.yaml suite.pl );
96 0 ▶ $self->_refuse( 'suite', 'suite.yaml and suite.pl in one directory: a suite has one of them' ) if $yaml && $pl;
Branch: 2 branches
BranchTrueFalseTotal
if $yaml and $pl 2 308 310
if $yaml and $pl 0 0 0
Condition50%3/6
$yaml and $pl
!ll&&!rl&&r
512572
$yaml and $pl
!ll&&!rl&&r
000
MC/DC100%2/2
$yaml and $pl
$yaml $pl
MC/DC0%0/2
$yaml and $pl
$yaml $pl
Truth table100%3/3
A and B
A= $yamlB= $pl
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $yamlB= $pl
ABresult
0X0
100
111
97 0 ▶ return $self->_load_dsl( $dir, $dirname ) if $pl;
Branch: 2 branches
BranchTrueFalseTotal
if $pl 51 257 308
if $pl 0 0 0
98 0 my $st = $self->structure;
99 0 my ( $head, $head_bytes ) = $self->_read_yaml( $dir.'/suite.yaml', 'suite.yaml' );
100 0 my %suite = $st->suite_head( $head, dirname => $dirname, format => 1 );
101  
102 0 my $sha = Digest::SHA->new(256);
103 0 $sha->add( "suite.yaml\0", $head_bytes, "\0" );
104  
105 0 my $cdir = path( $dir, 'cases' );
106 0 ▶ $self->_refuse( 'cases', 'directory cases/ missing' ) unless $cdir->is_dir;
Branch: 2 branches
BranchTrueFalseTotal
unless $cdir->is_dir 0 233 233
unless $cdir->is_dir 0 0 0
107 0 ▶ my @files = sort map { $_->basename } grep { $_->basename =~ /\.yaml\z/ && -f $_ } $cdir->children;
Condition16%1/6
$_->basename =~ /\.yaml\z/ && -f $_
!ll&&!rl&&r
00288
$_->basename =~ /\.yaml\z/ && -f $_
!ll&&!rl&&r
000
MC/DC0%0/2
$_->basename =~ /\.yaml\z/ && -f $_
$_->basename =~ /\.yaml\z/ -f $_
MC/DC0%0/2
$_->basename =~ /\.yaml\z/ && -f $_
$_->basename =~ /\.yaml\z/ -f $_
Truth table33%1/3
A && B
A= $_->basename =~ /\.yaml\z/B= -f $_
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= $_->basename =~ /\.yaml\z/B= -f $_
ABresult
0X0
100
111
108 0 ▶ $self->_refuse( 'cases', 'no cases' ) unless @files;
Branch: 2 branches
BranchTrueFalseTotal
unless @files 1 232 233
unless @files 0 0 0
109  
110 0 my @cases;
111 0 for my $file ( @files ) {
112 0 my $f = 'cases/'.$file;
113 0 my ( $data, $bytes ) = $self->_read_yaml( $dir.'/cases/'.$file, $f );
114 0 $sha->add( $f."\0", $bytes, "\0" );
115 0 $self->_digest_generated( $sha, $data, $f, $dir );
116 0 my $case = $st->case( $data, file => $file, tools => $suite{tools}, defaults => $suite{defaults}, dir => $dir );
117 0 $self->_digest_images( $sha, $case, $f );
118 0 $self->lint->lint( $case, $f );
119 0 push @cases, $case;
120 }
121 0 return Langertha::Holmgang::Suite->new( %suite, cases => \@cases, digest => $sha->hexdigest );
122 }
123  
124 # the generated texts of a case file, by field, as cai-platform's digest takes
125 # them -- excerpts from quellen/ (k52) set in first
126 403 ▶sub _digest_generated {
Subroutine _digest_generated: called CC=2 SCAR=9.2
127 0 ▶ my ( $self, $sha, $data, $f, $dir ) = @_;
Subroutine _digest_generated: not called CC=2 SCAR=9.2
128 0 for my $g ( $self->structure->generated( $data, $f, dir => $dir ) ) {
129 0 my ( $field, $text ) = @$g;
130 0 $sha->add( $field."\0", Digest::SHA::sha256_hex( Encode::encode( 'UTF-8', $text ) ), "\0" );
131 }
132 0 return;
133 }
134  
135 # images (k27): file, SHA-256 and size per image, in message order; a case
136 # without images adds nothing, so its digest is what it was before
137 339 ▶sub _digest_images {
Subroutine _digest_images: called CC=4 SCAR=17.9
138 0 ▶ my ( $self, $sha, $case, $f ) = @_;
Subroutine _digest_images: not called CC=4 SCAR=17.9
139 0 my $i = 0;
140 0 for my $m ( @{ $case->messages } ) {
141 0 my $j = 0;
142 0 ▶ for my $img ( ref $m->{images} eq 'ARRAY' ? @{ $m->{images} } : () ) {
Branch: 2 branches
BranchTrueFalseTotal
ref $$m{'images'} eq 'ARRAY' ? : 38 347 385
ref $$m{'images'} eq 'ARRAY' ? : 0 0 0
143 0 my $info = $case->image_files->{ $img->{file} };
144 $sha->add( $f.': messages['.$i.'].images['.$j.']'."\0",
145 0 join( ' ', @{$info}{qw( file sha256 width height )} ), "\0" );
146 0 $j++;
147 }
148 0 $i++;
149 }
150 0 return;
151 }
152  
153  
154 51 ▶sub _load_dsl {
Subroutine _load_dsl: called CC=3 SCAR=15.0
155 0 ▶ my ( $self, $dir, $dirname ) = @_;
Subroutine _load_dsl: not called CC=3 SCAR=15.0
156 0 my $code = eval { path( $dir, 'suite.pl' )->slurp_raw };
157 0 ▶ $self->_refuse( 'suite.pl', 'not readable: '.( $@ =~ s/\s+\z//r ) ) unless defined $code;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $code 0 51 51
unless defined $code 0 0 0
158 # compiled as UTF-8 source (k60): a byte string that is not UTF-8 is refused
159 # here, before Perl's lexer warns about it or reads it as Latin-1
160 0 ▶ $self->_refuse( 'suite.pl', 'not UTF-8: a suite file is UTF-8 source' ) unless utf8::decode( my $chars = $code );
Branch: 2 branches
BranchTrueFalseTotal
unless utf8::decode(my $chars = $code) 1 50 51
unless utf8::decode(my $chars = $code) 0 0 0
161 0 require Langertha::Holmgang;
162 0 return Langertha::Holmgang::_load_file(
163 loader => $self,
164 dir => $dir,
165 dirname => $dirname,
166 path => path( $dir, 'suite.pl' )->absolute->stringify,
167 code => $code,
168 );
169 }
170  
171 58 ▶sub assemble {
Subroutine assemble: called CC=12 SCAR=36.5
Pod documented
172 0 ▶ my ( $self, %o ) = @_;
Subroutine assemble: not called CC=12 SCAR=36.5
Pod documented
173 0 my $st = $self->structure;
174 0 ▶ my $label = $o{file} // 'suite.pl';
Condition25%1/4
$o{"file"} // "suite.pl"
l!l
580
$o{"file"} // "suite.pl"
l!l
00
MC/DC0%0/1
$o{"file"} // "suite.pl"
$o{"file"}
MC/DC0%0/1
$o{"file"} // "suite.pl"
$o{"file"}
Truth table50%1/2
A
A= $o{"file"}
Aresult
11
00
Truth table0%0/2
A
A= $o{"file"}
Aresult
11
00
175 0 my $head = $o{head};
176 58 ▶ my %suite = $self->_relabel( $label, undef, sub {
Subroutine __ANON__: called CC=2 SCAR=9.2
177 0 ▶ $st->suite_head( $head, defined $o{dirname} ? ( dirname => $o{dirname} ) : () );
Subroutine __ANON__: not called CC=2 SCAR=9.2
Branch: 2 branches
BranchTrueFalseTotal
defined $o{'dirname'} ? : 47 11 58
defined $o{'dirname'} ? : 0 0 0
178 0 } );
179  
180 # the digest, taken as load takes it from the suite's YAML export (k19):
181 # the same names, the same bytes
182 0 my $sha = Digest::SHA->new(256);
183 0 my $yaml = $self->_export_yaml( { format => 2, %$head }, 'suite.yaml', $label );
184 0 my @files = ( [ 'suite.yaml', $yaml ] );
185 0 $sha->add( "suite.yaml\0", $yaml, "\0" );
186  
187 0 my %seen;
188 0 my ( @cases, %images, %sources );
189 # ordered as the export's file names are, which is format 2's load order
190 0 ▶ for my $data ( sort { ( $a->{id} // '' ).'.yaml' cmp( $b->{id} // '' ).'.yaml' } @{ $o{cases} || [] } ) {
Condition25%3/12
$$a{"id"} // ""
l!l
1030
$$b{"id"} // ""
l!l
1030
$o{'cases'} || []
l!l
550
$$a{"id"} // ""
l!l
00
$$b{"id"} // ""
l!l
00
$o{'cases'} || []
l!l
00
MC/DC0%0/1
$$a{"id"} // ""
$$a{"id"}
MC/DC0%0/1
$$b{"id"} // ""
$$b{"id"}
MC/DC0%0/1
$o{'cases'} || []
$o{'cases'}
MC/DC0%0/1
$$a{"id"} // ""
$$a{"id"}
MC/DC0%0/1
$$b{"id"} // ""
$$b{"id"}
MC/DC0%0/1
$o{'cases'} || []
$o{'cases'}
Truth table50%1/2
A
A= $$a{"id"}
Aresult
11
00
Truth table50%1/2
A
A= $$b{"id"}
Aresult
11
00
Truth table50%1/2
A
A= $o{'cases'}
Aresult
11
00
Truth table0%0/2
A
A= $$a{"id"}
Aresult
11
00
Truth table0%0/2
A
A= $$b{"id"}
Aresult
11
00
Truth table0%0/2
A
A= $o{'cases'}
Aresult
11
00
191 0 ▶ my $id = $data->{id} // '';
Condition25%1/4
$$data{"id"} // ""
l!l
1260
$$data{"id"} // ""
l!l
00
MC/DC0%0/1
$$data{"id"} // ""
$$data{"id"}
MC/DC0%0/1
$$data{"id"} // ""
$$data{"id"}
Truth table50%1/2
A
A= $$data{"id"}
Aresult
11
00
Truth table0%0/2
A
A= $$data{"id"}
Aresult
11
00
192 0 ▶ $self->_refuse( $label.': case '.$id, 'case id twice' ) if $seen{$id}++;
Branch: 2 branches
BranchTrueFalseTotal
if $seen{$id}++ 0 126 126
if $seen{$id}++ 0 0 0
193 0 ▶ $self->_refuse( $label.': case '.$id, 'invalid id' ) unless $st->valid_id($id);
Branch: 2 branches
BranchTrueFalseTotal
unless $st->valid_id($id) 0 126 126
unless $st->valid_id($id) 0 0 0
194 0 my $f = 'cases/'.$id.'.yaml'; # as the export names the file
195 0 my $field = $label.': case '.$id;
196 0 my $case = $st->case( $data, field => $field, tools => $suite{tools}, defaults => $suite{defaults}, dir => $o{dir} );
197 0 my $bytes = $self->_export_yaml( $data, $f, $field );
198 0 push @files, [ $f, $bytes ];
199 0 $sha->add( $f."\0", $bytes, "\0" );
200 0 ▶ $self->_relabel( $field, $f, sub { $self->_digest_generated( $sha, $data, $f, $o{dir} ) } );
Subroutine __ANON__: called CC=1 SCAR=0.4
201 0 $self->_digest_images( $sha, $case, $f );
202 0 $self->lint->lint( $case, $field );
203 0 ▶ $images{ $_->{file} } //= $_->{path} for values %{ $case->image_files };
Condition33%2/6
$images{$$_{"file"}} //= $$_{"path"}
l!l&&r!l&&!r
2110
$images{$$_{"file"}} //= $$_{"path"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$images{$$_{"file"}} //= $$_{"path"}
$images{$$_{"file"}} $$_{"path"}
MC/DC0%0/2
$images{$$_{"file"}} //= $$_{"path"}
$images{$$_{"file"}} $$_{"path"}
Truth table66%2/3
A //= B
A= $images{$$_{"file"}}B= $$_{"path"}
ABresult
1X1
011
000
Truth table0%0/3
A //= B
A= $images{$$_{"file"}}B= $$_{"path"}
ABresult
1X1
011
000
204 0 $self->_excerpt_sources( \%sources, $data, $o{dir} );
205 0 push @cases, $case;
206 }
207 0 ▶ $self->_refuse( $label, 'no cases' ) unless @cases;
Branch: 2 branches
BranchTrueFalseTotal
unless @cases 1 42 43
unless @cases 0 0 0
208 0 return Langertha::Holmgang::Suite->new( %suite, cases => \@cases, digest => $sha->hexdigest,
209 _export => { files => \@files, images => \%images, sources => \%sources } );
210 }
211  
212 # the fixtures under quellen/ the excerpts of a (checked) case read, by their
213 # file relative to the suite directory, with their real path (k52)
214 114 ▶sub _excerpt_sources {
Subroutine _excerpt_sources: called CC=5 SCAR=16.3
215 114 my ( $self, $sources, $data, $dir ) = @_;
216 114 my $ex = $self->structure->excerpt;
217 114 ▶ for my $m ( grep { ref $_ eq 'HASH' } @{ $data->{messages} || [] } ) {
Condition50%1/2
$$data{'messages'} || []
l!l
1140
MC/DC0%0/1
$$data{'messages'} || []
$$data{'messages'}
Truth table50%1/2
A
A= $$data{'messages'}
Aresult
11
00
218 140 for my $file ( $ex->files( $m->{content} ) ) {
219 4 ▶ $sources->{$file} //= $ex->source( $dir, $file, 'quellen' )->{path};
Condition66%2/3
$$sources{$file} //= $ex->source($dir, $file, "quellen")->{"path"}
l!l&&r!l&&!r
220
MC/DC0%0/2
$$sources{$file} //= $ex->source($dir, $file, "quellen")->{"path"}
$$sources{$file} $ex->source($dir, $file, "quellen")->{"path"}
Truth table66%2/3
A //= B
A= $$sources{$file}B= $ex->source($dir, $file, "quellen")->{"path"}
ABresult
1X1
011
000
220 }
221 }
222 114 return;
223 }
224  
225  
226 10 ▶sub export {
Subroutine export: called CC=12 SCAR=25.6
Pod documented
227 10 my ( $self, $dir, $root ) = @_;
228 10 $dir =~ s{/+\z}{};
229 10 ▶ $self->_refuse( 'suite', 'no suite.pl: only a suite in the case DSL is exported, format 2 is YAML already' )
Branch: 1 branch
BranchTrueFalseTotal
unless -f $dir . '/suite.pl' 1 9 10
230 unless -f $dir.'/suite.pl';
231 9 my $suite = $self->load($dir);
232 9 ▶ my $exp = $suite->_export or $self->_refuse( 'suite.pl', 'the suite was not built by the case DSL' );
Branch: 1 branch
BranchTrueFalseTotal
my $exp = $suite->_export or $self->_refuse("suite.pl", "the suite was not built by the case DSL") 9 0 9
233 9 my $out = path( $root, $suite->id );
234 9 ▶ $self->_refuse( 'export', 'exists already: '.$out ) if -e $out || -l $out;
Branch: 1 branch
BranchTrueFalseTotal
if -e $out or -l $out 1 8 9
Condition66%2/3
-e $out or -l $out
l!l&&r!l&&!r
108
MC/DC50%1/2
-e $out or -l $out
-e $out -l $out
Truth table66%2/3
A or B
A= -e $outB= -l $out
ABresult
1X1
011
000
235 8 path($root)->mkpath;
236 8 my $tmp = Path::Tiny->tempdir( TEMPLATE => '.'.$suite->id.'-export-XXXXXX', DIR => "$root" );
237 8 for my $file ( @{ $exp->{files} } ) {
238 32 my $p = $tmp->child( $file->[0] );
239 32 $p->parent->mkpath;
240 32 $p->spew_raw( $file->[1] );
241 }
242 8 ▶ for my $copy ( map { my $h = $exp->{$_} || {}; map { [ $_, $h->{$_} ] } sort keys %$h } qw( images sources ) ) {
Condition50%1/2
$$exp{$_} || {}
l!l
160
MC/DC0%0/1
$$exp{$_} || {}
$$exp{$_}
Truth table50%1/2
A
A= $$exp{$_}
Aresult
11
00
243 5 my $p = $tmp->child( $copy->[0] );
244 5 $p->parent->mkpath;
245 5 path( $copy->[1] )->copy($p);
246 }
247 8 ▶ rename "$tmp", "$out" or $self->_refuse( 'export', 'cannot move the export to '.$out.': '.$! );
Branch: 1 branch
BranchTrueFalseTotal
rename "$tmp", "$out" or $self->_refuse("export", 'cannot move the export to ' . $out . ': ' . $!) 8 0 8
248 8 my $back = eval { $self->load("$out") };
249 8 ▶ my $why = $back ? ( $back->digest eq $suite->digest ? undef : 'another digest' ) : "$@" =~ s/\s+\z//r;
Branch: 2 branches
BranchTrueFalseTotal
$back ? : 8 0 8
$back->digest eq $suite->digest ? : 8 0 8
250 8 ▶ if ( defined $why ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $why) 0 8 8
251 0 path($out)->remove_tree;
252 0 $self->_refuse( 'export', 'the export does not load back as the same suite ('.$why.'); nothing written' );
253 }
254 8 return "$out";
255 }
256  
257  
258 #### the canonical YAML of the export (k19)
259  
260 35 my %FIRST = do { my $i = 0; map { ( $_ => $i++ ) } qw( format id name title tool role version description ) };
261  
262 35 my %RESERVED = map { ( $_ => 1 ) } qw( y n yes no on off true false null );
263  
264 # a scalar YAML must escape: C0, DEL, C1, the Unicode line breaks, BOM, surrogates
265 35 my $ESCAPE = qr/[\x00-\x08\x0b-\x1f\x7f-\x9f\x{2028}\x{2029}\x{feff}\x{d800}-\x{dfff}]/;
266  
267 171 ▶sub _export_yaml {
Subroutine _export_yaml: called CC=4 SCAR=13.9
268 171 my ( $self, $data, $file, $field ) = @_;
269 171 my $text = eval { _y_node( $data, 0 ) };
270 171 ▶ $self->_refuse( $field, 'no format 2 image: '.( $@ =~ s/\s+\z//r ) ) unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 1 170 171
271 170 my $bytes = Encode::encode( 'UTF-8', $text =~ s/\A\n//r );
272 170 my $back = eval { YAML::XS::Load($bytes) };
273 170 ▶ my $where = defined $back ? _y_differs( $data, $back, '' ) : 'not valid YAML: '.( $@ =~ s/\s+\z//r );
Branch: 1 branch
BranchTrueFalseTotal
defined $back ? : 170 0 170
274 170 ▶ $self->_refuse( $field, 'the export of '.$file.' does not read back: '.$where ) if defined $where;
Branch: 1 branch
BranchTrueFalseTotal
if defined $where 0 170 170
275 170 return $bytes;
276 }
277  
278 12743 ▶sub _y_bool {
Subroutine _y_bool: called CC=6 SCAR=18.0
279 12743 my ( $s ) = @_;
280 12743 ▶ return 1 if blessed $s && $s->isa('JSON::PP::Boolean');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($s) and $s->isa("JSON::PP::Boolean") 2 12741 12743
Condition66%2/3
builtin::blessed($s) and $s->isa("JSON::PP::Boolean")
!ll&&!rl&&r
1274102
MC/DC50%1/2
builtin::blessed($s) and $s->isa("JSON::PP::Boolean")
builtin::blessed($s) $s->isa("JSON::PP::Boolean")
Truth table66%2/3
A and B
A= builtin::blessed($s)B= $s->isa("JSON::PP::Boolean")
ABresult
0X0
100
111
281 12741 ▶ return 0 if ref $s || !defined &builtin::is_bool;
Branch: 1 branch
BranchTrueFalseTotal
if ref $s or not defined &builtin::is_bool 1 12740 12741
Condition66%2/3
ref $s or not defined &builtin::is_bool
l!l&&r!l&&!r
1012740
MC/DC50%1/2
ref $s or not defined &builtin::is_bool
ref $s not defined &builtin::is_bool
Truth table66%2/3
A or not(B)
A= ref $sB= not defined &builtin::is_bool
ABresult
1X1
011
000
282 35 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
283 12740 ▶ return builtin::is_bool($s) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
builtin::is_bool($s) ? : 1 12739 12740
284 }
285  
286 4247 ▶sub _y_number {
Subroutine _y_number: called CC=4 SCAR=14.1
287 4247 my ( $s ) = @_;
288 4247 my $f = B::svref_2object( \$s )->FLAGS;
289 4247 ▶ return ( $f & ( B::SVp_IOK() | B::SVp_NOK() ) ) && !( $f & B::SVp_POK() )
Branch: 1 branch
BranchTrueFalseTotal
$f & 12288 && !($f & 16384) && $s =~ /\A-?[0-9]+(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?\z/ ? : 500 3747 4247
Condition66%4/6
$f & 12288 and not $f & 16384 and $s =~ /\A-?[0-9]+(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?\z/
!ll&&!rl&&r
37470500
$f & 12288 and not $f & 16384
!ll&&!rl&&r
37470500
MC/DC33%1/3
$f & 12288 and not $f & 16384 and $s =~ /\A-?[0-9]+(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?\z/
$f & 12288 not $f & 16384 $s =~ /\A-?[0-9]+(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?\z/
Truth table50%2/4
A and not(B) and C
A= $f & 12288B= not $f & 16384C= $s =~ /\A-?[0-9]+(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?\z/
ABCresult
0XX0
10X0
1100
1111
290 && $s =~ /\A-?[0-9]+(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?\z/ ? 1 : 0;
291 }
292  
293 # the text after "key:" or "-", ending with a line break
294 8204 ▶sub _y_node {
Subroutine _y_node: called CC=12 SCAR=24.9
295 8204 my ( $d, $ind ) = @_;
296 8204 ▶ if ( ref $d eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $d eq "HASH") 2624 5580 8204
297 2624 ▶ return " {}\n" unless %$d;
Branch: 1 branch
BranchTrueFalseTotal
unless %$d 8 2616 2624
298 6226 return "\n".join '', map { ( ' ' x $ind )._y_key($_).':'._y_node( $d->{$_}, $ind + 2 ) }
299 2616 ▶ sort { ( $FIRST{$a} // 99 ) <=> ( $FIRST{$b} // 99 ) or $a cmp $b } keys %$d;
Condition85%6/7
($FIRST{$a} // 99) <=> ($FIRST{$b} // 99) || $a cmp $b
l!l&&r!l&&!r
290930440
$FIRST{$a} // 99
l!l
18234130
$FIRST{$b} // 99
l!l
15954358
MC/DC0%0/2
($FIRST{$a} // 99) <=> ($FIRST{$b} // 99) || $a cmp $b
$FIRST{$a} $a cmp $b
MC/DC100%1/1
$FIRST{$b} // 99
$FIRST{$b}
Truth table66%2/3
A || B
A= $FIRST{$a}B= $a cmp $b
ABresult
1X1
011
000
Truth table100%2/2
A
A= $FIRST{$b}
Aresult
11
00
300 }
301 5580 ▶ if ( ref $d eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $d eq "ARRAY") 1247 4333 5580
302 1247 ▶ return " []\n" unless @$d;
Branch: 1 branch
BranchTrueFalseTotal
unless @$d 2 1245 1247
303 return "\n".join '', map {
304 1245 my $t = _y_node( $_, $ind + 2 );
305 1807 ▶ $t =~ s/\A\n {$ind} / / if ref $_ eq 'HASH' && %$_ || ref $_ eq 'ARRAY' && @$_;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ eq "HASH" and %$_ or ref $_ eq "ARRAY" and @$_ 1375 432 1807
Condition77%7/9
ref $_ eq "HASH" and %$_ or ref $_ eq "ARRAY" and @$_
l!l&&r!l&&!r
136510432
ref $_ eq "HASH" and %$_
!ll&&!rl&&r
44201365
ref $_ eq "ARRAY" and @$_
!ll&&!rl&&r
432010
MC/DC50%2/4
ref $_ eq "HASH" and %$_ or ref $_ eq "ARRAY" and @$_
ref $_ eq "HASH" %$_ ref $_ eq "ARRAY" @$_
Truth table42%3/7
A and B or C and D
A= ref $_ eq "HASH"B= %$_C= ref $_ eq "ARRAY"D= @$_
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
306 1807 ( ' ' x $ind ).'-'.$t;
307 } @$d;
308 }
309 4333 return ' '._y_scalar( $d, $ind )."\n";
310 }
311  
312 6226 ▶sub _y_key {
Subroutine _y_key: called CC=2 SCAR=7.1
313 6226 my ( $k ) = @_;
314 6226 ▶ return _y_plain($k) // _y_quoted($k);
Condition66%2/3
_y_plain($k) // _y_quoted($k)
l!l&&r!l&&!r
6183430
MC/DC0%0/2
_y_plain($k) // _y_quoted($k)
_y_plain($k) _y_quoted($k)
Truth table66%2/3
A // B
A= _y_plain($k)B= _y_quoted($k)
ABresult
1X1
011
000
315 }
316  
317 4333 ▶sub _y_scalar {
Subroutine _y_scalar: called CC=8 SCAR=20.9
318 4333 my ( $s, $ind ) = @_;
319 4333 ▶ return '~' unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 84 4249 4333
320 4249 ▶ return $s ? 'true' : 'false' if _y_bool($s);
Branch: 2 branches
BranchTrueFalseTotal
if _y_bool($s) 1 4248 4249
$s ? : 1 0 1
321 4248 ▶ die 'a '.ref($s)." reference\n" if ref $s;
Branch: 1 branch
BranchTrueFalseTotal
if ref $s 1 4247 4248
322 4247 ▶ return "$s" if _y_number($s);
Branch: 1 branch
BranchTrueFalseTotal
if _y_number($s) 500 3747 4247
323 3747 ▶ return _y_literal( $s, $ind ) // _y_plain($s) // _y_quoted($s);
Condition83%5/6
(_y_literal($s, $ind) // _y_plain($s)) // _y_quoted($s)
l!l&&r!l&&!r
33274200
_y_literal($s, $ind) // _y_plain($s)
l!l&&r!l&&!r
1383189420
MC/DC0%0/3
(_y_literal($s, $ind) // _y_plain($s)) // _y_quoted($s)
_y_literal($s, $ind) _y_plain($s) _y_quoted($s)
Truth table75%3/4
A // B // C
A= _y_literal($s, $ind)B= _y_plain($s)C= _y_quoted($s)
ABCresult
1XX1
01X1
0011
0000
324 }
325  
326 9835 ▶sub _y_plain {
Subroutine _y_plain: called CC=5 SCAR=16.1
327 9835 my ( $s ) = @_;
328 9835 ▶ return undef unless $s =~ m{\A[\p{L}/][\p{L}\p{N} _./+,?'()=:-]*\z} && $s !~ /(?: |:)\z|: /;
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ m[\A[\p{L}/][\p{L}\p{N} _./+,?'()=:-]*\z] and not $s =~ /(?: |:)\z|: / 384 9451 9835
Condition100%3/3
$s =~ m[\A[\p{L}/][\p{L}\p{N} _./+,?'()=:-]*\z] and not $s =~ /(?: |:)\z|: /
!ll&&!rl&&r
344409451
MC/DC100%2/2
$s =~ m[\A[\p{L}/][\p{L}\p{N} _./+,?'()=:-]*\z] and not $s =~ /(?: |:)\z|: /
$s =~ m[\A[\p{L}/][\p{L}\p{N} _./+,?'()=:-]*\z] not $s =~ /(?: |:)\z|: /
Truth table100%3/3
A and not(B)
A= $s =~ m[\A[\p{L}/][\p{L}\p{N} _./+,?'()=:-]*\z]B= not $s =~ /(?: |:)\z|: /
ABresult
0X0
100
111
329 9451 ▶ return undef if $RESERVED{ lc $s } || Scalar::Util::looks_like_number($s);
Branch: 1 branch
BranchTrueFalseTotal
if $RESERVED{lc $s} or &Scalar::Util::looks_like_number($s) 79 9372 9451
Condition66%2/3
$RESERVED{lc $s} or &Scalar::Util::looks_like_number($s)
l!l&&r!l&&!r
7909372
MC/DC50%1/2
$RESERVED{lc $s} or &Scalar::Util::looks_like_number($s)
$RESERVED{lc $s} &Scalar::Util::looks_like_number($s)
Truth table66%2/3
A or B
A= $RESERVED{lc $s}B= &Scalar::Util::looks_like_number($s)
ABresult
1X1
011
000
330 9372 return $s;
331 }
332  
333 463 ▶sub _y_quoted {
Subroutine _y_quoted: called CC=2 SCAR=7.0
334 463 my ( $s ) = @_;
335 463 $s =~ s/([\\"])/\\$1/g;
336 463 $s =~ s/\n/\\n/g;
337 463 $s =~ s/\t/\\t/g;
338 463 ▶ $s =~ s/($ESCAPE)/ord($1) > 0xff ? sprintf( '\\u%04x', ord $1 ) : sprintf( '\\x%02x', ord $1 )/ge;
Branch: 1 branch
BranchTrueFalseTotal
ord $1 > 255 ? : 16 0 16
339 463 return '"'.$s.'"';
340 }
341  
342 # a text with line breaks as a literal block -- only when it reads back as
343 # exactly this text (no character to escape, first line not indented)
344 3747 ▶sub _y_literal {
Subroutine _y_literal: called CC=10 SCAR=23.3
345 3747 my ( $s, $ind ) = @_;
346 3747 ▶ return undef unless $s =~ /\n/ && $s !~ $ESCAPE && $s !~ /\A\n*[ \t]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /\n/ and not $s =~ /$ESCAPE/ and not $s =~ /\A\n*[ \t]/ 3609 138 3747
Condition100%6/6
$s =~ /\n/ and not $s =~ /$ESCAPE/ and not $s =~ /\A\n*[ \t]/
!ll&&!rl&&r
359316138
$s =~ /\n/ and not $s =~ /$ESCAPE/
!ll&&!rl&&r
357716154
MC/DC100%3/3
$s =~ /\n/ and not $s =~ /$ESCAPE/ and not $s =~ /\A\n*[ \t]/
$s =~ /\n/ not $s =~ /$ESCAPE/ not $s =~ /\A\n*[ \t]/
Truth table100%4/4
A and not(B) and not(C)
A= $s =~ /\n/B= not $s =~ /$ESCAPE/C= not $s =~ /\A\n*[ \t]/
ABCresult
0XX0
10X0
1100
1111
347 138 ▶ my $chomp = $s =~ /\n\n\z/ ? '+' : $s =~ /\n\z/ ? '' : '-';
Branch: 2 branches
BranchTrueFalseTotal
$s =~ /\n\n\z/ ? : 26 112 138
$s =~ /\n\z/ ? : 102 10 112
348 138 my @lines = split /\n/, $s, -1;
349 138 ▶ pop @lines if $chomp ne '-'; # the empty piece after the last line break
Branch: 1 branch
BranchTrueFalseTotal
if $chomp ne "-" 128 10 138
350 276 ▶ my $render = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
351 276 my ( $n ) = @_;
352 276 ▶ return '|'.$chomp."\n".join "\n", map { length ? ( ' ' x $n ).$_ : '' } @lines;
Branch: 1 branch
BranchTrueFalseTotal
length $_ ? : 308 60 368
353 138 };
354 138 my $back = eval { YAML::XS::Load( Encode::encode( 'UTF-8', 'k: '.$render->(2)."\n" ) ) };
355 138 ▶ return undef unless ref $back eq 'HASH' && defined $back->{k} && $back->{k} eq $s;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $back eq "HASH" and defined $$back{"k"} and $$back{"k"} eq $s 0 138 138
Condition33%2/6
ref $back eq "HASH" and defined $$back{"k"} and $$back{"k"} eq $s
!ll&&!rl&&r
00138
ref $back eq "HASH" and defined $$back{"k"}
!ll&&!rl&&r
00138
MC/DC0%0/3
ref $back eq "HASH" and defined $$back{"k"} and $$back{"k"} eq $s
ref $back eq "HASH" defined $$back{"k"} $$back{"k"} eq $s
Truth table25%1/4
A and B and C
A= ref $back eq "HASH"B= defined $$back{"k"}C= $$back{"k"} eq $s
ABCresult
0XX0
10X0
1100
1111
356 138 return $render->($ind);
357 }
358  
359 # where $back differs from $data, or undef; a boolean is its truth value
360 8199 ▶sub _y_differs {
Subroutine _y_differs: called CC=21 SCAR=32.6
361 8199 my ( $d, $b, $at ) = @_;
362 8199 ▶ my $where = length $at ? $at : 'the top';
Branch: 1 branch
BranchTrueFalseTotal
length $at ? : 8029 170 8199
363 8199 ▶ if ( ref $d eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $d eq "HASH") 2621 5578 8199
364 2621 ▶ return $where.': not a hash' unless ref $b eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $b eq "HASH" 0 2621 2621
365 2621 my %k = map { ( $_ => 1 ) } keys %$d, keys %$b;
366 2621 for my $k ( sort keys %k ) {
367 6222 ▶ my $sub = length $at ? $at.'.'.$k : $k;
Branch: 1 branch
BranchTrueFalseTotal
length $at ? : 4858 1364 6222
368 6222 ▶ return $sub.': missing' unless exists $d->{$k} && exists $b->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$d{$k} and exists $$b{$k} 0 6222 6222
Condition33%1/3
exists $$d{$k} and exists $$b{$k}
!ll&&!rl&&r
006222
MC/DC0%0/2
exists $$d{$k} and exists $$b{$k}
exists $$d{$k} exists $$b{$k}
Truth table33%1/3
A and B
A= exists $$d{$k}B= exists $$b{$k}
ABresult
0X0
100
111
369 6222 my $w = _y_differs( $d->{$k}, $b->{$k}, $sub );
370 6222 ▶ return $w if defined $w;
Branch: 1 branch
BranchTrueFalseTotal
if defined $w 0 6222 6222
371 }
372 2621 return undef;
373 }
374 5578 ▶ if ( ref $d eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $d eq "ARRAY") 1247 4331 5578
375 1247 ▶ return $where.': not a list' unless ref $b eq 'ARRAY' && @$b == @$d;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $b eq "ARRAY" and @$b == @$d 0 1247 1247
Condition33%1/3
ref $b eq "ARRAY" and @$b == @$d
!ll&&!rl&&r
001247
MC/DC0%0/2
ref $b eq "ARRAY" and @$b == @$d
ref $b eq "ARRAY" @$b == @$d
Truth table33%1/3
A and B
A= ref $b eq "ARRAY"B= @$b == @$d
ABresult
0X0
100
111
376 1247 for my $i ( 0 .. $#$d ) {
377 1807 my $w = _y_differs( $d->[$i], $b->[$i], $at.'['.$i.']' );
378 1807 ▶ return $w if defined $w;
Branch: 1 branch
BranchTrueFalseTotal
if defined $w 0 1807 1807
379 }
380 1247 return undef;
381 }
382 4331 ▶ return defined $b ? $where.': not undef' : undef unless defined $d;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $d 84 4247 4331
defined $b ? : 0 84 84
383 4247 ▶ return $where.': undef' unless defined $b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b 0 4247 4247
384 4247 ▶ return $where.': not a text' if ref $b;
Branch: 1 branch
BranchTrueFalseTotal
if ref $b 0 4247 4247
385 4247 ▶ my ( $x, $y ) = map { _y_bool($_) ? ( $_ ? 1 : '' ) : "$_" } $d, $b;
Branch: 2 branches
BranchTrueFalseTotal
_y_bool($_) ? : 2 8492 8494
$_ ? : 2 0 2
386 4247 ▶ return $x eq $y ? undef : $where.': reads back as another value';
Branch: 1 branch
BranchTrueFalseTotal
$x eq $y ? : 4247 0 4247
387 }
388  
389 # runs $code; a refusal from it gets the field path of this front end: a field
390 # starting with $from (or 'suite.yaml', or anything for the head) starts with
391 # $label instead
392 173 ▶sub _relabel {
Subroutine _relabel: called CC=6 SCAR=18.7
393 173 my ( $self, $label, $from, $code ) = @_;
394 173 my @out = eval { $code->() };
395 173 ▶ if ( my $err = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 3 170 173
396 3 ▶ my $e = Langertha::Holmgang::Error->caught($err) or die $err;
Branch: 1 branch
BranchTrueFalseTotal
my $e = "Langertha::Holmgang::Error"->caught($err) or die $err 3 0 3
397 3 my $field = $e->field;
398 0 ▶ if ( defined $from ) { $field =~ s/\A\Q$from\E/$label/ or die $err }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $from) { } 0 3 3
$field =~ s/\A\Q$from\E/$label/ or die $err 0 0 0
399 3 ▶ else { $field =~ s/\Asuite\.yaml/$label/ or $field = $label.': '.$field }
Branch: 1 branch
BranchTrueFalseTotal
$field =~ s/\Asuite\.yaml/$label/ or $field = $label . ': ' . $field 1 2 3
400 3 $self->_refuse( $field, $e->reason );
401 }
402 170 return @out;
403 }
404  
405 # a suite directory holds suite.yaml (format 2) or suite.pl (the DSL)
406 22 ▶sub _suite_file {
Subroutine _suite_file: called CC=3 SCAR=11.0
407 22 my ( $self, $dir ) = @_;
408 22 ▶ return ( -f $dir.'/suite.yaml' || -f $dir.'/suite.pl' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
-f $dir . '/suite.yaml' || -f $dir . '/suite.pl' ? : 18 4 22
Condition100%3/3
-f $dir . '/suite.yaml' or -f $dir . '/suite.pl'
l!l&&r!l&&!r
1624
MC/DC100%2/2
-f $dir . '/suite.yaml' or -f $dir . '/suite.pl'
-f $dir . '/suite.yaml' -f $dir . '/suite.pl'
Truth table100%3/3
A or B
A= -f $dir . '/suite.yaml'B= -f $dir . '/suite.pl'
ABresult
1X1
011
000
409 }
410  
411 8 ▶sub _roots {
Subroutine _roots: called CC=1 SCAR=0.0
412 8 my ( $self, @roots ) = @_;
413 8 return grep { length } map { split /:/ } grep { defined } @roots;
414 }
415  
416 # A suite.yaml whose format is a name rather than a number (cai-platform's
417 # pii-1 corpus) is another kind of corpus, not a broken suite (k33).
418 12 ▶sub _foreign {
Subroutine _foreign: called CC=5 SCAR=16.1
419 12 my ( $self, $dir ) = @_;
420 12 my ( $head ) = eval { $self->_read_yaml( $dir.'/suite.yaml', 'suite.yaml' ) };
421 12 ▶ return 0 unless $head;
Branch: 1 branch
BranchTrueFalseTotal
unless $head 2 10 12
422 10 my $format = $head->{format};
423 10 ▶ return defined $format && !ref $format && $format !~ /\A[0-9]+\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $format && !ref($format) && !($format =~ /\A[0-9]+\z/) ? : 1 9 10
Condition83%5/6
defined $format and not ref $format and not $format =~ /\A[0-9]+\z/
!ll&&!rl&&r
181
defined $format and not ref $format
!ll&&!rl&&r
109
MC/DC66%2/3
defined $format and not ref $format and not $format =~ /\A[0-9]+\z/
defined $format not ref $format not $format =~ /\A[0-9]+\z/
Truth table75%3/4
A and not(B) and not(C)
A= defined $formatB= not ref $formatC= not $format =~ /\A[0-9]+\z/
ABCresult
0XX0
10X0
1100
1111
424 }
425  
426 4 ▶sub list {
Subroutine list: called CC=11 SCAR=24.1
Pod documented
427 4 my ( $self, @roots ) = @_;
428 4 my ( %where, @ids );
429 4 for my $root ( $self->_roots(@roots) ) {
430 6 my $r = path($root);
431 6 ▶ next unless $r->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $r->is_dir 0 6 6
432 6 ▶ for my $id ( sort grep { $self->structure->valid_id($_) && $self->_suite_file( $root.'/'.$_ ) } map { $_->basename } $r->children ) {
Condition33%1/3
$self->structure->valid_id($_) && $self->_suite_file($root . '/' . $_)
!ll&&!rl&&r
0014
MC/DC0%0/2
$self->structure->valid_id($_) && $self->_suite_file($root . '/' . $_)
$self->structure->valid_id($_) $self->_suite_file($root . '/' . $_)
Truth table33%1/3
A && B
A= $self->structure->valid_id($_)B= $self->_suite_file($root . '/' . $_)
ABresult
0X0
100
111
433 14 ▶ push @ids, $id unless $where{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless $where{$id} 13 1 14
434 14 push @{ $where{$id} }, $root;
435 }
436 }
437 4 my @out;
438 4 for my $id ( sort @ids ) {
439 13 ▶ if ( @{ $where{$id} } > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$where{$id};} > 1) 1 12 13
440 1 push @out, { id => $id, error => 'suite id in more than one search directory: '.join( ' ', @{ $where{$id} } ) };
441 1 next;
442 }
443 12 ▶ next if $self->_foreign( $where{$id}[0].'/'.$id );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_foreign($where{$id}[0] . '/' . $id) 1 11 12
444 11 my $s = eval { $self->load( $where{$id}[0].'/'.$id ) };
445 11 ▶ unless ( $s ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s) 6 5 11
446 6 my $err = $@;
447 6 ▶ push @out, { id => $id, error => ref $err ? "$err" : ( $err =~ s/\s+\z//r ) };
Branch: 1 branch
BranchTrueFalseTotal
ref $err ? : 6 0 6
448 6 next;
449 }
450 push @out, {
451 id => $s->id,
452 version => $s->version,
453 title => $s->title,
454 description => $s->description,
455 topic => $s->topic,
456 5 cases => scalar @{ $s->cases },
457 5 tools => scalar @{ $s->tools },
458 digest => $s->digest,
459 error => undef,
460 };
461 }
462 4 return \@out;
463 }
464  
465  
466 5 ▶sub locate {
Subroutine locate: called CC=4 SCAR=13.9
Pod documented
467 5 my ( $self, $roots, $id ) = @_;
468 5 ▶ return undef unless $self->structure->valid_id($id);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->structure->valid_id($id) 1 4 5
469 4 my @hits = grep { $self->_suite_file( $_.'/'.$id ) } $self->_roots($roots);
470 4 ▶ $self->_refuse( suite => "suite id '".$id."' in more than one search directory: ".join( ' ', @hits ) ) if @hits > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @hits > 1 1 3 4
471 3 ▶ return @hits ? $hits[0].'/'.$id : undef;
Branch: 1 branch
BranchTrueFalseTotal
@hits ? : 2 1 3
472 }
473  
474  
475 6 ▶sub select_suites {
Subroutine select_suites: called CC=12 SCAR=24.8
Pod documented
476 6 my ( $self, $suites, %o ) = @_;
477 6 my %ok = map { $_->{id} => $_ } grep { !$_->{error} } @$suites;
478 6 my %pick;
479 6 ▶ if ( $o{all} ) { $pick{$_} = 1 for keys %ok }
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"all"}) 1 5 6
480 6 my %topic;
481 6 push @{ $topic{ $_->{topic} } }, $_->{id} for values %ok;
482 6 ▶ for my $t ( @{ $o{topics} || [] } ) {
Condition100%2/2
$o{'topics'} || []
l!l
33
MC/DC100%1/1
$o{'topics'} || []
$o{'topics'}
Truth table100%2/2
A
A= $o{'topics'}
Aresult
11
00
483 3 ▶ $self->_refuse( topics => "unknown topic '".$t."' (".join( ', ', sort keys %topic ).')' ) unless $topic{$t};
Branch: 1 branch
BranchTrueFalseTotal
unless $topic{$t} 1 2 3
484 2 $pick{$_} = 1 for @{ $topic{$t} };
485 }
486 5 ▶ for my $id ( @{ $o{suites} || [] } ) {
Condition100%2/2
$o{'suites'} || []
l!l
23
MC/DC100%1/1
$o{'suites'} || []
$o{'suites'}
Truth table100%2/2
A
A= $o{'suites'}
Aresult
11
00
487 2 ▶ $self->_refuse( suites => "unknown or broken suite '".$id."'" ) unless $ok{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless $ok{$id} 1 1 2
488 1 $pick{$id} = 1;
489 }
490 4 ▶ $self->_refuse( suites => 'no suite chosen (topic, suite or all)' ) unless %pick;
Branch: 1 branch
BranchTrueFalseTotal
unless %pick 1 3 4
491 3 return sort keys %pick;
492 }
493  
494  
495 35 __PACKAGE__->meta->make_immutable;
496  
497 __END__
« blib/lib/Langertha/Holmgang/Simulators.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/IOS.pm »