Storage/S3.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.6% 13 / 15 CC 1 SCAR 0.7
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Storage/S3/Adapter/NetAmazonS3.pm ↑ Summary
1 package AnyPAN::Storage::S3;
2 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 our $VERSION = "0.05";
7  
8 0 ▶use Class::Accessor::Lite ro => [qw/retry_policy adapter/];
Subroutine BEGIN: called CC=1 SCAR=2.6
9  
10 use Carp qw/croak/;
11 use Path::Tiny ();
12  
13 use AnyPAN::RetryPolicy::ExponentialBackoff;
14  
15 our $DEFAULT_RETRY_POLICY = AnyPAN::RetryPolicy::ExponentialBackoff->new(
16 max_retries => 5,
17 interval => 1,
18 jitter_factor => 0.05,
19 );
20  
21 sub new {
22 my ($class, %args) = @_;
23 croak 'adapter required' unless defined $args{adapter};
24 $args{retry_policy} ||= $DEFAULT_RETRY_POLICY;
25 bless \%args, $class;
26 }
27  
28 sub copy {
29 my ($self, $from_path, $save_key) = @_;
30 $self->retry_policy->apply_and_doit(sub {
31 $self->adapter->upload($from_path, $save_key);
32 });
33 }
34  
35 sub exists :method {
36 my ($self, $save_key) = @_;
37 return $self->retry_policy->apply_and_doit(sub {
38 return $self->adapter->exists($save_key);
39 });
40 }
41  
42 sub fetch {
43 my ($self, $save_key) = @_;
44 return $self->retry_policy->apply_and_doit(sub {
45 my $tempfile = Path::Tiny->tempfile(UNLINK => 1);
46  
47 my $downloaded = $self->adapter->download($save_key, $tempfile->cached_temp);
48 return unless $downloaded;
49  
50 return $tempfile;
51 });
52 }
53  
54 1;
55 __END__
« Storage/S3/Adapter/NetAmazonS3.pm ↑ Summary