ASP/UploadHandler.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 53 CC 3 SCAR 13.9
CC
3
Cov
0%
upload_start
6.0
upload_hook
6.0
upload_end
2.0
CRAP 4.0
1
2 package Apache2::ASP::UploadHandler;
3
4 use strict;
5 use base 'Apache2::ASP::HTTPHandler';
6 our $LastUpdate;
7 our $LastPercent;
8
9
10 #==============================================================================
11 sub upload_start
12 {
13 my ($s, $context, $Upload) = @_;
14
15 return unless $Upload;
16 # Store the upload information in the Session for external retrieval:
17 $LastUpdate = time();
18 $LastPercent = $Upload->{percent_complete} || 0;
19 my $uploadID = $s->_args('uploadID');
20 $context->session->{"upload$uploadID$_"} = $Upload->{$_}
21 foreach grep { $_ !~ m/data/ } keys(%$Upload);
22 $context->session->save;
23 }# end upload_start()
24
25
26 #==============================================================================
27 # The logic *we* need is already taken care of by the UploadHook's RegisterCleanup,
28 # so we can just leave this stub for subclassing:
29 sub upload_end
30 {
31 my ($s, $context, $Upload) = @_;
32
33 1;
34 }# end upload_end()
35
36
37 #==============================================================================
38 sub upload_hook
39 {
40 my ($s, $context, $Upload) = @_;
41
42 # Since this method may be called several times per second, we only
43 # want to save the Session state once per second:
44 my $Diff = time() - $LastUpdate;
45 my $PercentDiff = $Upload->{percent_complete} - $LastPercent;
46
47 if( $Diff >= 1 || $PercentDiff >= 5 )
48 {
49 my $uploadID = $s->_args('uploadID') || '';
50 # Store everything in the session except for the data
51 # (since that could be too large to serialize quickly):
52 $context->session->{"upload$uploadID$_"} = $Upload->{$_}
53 foreach grep { $_ !~ m/data/ } keys(%$Upload);
54 $context->session->save;
55 $LastUpdate = time();
56 $LastPercent = $Upload->{percent_complete};
57 }# end if()
58 }# end upload_hook()
59  
60
61 #==============================================================================
62 sub _args
63 {
64 my ($s, $key) = @_;
65
66 my %args = map {
67 split /\=/, $_
68 } split /&/, $ENV{QUERY_STRING};
69
70 return $args{$key};
71 }# end _args()
72
73 1;# return true:
74
75 __END__