File Coverage

lib/App/MtAws/QueueJob/Upload.pm
Criterion Covered Total %
statement 43 44 97.7
branch 19 20 95.0
condition 4 4 100.0
subroutine 13 13 100.0
pod 0 4 0.0
total 79 85 92.9


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::Upload;
22              
23             our $VERSION = '1.114_2';
24              
25 8     8   526 use strict;
  8         11  
  8         210  
26 8     8   29 use warnings;
  8         10  
  8         177  
27 8     8   29 use Carp;
  8         8  
  8         346  
28              
29 8     8   34 use App::MtAws::QueueJobResult;
  8         9  
  8         426  
30 8     8   3816 use App::MtAws::QueueJob::UploadMultipart;
  8         18  
  8         232  
31 8     8   3451 use App::MtAws::QueueJob::Delete;
  8         16  
  8         174  
32 8     8   35 use base 'App::MtAws::QueueJob';
  8         10  
  8         2771  
33              
34             sub init
35             {
36 44     44 0 52 my ($self) = @_;
37 44 100 100     644 defined($self->{filename}) xor $self->{stdin} or confess "filename xor stdin should be specified";
38 41 100       229 defined($self->{relfilename}) || confess "no relfilename";
39 40 100       223 defined($self->{delete_after_upload}) || confess "delete_after_upload must be defined";
40 39 100       396 $self->{partsize}||confess;
41 37 100       91 if ($self->{delete_after_upload}) {
42 15 100       180 confess "archive_id must present if you're deleting" unless $self->{archive_id};
43             } else {
44 22 100       178 confess "archive_id not needed here" if $self->{archive_id};
45             }
46 35         127 $self->enter("multipart_upload");
47 35         69 return $self;
48             }
49              
50              
51             sub on_multipart_upload
52             {
53 11     11 0 20 my ($self) = @_;
54             return
55             state("wait"),
56 44         128 job( App::MtAws::QueueJob::UploadMultipart->new(map { $_ => $self->{$_} } qw/filename stdin relfilename partsize/), sub {
57 11 100   11   60 $self->{delete_after_upload} ? state("delete") : state("done");
58 11         40 });
59             }
60              
61              
62             sub on_delete
63             {
64 5     5 0 10 my ($self) = @_;
65             return
66             state("wait"),
67 10         64 job( App::MtAws::QueueJob::Delete->new(map { $_ => $self->{$_} } qw/relfilename archive_id/), sub {
68 5     5   17 state("done");
69 5         18 });
70             }
71              
72             sub will_do
73             {
74 2     2 0 12 my ($self) = @_;
75 2 100       11 if (defined($self->{filename})) {
    50          
76 1         11 "Will UPLOAD $self->{filename}";
77             } elsif ($self->{stdin}) {
78 1         5 "Will UPLOAD stream from STDIN";
79             } else {
80 0           confess;
81             }
82             }
83              
84             1;