| 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
| |||||||||||||||||||||
| 18 | 0 | ▶ | $__platform =~ /^MAC/ && return 'MacOS'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 19 | 0 | ▶ | $__platform =~ /x$/ && return ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 50 | 0 | ▶ | if ($basename =~ m/^(.*)$/) { $basename = $1; } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | open O, ">$path/$basename" || die $!; | ||||||||||||||||||
|
Condition0%0/2
">$path/$basename" || die($!)
MC/DC0%0/1
">$path/$basename" || die($!)
">$path/$basename"
Truth table0%0/2
A
A= ">$path/$basename"
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | ▶ | (open K, ">$temp_dir/$basename" || die $!) if $kludge; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
">$temp_dir/$basename" || die($!)
MC/DC0%0/1
">$temp_dir/$basename" || die($!)
">$temp_dir/$basename"
Truth table0%0/2
A
A= ">$temp_dir/$basename"
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 66 | 0 | ▶ | if ($kludge) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | 0 | ▶ | die "error with print: $!" unless (print K $buffer); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 0 | close O; | |||||||||||||||||||
| 75 | 0 | ▶ | close K if $kludge; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | return $basename; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 1 | 1; | |||||||||||||||||||
| 85 | |||||||||||||||||||||