File.pm

filter: Statementstmt 22.4% 11 / 49 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 3 / 6 Podpod 66.6% 2 / 3 totaltotal 17.0% 16 / 94 CC 18 SCAR 48.8
CC
18
Cov
13%
upload
210.0
platform
20.0
wifd
6.0
CRAP 132.0
↑ Summary GetString.pl »
1 #!/usr/bin/perl -w
2  
3  
4 1 ▶use HTTP::Headers::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 1 $HTTP::File::VERSION = '4.0';
10  
11 package HTTP::File;
12 0 ▶sub platform {
Subroutine platform: not called CC=4 SCAR=30.0
Pod documented
13  
14 0 my $__platform;
15  
16 0 $__platform = HTTP::Headers::UserAgent::GetPlatform ($ENV{HTTP_USER_AGENT});
17 0 ▶ $__platform =~ /^Win/ && return 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
$__platform =~ /^Win/ and return "MSWin32" 0 0 0
18 0 ▶ $__platform =~ /^MAC/ && return 'MacOS';
Branch: 1 branch
BranchTrueFalseTotal
$__platform =~ /^MAC/ and return "MacOS" 0 0 0
19 0 ▶ $__platform =~ /x$/ && return '';
Branch: 1 branch
BranchTrueFalseTotal
$__platform =~ /x$/ and return "" 0 0 0
20  
21  
22 }
23  
24 # wifd == warn if debug
25  
26 0 ▶sub wifd { warn "HTTP::File --- $_[0]" if $_[1]; }
Subroutine wifd: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 0 0 0
27  
28 0 ▶sub upload {
Subroutine upload: not called CC=14 SCAR=53.5
Pod documented
29  
30 0 my ($raw_file, $path,$debug,$kludge) = @_;
31 0 my $temp_dir = '/tmp';
32  
33 0 ▶ $path = $path ? $path : $temp_dir;
Branch: 1 branch
BranchTrueFalseTotal
$path ? : 0 0 0
34 0 my $platform = platform;
35  
36 0 wifd "raw_file \t $raw_file" , $debug;
37 0 wifd "path \t $path" , $debug;
38 0 wifd "platform \t $platform" , $debug;
39  
40 0 File::Basename::fileparse_set_fstype(platform);
41 0 my ($basename,$junk,$junk2) = File::Basename::fileparse $raw_file;
42  
43 0 wifd(sprintf("ref(raw_file) \t %s", ref($raw_file)) , $debug);
44 0 wifd "raw_file \t $raw_file" , $debug;
45 0 wifd "path \t $path" , $debug;
46 0 wifd "platform \t $platform" , $debug;
47 0 wifd "basename \t $basename" , $debug;
48  
49 0 ▶ if ($path =~ m/^(.*)$/) { $path = $1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ /^(.*)$/) 0 0 0
50 0 ▶ if ($basename =~ m/^(.*)$/) { $basename = $1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($basename =~ /^(.*)$/) 0 0 0
51  
52 0 ▶ open O, ">$path/$basename" || die $!;
Condition0%0/2
">$path/$basename" || die($!)
l!l
00
MC/DC0%0/1
">$path/$basename" || die($!)
">$path/$basename"
Truth table0%0/2
A
A= ">$path/$basename"
Aresult
11
00
53 # If the input file is binary, the output file should also be binary
54 0 ▶ binmode O if (-B $raw_file);
Branch: 1 branch
BranchTrueFalseTotal
if -B $raw_file 0 0 0
55  
56 0 ▶ (open K, ">$temp_dir/$basename" || die $!) if $kludge;
Branch: 1 branch
BranchTrueFalseTotal
if $kludge 0 0 0
Condition0%0/2
">$temp_dir/$basename" || die($!)
l!l
00
MC/DC0%0/1
">$temp_dir/$basename" || die($!)
">$temp_dir/$basename"
Truth table0%0/2
A
A= ">$temp_dir/$basename"
Aresult
11
00
57 {
58 0 my $buffer;
59 0 my $bytesread = read($raw_file,$buffer,1024);
60  
61 # let's exit with an error if read() returned undef
62 0 ▶ die "error with file read: $!" if !defined($bytesread);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytesread 0 0 0
63  
64 # let's exit with an error if print() did not return true
65 0 ▶ die "error with print: $!" unless (print O $buffer);
Branch: 1 branch
BranchTrueFalseTotal
unless print O $buffer 0 0 0
66 0 ▶ if ($kludge) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kludge) 0 0 0
67 0 ▶ die "error with print: $!" unless (print K $buffer);
Branch: 1 branch
BranchTrueFalseTotal
unless print K $buffer 0 0 0
68 }
69  
70 # let's redo the loop if we read > 0 chars on the last read
71 0 ▶ redo unless !$bytesread;
Branch: 1 branch
BranchTrueFalseTotal
if $bytesread 0 0 0
72  
73 }
74 0 close O;
75 0 ▶ close K if $kludge;
Branch: 1 branch
BranchTrueFalseTotal
if $kludge 0 0 0
76  
77
78  
79 0 return $basename;
80  
81 }
82  
83  
84 1 1;
85  
↑ Summary GetString.pl »