File Coverage

blib/lib/Enterprise/Licence.pm
Criterion Covered Total %
statement 49 51 96.0
branch 2 6 33.3
condition 1 3 33.3
subroutine 15 15 100.0
pod 0 7 0.0
total 67 82 81.7


line stmt bran cond sub pod time code
1             package Enterprise::Licence;
2 2     2   93920 our $VERSION = '0.01'; use utf8; use strict; use warnings;
  2     2   17  
  2     2   9  
  2         59  
  2         5  
  2         35  
  2         9  
  2         3  
  2         49  
3 2     2   1811 use DateTime; use Math::BigInt; use Compress::Huffman;
  2     2   1011537  
  2     2   99  
  2         2683  
  2         53527  
  2         15  
  2         54747  
  2         11096  
  2         115  
4 2     2   940 use Shannon::Entropy qw/entropy/; use Bijection qw/all/;
  2     2   3442  
  2         24  
  2         1038  
  2         1759  
  2         17  
5              
6             sub new {
7 4     4 0 1001385 my ($pkg, $args) = (@_, {});
8 4         15 my $self = bless {}, $pkg;
9 4 50 33     36 unless ($args->{secret} && entropy($args->{secret}) > 3) {
10 0         0 die 'no secure secret passed to new';
11             }
12 4         256 $self->{secret} = $args->{secret};
13 4         38 my $ch = huffman([split '', $args->{secret}]);
14 4         15 $self->{ch} = $ch;
15             bijection_set(
16             ($args->{offset} ? $args->{offset} : ()),
17 0         0 @{$args->{biject}}
18 4 0       16 ) if $args->{biject};
    50          
19 4         28 $self;
20             }
21              
22             sub bin2dec {
23 6     6 0 179 my $dec = $_[1];
24 6         59 return Math::BigInt->new("0b$dec");
25             }
26              
27             sub dec2bin {
28 2     2 0 9 my $i = Math::BigInt->new($_[1]);
29 2         91 return substr($i->as_bin(), 2);
30             }
31              
32             sub customer_offset {
33 4     4 0 815 my $encode = [split '', $_[1]];
34 4         13 my $ch = huffman($encode);
35 4         16 return $ch->encode($encode);
36             }
37              
38             sub huffman {
39 8     8 0 17 my $encode = shift;
40 8         39 my $ch = Compress::Huffman->new();
41 8         33 my $i = 0.1;
42             my %symbols = map {
43 68         169 $_ => ( $i += 0.1 )
44 8         16 } @{$encode};
  8         18  
45 8         41 $ch->symbols(\%symbols, notprob => 1);
46 8         6375 return $ch;
47             }
48              
49 8     8 0 11609 sub bi { return scalar biject($_[1]); }
50 8     8 0 74 sub in { return scalar inverse($_[1]); }
51              
52             1;
53              
54             __END__
55              
56             =head1 NAME
57              
58             Enterprise::Licence - The great new Enterprise::Licence!
59              
60             =head1 VERSION
61              
62             Version 0.01
63              
64             =cut
65              
66             =head1 SYNOPSIS
67              
68             use Enterprise::Licence::Generate;
69             use Enterprise::Licence::Validate;
70              
71             my $sec = 'IAmLimited';
72             my $generator = Enterprise::Licence::Generate->new({ secret => $sec });
73              
74             my $client = 'unique';
75             my $licence = $generator->generate($client, { years => 99 });
76              
77             my $validator = Enterprise::Licence::Validate->new({ secret => $sec });
78             my @valid = $validator->valid($licence, $client);
79             # (1) == valid
80             # (0, 1) == expired
81             # (0, 0) == invalid
82              
83             =cut
84              
85             =head1 AUTHOR
86              
87             LNATION, C<< <thisusedtobeanemail at gmail.com> >>
88              
89             =head1 BUGS
90              
91             Please report any bugs or feature requests to C<bug-enterprise-licence at rt.cpan.org>, or through
92             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Enterprise-Licence>. I will be notified, and then you'll
93             automatically be notified of progress on your bug as I make changes.
94              
95             =head1 SUPPORT
96              
97             You can find documentation for this module with the perldoc command.
98              
99             perldoc Enterprise::Licence
100              
101              
102             You can also look for information at:
103              
104             =over 4
105              
106             =item * RT: CPAN's request tracker (report bugs here)
107              
108             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Enterprise-Licence>
109              
110             =item * AnnoCPAN: Annotated CPAN documentation
111              
112             L<http://annocpan.org/dist/Enterprise-Licence>
113              
114             =item * CPAN Ratings
115              
116             L<http://cpanratings.perl.org/d/Enterprise-Licence>
117              
118             =item * Search CPAN
119              
120             L<http://search.cpan.org/dist/Enterprise-Licence/>
121              
122             =back
123              
124              
125             =head1 ACKNOWLEDGEMENTS
126              
127              
128             =head1 LICENSE AND COPYRIGHT
129              
130             Copyright 2019 LNATION.
131              
132             This program is free software; you can redistribute it and/or modify it
133             under the terms of the the Artistic License (2.0). You may obtain a
134             copy of the full license at:
135              
136             L<http://www.perlfoundation.org/artistic_license_2_0>
137              
138             Any use, modification, and distribution of the Standard or Modified
139             Versions is governed by this Artistic License. By using, modifying or
140             distributing the Package, you accept this license. Do not use, modify,
141             or distribute the Package, if you do not accept this license.
142              
143             If your Modified Version has been derived from a Modified Version made
144             by someone other than you, you are nevertheless required to ensure that
145             your Modified Version complies with the requirements of this license.
146              
147             This license does not grant you the right to use any trademark, service
148             mark, tradename, or logo of the Copyright Holder.
149              
150             This license includes the non-exclusive, worldwide, free-of-charge
151             patent license to make, have made, use, offer to sell, sell, import and
152             otherwise transfer the Package with respect to any patent claims
153             licensable by the Copyright Holder that are necessarily infringed by the
154             Package. If you institute patent litigation (including a cross-claim or
155             counterclaim) against any party alleging that the Package constitutes
156             direct or contributory patent infringement, then this Artistic License
157             to you shall terminate on the date that such litigation is filed.
158              
159             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
160             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
161             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
162             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
163             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
164             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
165             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
166             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
167              
168              
169             =cut
170              
171             1; # End of Enterprise::Licence