| 1 | 2 | ▶ | use 5.008; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Games::Go::Rank; | ||||||||||||||||||||
| 6 | 2 | our $VERSION = '1.100860'; | |||||||||||||||||||
| 7 | # ABSTRACT: Represents a player's rank in the game of Go | ||||||||||||||||||||
| 8 | 2 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | use overload | ||||||||||||||||||||
| 10 | 2 | ▶ | '""' => 'stringify', | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | '<=>' => 'num_cmp'; | |||||||||||||||||||
| 12 | 2 | has 'rank' => (is => 'rw'); | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 0 | ▶ | sub stringify { | ||||||||||||||||||
|
Subroutine
stringify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 15 | 0 | my $self = shift; | |||||||||||||||||||
| 16 | 0 | $self->rank; | |||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 145 | ▶ | sub as_value { | ||||||||||||||||||
|
Subroutine
as_value: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||
| 20 | 145 | my $self = shift; | |||||||||||||||||||
| 21 | 145 | my $rank = $self->rank; | |||||||||||||||||||
| 22 | 145 | ▶ | return unless defined $rank; # so m// doesn't complain | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 145 | ▶ | if ($rank =~ /^\s*(\d+)[\s-]*k/) { return -$1 + 1 } | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 24 | 60 | elsif ($rank =~ /^\s*(\d+)[\s-]*d/) { return $1 } | |||||||||||||||||||
| 25 | 45 | elsif ($rank =~ /^\s*(\d+)[\s-]*p/) { return $1 + 7 } | |||||||||||||||||||
| 26 | 0 | else { return } | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 8 | ▶ | sub from_value { | ||||||||||||||||||
|
Subroutine
from_value: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||
| 30 | 8 | my ($self, $value) = @_; | |||||||||||||||||||
| 31 | 8 | ▶ | if ($value <= 0) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 32 | 3 | $self->rank(sprintf "%sk" => -$value + 1); | |||||||||||||||||||
| 33 | ▶ | } elsif ($value > 0 && $value <= 7) { | |||||||||||||||||||
|
Condition66%2/3
$value > 0 and $value <= 7
MC/DC50%1/2
$value > 0 and $value <= 7
$value > 0
$value <= 7
Truth table66%2/3
A and B
A= $value > 0B= $value <= 7
| |||||||||||||||||||||
| 34 | 3 | $self->rank(sprintf "%sd" => $value); | |||||||||||||||||||
| 35 | } elsif ($value > 7) { | ||||||||||||||||||||
| 36 | 2 | $self->rank(sprintf "%sp" => $value - 7); | |||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||
| 38 | 0 | $self->clear_rank; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | 8 | return $self; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 66 | ▶ | sub num_cmp { | ||||||||||||||||||
|
Subroutine
num_cmp: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 44 | 66 | my ($lhs, $rhs, $reversed) = @_; | |||||||||||||||||||
| 45 | 66 | for ($lhs, $rhs) { | |||||||||||||||||||
| 46 | 132 | ▶ | if (ref $_ eq __PACKAGE__) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 88 | $_ = $_->as_value; | |||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||
| 49 | 44 | $_ = __PACKAGE__->new(rank => $_)->as_value; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | 66 | ▶ | ($lhs, $rhs) = ($rhs, $lhs) if $reversed; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 66 | ▶ | for ($lhs, $rhs) { $_ = -99 unless defined($_) } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 66 | $lhs <=> $rhs; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | 2 | 1; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||