blib/lib/Game/Oware/Variant.pm

filter: Statementstmt 85.2% 29 / 34 Branchbran 100% 6 / 6 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 80.0% 8 / 10 Podpod 100% 5 / 5 totaltotal 87.9% 51 / 58 CC 5 SCAR 6.9
CC
5
Cov
88%
is_variant
3.0
check_variant
3.0
fields
2.0
CRAP 2.0
« blib/lib/Game/Oware/Scoring.pm ↑ Summary bin/oware »
1 package Game::Oware::Variant;
2  
3 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 22 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 22 our $VERSION = '0.04';
9  
10 22 our @EXPORT_OK = qw(variants is_variant check_variant spec_for fields
11 grand_slam target draw_at
12 repetition_limit plies_without_capture);
13  
14 22 my %SPEC = (
15 abapa => {
16 grand_slam => 'no_capture',
17 target => 25,
18 draw_at => 24,
19 repetition_limit => 3,
20 plies_without_capture => 500,
21 },
22 awari => {
23 grand_slam => 'illegal_unless_only',
24 target => 25,
25 draw_at => 24,
26 repetition_limit => 3,
27 plies_without_capture => 500,
28 },
29 );
30  
31 22 my @FIELDS = sort keys %{ $SPEC{abapa} };
32  
33 11 ▶sub variants { return sort keys %SPEC }
Subroutine variants: called CC=1 SCAR=0.0
Pod documented
34  
35 0 ▶sub fields { return @FIELDS }
Subroutine fields: not called CC=1 SCAR=6.9
Pod documented
36  
37 1704076 ▶sub is_variant { return exists $SPEC{ $_[0] // '' } ? 1 : 0 }
Subroutine is_variant: called CC=3 SCAR=11.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
exists $SPEC{$_[0] // ''} ? : 1704071 5 1704076
Condition100%2/2
$_[0] // ""
l!l
17040751
MC/DC100%1/1
$_[0] // ""
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
38  
39 1704073 ▶sub check_variant {
Subroutine check_variant: called CC=3 SCAR=11.0
Pod documented
40 1704073 my ($variant) = @_;
41 1704073 ▶ die "Game::Oware::Variant: there is no variant '"
Branch: 2 branches
BranchTrueFalseTotal
unless is_variant($variant) 4 1704069 1704073
defined $variant ? : 3 1 4
42 . (defined $variant ? $variant : 'undef') . "'"
43 unless is_variant($variant);
44 1704069 return $variant;
45 }
46  
47 0 ▶sub spec_for {
Subroutine spec_for: not called CC=1 SCAR=6.9
Pod documented
48 0 my ($variant) = @_;
49 0 check_variant($variant);
50 0 return { %{ $SPEC{$variant} } };
51 }
52  
53 22 for my $field (@FIELDS) {
54 22 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
55 110 ▶ *{ __PACKAGE__ . '::' . $field } = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
56 857637 my ($variant) = @_;
57 857637 check_variant($variant);
58 857637 return $SPEC{$variant}{$field};
59 110 };
60 }
61  
62 22 1;
63  
64 __END__
« blib/lib/Game/Oware/Scoring.pm ↑ Summary bin/oware »