File Coverage

blib/lib/MIME/Decoder/Binary.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 4 50.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 34 36 94.4


line stmt bran cond sub pod time code
1             package MIME::Decoder::Binary;
2 6     6   20 use strict;
  6         8  
  6         142  
3 6     6   18 use warnings;
  6         7  
  6         170  
4              
5              
6             =head1 NAME
7              
8             MIME::Decoder::Binary - perform no encoding/decoding
9              
10              
11             =head1 SYNOPSIS
12              
13             A generic decoder object; see L for usage.
14              
15              
16             =head1 DESCRIPTION
17              
18             A MIME::Decoder subclass for the C<"binary"> encoding (in other words,
19             no encoding).
20              
21             The C<"binary"> decoder is a special case, since it's ill-advised
22             to read the input line-by-line: after all, an uncompressed image file might
23             conceivably have loooooooooong stretches of bytes without a C<"\n"> among
24             them, and we don't want to risk blowing out our core. So, we
25             read-and-write fixed-size chunks.
26              
27             Both the B and B do a simple pass-through of the data
28             from input to output.
29              
30             =head1 SEE ALSO
31              
32             L
33              
34              
35             =head1 AUTHOR
36              
37             Eryq (F), ZeeGee Software Inc (F).
38              
39             All rights reserved. This program is free software; you can redistribute
40             it and/or modify it under the same terms as Perl itself.
41              
42             =cut
43              
44 6     6   17 use MIME::Decoder;
  6         6  
  6         113  
45 6     6   17 use vars qw(@ISA $VERSION);
  6         6  
  6         1072  
46              
47             @ISA = qw(MIME::Decoder);
48              
49             ### The package version, both in 1.23 style *and* usable by MakeMaker:
50             $VERSION = "5.508";
51              
52             ### Buffer length:
53             my $BUFLEN = 8192;
54              
55             #------------------------------
56             #
57             # decode_it IN, OUT
58             #
59             sub decode_it {
60 13     13 1 14 my ($self, $in, $out) = @_;
61              
62 13         17 my ($buf, $nread) = ('', 0);
63 13         41 while ($nread = $in->read($buf, $BUFLEN)) {
64 13         173 $out->print($buf);
65             }
66 13 50       141 defined($nread) or return undef; ### check for error
67 13         31 1;
68             }
69              
70             #------------------------------
71             #
72             # encode_it IN, OUT
73             #
74             sub encode_it {
75 17     17 1 17 my ($self, $in, $out) = @_;
76              
77 17         20 my ($buf, $nread) = ('', 0);
78 17         56 while ($nread = $in->read($buf, $BUFLEN)) {
79 17         253 $out->print($buf);
80             }
81 17 50       151 defined($nread) or return undef; ### check for error
82 17         85 1;
83             }
84              
85             #------------------------------
86             1;