| 1 | package Game::Brandubh::Variant; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 45 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 45 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 45 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 45 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 45 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 45 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 45 | our (@FIELDS, %DEFAULT, %NAMED); | |||||||||||||||||||||||||||||||||||||||||
| 13 | 45 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 45 | @FIELDS = qw( | |||||||||||||||||||||||||||||||||||||||||
| 15 | escape | ||||||||||||||||||||||||||||||||||||||||||
| 16 | king_everywhere_two | ||||||||||||||||||||||||||||||||||||||||||
| 17 | king_strong | ||||||||||||||||||||||||||||||||||||||||||
| 18 | throne_reentry | ||||||||||||||||||||||||||||||||||||||||||
| 19 | throne_pass | ||||||||||||||||||||||||||||||||||||||||||
| 20 | repeat | ||||||||||||||||||||||||||||||||||||||||||
| 21 | ply_cap | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 45 | %DEFAULT = ( | |||||||||||||||||||||||||||||||||||||||||
| 24 | escape => 'corner', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | king_everywhere_two => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | king_strong => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | throne_reentry => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | throne_pass => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | repeat => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ply_cap => 400, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 45 | %NAMED = ( | |||||||||||||||||||||||||||||||||||||||||
| 33 | brandubh => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 45 | ▶ | use constant PLY_CAP_MAX => 4096; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 45 | has name => (is => 'ro', default => 'brandubh'); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 45 | has escape => (is => 'ro', default => 'corner'); | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 45 | has king_everywhere_two => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 45 | has king_strong => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 45 | has throne_reentry => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 45 | has throne_pass => (is => 'ro', default => 1); | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 45 | has repeat => (is => 'ro', default => 3); | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 45 | has ply_cap => (is => 'ro', default => 400); | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 45 | my $MAKING = 0; | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 2086 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 2086 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 2086 | ▶ | Carp::croak('Game::Brandubh::Variant: a rule set is made by named, custom or from_string') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | unless $MAKING; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 2083 | return; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 2105 | ▶ | my $checked = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=20 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 2105 | my ($class, %fields) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2105 | for my $field (sort keys %fields) { | |||||||||||||||||||||||||||||||||||||||||
| 68 | Carp::croak("Game::Brandubh::Variant: no field is called '$field'") | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 1796 | ▶ | unless exists $DEFAULT{$field}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | Carp::croak("Game::Brandubh::Variant: $field has no value") | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 1790 | ▶ | unless defined $fields{$field} && !ref $fields{$field}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $fields{$field} and not ref $fields{$field}
MC/DC100%2/2
defined $fields{$field} and not ref $fields{$field}
defined $fields{$field}
not ref $fields{$field}
Truth table100%3/3
A and not(B)
A= defined $fields{$field}B= not ref $fields{$field}
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 2097 | my %all = (%DEFAULT, %fields); | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | Carp::croak("Game::Brandubh::Variant: escape is 'corner' or 'edge', not '$all{escape}'") | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 2097 | ▶ | unless $all{escape} eq 'corner' || $all{escape} eq 'edge'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$all{"escape"} eq "corner" or $all{"escape"} eq "edge"
MC/DC100%2/2
$all{"escape"} eq "corner" or $all{"escape"} eq "edge"
$all{"escape"} eq "corner"
$all{"escape"} eq "edge"
Truth table100%3/3
A or B
A= $all{"escape"} eq "corner"B= $all{"escape"} eq "edge"
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 2095 | for my $flag (qw(king_everywhere_two king_strong throne_reentry throne_pass)) { | |||||||||||||||||||||||||||||||||||||||||
| 78 | Carp::croak("Game::Brandubh::Variant: $flag is 0 or 1, not '$all{$flag}'") | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 8378 | ▶ | unless $all{$flag} =~ /\A[01]\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 8376 | $all{$flag} += 0; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | Carp::croak("Game::Brandubh::Variant: repeat is a whole number from 2 up, not '$all{repeat}'") | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 2093 | ▶ | unless $all{repeat} =~ /\A[0-9]{1,6}\z/ && $all{repeat} >= 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$all{"repeat"} =~ /\A[0-9]{1,6}\z/ and $all{"repeat"} >= 2
MC/DC100%2/2
$all{"repeat"} =~ /\A[0-9]{1,6}\z/ and $all{"repeat"} >= 2
$all{"repeat"} =~ /\A[0-9]{1,6}\z/
$all{"repeat"} >= 2
Truth table100%3/3
A and B
A= $all{"repeat"} =~ /\A[0-9]{1,6}\z/B= $all{"repeat"} >= 2
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | Carp::croak("Game::Brandubh::Variant: ply_cap is a whole number from 1 to " . PLY_CAP_MAX . ", not '$all{ply_cap}'") | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 2088 | ▶ | unless $all{ply_cap} =~ /\A[0-9]{1,5}\z/ && $all{ply_cap} >= 1 && $all{ply_cap} <= PLY_CAP_MAX; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$all{"ply_cap"} =~ /\A[0-9]{1,5}\z/ and $all{"ply_cap"} >= 1 and $all{"ply_cap"} <= 4096
$all{"ply_cap"} =~ /\A[0-9]{1,5}\z/ and $all{"ply_cap"} >= 1
MC/DC100%3/3
$all{"ply_cap"} =~ /\A[0-9]{1,5}\z/ and $all{"ply_cap"} >= 1 and $all{"ply_cap"} <= 4096
$all{"ply_cap"} =~ /\A[0-9]{1,5}\z/
$all{"ply_cap"} >= 1
$all{"ply_cap"} <= 4096
Truth table100%4/4
A and B and C
A= $all{"ply_cap"} =~ /\A[0-9]{1,5}\z/B= $all{"ply_cap"} >= 1C= $all{"ply_cap"} <= 4096
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 2085 | $all{$_} += 0 for qw(repeat ply_cap); | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | Carp::croak('Game::Brandubh::Variant: king_everywhere_two and king_strong contradict each other') | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 2085 | ▶ | if $all{king_everywhere_two} && $all{king_strong}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$all{"king_everywhere_two"} and $all{"king_strong"}
MC/DC100%2/2
$all{"king_everywhere_two"} and $all{"king_strong"}
$all{"king_everywhere_two"}
$all{"king_strong"}
Truth table100%3/3
A and B
A= $all{"king_everywhere_two"}B= $all{"king_strong"}
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 2083 | my $name = 'custom'; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 2083 | for my $known (sort keys %NAMED) { | |||||||||||||||||||||||||||||||||||||||||
| 93 | 2083 | my %set = (%DEFAULT, %{ $NAMED{$known} }); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 2083 | ▶ | next if grep { $set{$_} ne $all{$_} } @FIELDS; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 642 | $name = $known; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 642 | last; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 2083 | $MAKING = 1; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 2083 | my $made = eval { $class->new(name => $name, %all) }; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 2083 | my $died = $@; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 2083 | $MAKING = 0; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 2083 | ▶ | Carp::croak($died) unless $made; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 2083 | return $made; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 45 | }; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 641 | ▶ | sub named { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
named: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 641 | my ($class, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 641 | ▶ | $name = 'brandubh' unless defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | Carp::croak("Game::Brandubh::Variant: no rule set is called '$name'") | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 641 | ▶ | unless !ref $name && exists $NAMED{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $name and exists $Game::Brandubh::Variant::NAMED{$name}
MC/DC50%1/2
not ref $name and exists $Game::Brandubh::Variant::NAMED{$name}
not ref $name
exists $Game::Brandubh::Variant::NAMED{$name}
Truth table66%2/3
not(A) and B
A= not ref $nameB= exists $Game::Brandubh::Variant::NAMED{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 639 | return $checked->($class, %{ $NAMED{$name} }); | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 1394 | ▶ | sub custom { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
custom: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 1394 | my ($class, @fields) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 1394 | ▶ | Carp::croak('Game::Brandubh::Variant: custom takes field => value pairs') if @fields % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 1393 | return $checked->($class, @fields); | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 223 | ▶ | sub from_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_string: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 223 | my ($class, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 223 | ▶ | return undef unless defined $text && !ref $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $text and not ref $text
MC/DC100%2/2
defined $text and not ref $text
defined $text
not ref $text
Truth table100%3/3
A and not(B)
A= defined $textB= not ref $text
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 221 | $text =~ s/\A\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 221 | $text =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 221 | ▶ | return eval { $class->named($text) } if exists $NAMED{$text}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 84 | ▶ | my ($list) = $text =~ /\Acustom(?:[ \t]+(\S+))?\z/ or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 75 | my %fields; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 75 | ▶ | for my $pair (split /,/, defined $list ? $list : '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 137 | ▶ | my ($field, $value) = $pair =~ /\A(\w+)=(\w+)\z/ or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 136 | ▶ | return undef if exists $fields{$field}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 135 | $fields{$field} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 73 | return eval { $checked->($class, %fields) }; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 304 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 304 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 304 | ▶ | return $self->name if exists $NAMED{ $self->name }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 93 | my @differ = grep { $self->$_ ne $DEFAULT{$_} } @FIELDS; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 93 | return 'custom ' . join(',', map { "$_=" . $self->$_ } @differ); | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 2853 | ▶ | sub as_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_hash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 2853 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 2853 | return { map { $_ => $self->$_ } @FIELDS }; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 616 | ▶ | sub equals { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equals: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 616 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 616 | ▶ | return 0 unless ref $other && ref $other eq ref $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $other and ref $other eq ref $self
MC/DC100%2/2
ref $other and ref $other eq ref $self
ref $other
ref $other eq ref $self
Truth table100%3/3
A and B
A= ref $otherB= ref $other eq ref $self
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 613 | ▶ | return (grep { $self->$_ ne $other->$_ } @FIELDS) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | ▶ | sub fields { @FIELDS } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | ▶ | sub names { sort keys %NAMED } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 45 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||||||||||||||||||||||||