TicTacToe/Player.pm

filter: Statementstmt 68.9% 20 / 29 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 100% 3 / 3 totaltotal 60.4% 29 / 48 CC 4 SCAR 12.0
CC
4
Cov
57%
otherSymbol
6.0
desc
6.0
getMessage
6.0
CRAP 3.3
« TicTacToe/Board.pm ↑ Summary TicTacToe/Params.pm »
1 package Games::TicTacToe::Player;
2  
3 11 $Games::TicTacToe::Player::VERSION = '0.25';
4 11 $Games::TicTacToe::Player::AUTHOR = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 Games::TicTacToe::Player - Interface to the TicTacToe game's player.
9  
10 =head1 VERSION
11  
12 Version 0.25
13  
14 =cut
15  
16 11 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶use Games::TicTacToe::Params qw(Symbol PlayerType);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 11 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 0 ▶has 'type' => (is => 'ro', isa => PlayerType, default => sub { return 'H' }, required => 1);
Subroutine __ANON__: not called CC=1 SCAR=1.2
24 1 ▶has 'symbol' => (is => 'ro', isa => Symbol, default => sub { return 'X' }, required => 1);
Subroutine __ANON__: called CC=1 SCAR=0.0
25  
26 =head1 DESCRIPTION
27  
28 It is used internally by L<Games::TicTacToe>.
29  
30 =head1 METHODS
31  
32 =head2 otherSymbol()
33  
34 Returns opposition player's symbol.
35  
36 =cut
37  
38 sub otherSymbol {
39 0 ▶ my ($self) = @_;
Subroutine otherSymbol: not called CC=2 SCAR=17.9
Pod documented
40  
41 0 ▶ return (uc($self->symbol) eq 'X')?('O'):('X');
Branch: 1 branch
BranchTrueFalseTotal
uc $self->symbol eq 'X' ? : 0 0 0
42 }
43  
44 =head2 desc()
45  
46 Returns the description of the player.
47  
48 =cut
49  
50 sub desc {
51 0 ▶ my ($self) = @_;
Subroutine desc: not called CC=2 SCAR=17.9
Pod documented
52  
53 0 ▶ return ($self->{type} eq 'H')?('Human'):('Computer');
Branch: 1 branch
BranchTrueFalseTotal
$self->{'type'} eq 'H' ? : 0 0 0
54 }
55  
56 =head2 getMessage()
57  
58 Returns the winning message for the player.
59  
60 =cut
61  
62 sub getMessage {
63 0 ▶ my ($self) = @_;
Subroutine getMessage: not called CC=2 SCAR=17.9
Pod documented
64  
65 0 ▶ if ($self->type eq 'H') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type eq 'H') { } 0 0 0
66 0 return "<green><bold>Congratulation, you won the game.</bold></green>\n";
67 }
68 else {
69 0 return "<red><bold>Computer beat you this time. Better luck next time.</bold></red>\n";
70 }
71 }
72  
73 =head1 AUTHOR
74  
75 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
76  
77 =head1 REPOSITORY
78  
79 L<https://github.com/manwar/Games-TicTacToe>
80  
81 =head1 BUGS
82  
83 Please report any bugs / feature requests to C<bug-games-tictactoe at rt.cpan.org>
84 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-TicTacToe>.
85 I will be notified & then you'll automatically be notified of progress on your bug
86 as I make changes.
87  
88 =head1 SUPPORT
89  
90 You can find documentation for this module with the perldoc command.
91  
92 perldoc Games::TicTacToe::Player
93  
94 You can also look for information at:
95  
96 =over 4
97  
98 =item * RT: CPAN's request tracker
99  
100 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-TicTacToe>
101  
102 =item * AnnoCPAN: Annotated CPAN documentation
103  
104 L<http://annocpan.org/dist/Games-TicTacToe>
105  
106 =item * CPAN Ratings
107  
108 L<http://cpanratings.perl.org/d/Games-TicTacToe>
109  
110 =item * Search CPAN
111  
112 L<http://search.cpan.org/dist/Games-TicTacToe/>
113  
114 =back
115  
116 =head1 LICENSE AND COPYRIGHT
117  
118 Copyright (C) 2011 - 2016 Mohammad S Anwar.
119  
120 This program is free software; you can redistribute it and/or modify it under
121 the terms of the the Artistic License (2.0). You may obtain a copy of the full
122 license at:
123  
124 L<http://www.perlfoundation.org/artistic_license_2_0>
125  
126 Any use, modification, and distribution of the Standard or Modified Versions is
127 governed by this Artistic License.By using, modifying or distributing the Package,
128 you accept this license. Do not use, modify, or distribute the Package, if you do
129 not accept this license.
130  
131 If your Modified Version has been derived from a Modified Version made by someone
132 other than you,you are nevertheless required to ensure that your Modified Version
133 complies with the requirements of this license.
134  
135 This license does not grant you the right to use any trademark, service mark,
136 tradename, or logo of the Copyright Holder.
137  
138 This license includes the non-exclusive, worldwide, free-of-charge patent license
139 to make, have made, use, offer to sell, sell, import and otherwise transfer the
140 Package with respect to any patent claims licensable by the Copyright Holder that
141 are necessarily infringed by the Package. If you institute patent litigation
142 (including a cross-claim or counterclaim) against any party alleging that the
143 Package constitutes direct or contributory patent infringement,then this Artistic
144 License to you shall terminate on the date that such litigation is filed.
145  
146 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
147 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
148 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
149 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
150 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
151 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
152 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
153  
154 =cut
155  
156 11 1; # End of Games::TicTacToe::Player
« TicTacToe/Board.pm ↑ Summary TicTacToe/Params.pm »