blib/lib/Convert/UU.pm

filter: Statementstmt 88.0% 59 / 67 Branchbran 59.5% 25 / 42 Conditioncond 50.0% 20 / 40 MC/DCmcdc 22.7% 5 / 22 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 65.7% 119 / 181 CC 37 SCAR 39.6
CC
37
Cov
70%
uudecode
84.3
uuencode
10.5
_uudecode_chunk
3.0
CRAP 52.5
↑ Summary
1 package Convert::UU;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶BEGIN {require 5.004} # m//gc
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use vars qw($VERSION @ISA @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 require Exporter;
9  
10 2 @ISA = qw(Exporter);
11 # Items to export into callers namespace by default. Note: do not export
12 # names by default without a very good reason. Use EXPORT_OK instead.
13 # Do not simply export all your public functions/methods/constants.
14 2 @EXPORT_OK = qw(
15 uudecode uuencode
16 );
17 2 $VERSION = '0.5201';
18  
19 #
20 # From comp.lang.perl 3/1/95.
21 # Posted by Hans Mulder (hansm@wsinti05.win.tue.nl)
22 #
23  
24 3 ▶sub uuencode {
Subroutine uuencode: called CC=10 SCAR=23.5
Pod documented
25 3 ▶ croak("Usage: uuencode( {string|filehandle} [,filename] [, mode] )")
Branch: 1 branch
BranchTrueFalseTotal
unless @_ >= 1 and @_ <= 3 0 3 3
Condition33%1/3
@_ >= 1 and @_ <= 3
!ll&&!rl&&r
003
MC/DC0%0/2
@_ >= 1 and @_ <= 3
@_ >= 1 @_ <= 3
Truth table33%1/3
A and B
A= @_ >= 1B= @_ <= 3
ABresult
0X0
100
111
26 unless(@_ >= 1 && @_ <= 3);
27  
28 3 my($in,$file,$mode) = @_;
29 3 ▶ $mode ||= "644";
Condition100%2/2
$mode ||= 644
l!l
12
MC/DC100%1/1
$mode ||= 644
$mode
Truth table100%2/2
A
A= $mode
Aresult
11
00
30 3 ▶ $file ||= "uuencode.uu";
Condition100%2/2
$file ||= "uuencode.uu"
l!l
12
MC/DC100%1/1
$file ||= "uuencode.uu"
$file
Truth table100%2/2
A
A= $file
Aresult
11
00
31  
32 3 my($chunk,@result,$r);
33 3 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($in, "IO::Handle") or ref \$in eq "GLOB" or ref $in eq "GLOB" or ref $in eq "FileHandle") 1 2 3
Condition66%6/9
UNIVERSAL::isa($in, "IO::Handle") or ref \$in eq "GLOB" or ref $in eq "GLOB" or ref $in eq "FileHandle"
l!l&&r!l&&!r
102
UNIVERSAL::isa($in, "IO::Handle") or ref \$in eq "GLOB" or ref $in eq "GLOB"
l!l&&r!l&&!r
102
UNIVERSAL::isa($in, "IO::Handle") or ref \$in eq "GLOB"
l!l&&r!l&&!r
012
MC/DC25%1/4
UNIVERSAL::isa($in, "IO::Handle") or ref \$in eq "GLOB" or ref $in eq "GLOB" or ref $in eq "FileHandle"
UNIVERSAL::isa($in, "IO::Handle") ref \$in eq "GLOB" ref $in eq "GLOB" ref $in eq "FileHandle"
Truth table40%2/5
A or B or C or D
A= UNIVERSAL::isa($in, "IO::Handle")B= ref \$in eq "GLOB"C= ref $in eq "GLOB"D= ref $in eq "FileHandle"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
34 UNIVERSAL::isa( $in, 'IO::Handle' ) or
35 ref(\$in) eq "GLOB" or
36 ref($in) eq "GLOB" or
37 ref($in) eq 'FileHandle'
38 ) {
39 # local $^W = 0; # Why did I get use of undefined value here ?
40 1 binmode($in);
41 1 local $/;
42 1 $in = <$in>;
43 }
44 3 pos($in)=0;
45 3 ▶ while ($in =~ m/\G(.{1,45})/sgc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in =~ /\G(.{1,45})/cgs) 74 3 77
46 74 push @result, _uuencode_chunk($1);
47 }
48 3 push @result, "`\n";
49 3 join "", "begin $mode $file\n", @result, "end\n";
50 }
51  
52 74 ▶sub _uuencode_chunk {
Subroutine _uuencode_chunk: called CC=1 SCAR=0.0
53 74 my($string) = shift;
54 # for the Mac?
55 # my($mod3) = length($string) % 3;
56 # $string .= "\0", $mod3 -= 3 if $mod3;
57 74 my $encoded_string = pack("u", $string); # unix uuencode
58 # for the Mac?
59 # $encoded_string =~ s/.//; # remove length byte
60 # chop($encoded_string); # remove trailing \n
61 # $encoded_string =~ tr#`!-_#A-Za-z0-9+/#; # tr to mime alphabet
62 # substr($encoded_string, $mod3) =~ tr/A/=/; # adjust padding
63 74 $encoded_string;
64 }
65  
66 6 ▶sub uudecode {
Subroutine uudecode: called CC=26 SCAR=44.3
Pod documented
67 6 ▶ croak("Usage: uudecode( {string|filehandle|array ref}) ")
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 6 6
68 unless(@_ == 1);
69 6 my($in) = @_;
70  
71 6 my(@result,$file,$mode);
72 6 $mode = $file = "";
73 6 ▶ if (
Branch: 3 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($in, 'IO::Handle') or ref \$in eq 'GLOB' or ref $in eq 'GLOB' or ref $in eq 'FileHandle') { } 0 6 6
elsif (ref \$in eq 'SCALAR') { } 5 1 6
elsif (ref $in eq 'ARRAY') { } 1 0 1
Condition33%3/9
UNIVERSAL::isa($in, "IO::Handle") or ref \$in eq "GLOB" or ref $in eq "GLOB" or ref $in eq "FileHandle"
l!l&&r!l&&!r
006
UNIVERSAL::isa($in, "IO::Handle") or ref \$in eq "GLOB" or ref $in eq "GLOB"
l!l&&r!l&&!r
006
UNIVERSAL::isa($in, "IO::Handle") or ref \$in eq "GLOB"
l!l&&r!l&&!r
006
MC/DC0%0/4
UNIVERSAL::isa($in, "IO::Handle") or ref \$in eq "GLOB" or ref $in eq "GLOB" or ref $in eq "FileHandle"
UNIVERSAL::isa($in, "IO::Handle") ref \$in eq "GLOB" ref $in eq "GLOB" ref $in eq "FileHandle"
Truth table20%1/5
A or B or C or D
A= UNIVERSAL::isa($in, "IO::Handle")B= ref \$in eq "GLOB"C= ref $in eq "GLOB"D= ref $in eq "FileHandle"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
74 UNIVERSAL::isa( $in, 'IO::Handle' ) or
75 ref(\$in) eq "GLOB" or
76 ref($in) eq "GLOB" or
77 ref($in) eq 'FileHandle'
78 ) {
79 0 local($\) = "\n";
80 0 binmode($in);
81 0 ▶ while (<$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $in)) 0 0 0
82 0 ▶ if ($file eq "" and !$mode){
Branch: 1 branch
BranchTrueFalseTotal
if ($file eq "" and not $mode) 0 0 0
Condition0%0/3
$file eq "" and not $mode
!ll&&!rl&&r
000
MC/DC0%0/2
$file eq "" and not $mode
$file eq "" not $mode
Truth table0%0/3
A and not(B)
A= $file eq ""B= not $mode
ABresult
0X0
100
111
83 0 ▶ ($mode,$file) = ($1, $2) if /^begin\s+(\d+)\s+(.+)$/ ;
Branch: 1 branch
BranchTrueFalseTotal
if /^begin\s+(\d+)\s+(.+)$/ 0 0 0
84 0 next;
85 }
86 0 ▶ last if /^end/;
Branch: 1 branch
BranchTrueFalseTotal
if /^end/ 0 0 0
87 0 push @result, _uudecode_chunk($_);
88 }
89 } elsif (ref(\$in) eq "SCALAR") {
90 5 ▶ while ($in =~ m/\G(.*?(\n|\r|\r\n|\n\r))/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in =~ /\G(.*?(\n|\r|\r\n|\n\r))/cg) 93 0 93
91 93 my $line = $1;
92 93 ▶ if ($file eq "" and !$mode){
Branch: 1 branch
BranchTrueFalseTotal
if ($file eq "" and not $mode) 5 88 93
Condition66%2/3
$file eq "" and not $mode
!ll&&!rl&&r
8805
MC/DC50%1/2
$file eq "" and not $mode
$file eq "" not $mode
Truth table66%2/3
A and not(B)
A= $file eq ""B= not $mode
ABresult
0X0
100
111
93 5 ($mode,$file) = $line =~ /^begin\s+(\d+)\s+(.+)$/ ;
94 5 next;
95 }
96 88 ▶ next if $file eq "" and !$mode;
Branch: 1 branch
BranchTrueFalseTotal
if $file eq "" and not $mode 0 88 88
Condition33%1/3
$file eq "" and not $mode
!ll&&!rl&&r
8800
MC/DC0%0/2
$file eq "" and not $mode
$file eq "" not $mode
Truth table33%1/3
A and not(B)
A= $file eq ""B= not $mode
ABresult
0X0
100
111
97 88 ▶ last if $line =~ /^end/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^end/ 5 83 88
98 83 push @result, _uudecode_chunk($line);
99 }
100 } elsif (ref($in) eq "ARRAY") {
101 1 my $line;
102 1 foreach $line (@$in) {
103 3 ▶ if ($file eq "" and !$mode){
Branch: 1 branch
BranchTrueFalseTotal
if ($file eq "" and not $mode) 1 2 3
Condition66%2/3
$file eq "" and not $mode
!ll&&!rl&&r
201
MC/DC50%1/2
$file eq "" and not $mode
$file eq "" not $mode
Truth table66%2/3
A and not(B)
A= $file eq ""B= not $mode
ABresult
0X0
100
111
104 1 ($mode,$file) = $line =~ /^begin\s+(\d+)\s+(.+)$/ ;
105 1 next;
106 }
107 2 ▶ next if $file eq "" and !$mode;
Branch: 1 branch
BranchTrueFalseTotal
if $file eq "" and not $mode 0 2 2
Condition33%1/3
$file eq "" and not $mode
!ll&&!rl&&r
200
MC/DC0%0/2
$file eq "" and not $mode
$file eq "" not $mode
Truth table33%1/3
A and not(B)
A= $file eq ""B= not $mode
ABresult
0X0
100
111
108 2 ▶ last if $line =~ /^end/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^end/ 1 1 2
109 1 push @result, _uudecode_chunk($line);
110 }
111 }
112 6 ▶ wantarray ? (join("",@result),$file,$mode) : join("",@result);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 6 6
113 }
114  
115 84 ▶sub _uudecode_chunk {
Subroutine _uudecode_chunk: called CC=3 SCAR=11.0
116 84 my($chunk) = @_;
117 # return "" if $chunk =~ /^(--|\#|CREATED)/; # the "#" was an evil
118 # bug: a "#" in column
119 # one is legal!
120 84 ▶ return "" if $chunk =~ /^(?:--|CREATED)/;
Branch: 1 branch
BranchTrueFalseTotal
if $chunk =~ /^(?:--|CREATED)/ 0 84 84
121 84 my $string = substr($chunk,0,int((((ord($chunk) - 32) & 077) + 2) / 3)*4+1);
122 # warn "DEBUG: string [$string]";
123 # my $return = unpack("u", $string);
124 # warn "DEBUG: return [$return]";
125 # $return;
126  
127 84 my $ret = unpack("u", $string);
128 84 ▶ defined $ret ? $ret : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $ret ? : 79 5 84
129 }
130  
131 2 1;
132  
133 __END__
↑ Summary