File Coverage

blib/lib/PerlIO/Via/Base64.pm
Criterion Covered Total %
statement 20 20 100.0
branch 7 8 87.5
condition n/a
subroutine 7 7 100.0
pod 1 4 25.0
total 35 39 89.7


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 1     1   69610 use strict;
  1         3  
  1         39  
7             $PerlIO::Via::Base64::VERSION = 0.03;
8              
9             # Make sure the encoding/decoding stuff is available
10              
11 1     1   488 use MIME::Base64 (); # no need to pollute this namespace
  1         741  
  1         248  
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 99 shift;
34 3 100       11 $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 0 1678 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 0 21 local $/ = undef;
62 6         92 my $line = readline( $_[1] );
63 6 100       66 (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   10 $_[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 4 100   4 0 15 if ($_[0]->[0]) {
94 2 50       4 print {$_[1]} MIME::Base64::encode_base64( $_[0]->[0],$_[0]->[1] )
  2         20  
95             or return -1;
96 2         6 $_[0]->[0] = '';
97             }
98 4         205 0;
99             } #FLUSH
100              
101             # Satisfy -require-
102              
103             1;
104              
105             __END__