| 1 | package Game::WordBrain::Letter; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 16 | ▶ | use overload '==' => \&_operator_equality, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 16 | '""' => \&_operator_stringify; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 16 | our $VERSION = '0.2.2'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 10 | # ABSTRACT: Representation of a Letter in a WordBrain Game | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | Game::WordBrain::Letter - Representation of a Letter in a WordBrain Game | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | # Create a new Game::WordBrain::Letter | ||||||||||||||||||||||||||||||||||||||||||
| 19 | my $letter = Game::WordBrain::Letter->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 20 | letter => 'a', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | row => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | col => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # Stringification is overloaded | ||||||||||||||||||||||||||||||||||||||||||
| 26 | print $letter; # prints 'a' | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # Equality is overloaded | ||||||||||||||||||||||||||||||||||||||||||
| 29 | if( $letter == $letter ) { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | print "Same letter!'; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | Represents a Letter in a WordBrain Game. | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =head2 B<letter> | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | A single character string that contains the actual letter represented [a-z]. | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | =head2 B<row> | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | The row in a WordBrain game where this letter appears. | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | =head2 B<col> | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | The col in a WordBrain game where this letter appears. | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | my $letter = Game::WordBrain::Letter->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 56 | letter => 'a', | ||||||||||||||||||||||||||||||||||||||||||
| 57 | row => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | col => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | Given a letter, a row, and a col, returns an instance of a Game::WordBrain::Letter. | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 696 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 696 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 696 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 696 | return bless $args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 39314 | ▶ | sub _operator_equality { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_operator_equality: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 39314 | my ( $a, $b ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 39314 | ▶ | if( $a->{letter} eq $b->{letter} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$a->{"letter"} eq $b->{"letter"} and $a->{"row"} == $b->{"row"} and $a->{"col"} == $b->{"col"}
$a->{"letter"} eq $b->{"letter"} and $a->{"row"} == $b->{"row"}
MC/DC100%3/3
$a->{"letter"} eq $b->{"letter"} and $a->{"row"} == $b->{"row"} and $a->{"col"} == $b->{"col"}
$a->{"letter"} eq $b->{"letter"}
$a->{"row"} == $b->{"row"}
$a->{"col"} == $b->{"col"}
Truth table100%4/4
A and B and C
A= $a->{"letter"} eq $b->{"letter"}B= $a->{"row"} == $b->{"row"}C= $a->{"col"} == $b->{"col"}
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | && $a->{row} == $b->{row} | ||||||||||||||||||||||||||||||||||||||||||
| 77 | && $a->{col} == $b->{col} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 6616 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 32698 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 13000 | ▶ | sub _operator_stringify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_operator_stringify: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 13000 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 13000 | return $self->{letter}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||