File Coverage

blib/lib/Games/TicTacToe/Player.pm
Criterion Covered Total %
statement 14 22 63.6
branch 0 6 0.0
condition n/a
subroutine 5 8 62.5
pod 3 3 100.0
total 22 39 56.4


line stmt bran cond sub pod time code
1             package Games::TicTacToe::Player;
2              
3             $Games::TicTacToe::Player::VERSION = '0.25';
4             $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     11   710 use 5.006;
  11         38  
17 11     11   619 use Data::Dumper;
  11         7795  
  11         529  
18 11     11   3561 use Games::TicTacToe::Params qw(Symbol PlayerType);
  11         38  
  11         132  
19              
20 11     11   6808 use Moo;
  11         15409  
  11         164  
21 11     11   5822 use namespace::clean;
  11         16108  
  11         86  
22              
23             has 'type' => (is => 'ro', isa => PlayerType, default => sub { return 'H' }, required => 1);
24             has 'symbol' => (is => 'ro', isa => Symbol, default => sub { return 'X' }, required => 1);
25              
26             =head1 DESCRIPTION
27              
28             It is used internally by L.
29              
30             =head1 METHODS
31              
32             =head2 otherSymbol()
33              
34             Returns opposition player's symbol.
35              
36             =cut
37              
38             sub otherSymbol {
39 0     0 1   my ($self) = @_;
40              
41 0 0         return (uc($self->symbol) eq 'X')?('O'):('X');
42             }
43              
44             =head2 desc()
45              
46             Returns the description of the player.
47              
48             =cut
49              
50             sub desc {
51 0     0 1   my ($self) = @_;
52              
53 0 0         return ($self->{type} eq 'H')?('Human'):('Computer');
54             }
55              
56             =head2 getMessage()
57              
58             Returns the winning message for the player.
59              
60             =cut
61              
62             sub getMessage {
63 0     0 1   my ($self) = @_;
64              
65 0 0         if ($self->type eq 'H') {
66 0           return "Congratulation, you won the game.\n";
67             }
68             else {
69 0           return "Computer beat you this time. Better luck next time.\n";
70             }
71             }
72              
73             =head1 AUTHOR
74              
75             Mohammad S Anwar, C<< >>
76              
77             =head1 REPOSITORY
78              
79             L
80              
81             =head1 BUGS
82              
83             Please report any bugs / feature requests to C
84             or through the web interface at L.
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
101              
102             =item * AnnoCPAN: Annotated CPAN documentation
103              
104             L
105              
106             =item * CPAN Ratings
107              
108             L
109              
110             =item * Search CPAN
111              
112             L
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
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             1; # End of Games::TicTacToe::Player