| 1 | package Games::YASudoku::Square; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # Andrew Wyllie <wyllie@dilex.net> | ||||||||||||||||||||
| 4 | # July 2005 | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | =head1 MODULE | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | Games::YASudoku::Square | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | this object will be used to represent a single square | ||||||||||||||||||||
| 13 | on the sudoku board. | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =head1 METHODS | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =over | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =item B<new( $id )> | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | create a new square on the board at location $id | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 327 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||
| 29 | 327 | my $proto = shift; | |||||||||||||||||||
| 30 | 327 | ▶ | my $class = ref ( $proto ) || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | # this is the element_id | ||||||||||||||||||||
| 33 | 327 | my $id = shift; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 327 | my $self = { | |||||||||||||||||||
| 36 | id => $id, | ||||||||||||||||||||
| 37 | value => undef, | ||||||||||||||||||||
| 38 | valid => {} | ||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 327 | bless $self, $class; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | =item B<id> | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | get the id of the element | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 5916 | ▶ | sub id { | ||||||||||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 52 | 5916 | my $self = shift; | |||||||||||||||||||
| 53 | 5916 | return $self->{'id'}; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =item B<value> | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | get or set the value for this square | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =cut | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 70695 | ▶ | sub value { | ||||||||||||||||||
|
Subroutine
value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 64 | 70695 | my $self = shift; | |||||||||||||||||||
| 65 | 70695 | my $value = shift; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 70695 | ▶ | $self->{'value'} = $value if $value; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 70695 | return $self->{'value'}; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | =item B<valid> | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | get the values in the valid array. | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =cut | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 20994 | ▶ | sub valid { | ||||||||||||||||||
|
Subroutine
valid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 80 | 20994 | my $self = shift; | |||||||||||||||||||
| 81 | 20994 | @valid = sort( keys %{$self->{'valid'}} ); | |||||||||||||||||||
| 82 | 20994 | return \@valid; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =item B<valid_add> | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | add a number to the valid array | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 733 | ▶ | sub valid_add { | ||||||||||||||||||
|
Subroutine
valid_add: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 93 | 733 | my $self = shift; | |||||||||||||||||||
| 94 | 733 | my $number = shift; | |||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 733 | $self->{'valid'}{ $number } = $number; | |||||||||||||||||||
| 97 | 733 | return $number; | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =item B<valid_del> | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | remove a number from the valid array | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 16520 | ▶ | sub valid_del { | ||||||||||||||||||
|
Subroutine
valid_del: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 108 | 16520 | my $self = shift; | |||||||||||||||||||
| 109 | 16520 | my $number = shift; | |||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 16520 | ▶ | delete $self->{'valid'}{ $number } if $self->{'valid'}{ $number }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 2 | 1; | |||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | =head1 AUTHOR | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | Andrew Wyllie <wyllie@dilex.net> | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =head1 BUGS | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | Please send any bugs to the author | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =head1 COPYRIGHT | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | The Games::YASudoku moudule is free software and can be redistributed | ||||||||||||||||||||
| 128 | and/or modified under the same terms as Perl itself. | ||||||||||||||||||||
| 129 | |||||||||||||||||||||