File Coverage

blib/lib/Crypt/Trifid/Utils.pm
Criterion Covered Total %
statement 37 37 100.0
branch 2 2 100.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 47 48 97.9


line stmt bran cond sub pod time code
1             package Crypt::Trifid::Utils;
2              
3             $Crypt::Trifid::Utils::VERSION = '0.10';
4             $Crypt::Trifid::Utils::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             Crypt::Trifid::Utils - Helper package for Crypt::Trifid.
9              
10             =head1 VERSION
11              
12             Version 0.10
13              
14             =cut
15              
16 6     6   124 use 5.006;
  6         22  
17 6     6   32 use strict; use warnings;
  6     6   11  
  6         133  
  6         38  
  6         9  
  6         172  
18 6     6   29 use Data::Dumper;
  6         12  
  6         295  
19 6     6   2485 use parent 'Exporter';
  6         1851  
  6         32  
20              
21             our @EXPORT_OK = qw(generate_chart);
22              
23             =head1 DESCRIPTION
24              
25             B
26              
27             =cut
28              
29             sub generate_chart {
30              
31 3     3 0 13 my $chars = _generate_charset();
32 3         9 my $chart = {};
33 3         11 foreach my $i (0..2) {
34 9         18 foreach my $j (0..2) {
35 27         42 foreach my $k (0..2) {
36 81         217 $chart->{$chars->[$i]->[$j]->[$k]} = sprintf("%d%d%d", $i+1, $j+1, $k+1);
37             }
38             }
39             }
40              
41 3         41 return $chart;
42             }
43              
44             #
45             #
46             # PRIVATE METHODS
47              
48             sub _generate_charset {
49              
50 3     3   25 my @chars = ('A' .. 'Z', ' ');
51 3         8 my $chars = [];
52 3         7 my $seen = {};
53 3         14 foreach my $i (0..2) {
54 9         19 foreach my $j (0..2) {
55 27         43 foreach my $k (0..2) {
56 81         111 my $char = '';
57 81         135 while ($char eq '') {
58 317         487 $char = _get_char(@chars);
59 317 100       534 if (exists $seen->{$char}) {
60 236         391 $char = '';
61             }
62             else {
63 81         214 $seen->{$char} = 1;
64             }
65             }
66 81         164 $chars->[$i]->[$j]->[$k] = $char;
67             }
68             }
69             }
70              
71 3         20 return $chars;
72             }
73              
74 317     317   1333 sub _get_char { my (@chars) = @_; return $chars[ rand @chars ]; }
  317         1064  
75              
76             =head1 AUTHOR
77              
78             Mohammad S Anwar, C<< >>
79              
80             =head1 REPOSITORY
81              
82             L
83              
84             =head1 BUGS
85              
86             Please report any bugs/feature requests to C or
87             through the web interface at L.
88             I will be notified & then you'll automatically be notified of progress on your bug
89             as I make changes.
90              
91             =head1 SUPPORT
92              
93             You can find documentation for this module with the perldoc command.
94              
95             perldoc Crypt::Trifid::Utils
96              
97             You can also look for information at:
98              
99             =over 4
100              
101             =item * RT: CPAN's request tracker
102              
103             L
104              
105             =item * AnnoCPAN: Annotated CPAN documentation
106              
107             L
108              
109             =item * CPAN Ratings
110              
111             L
112              
113             =item * Search CPAN
114              
115             L
116              
117             =back
118              
119             =head1 LICENSE AND COPYRIGHT
120              
121             Copyright (C) 2014 - 2017 Mohammad S Anwar.
122              
123             This program is free software; you can redistribute it and / or modify it under
124             the terms of the the Artistic License (2.0). You may obtain a copy of the full
125             license at:
126              
127             L
128              
129             Any use, modification, and distribution of the Standard or Modified Versions is
130             governed by this Artistic License.By using, modifying or distributing the Package,
131             you accept this license. Do not use, modify, or distribute the Package, if you do
132             not accept this license.
133              
134             If your Modified Version has been derived from a Modified Version made by someone
135             other than you,you are nevertheless required to ensure that your Modified Version
136             complies with the requirements of this license.
137              
138             This license does not grant you the right to use any trademark, service mark,
139             tradename, or logo of the Copyright Holder.
140              
141             This license includes the non-exclusive, worldwide, free-of-charge patent license
142             to make, have made, use, offer to sell, sell, import and otherwise transfer the
143             Package with respect to any patent claims licensable by the Copyright Holder that
144             are necessarily infringed by the Package. If you institute patent litigation
145             (including a cross-claim or counterclaim) against any party alleging that the
146             Package constitutes direct or contributory patent infringement,then this Artistic
147             License to you shall terminate on the date that such litigation is filed.
148              
149             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
150             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
151             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
152             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
153             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
154             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
155             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
156              
157             =cut
158              
159             1; # End of Crypt::Trifid::Utils