line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PerlIO::Via::Base64; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Make sure we do things by the book |
4
|
|
|
|
|
|
|
# Set the version info |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
115359
|
use strict; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
70
|
|
7
|
|
|
|
|
|
|
$PerlIO::Via::Base64::VERSION = 0.04; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Make sure the encoding/decoding stuff is available |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
785
|
use MIME::Base64 (); # no need to pollute this namespace |
|
2
|
|
|
|
|
1244
|
|
|
2
|
|
|
|
|
474
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Set the default setting for the end of line character |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $eol = "\n"; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Methods for settings that will be used by the objects |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# IN: 1 class (ignored) |
24
|
|
|
|
|
|
|
# 2 new setting for eol (default: no change) |
25
|
|
|
|
|
|
|
# OUT: 1 current setting for eol |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub eol { |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Lose the class |
30
|
|
|
|
|
|
|
# Set the new value if one specified |
31
|
|
|
|
|
|
|
# Return whatever we have now |
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
3
|
1
|
92
|
shift; |
34
|
3
|
100
|
|
|
|
10
|
$eol = shift if @_; |
35
|
3
|
|
|
|
|
10
|
$eol; |
36
|
|
|
|
|
|
|
} #eol |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Methods for the actual layer implementation |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
43
|
|
|
|
|
|
|
# IN: 1 class |
44
|
|
|
|
|
|
|
# 2 mode string (ignored) |
45
|
|
|
|
|
|
|
# 3 file handle of PerlIO layer below (ignored) |
46
|
|
|
|
|
|
|
# OUT: 1 blessed object |
47
|
|
|
|
|
|
|
|
48
|
4
|
|
|
4
|
1
|
1568
|
sub PUSHED { bless ['',$eol],$_[0] } #PUSHED |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
51
|
|
|
|
|
|
|
# IN: 1 instantiated object (ignored) |
52
|
|
|
|
|
|
|
# 2 handle to read from |
53
|
|
|
|
|
|
|
# OUT: 1 decoded string |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub FILL { |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Make sure we slurp everything we can in one go |
58
|
|
|
|
|
|
|
# Read the line from the handle |
59
|
|
|
|
|
|
|
# Decode if there is something decode and return result or signal eof |
60
|
|
|
|
|
|
|
|
61
|
6
|
|
|
6
|
1
|
18
|
local $/ = undef; |
62
|
6
|
|
|
|
|
80
|
my $line = readline( $_[1] ); |
63
|
6
|
100
|
|
|
|
60
|
(defined $line) ? MIME::Base64::decode_base64( $line ) : undef; |
64
|
|
|
|
|
|
|
} #FILL |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
67
|
|
|
|
|
|
|
# IN: 1 instantiated object (reference to buffer) |
68
|
|
|
|
|
|
|
# 2 buffer to be written |
69
|
|
|
|
|
|
|
# 3 handle to write to (ignored) |
70
|
|
|
|
|
|
|
# OUT: 1 number of bytes "written" |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub WRITE { |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Add to the buffer (encoding will take place on FLUSH) |
75
|
|
|
|
|
|
|
# Return indicating we read the entire buffer |
76
|
|
|
|
|
|
|
|
77
|
2
|
|
|
2
|
|
9
|
$_[0]->[0] .= $_[1]; |
78
|
2
|
|
|
|
|
13
|
length( $_[1] ); |
79
|
|
|
|
|
|
|
} #WRITE |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
82
|
|
|
|
|
|
|
# IN: 1 instantiated object (reference to buffer) |
83
|
|
|
|
|
|
|
# 2 handle to write to |
84
|
|
|
|
|
|
|
# OUT: 1 flag indicating error |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub FLUSH { |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# If there is something in the buffer to be handled |
89
|
|
|
|
|
|
|
# Write out what we have in the buffer, encoding it on the fly |
90
|
|
|
|
|
|
|
# Reset the buffer |
91
|
|
|
|
|
|
|
# Return indicating success |
92
|
|
|
|
|
|
|
|
93
|
5
|
100
|
|
5
|
1
|
97
|
if ($_[0]->[0]) { |
94
|
3
|
100
|
|
|
|
6
|
print {$_[1]} MIME::Base64::encode_base64( $_[0]->[0],$_[0]->[1] ) |
|
3
|
|
|
|
|
30
|
|
95
|
|
|
|
|
|
|
or return -1; |
96
|
2
|
|
|
|
|
5
|
$_[0]->[0] = ''; |
97
|
|
|
|
|
|
|
} |
98
|
4
|
|
|
|
|
229
|
0; |
99
|
|
|
|
|
|
|
} #FLUSH |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Satisfy -require- |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |