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   30 use strict;
  6         11  
  6         152  
3 6     6   28 use warnings;
  6         10  
  6         238  
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   28 use MIME::Decoder;
  6         21  
  6         138  
45 6     6   27 use vars qw(@ISA $VERSION);
  6         10  
  6         1356  
46              
47             @ISA = qw(MIME::Decoder);
48              
49             ### The package version, both in 1.23 style *and* usable by MakeMaker:
50             $VERSION = "5.507";
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 25 my ($self, $in, $out) = @_;
61              
62 13         27 my ($buf, $nread) = ('', 0);
63 13         67 while ($nread = $in->read($buf, $BUFLEN)) {
64 13         238 $out->print($buf);
65             }
66 13 50       196 defined($nread) or return undef; ### check for error
67 13         48 1;
68             }
69              
70             #------------------------------
71             #
72             # encode_it IN, OUT
73             #
74             sub encode_it {
75 17     17 1 27 my ($self, $in, $out) = @_;
76              
77 17         22 my ($buf, $nread) = ('', 0);
78 17         134 while ($nread = $in->read($buf, $BUFLEN)) {
79 17         377 $out->print($buf);
80             }
81 17 50       216 defined($nread) or return undef; ### check for error
82 17         116 1;
83             }
84              
85             #------------------------------
86             1;