S3/Indexer.pm untested

filter: Statementstmt 0.0% 0 / 59 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 115 CC 5 SCAR 17.0
CC
5
Cov
0%
new
20.0
AUTOLOAD
6.0
get_logger
2.0
CRAP 5.5
1 package OrePAN2::S3::Indexer;
2  
3 use strict;
4 use warnings;
5  
6 use Carp;
7 use Cwd qw(getcwd);
8 use Log::Log4perl;
9 use Data::Dumper;
10 use JSON qw(decode_json);
11 use English qw(-no_match_vars);
12  
13 use Role::Tiny::With;
14  
15 with qw(
16 OrePAN2::S3::Role::Inject
17 OrePAN2::S3::Role::UploadArtifacts
18 );
19  
20 ########################################################################
21 sub new {
22 ########################################################################
23 my ( $class, %args ) = @_;
24  
25 my $self = bless \%args, $class;
26  
27 my $home = $ENV{HOME} ? "$ENV{HOME}/" : getcwd . q{/};
28  
29 my $config_file = $ENV{CONFIG} // q{}; # specify the absolute path
30  
31 my @candidates = ( "${home}.orepan2-s3.json", '/var/task/orepan2-s3.json', 'orepan2-s3.json', $config_file );
32  
33 $self->get_logger->debug( Dumper( [ candidates => \@candidates ] ) );
34  
35 my ($config_path) = grep { $_ && -e $_ } @candidates;
36  
37 die "ERROR: no config file found.\n"
38 if !$config_path;
39  
40 my $profile_name = $ENV{OREPAN2_PROFILE_NAME} // 'default';
41  
42 eval {
43 local $RS = undef;
44 open my $fh, '<', $config_file
45 or die "ERROR: could not open $config_file for reading: $OS_ERROR\n";
46  
47 my $config = decode_json(<$fh>);
48  
49 $self->{config} = $config->{$profile_name};
50  
51 close $fh;
52 };
53  
54 die $EVAL_ERROR
55 if $EVAL_ERROR;
56  
57 return $self;
58 }
59  
60 sub get_logger { return $_[0]->{logger} // Log::Log4perl->get_logger }
61 sub get_author_path { return $_[0]->{author_path} }
62 sub get_s3 { return $_[0]->{s3} }
63 sub get_bucket_name { return $_[0]->{bucket_name} }
64 sub get_config { return $_[0]->{config} }
65 sub get_dryrun { return $_[0]->{dryrun} }
66 sub get_save_index { return $_[0]->{save_index} }
67 sub get_update_site_index { return $_[0]->{update_save_index} }
68  
69 ########################################################################
70 sub AUTOLOAD { ## no critic
71 ########################################################################
72 our $AUTOLOAD;
73  
74 return if $AUTOLOAD =~ /DESTROY/;
75  
76 carp "You've probably injected a role that is calling a method you don't support ($AUTOLOAD)\n";
77  
78 return;
79 }
80  
81 1;