File Coverage

lib/App/MtAws/QueueJob/UploadMultipart.pm
Criterion Covered Total %
statement 47 47 100.0
branch 6 6 100.0
condition 7 13 53.8
subroutine 15 15 100.0
pod 0 4 0.0
total 75 85 88.2


line stmt bran cond sub pod time code
1             # mt-aws-glacier - Amazon Glacier sync client
2             # Copyright (C) 2012-2014 Victor Efimov
3             # http://mt-aws.com (also http://vs-dev.com) vs@vs-dev.com
4             # License: GPLv3
5             #
6             # This file is part of "mt-aws-glacier"
7             #
8             # mt-aws-glacier is free software: you can redistribute it and/or modify
9             # it under the terms of the GNU General Public License as published by
10             # the Free Software Foundation, either version 3 of the License, or
11             # (at your option) any later version.
12             #
13             # mt-aws-glacier is distributed in the hope that it will be useful,
14             # but WITHOUT ANY WARRANTY; without even the implied warranty of
15             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16             # GNU General Public License for more details.
17             #
18             # You should have received a copy of the GNU General Public License
19             # along with this program. If not, see <http://www.gnu.org/licenses/>.
20              
21             package App::MtAws::QueueJob::UploadMultipart;
22              
23             our $VERSION = '1.114_2';
24              
25 9     9   819 use strict;
  9         13  
  9         333  
26 9     9   36 use warnings;
  9         10  
  9         200  
27 9     9   41 use Carp;
  9         14  
  9         428  
28              
29 9     9   37 use App::MtAws::QueueJobResult;
  9         12  
  9         532  
30 9     9   3872 use App::MtAws::QueueJob::MultipartCreate;
  9         17  
  9         217  
31 9     9   4310 use App::MtAws::QueueJob::MultipartPart;
  9         23  
  9         239  
32 9     9   4234 use App::MtAws::QueueJob::MultipartFinish;
  9         17  
  9         216  
33 9     9   55 use base 'App::MtAws::QueueJob';
  9         15  
  9         3975  
34              
35             sub init
36             {
37 24     24 0 34 my ($self) = @_;
38 24 100 100     384 defined($self->{filename}) xor $self->{stdin} or confess "filename xor stdin should be specified";
39 21 100       154 defined($self->{relfilename}) || confess "no relfilename";
40 20 100       311 $self->{partsize}||confess;
41 18         72 $self->enter("create");
42 18         30 return $self;
43             }
44              
45              
46             sub on_create
47             {
48 13     13 0 22 my ($self) = @_;
49             return
50             state("wait"),
51 52         148 job( App::MtAws::QueueJob::MultipartCreate->new(map { $_ => $self->{$_} } qw/filename stdin relfilename partsize/), sub {
52 13     13   24 my $j = shift;
53 13   33     213 defined($self->{$_} = $j->{$_}) or confess for qw/fh upload_id mtime/;
54 13         39 state("part")
55 13         46 });
56             }
57              
58              
59             sub on_part
60             {
61 13     13 0 39 my ($self) = @_;
62             return
63             state("wait"),
64 78         179 job( App::MtAws::QueueJob::MultipartPart->new(map { $_ => $self->{$_} } qw/relfilename stdin partsize mtime upload_id fh/), sub {
65 13     13   24 my $j = shift;
66 13   33     63 $self->{filesize} = $j->{position} || confess;
67 13   33     104 $self->{th} = $j->{th} || confess;
68 13         40 state("finish")
69 13         37 });
70             }
71              
72             sub on_finish
73             {
74 13     13 0 26 my ($self) = @_;
75             return
76             state("wait"),
77 65         213 job( App::MtAws::QueueJob::MultipartFinish->new(map { $_ => $self->{$_} } qw/upload_id filesize mtime relfilename th/), sub {
78 13     13   43 state("done")
79 13         38 });
80             }
81              
82             1;
83              
84             __END__