blib/lib/MIME/Base32.pm

filter: Statementstmt 100% 63 / 63 Branchbran 100% 16 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 10 / 10 totaltotal 100% 102 / 102 SCAR 22.0
CC
9
Cov
100%
encode_base32
3.0
decode_base32
3.0
encode_base32hex
3.0
CRAP 9.0
↑ Summary
1 package MIME::Base32;
2  
3 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 require Exporter;
8 2 our @ISA = qw(Exporter);
9 2 our @EXPORT = qw(encode_base32 decode_base32);
10 2 our @EXPORT_OK = qw(
11 encode_rfc3548 decode_rfc3548 encode_09AV decode_09AV
12 encode_base32hex decode_base32hex
13 );
14  
15 2 our $VERSION = "1.300_001";
16 2 $VERSION = eval $VERSION;
17  
18 1 ▶sub encode { return encode_base32(@_) }
Subroutine encode: called CC=1 SCAR=0.0
Pod documented
19 1 ▶sub encode_rfc3548 { return encode_base32(@_) }
Subroutine encode_rfc3548: called CC=1 SCAR=0.0
Pod documented
20  
21 sub encode_base32 {
22 5 ▶ my $arg = shift;
Subroutine encode_base32: called CC=3 SCAR=11.0
Pod documented
23 5 ▶ return '' unless defined($arg); # mimic MIME::Base64
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 1 4 5
24  
25 4 $arg = unpack('B*', $arg);
26 4 $arg =~ s/(.....)/000$1/g;
27 4 my $l = length($arg);
28 4 ▶ if ($l & 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l & 7) 3 1 4
29 3 my $e = substr($arg, $l & ~7);
30 3 $arg = substr($arg, 0, $l & ~7);
31 3 $arg .= "000$e" . '0' x (5 - length $e);
32 }
33 4 $arg = pack('B*', $arg);
34 4 $arg =~ tr|\0-\37|A-Z2-7|;
35 4 return $arg;
36 }
37  
38 1 ▶sub decode { return decode_base32(@_) }
Subroutine decode: called CC=1 SCAR=0.0
Pod documented
39 1 ▶sub decode_rfc3548 { return decode_base32(@_) }
Subroutine decode_rfc3548: called CC=1 SCAR=0.0
Pod documented
40  
41 sub decode_base32 {
42 5 ▶ my $arg = shift;
Subroutine decode_base32: called CC=3 SCAR=11.0
Pod documented
43 5 ▶ return '' unless defined($arg); # mimic MIME::Base64
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 1 4 5
44  
45 4 $arg =~ tr|A-Z2-7|\0-\37|;
46 4 $arg = unpack('B*', $arg);
47 4 $arg =~ s/000(.....)/$1/g;
48 4 my $l = length $arg;
49 4 ▶ $arg = substr($arg, 0, $l & ~7) if $l & 7;
Branch: 1 branch
BranchTrueFalseTotal
if $l & 7 3 1 4
50 4 $arg = pack('B*', $arg);
51 4 return $arg;
52 }
53  
54 1 ▶sub encode_09AV { return encode_base32hex(@_) }
Subroutine encode_09AV: called CC=1 SCAR=0.0
Pod documented
55  
56 sub encode_base32hex {
57 4 ▶ my $arg = shift;
Subroutine encode_base32hex: called CC=3 SCAR=11.0
Pod documented
58 4 ▶ return '' unless defined($arg); # mimic MIME::Base64
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 1 3 4
59  
60 3 $arg = unpack('B*', $arg);
61 3 $arg =~ s/(.....)/000$1/g;
62 3 my $l = length($arg);
63 3 ▶ if ($l & 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l & 7) 2 1 3
64 2 my $e = substr($arg, $l & ~7);
65 2 $arg = substr($arg, 0, $l & ~7);
66 2 $arg .= "000$e" . '0' x (5 - length $e);
67 }
68 3 $arg = pack('B*', $arg);
69 3 $arg =~ tr|\0-\37|0-9A-V|;
70 3 return $arg;
71 }
72  
73 1 ▶sub decode_09AV { return decode_base32hex(@_) }
Subroutine decode_09AV: called CC=1 SCAR=0.0
Pod documented
74  
75 sub decode_base32hex {
76 4 ▶ my $arg = shift;
Subroutine decode_base32hex: called CC=3 SCAR=11.0
Pod documented
77 4 ▶ return '' unless defined($arg); # mimic MIME::Base64
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 1 3 4
78  
79 3 $arg =~ tr|0-9A-V|\0-\37|;
80 3 $arg = unpack('B*', $arg);
81 3 $arg =~ s/000(.....)/$1/g;
82 3 my $l = length($arg);
83 3 ▶ $arg = substr($arg, 0, $l & ~7) if $l & 7;
Branch: 1 branch
BranchTrueFalseTotal
if $l & 7 2 1 3
84 3 $arg = pack('B*', $arg);
85 3 return $arg;
86 }
87  
88 2 1;
89  
90 =encoding utf8
91  
92 =head1 NAME
93  
94 MIME::Base32 - Base32 encoder and decoder
95  
96 =head1 SYNOPSIS
97  
98 #!/usr/bin/env perl
99 use strict;
100 use warnings;
101 use MIME::Base32;
102  
103 my $encoded = encode_base32('Aladdin: open sesame');
104 my $decoded = decode_base32($encoded);
105  
106 =head1 DESCRIPTION
107  
108 This module is for encoding/decoding data much the way that L<MIME::Base64> does.
109  
110 Prior to version 1.0, L<MIME::Base32> used the C<base32hex> (or C<[0-9A-V]>) encoding and
111 decoding methods by default. If you need to maintain that behavior, please call
112 C<encode_base32hex> or C<decode_base32hex> functions directly.
113  
114 Now, in accordance with L<RFC-3548, Section 6|https://tools.ietf.org/html/rfc3548#section-6>,
115 L<MIME::Base32> uses the C<encode_base32> and C<decode_base32> functions by default.
116  
117 =head1 FUNCTIONS
118  
119 The following primary functions are provided:
120  
121 =head2 decode
122  
123 Synonym for C<decode_base32>
124  
125 =head2 decode_rfc3548
126  
127 Synonym for C<decode_base32>
128  
129 =head2 decode_base32
130  
131 my $string = decode_base32($encoded_data);
132  
133 Decode some encoded data back into a string of text or binary data.
134  
135 =head2 decode_09AV
136  
137 Synonym for C<decode_base32hex>
138  
139 =head2 decode_base32hex
140  
141 my $string_or_binary_data = MIME::Base32::decode_base32hex($encoded_data);
142  
143 Decode some encoded data back into a string of text or binary data.
144  
145 =head2 encode
146  
147 Synonym for C<encode_base32>
148  
149 =head2 encode_rfc3548
150  
151 Synonym for C<encode_base32>
152  
153 =head2 encode_base32
154  
155 my $encoded = encode_base32("some string");
156  
157 Encode a string of text or binary data.
158  
159 =head2 encode_09AV
160  
161 Synonym for C<encode_base32hex>
162  
163 =head2 encode_base32hex
164  
165 my $encoded = MIME::Base32::encode_base32hex("some string");
166  
167 Encode a string of text or binary data. This uses the C<hex> (or C<[0-9A-V]>) method.
168  
169 =head1 AUTHORS
170  
171 Jens Rehsack - <rehsack@cpan.org> - Current maintainer
172  
173 Chase Whitener
174  
175 Daniel Peder - sponsored by Infoset s.r.o., Czech Republic
176 - <Daniel.Peder@InfoSet.COM> http://www.infoset.com - Original author
177  
178 =head1 BUGS
179  
180 Before reporting any new issue, bug or alike, please check
181 L<https://rt.cpan.org/Dist/Display.html?Queue=MIME-Base32>,
182 L<https://github.com/perl5-utils/MIME-Base32/issues> or
183 L<https://github.com/perl5-utils/MIME-Base32/pulls>, respectively, whether
184 the issue is already reported.
185  
186 Please report any bugs or feature requests to
187 C<bug-mime-base32 at rt.cpan.org>, or through the web interface at
188 L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=MIME-Base32>.
189 I will be notified, and then you'll automatically be notified of progress
190 on your bug as I make changes.
191  
192 Any and all criticism, bug reports, enhancements, fixes, etc. are appreciated.
193  
194 =head1 SUPPORT
195  
196 You can find documentation for this module with the perldoc command.
197  
198 perldoc MIME::Base32
199  
200 You can also look for information at:
201  
202 =over 4
203  
204 =item * RT: CPAN's request tracker
205  
206 L<https://rt.cpan.org/Dist/Display.html?Name=MIME-Base32>
207  
208 =item * AnnoCPAN: Annotated CPAN documentation
209  
210 L<http://annocpan.org/dist/MIME-Base32>
211  
212 =item * MetaCPAN
213  
214 L<https://metacpan.org/release/MIME-Base32>
215  
216 =back
217  
218 =head1 COPYRIGHT AND LICENSE INFORMATION
219  
220 Copyright (c) 2003-2010 Daniel Peder. All rights reserved.
221 Copyright (c) 2015-2016 Chase Whitener. All rights reserved.
222 Copyright (c) 2016 Jens Rehsack. All rights reserved.
223  
224 This library is free software; you can redistribute it and/or
225 modify it under the same terms as Perl itself.
226  
227 =head1 SEE ALSO
228  
229 L<MIME::Base64>, L<RFC-3548|https://tools.ietf.org/html/rfc3548#section-6>
230  
231 =cut
↑ Summary