File Coverage

blib/lib/String/HexConvert.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 20 20 100.0


line stmt bran cond sub pod time code
1             package String::HexConvert; ## Converts ascii strings to hex and reverse
2              
3              
4              
5              
6 1     1   16075 use strict;
  1         2  
  1         28  
7              
8 1     1   4 use vars qw(@ISA @EXPORT %EXPORT_TAGS $VERSION);
  1         1  
  1         79  
9 1     1   6 use Exporter;
  1         2  
  1         140  
10              
11             our $VERSION='0.02';
12              
13              
14             @ISA = qw(Exporter);
15              
16             %EXPORT_TAGS = ( all => [qw(
17             hex_to_ascii
18             ascii_to_hex
19             )] );
20              
21             Exporter::export_ok_tags('all');
22              
23              
24             # It is a wrapper around pack and unpack of perl to convert a string of hex digits
25             # to ascii and other way around.
26             #
27             # SYNOPSIS
28             # ========
29             #
30             # use String::HexConvert ':all';
31             #
32             # print ascii_to_hex("hello world"); # writes: 68656c6c6f20776f726c64
33             #
34             # print hex_to_ascii("68656c6c6f20776f726c64"); # writes: hello world
35             #
36             #
37             #
38             # SEE ALSO
39             # ========
40             # pack, unpack, L
41             #
42             # LICENSE
43             # =======
44             # You can redistribute it and/or modify it under the conditions of LGPL.
45             #
46             # WHY?
47             # ====
48             # In know the comments like "is that realy needed?". IMHO yes, because I forget the
49             # exact syntax and possibilities of pack and unpack but hex_to_ascii tells me directly
50             # what pack "H*" does.
51             #
52             # AUTHOR
53             # ======
54             # Andreas Hernitscheck ahernit(AT)cpan.org
55              
56              
57             # Converts pairs of hex digits to asci
58             sub hex_to_ascii { # $ascii ($hex)
59 1     1 1 3 my $s = shift;
60              
61 1         12 return pack 'H*', $s;
62             }
63              
64             # Converts a string to pairs of hex digits
65             sub ascii_to_hex { # $hex ($ascii)
66 1     1 1 5 my $s = shift;
67              
68 1         9 return unpack("H*", $s);
69             }
70              
71             1;
72             #################### pod generated by Pod::Autopod - keep this line to make pod updates possible ####################
73              
74             =head1 NAME
75              
76             String::HexConvert - Converts ascii strings to hex and reverse
77              
78              
79             =head1 SYNOPSIS
80              
81              
82             use String::HexConvert ':all';
83              
84             print ascii_to_hex("hello world"); # writes: 68656c6c6f20776f726c64
85              
86             print hex_to_ascii("68656c6c6f20776f726c64"); # writes: hello world
87              
88            
89              
90              
91              
92             =head1 DESCRIPTION
93              
94             It is a wrapper around pack and unpack of perl to convert a string of hex digits
95             to ascii and other way around.
96              
97              
98              
99             =head1 REQUIRES
100              
101             L
102              
103              
104             =head1 METHODS
105              
106             =head2 ascii_to_hex
107              
108             my $hex = ascii_to_hex($ascii);
109              
110             Converts a string to pairs of hex digits
111              
112              
113             =head2 hex_to_ascii
114              
115             my $ascii = hex_to_ascii($hex);
116              
117             Converts pairs of hex digits to asci
118              
119              
120              
121             =head1 WHY?
122              
123             In know the comments like "is that realy needed?". IMHO yes, because I forget the
124             exact syntax and possibilities of pack and unpack but hex_to_ascii tells me directly
125             what pack "H*" does.
126              
127              
128              
129             =head1 SEE ALSO
130              
131             pack, unpack, L
132              
133              
134              
135             =head1 AUTHOR
136              
137             Andreas Hernitscheck ahernit(AT)cpan.org
138              
139              
140             =head1 LICENSE
141              
142             You can redistribute it and/or modify it under the conditions of LGPL.
143              
144              
145              
146             =cut
147