File Coverage

blib/lib/Spreadsheet/HTML/Presets/Chess.pm
Criterion Covered Total %
statement 6 26 23.0
branch 0 16 0.0
condition 0 4 0.0
subroutine 2 6 33.3
pod 1 1 100.0
total 9 53 16.9


line stmt bran cond sub pod time code
1             package Spreadsheet::HTML::Presets::Chess;
2 5     5   19 use strict;
  5         5  
  5         135  
3 5     5   16 use warnings FATAL => 'all';
  5         7  
  5         1708  
4              
5             sub chess {
6 0     0 1   my ($self,$data,$args);
7 0 0         $self = shift if ref($_[0]) =~ /^Spreadsheet::HTML/;
8 0 0         ($self,$data,$args) = $self ? $self->_args( @_ ) : Spreadsheet::HTML::_args( @_ );
9              
10 0           my @data = (
11             [ '♜', '♞', '♝', '♛', '♚', '♝', '♞', '♜' ],
12             [ '♟', '♟', '♟', '♟', '♟', '♟', '♟', '♟' ],
13             [ ('') x 8 ], [ ('') x 8 ], [ ('') x 8 ], [ ('') x 8 ],
14             [ '♙', '♙', '♙', '♙', '♙', '♙', '♙', '♙' ],
15             [ '♖', '♘', '♗', '♕', '♔', '♗', '♘', '♖' ],
16             );
17              
18 0   0       my $on = $args->{on} || '#aaaaaa';
19 0   0       my $off = $args->{off} || 'white';
20              
21             my @args = (
22             table => {
23             width => '65%',
24             style => {
25             border => 'thick outset',
26 0 0         %{ $args->{table}{style} || {} },
27             },
28 0 0         %{ $args->{table} || {} },
29             },
30             @_,
31             td => [
32             {
33             height => 65,
34             width => 65,
35             align => 'center',
36             style => {
37             'font-size' => 'xx-large',
38             border => 'thin inset',
39             'background-color' => [ ($off, $on)x4, ($on, $off)x4 ],
40 0 0         %{ $args->{td}{style} || {} },
41             },
42 0 0         %{ $args->{td} || {} },
43 0 0   0     }, sub { $_[0] ? qq(
$_[0]
) : '' }
44 0           ],
45             tgroups => 0,
46             headless => 0,
47             pinhead => 0,
48             matrix => 1,
49             wrap => 0,
50             fill => '8x8',
51             data => \@data,
52             );
53              
54 0           my $js = Spreadsheet::HTML::Presets::Chess::_javascript( %$args );
55 0 0         my $table = $self ? $self->generate( @args ) : Spreadsheet::HTML::generate( @args );
56 0           return $js . $table;
57             }
58              
59             sub _javascript {
60 0     0     my %args = @_;
61              
62 0           my $js = sprintf _js_tmpl(),
63             ;
64              
65 0           $args{jqueryui} = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js';
66              
67 0           return Spreadsheet::HTML::Presets::_js_wrapper( code => $js, %args );
68             }
69              
70             sub _js_tmpl {
71 0     0     return <<'END_JAVASCRIPT';
72              
73             /* Copyright 2017 Jeff Anderson */
74             /* install JavaScript::Minifier to minify this code */
75              
76             $(document).ready(function(){
77              
78             $(function() {
79             $( '.game-piece' ).draggable();
80             });
81              
82             });
83              
84             END_JAVASCRIPT
85             }
86              
87             =head1 NAME
88              
89             Spreadsheet::HTML::Presets::Chess - Chess/checkers boards implemented with Javascript and HTML tables.
90              
91             =head1 DESCRIPTION
92              
93             This is a container for L preset methods.
94             These methods are not meant to be called from this package.
95             Instead, use the Spreadsheet::HTML interface:
96              
97             use Spreadsheet::HTML;
98             my $generator = Spreadsheet::HTML->new;
99             print $generator->chess;
100              
101             # or
102             use Spreadsheet::HTML qw( chess );
103             print chess();
104              
105             =head1 METHODS
106              
107             =over 4
108              
109             =item * C
110              
111             Generates a chess game board. Currently you can only
112             move the pieces around without regard to any rules.
113              
114             =back
115              
116             =head1 SEE ALSO
117              
118             =over 4
119              
120             =item L
121              
122             The interface for this functionality.
123              
124             =item L
125              
126             More presets.
127              
128             =back
129              
130             =head1 AUTHOR
131              
132             Jeff Anderson, C<< >>
133              
134             =head1 LICENSE AND COPYRIGHT
135              
136             Copyright 2017 Jeff Anderson.
137              
138             This program is free software; you can redistribute it and/or modify it
139             under the terms of the the Artistic License (2.0). You may obtain a
140             copy of the full license at:
141              
142             L
143              
144             Any use, modification, and distribution of the Standard or Modified
145             Versions is governed by this Artistic License. By using, modifying or
146             distributing the Package, you accept this license. Do not use, modify,
147             or distribute the Package, if you do not accept this license.
148              
149             If your Modified Version has been derived from a Modified Version made
150             by someone other than you, you are nevertheless required to ensure that
151             your Modified Version complies with the requirements of this license.
152              
153             This license does not grant you the right to use any trademark, service
154             mark, tradename, or logo of the Copyright Holder.
155              
156             This license includes the non-exclusive, worldwide, free-of-charge
157             patent license to make, have made, use, offer to sell, sell, import and
158             otherwise transfer the Package with respect to any patent claims
159             licensable by the Copyright Holder that are necessarily infringed by the
160             Package. If you institute patent litigation (including a cross-claim or
161             counterclaim) against any party alleging that the Package constitutes
162             direct or contributory patent infringement, then this Artistic License
163             to you shall terminate on the date that such litigation is filed.
164              
165             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
166             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
167             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
168             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
169             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
170             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
171             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
172             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
173              
174             =cut
175              
176             1;