File Coverage

lib/App/MtAws/Glacier/ListJobs.pm
Criterion Covered Total %
statement 43 45 95.5
branch 8 12 66.6
condition 5 6 83.3
subroutine 16 17 94.1
pod 0 3 0.0
total 72 83 86.7


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::Glacier::ListJobs;
22              
23             our $VERSION = '1.114_2';
24              
25 9     9   31470 use strict;
  9         15  
  9         229  
26 9     9   36 use warnings;
  9         14  
  9         206  
27 9     9   39 use utf8;
  9         11  
  9         47  
28              
29 9     9   176 use Carp;
  9         12  
  9         465  
30 9     9   1289 use JSON::XS 1.00;
  9         12889  
  9         461  
31              
32 9     9   52 use App::MtAws::Utils;
  9         17  
  9         1164  
33 9     9   1922 use App::MtAws::MetaData;
  9         16  
  9         4406  
34              
35              
36             sub new
37             {
38 296     296 0 16639 my $class = shift;
39 296         669 my $self = { rawdata => \$_[0] };
40 296         446 bless $self, $class;
41 296         666 $self;
42             }
43              
44             sub _parse
45             {
46 296     296   296 my ($self) = @_;
47 296 50       597 return if $self->{data};
48 296 50       1060 $self->{data} = JSON::XS->new->allow_nonref->decode(${ delete $self->{rawdata} || confess });
  296         14110  
49              
50             # get rid of JSON::XS boolean object, just in case.
51             # also JSON::XS between versions 1.0 and 2.1 (inclusive) do not allow to modify this field
52             # (modification of read only error thrown)
53 296         766 $_->{Completed} = !!(delete $_->{Completed}) for @{$self->{data}{JobList}};
  296         6496  
54             }
55              
56              
57             sub _completed
58             {
59 2008 100   2008   8057 $_->{Completed} && $_->{StatusCode} eq 'Succeeded'
60             }
61              
62             sub _full_inventory
63             {
64             !(
65             $_->{InventoryRetrievalParameters} &&
66             (
67             defined $_->{InventoryRetrievalParameters}{StartDate} ||
68             defined $_->{InventoryRetrievalParameters}{EndDate} ||
69             defined $_->{InventoryRetrievalParameters}{Limit} ||
70             defined $_->{InventoryRetrievalParameters}{Marker}
71             )
72 322   66 322   1447 )
73             }
74              
75             # TODO: yet unused. release after some time
76             sub _meta_full_inventory
77             {
78 0     0   0 my ($type) = meta_job_decode($_->{JobDescription});
79 0 0       0 $type && $type eq META_JOB_TYPE_FULL;
80             }
81              
82             sub _filter_and_return_entries
83             {
84 296     296   345 my ($self, $filter_cb) = @_;
85 296         518 $self->_parse;
86 296         8043 my $x = \&inventory;
87 296         388 return $self->{data}{Marker}, grep { $filter_cb->() } @{$self->{data}{JobList}};
  2788         2619  
  296         524  
88             }
89              
90             sub get_inventory_entries
91             {
92 864 100 100 864 0 2135 shift->_filter_and_return_entries(sub { $_->{Action} eq 'InventoryRetrieval' && _completed() && _full_inventory() }); # && _meta_full_inventory()
  100     100   475  
93             }
94              
95             sub get_archive_entries
96             {
97 1924 100   1924 0 3419 shift->_filter_and_return_entries(sub { $_->{Action} eq 'ArchiveRetrieval' && _completed() });
  196     196   732  
98             }
99              
100             1;