File Coverage

blib/lib/Convert/ModHex.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 4 4 100.0
total 31 31 100.0


line stmt bran cond sub pod time code
1             package Convert::ModHex;
2              
3             # ABSTRACT: Conversion utilities between Yubico ModHex and hexa/decimal
4              
5 1     1   22156 use strict;
  1         3  
  1         47  
6 1     1   5 use warnings;
  1         2  
  1         30  
7 1     1   818 use parent 'Exporter';
  1         322  
  1         5  
8              
9             our $VERSION = '0.001'; # VERSION
10             our $AUTHORITY = 'cpan:MELO'; # AUTHORITY
11              
12             our @EXPORT_OK = qw( modhex2hex modhex2dec hex2modhex dec2modhex );
13              
14             sub modhex2hex {
15 22     22 1 16617 my $m = $_[0];
16              
17 22         30 $m =~ tr/cbdefghijklnrtuv/0123456789abcdef/;
18              
19 22         52 return $m;
20             }
21              
22             sub modhex2dec {
23 11     11 1 34 return hex(modhex2hex(@_));
24             }
25              
26             sub hex2modhex {
27 22     22 1 35 my $m = $_[0];
28              
29 22         24 $m =~ tr/0123456789abcdef/cbdefghijklnrtuv/;
30 22 100       49 $m = "c$m" if length($m) % 2;
31              
32 22         43 return $m;
33             }
34              
35             sub dec2modhex {
36 11     11 1 61 return hex2modhex(sprintf('%x', shift));
37             }
38              
39             1;
40              
41              
42              
43             =pod
44              
45             =for :stopwords Pedro Melo ACKNOWLEDGEMENTS cpan testmatrix url annocpan anno bugtracker rt
46             cpants kwalitee diff irc mailto metadata placeholders
47              
48             =encoding utf-8
49              
50             =head1 NAME
51              
52             Convert::ModHex - Conversion utilities between Yubico ModHex and hexa/decimal
53              
54             =head1 VERSION
55              
56             version 0.001
57              
58             =head1 SYNOPSIS
59              
60             use Convert::ModHex qw( modhex2hex modhex2dec hex2modhex dec2modhex );
61            
62             my $modhex = 'ccbc';
63             my $hex = modhex2hex($modhex);
64             my $dec = modhex2dec($modhex);
65            
66             $modhex = hex2modhex($hex);
67             $modhex = dec2modhex($dec);
68              
69             =head1 DESCRIPTION
70              
71             This module provides utility functions that you can use to convert between
72             L (as used by the
73             L).
74              
75             =encoding utf8
76              
77             =head1 FUNCTIONS
78              
79             =head2 modhex2hex
80              
81             Accepts a ModHex-encoded scalar, returns a hexadecimal-encoded scalar.
82              
83             =head2 modhex2dec
84              
85             Accepts a ModHex-encoded scalar, returns a numeric scalar.
86              
87             =head2 hex2modhex
88              
89             Accepts a hexadecimal scalar and returns the ModHex-encoded scalar.
90              
91             =head2 dec2modhex
92              
93             Accepts a numeric scalar and returns the ModHex-encoded scalar.
94              
95             =head1 SUPPORT
96              
97             =head2 Perldoc
98              
99             You can find documentation for this module with the perldoc command.
100              
101             perldoc Convert::ModHex
102              
103             =head2 Websites
104              
105             The following websites have more information about this module, and may be of help to you. As always,
106             in addition to those websites please use your favorite search engine to discover more resources.
107              
108             =over 4
109              
110             =item *
111              
112             CPAN Testers
113              
114             The CPAN Testers is a network of smokers who run automated tests on uploaded CPAN distributions.
115              
116             L
117              
118             =item *
119              
120             CPAN Testers Matrix
121              
122             The CPAN Testers Matrix is a website that provides a visual way to determine what Perls/platforms PASSed for a distribution.
123              
124             L
125              
126             =item *
127              
128             CPAN Testers Dependencies
129              
130             The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
131              
132             L
133              
134             =item *
135              
136             CPAN Ratings
137              
138             The CPAN Ratings is a website that allows community ratings and reviews of Perl modules.
139              
140             L
141              
142             =back
143              
144             =head2 Email
145              
146             You can email the author of this module at C asking for help with any problems you have.
147              
148             =head2 Bugs / Feature Requests
149              
150             Please report any bugs or feature requests by email to C, or through
151             the web interface at L. You will be automatically notified of any
152             progress on the request by the system.
153              
154             =head2 Source Code
155              
156              
157             L
158              
159             git clone https://github.com/melo/Convert-ModHex.git
160              
161             =head1 AUTHOR
162              
163             Pedro Melo
164              
165             =head1 COPYRIGHT AND LICENSE
166              
167             This software is Copyright (c) 2011 by Pedro Melo.
168              
169             This is free software, licensed under:
170              
171             The Artistic License 2.0 (GPL Compatible)
172              
173             =cut
174              
175              
176             __END__