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 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 19 our $VERSION = '0.03';
9  
10 19 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 19 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 19 my @FIELDS = sort keys %{ $SPEC{abapa} };
32  
33 2 ▶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 1509891 ▶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] // ''} ? : 1509887 4 1509891
Condition100%2/2
$_[0] // ""
l!l
15098901
MC/DC100%1/1
$_[0] // ""
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
38  
39 1509891 ▶sub check_variant {
Subroutine check_variant: called CC=3 SCAR=11.0
Pod documented
40 1509891 my ($variant) = @_;
41 1509891 ▶ die "Game::Oware::Variant: there is no variant '"
Branch: 2 branches
BranchTrueFalseTotal
unless is_variant($variant) 4 1509887 1509891
defined $variant ? : 3 1 4
42 . (defined $variant ? $variant : 'undef') . "'"
43 unless is_variant($variant);
44 1509887 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 19 for my $field (@FIELDS) {
54 19 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
55 95 ▶ *{ __PACKAGE__ . '::' . $field } = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
56 757893 my ($variant) = @_;
57 757893 check_variant($variant);
58 757893 return $SPEC{$variant}{$field};
59 95 };
60 }
61  
62 19 1;
63  
64 __END__
« blib/lib/Game/Oware/Scoring.pm ↑ Summary bin/oware »