| 1 | package Game::Dominoes::Tile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 6304571 | ▶ | sub _offset { my ($l) = @_; return 7 * $l - ($l * ($l - 1)) / 2 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_offset: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | has high => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | isa => Int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 17 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | has low => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | isa => Int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 17 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 772 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 772 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 772 | for my $face (qw/high low/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1543 | my $v = $self->$face; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1543 | ▶ | die "Game::Dominoes::Tile: $face must be a face from 0 to 6" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $v and $v =~ /\A[0-6]\z/
MC/DC50%1/2
defined $v and $v =~ /\A[0-6]\z/
defined $v
$v =~ /\A[0-6]\z/
Truth table66%2/3
A and B
A= defined $vB= $v =~ /\A[0-6]\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | unless defined $v && $v =~ /\A[0-6]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 770 | ▶ | die 'Game::Dominoes::Tile: high must not be less than low' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | if $self->high < $self->low; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 769 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 264 | ▶ | sub of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
of: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 264 | my ($class, $a, $b) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 264 | ▶ | ($a, $b) = ($b, $a) if defined $a && defined $b && $a < $b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $a and defined $b and $a < $b
defined $a and defined $b
MC/DC33%1/3
defined $a and defined $b and $a < $b
defined $a
defined $b
$a < $b
Truth table50%2/4
A and B and C
A= defined $aB= defined $bC= $a < $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 264 | return $class->new(high => $a, low => $b); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 6302184 | ▶ | sub id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 6302184 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 6302184 | return _offset($self->low) + ($self->high - $self->low) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 478 | ▶ | sub from_id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_id: called CC=8 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 478 | my ($class, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 478 | ▶ | die "Game::Dominoes::Tile: no tile has id " . (defined $id ? $id : 'undef') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition44%4/9
defined $id and $id =~ /\A\d+\z/ and $id >= 1 and $id <= 28
defined $id and $id =~ /\A\d+\z/ and $id >= 1
defined $id and $id =~ /\A\d+\z/
MC/DC25%1/4
defined $id and $id =~ /\A\d+\z/ and $id >= 1 and $id <= 28
defined $id
$id =~ /\A\d+\z/
$id >= 1
$id <= 28
Truth table40%2/5
A and B and C and D
A= defined $idB= $id =~ /\A\d+\z/C= $id >= 1D= $id <= 28
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | unless defined $id && $id =~ /\A\d+\z/ && $id >= 1 && $id <= 28; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 477 | for my $low (reverse 0 .. 6) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2387 | my $offset = _offset($low); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2387 | ▶ | next if $offset >= $id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 477 | return $class->new(low => $low, high => $low + ($id - $offset - 1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | die 'unreachable'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3071004 | ▶ | sub is_double { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_double: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3071004 | ▶ | return $_[0]->high == $_[0]->low ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 469500 | ▶ | sub pips { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pips: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 469500 | return $_[0]->high + $_[0]->low; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 5550587 | ▶ | sub has_face { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_face: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 5550587 | my ($self, $face) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 5550587 | ▶ | return 0 unless defined $face; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 5550586 | ▶ | return ($self->high == $face || $self->low == $face) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->high == $face or $self->low == $face
MC/DC100%2/2
$self->high == $face or $self->low == $face
$self->high == $face
$self->low == $face
Truth table100%3/3
A or B
A= $self->high == $faceB= $self->low == $face
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 872951 | ▶ | sub other { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
other: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 872951 | my ($self, $face) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 872951 | ▶ | die 'Game::Dominoes::Tile: that tile does not carry face ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | . (defined $face ? $face : 'undef') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | unless $self->has_face($face); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 872950 | ▶ | return $self->high == $face ? $self->low : $self->high; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub equals { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equals: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | return 0 unless ref $other; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | return $self->id == $other->id ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 9800 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 9800 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 9800 | return $self->high . '-' . $self->low; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||