Decoder/UU.pm

filter: Statementstmt 100% 56 / 56 Branchbran 72.7% 16 / 22 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 10 / 10 Podpod 40.0% 2 / 5 totaltotal 83.0% 88 / 106 CC 16 SCAR 17.4
CC
16
Cov
87%
decode_it
10.2
encode_it
5.3
last_filename
2.1
CRAP 5.7
« Decoder.pm ↑ Summary Parser/Filer.pm »
1 package MIME::Decoder::UU;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 MIME::Decoder::UU - decode a "uuencoded" stream
8  
9  
10 =head1 SYNOPSIS
11  
12 A generic decoder object; see L<MIME::Decoder> for usage.
13  
14 Also supports a preamble() method to recover text before
15 the uuencoded portion of the stream.
16  
17  
18 =head1 DESCRIPTION
19  
20 A MIME::Decoder subclass for a nonstandard encoding whereby
21 data are uuencoded. Common non-standard MIME encodings for this:
22  
23 x-uu
24 x-uuencode
25  
26 =head1 SEE ALSO
27  
28 L<MIME::Decoder>
29  
30 =head1 AUTHOR
31  
32 Eryq (F<eryq@zeegee.com>), ZeeGee Software Inc (F<http://www.zeegee.com>).
33  
34 UU-decoding code lifted from "uuexplode", a Perl script by an
35 unknown author...
36  
37 All rights reserved. This program is free software; you can redistribute
38 it and/or modify it under the same terms as Perl itself.
39  
40 =cut
41  
42  
43 2 require 5.002;
44 2 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
45 2 ▶use MIME::Decoder;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 2 ▶use MIME::Tools qw(whine);
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 2 @ISA = qw(MIME::Decoder);
49  
50 # The package version, both in 1.23 style *and* usable by MakeMaker:
51 2 $VERSION = "5.522";
52  
53  
54 #------------------------------
55 #
56 # decode_it IN, OUT
57 #
58 7 ▶sub decode_it {
Subroutine decode_it: called CC=10 SCAR=23.2
Pod documented
59 7 my ($self, $in, $out) = @_;
60 7 my ($mode, $file);
61 7 my @preamble;
62  
63 ### Init:
64 7 $self->{MDU_Preamble} = \@preamble;
65 7 $self->{MDU_Mode} = undef;
66 7 $self->{MDU_File} = undef;
67  
68 ### Find beginning...
69 7 local $_;
70 7 ▶ while (defined($_ = $in->getline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $in->getline)) 16 2 18
71 16 ▶ if (/^begin(.*)/) { ### found it: now decode it...
Branch: 1 branch
BranchTrueFalseTotal
if (/^begin(.*)/) 5 11 16
72 5 my $modefile = $1;
73 5 ▶ if ($modefile =~ /^(\s+(\d+))?(\s+(.*?\S))?\s*\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modefile =~ /^(\s+(\d+))?(\s+(.*?\S))?\s*\Z/) 5 0 5
74 5 ($mode, $file) = ($2, $4);
75 }
76 5 last; ### decoded or not, we're done
77 }
78 11 push @preamble, $_;
79 }
80 7 ▶ die("uu decoding: no begin found\n") if !defined($_); # hit eof!
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 2 5 7
81  
82 ### Store info:
83 5 $self->{MDU_Mode} = $mode;
84 5 $self->{MDU_File} = $file;
85  
86 ### Decode:
87 5 ▶ while (defined($_ = $in->getline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $in->getline)) 299 0 299
88 299 ▶ last if /^end/;
Branch: 1 branch
BranchTrueFalseTotal
if /^end/ 5 294 299
89 294 ▶ next if /[a-z]/;
Branch: 1 branch
BranchTrueFalseTotal
if /[a-z]/ 0 294 294
90 294 ▶ next unless int((((ord() - 32) & 077) + 2) / 3) == int(length() / 4);
Branch: 1 branch
BranchTrueFalseTotal
unless int(((ord($_) - 32 & 63) + 2) / 3) == int length($_) / 4 0 294 294
91 294 $out->print(unpack('u', $_));
92 }
93 ### chmod oct($mode), $file; # sheeyeah... right...
94 5 ▶ whine "file incomplete, no end found\n" if !defined($_); # eof
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 5 5
95 5 1;
96 }
97  
98 #------------------------------
99 #
100 # encode_it IN, OUT
101 #
102 1 ▶sub encode_it {
Subroutine encode_it: called CC=5 SCAR=16.6
Pod documented
103 1 my ($self, $in, $out) = @_;
104 1 my $buf = '';
105  
106 1 ▶ my $fname = (($self->head &&
Condition40%2/5
$self->head && $self->head->mime_attr('content-disposition.filename') || ''
l!l
01
$self->head and $self->head->mime_attr("content-disposition.filename")
!ll&&!rl&&r
100
MC/DC0%0/2
$self->head && $self->head->mime_attr('content-disposition.filename') || ''
$self->head $self->head->mime_attr("content-disposition.filename")
Truth table33%1/3
A and B
A= $self->headB= $self->head->mime_attr("content-disposition.filename")
ABresult
111
0X0
100
107 $self->head->mime_attr('content-disposition.filename')) ||
108 '');
109 1 ▶ my $nl = $MIME::Entity::BOUNDARY_DELIMITER || "\n";
Condition50%1/2
$MIME::Entity::BOUNDARY_DELIMITER || "\n"
l!l
01
MC/DC0%0/1
$MIME::Entity::BOUNDARY_DELIMITER || "\n"
$MIME::Entity::BOUNDARY_DELIMITER
Truth table50%1/2
A
A= $MIME::Entity::BOUNDARY_DELIMITER
Aresult
11
00
110 1 $out->print("begin 644 $fname$nl");
111 1 ▶ while ($in->read($buf, 45)) { $out->print(pack('u', $buf)) }
Branch: 1 branch
BranchTrueFalseTotal
if ($in->read($buf, 45)) 68 1 69
112 1 $out->print("end$nl");
113 1 1;
114 }
115  
116 #------------------------------
117 #
118 # last_preamble
119 #
120 # Return the last preamble as ref to array of lines.
121 # Gets reset by decode_it().
122 #
123 4 ▶sub last_preamble {
Subroutine last_preamble: called CC=2 SCAR=7.2
Pod undocumented
124 4 my $self = shift;
125 4 ▶ return $self->{MDU_Preamble} || [];
Condition50%1/2
$self->{'MDU_Preamble'} || []
l!l
40
MC/DC0%0/1
$self->{'MDU_Preamble'} || []
$self->{'MDU_Preamble'}
Truth table50%1/2
A
A= $self->{'MDU_Preamble'}
Aresult
11
00
126 }
127  
128 #------------------------------
129 #
130 # last_mode
131 #
132 # Return the last mode.
133 # Gets reset to undef by decode_it().
134 #
135 4 ▶sub last_mode {
Subroutine last_mode: called CC=1 SCAR=0.0
Pod undocumented
136 4 shift->{MDU_Mode};
137 }
138  
139 #------------------------------
140 #
141 # last_filename
142 #
143 # Return the last filename.
144 # Gets reset by decode_it().
145 #
146 4 ▶sub last_filename {
Subroutine last_filename: called CC=2 SCAR=7.6
Pod undocumented
147 4 ▶ shift->{MDU_File} || [];
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"MDU_File"} or [] 4 0 4
148 }
149  
150 #------------------------------
151 2 1;
« Decoder.pm ↑ Summary Parser/Filer.pm »