| 1 | package Game::RoyalUr::Variant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 58 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 58 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 58 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 58 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 58 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 58 | ▶ | use Object::Proto::Sugar; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 58 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 58 | my (@FIELDS, %NAMED, %ALLOWED); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 58 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 58 | @FIELDS = qw(route dice zero_rolls safe_rosettes pieces); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 58 | %NAMED = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | finkel => { route => 'short', dice => 4, zero_rolls => 0, safe_rosettes => 1, pieces => 7 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | masters => { route => 'long', dice => 3, zero_rolls => 4, safe_rosettes => 0, pieces => 7 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 58 | %ALLOWED = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | route => qr/\A(?:short|long)\z/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | dice => qr/\A[34]\z/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | zero_rolls => qr/\A[04]\z/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | safe_rosettes => qr/\A[01]\z/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | pieces => qr/\A[1-7]\z/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 58 | has route => (is => 'ro', default => 'short'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 58 | has dice => (is => 'ro', default => 4); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 58 | has zero_rolls => (is => 'ro', default => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 58 | has safe_rosettes => (is => 'ro', default => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 58 | has pieces => (is => 'ro', default => 7); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1549 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1549 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1549 | for my $field (@FIELDS) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 7693 | my $value = $self->$field; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | Carp::croak("Game::RoyalUr::Variant: $field may not be '" . ($value // 'undef') . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 7693 | ▶ | unless defined $value && !ref $value && $value =~ $ALLOWED{$field}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%8/8
defined $value and not ref $value and $value =~ /$ALLOWED{$field}/
defined $value and not ref $value
$value // "undef"
MC/DC100%3/3
defined $value and not ref $value and $value =~ /$ALLOWED{$field}/
defined $value
not ref $value
$value =~ /$ALLOWED{$field}/
MC/DC100%1/1
$value // "undef"
$value
Truth table100%4/4
A and not(B) and C
A= defined $valueB= not ref $valueC= $value =~ /$ALLOWED{$field}/
Truth table100%2/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1525 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | sub fields { @FIELDS } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2430 | ▶ | sub names { sort keys %NAMED } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1500 | ▶ | sub named { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
named: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1500 | my ($class, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | Carp::croak("Game::RoyalUr::Variant: no rule set is called '" . ($name // 'undef') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | . "'; the names are " . join(', ', $class->names)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1500 | ▶ | unless defined $name && !ref $name && exists $NAMED{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition87%7/8
defined $name and not ref $name and exists $NAMED{$name}
defined $name and not ref $name
$name // "undef"
MC/DC66%2/3
defined $name and not ref $name and exists $NAMED{$name}
defined $name
not ref $name
exists $NAMED{$name}
MC/DC100%1/1
$name // "undef"
$name
Truth table75%3/4
A and not(B) and C
A= defined $nameB= not ref $nameC= exists $NAMED{$name}
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1495 | return $class->new(%{ $NAMED{$name} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 44 | ▶ | sub custom { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
custom: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 44 | my ($class, %given) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 44 | for my $key (sort keys %given) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 78 | ▶ | Carp::croak("Game::RoyalUr::Variant: no rule is called '$key'") unless exists $ALLOWED{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 42 | return $class->new(%given); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 13098 | ▶ | sub of { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
of: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 13098 | my ($class, $rules) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 13098 | ▶ | return $class->named('finkel') unless defined $rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 12963 | ▶ | return $rules if Scalar::Util::blessed($rules) && $rules->isa($class); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($rules) and $rules->isa($class)
MC/DC50%1/2
builtin::blessed($rules) and $rules->isa($class)
builtin::blessed($rules)
$rules->isa($class)
Truth table66%2/3
A and B
A= builtin::blessed($rules)B= $rules->isa($class)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1379 | ▶ | return $class->custom(%$rules) if ref $rules eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1353 | ▶ | Carp::croak('Game::RoyalUr::Variant: a rule set is a name, a hash reference or a variant') if ref $rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1352 | return $class->named($rules); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 7097 | ▶ | sub as_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_hash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 7097 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 7097 | return { map { $_ => $self->$_ } @FIELDS }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 5 | ▶ | sub equals { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equals: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 5 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 5 | ▶ | return 0 unless Scalar::Util::blessed($other) && $other->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($other) and $other->isa(__PACKAGE__)
MC/DC50%1/2
builtin::blessed($other) and $other->isa(__PACKAGE__)
builtin::blessed($other)
$other->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= builtin::blessed($other)B= $other->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | for my $field (@FIELDS) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 11 | ▶ | return 0 unless $self->$field eq $other->$field; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2424 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2424 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2424 | for my $name ($self->names) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 3284 | ▶ | return $name unless grep { $self->$_ ne $NAMED{$name}{$_} } @FIELDS; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 9 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 6338 | ▶ | sub describe { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
describe: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 6338 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 6338 | return join ' ', map { $_ . '=' . $self->$_ } @FIELDS; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 58 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||