ASP/UploadHandler.pm untested

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