← Index
NYTProf Performance Profile   « block view • line view • sub view »
For 01.HTTP.t
  Run on Tue May 4 15:25:55 2010
Reported on Tue May 4 15:26:05 2010

File /usr/local/lib/perl5/5.10.1/darwin-2level/MIME/Base64.pm
Statements Executed 15
Statement Execution Time 432µs
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11129µs40µsMIME::Base64::::BEGIN@3MIME::Base64::BEGIN@3
11110µs78µsMIME::Base64::::BEGIN@4MIME::Base64::BEGIN@4
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package MIME::Base64;
2
3343µs251µs
# spent 40µs (29+11) within MIME::Base64::BEGIN@3 which was called # once (29µs+11µs) by SimpleDB::Client::BEGIN@47 at line 3
use strict;
# spent 40µs making 1 call to MIME::Base64::BEGIN@3 # spent 11µs making 1 call to strict::import
43118µs2146µs
# spent 78µs (10+68) within MIME::Base64::BEGIN@4 which was called # once (10µs+68µs) by SimpleDB::Client::BEGIN@47 at line 4
use vars qw(@ISA @EXPORT $VERSION);
# spent 78µs making 1 call to MIME::Base64::BEGIN@4 # spent 68µs making 1 call to vars::import
5
61900nsrequire Exporter;
719µs@ISA = qw(Exporter);
81700ns@EXPORT = qw(encode_base64 decode_base64);
9
101300ns$VERSION = '3.08';
11
121500nsrequire XSLoader;
131242µs1236µsXSLoader::load('MIME::Base64', $VERSION);
# spent 236µs making 1 call to XSLoader::load
14
1511µs*encode = \&encode_base64;
161300ns*decode = \&decode_base64;
17
18117µs1;
19
20__END__
21
22=head1 NAME
23
24MIME::Base64 - Encoding and decoding of base64 strings
25
26=head1 SYNOPSIS
27
28 use MIME::Base64;
29
30 $encoded = encode_base64('Aladdin:open sesame');
31 $decoded = decode_base64($encoded);
32
33=head1 DESCRIPTION
34
35This module provides functions to encode and decode strings into and from the
36base64 encoding specified in RFC 2045 - I<MIME (Multipurpose Internet
37Mail Extensions)>. The base64 encoding is designed to represent
38arbitrary sequences of octets in a form that need not be humanly
39readable. A 65-character subset ([A-Za-z0-9+/=]) of US-ASCII is used,
40enabling 6 bits to be represented per printable character.
41
42The following functions are provided:
43
44=over 4
45
46=item encode_base64($str)
47
48=item encode_base64($str, $eol);
49
50Encode data by calling the encode_base64() function. The first
51argument is the string to encode. The second argument is the
52line-ending sequence to use. It is optional and defaults to "\n". The
53returned encoded string is broken into lines of no more than 76
54characters each and it will end with $eol unless it is empty. Pass an
55empty string as second argument if you do not want the encoded string
56to be broken into lines.
57
58=item decode_base64($str)
59
60Decode a base64 string by calling the decode_base64() function. This
61function takes a single argument which is the string to decode and
62returns the decoded data.
63
64Any character not part of the 65-character base64 subset is
65silently ignored. Characters occurring after a '=' padding character
66are never decoded.
67
68If the length of the string to decode, after ignoring
69non-base64 chars, is not a multiple of 4 or if padding occurs too early,
70then a warning is generated if perl is running under C<-w>.
71
72=back
73
74If you prefer not to import these routines into your namespace, you can
75call them as:
76
77 use MIME::Base64 ();
78 $encoded = MIME::Base64::encode($decoded);
79 $decoded = MIME::Base64::decode($encoded);
80
81=head1 DIAGNOSTICS
82
83The following warnings can be generated if perl is invoked with the
84C<-w> switch:
85
86=over 4
87
88=item Premature end of base64 data
89
90The number of characters to decode is not a multiple of 4. Legal
91base64 data should be padded with one or two "=" characters to make
92its length a multiple of 4. The decoded result will be the same
93whether the padding is present or not.
94
95=item Premature padding of base64 data
96
97The '=' padding character occurs as the first or second character
98in a base64 quartet.
99
100=back
101
102The following exception can be raised:
103
104=over 4
105
106=item Wide character in subroutine entry
107
108The string passed to encode_base64() contains characters with code
109above 255. The base64 encoding is only defined for single-byte
110characters. Use the Encode module to select the byte encoding you
111want.
112
113=back
114
115=head1 EXAMPLES
116
117If you want to encode a large file, you should encode it in chunks
118that are a multiple of 57 bytes. This ensures that the base64 lines
119line up and that you do not end up with padding in the middle. 57
120bytes of data fills one complete base64 line (76 == 57*4/3):
121
122 use MIME::Base64 qw(encode_base64);
123
124 open(FILE, "/var/log/wtmp") or die "$!";
125 while (read(FILE, $buf, 60*57)) {
126 print encode_base64($buf);
127 }
128
129or if you know you have enough memory
130
131 use MIME::Base64 qw(encode_base64);
132 local($/) = undef; # slurp
133 print encode_base64(<STDIN>);
134
135The same approach as a command line:
136
137 perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)' <file
138
139Decoding does not need slurp mode if every line contains a multiple
140of four base64 chars:
141
142 perl -MMIME::Base64 -ne 'print decode_base64($_)' <file
143
144Perl v5.8 and better allow extended Unicode characters in strings.
145Such strings cannot be encoded directly, as the base64
146encoding is only defined for single-byte characters. The solution is
147to use the Encode module to select the byte encoding you want. For
148example:
149
150 use MIME::Base64 qw(encode_base64);
151 use Encode qw(encode);
152
153 $encoded = encode_base64(encode("UTF-8", "\x{FFFF}\n"));
154 print $encoded;
155
156=head1 COPYRIGHT
157
158Copyright 1995-1999, 2001-2004 Gisle Aas.
159
160This library is free software; you can redistribute it and/or
161modify it under the same terms as Perl itself.
162
163Distantly based on LWP::Base64 written by Martijn Koster
164<m.koster@nexor.co.uk> and Joerg Reichelt <j.reichelt@nexor.co.uk> and
165code posted to comp.lang.perl <3pd2lp$6gf@wsinti07.win.tue.nl> by Hans
166Mulder <hansm@wsinti07.win.tue.nl>
167
168The XS implementation uses code from metamail. Copyright 1991 Bell
169Communications Research, Inc. (Bellcore)
170
171=head1 SEE ALSO
172
173L<MIME::QuotedPrint>
174
175=cut