File Coverage

blib/lib/Games/Sudoku/Html.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 2 50.0
total 26 27 96.3


line stmt bran cond sub pod time code
1             package Games::Sudoku::Html;
2              
3 2     2   224806 use strict;
  2         4  
  2         85  
4 2     2   11 use warnings;
  2         10  
  2         176  
5              
6             our $VERSION = '0.07';
7              
8 2     2   4189 use HTML::Template;
  2         42500  
  2         1189  
9              
10             our @ISA = qw( Exporter );
11             our @EXPORT_OK = qw( sudoku_html_page );
12              
13             ###########################################################
14              
15             sub sudoku_html_page {
16 1     1 1 238376 my ($puzzles) = @_;
17              
18 1         6 my $template = HTML::Template->new(
19             scalarref => page(),
20             loop_context_vars => 1,
21             );
22              
23             my @puzzle_list = map {
24 1         9586 my $puzzle_string = $_->[0];
  10         21  
25 10         53 $puzzle_string =~ s/[^\.1-9]/\./g;
26 10         14 my $puzzle_parameter = $puzzle_string;
27 10         154 $puzzle_parameter =~ s/\./0/g;
28             {
29 10         50 strPuzzle => $puzzle_string,
30             properties => $_->[1],
31             paramBoard => $puzzle_parameter,
32             }
33             } @$puzzles;
34              
35 1         16 $template->param(
36             puzzleCount => ($#puzzle_list + 1),
37             puzzles => \@puzzle_list,
38             grid => [({sudokuBand => [({sudokuRow => [(+{}) x 9]}) x 3]}) x 3]
39             );
40              
41 1         93 return $template->output()
42             }
43              
44             sub page {
45             return \<<'PAGE_TEMPLATE'
46            
47            
48            
49            
50            
51            
52              
53             <TMPL_VAR puzzleCount> Sudoku generated with PatternSolver
54            
74            
75            
76              
77            
109            
110            

Sudoku generated with PatternSolver

111              
112            

Playing it on Grant McLean's web site offers thorough step-by-step help and a well-founded,

113             much better difficulty rating (after a click on the light bulb).
114             *However, playing puzzles with less than 8 different givens on sudokuexchenge, produces a warning and may even bring the javascript hint feature to crash.

115            

The cursor can be moved around with the arrow keys, a stepwise undo is achieved with either escape or the backspace key.

116              
117            
118            
119             #
120             Puzzle string
121             Properties
122             Play it
123            
124            
125            
126            
127            
128             open here, play online
129            
130            
131              
132            
133            
Click here to move    continue onlineclose
134              
135            
377              
378            
428              
429            
430            
431            
432            
433            
434            
435            
436            
437            
438              
439            
440            
457            
489              
490            
491            
492            
493            
494            
495            
496            
497            
498            
499            
500            
501             PAGE_TEMPLATE
502 1     1 0 14 }
503              
504             1;
505              
506             =encoding UTF-8
507              
508             =head1 NAME
509              
510             Games::Sudoku::Html - Visualize and play collections of standard 9x9 Sudoku in your browser.
511              
512             =head1 DESCRIPTION
513              
514             A very simple Module which converts an array with sudoku puzzles into a static html page.
515             Thus, long lists of your digital (text format) sudoku can be revised and played in a browser.
516              
517             Currently only the standard sudoku are supported, no variants.
518              
519             =head1 SYNOPSIS
520              
521             use Games::Sudoku::PatternSolver::Html qw( sudoku_html_page );
522              
523             @list = ( [$sudokuHash->{strPuzzle}, ""], ... )
524             $htmlpage = sudoku_html_page( \@list )
525              
526             =head2 sudoku_html_page( arrayref )
527              
528             Returns a scalar with a static html page, playable in a browser
529              
530             Its only parameter is an array of arrays, each entry consisting of 2 items: an 81 character puzzle string and any descriptive text for the puzzle.
531             You may put as many puzzles as you like into the array, they can all be played from the one, javascript-driven static page.
532             Can also be used to play lists with numerous 9x9 Sudoku from various sources.
533              
534             =head1 SCRIPTS
535              
536             =head2 sudoku2html
537              
538             After installation of Games::Sudoku::Html this command line script should be in your path.
539             Flexible input options are available. Invoke Csudoku2html -h> for details.
540              
541             =head1 DEPENDENCIES
542              
543             =over 4
544              
545             =item * L
546              
547             =back
548              
549             =head1 SEE ALSO
550              
551             L, L
552              
553             =head1 COPYRIGHT AND LICENSE
554              
555             The following copyright notice applies to all the files provided in
556             this distribution, including binary files, unless explicitly noted
557             otherwise.
558              
559             This software is copyright (c) 2024 by Steffen Heinrich
560              
561             This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
562              
563             =cut