| 1 | package OrePAN2::S3::Role::Inject; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use CLI::Simple::Constants qw(:booleans); | ||
| 7 | use CLI::Simple::Utils qw(slurp); | ||
| 8 | use English qw(-no_match_vars); | ||
| 9 | use File::Basename qw(basename); | ||
| 10 | |||
| 11 | use Role::Tiny; | ||
| 12 | |||
| 13 | ######################################################################## | ||
| 14 | sub cmd_inject { | ||
| 15 | ######################################################################## | ||
| 16 | my ($self) = @_; | ||
| 17 | |||
| 18 | require IO::Compress::Gzip; | ||
| 19 | require OrePAN2::Index; | ||
| 20 | |||
| 21 | my ($file) = $self->get_args; | ||
| 22 | $file //= $self->get_distribution; | ||
| 23 | |||
| 24 | die "ERROR: no file specified\n" | ||
| 25 | if !$file; | ||
| 26 | |||
| 27 | die "ERROR: $file not found\n" | ||
| 28 | if !-e $file; | ||
| 29 | |||
| 30 | my $config = $self->get_config; | ||
| 31 | my $prefix = $config->{AWS}{prefix}; | ||
| 32 | |||
| 33 | my $base = basename($file); | ||
| 34 | |||
| 35 | # 1. upload the tarball | ||
| 36 | my $tarball_key = sprintf '%s/authors/id/%s/%s', $prefix, $self->get_author_path, $base; | ||
| 37 | |||
| 38 | my $content = slurp($file); | ||
| 39 | $self->get_s3->put_object( $self->get_bucket_name, $tarball_key, $content, content_type => 'application/gzip', ); | ||
| 40 | |||
| 41 | $self->get_logger->info( sprintf 'uploaded %s to %s', $base, $tarball_key ); | ||
| 42 | |||
| 43 | # scan the tarball for provides | ||
| 44 | my $provides = $self->scan_provides($file); | ||
| 45 | my $index_path = sprintf '%s/%s', $self->get_author_path, $base; | ||
| 46 | |||
| 47 | $self->update_index( | ||
| 48 | sub { | ||
| 49 | my ($index) = @_; | ||
| 50 | for my $package ( sort keys %{$provides} ) { | ||
| 51 | my $version = $provides->{$package}{version}; | ||
| 52 | $index->add_index( $package, $version, $index_path ); | ||
| 53 | $self->get_logger->info( sprintf 'indexed %s %s', $package, $version // 'undef' ); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | ); | ||
| 57 | |||
| 58 | return $SUCCESS; | ||
| 59 | } | ||
| 60 | |||
| 61 | 1; | ||
| 62 | |||
| 63 | __END__ | ||
| 64 | |||
| 65 | =pod | ||
| 66 | |||
| 67 | =head1 NAME | ||
| 68 | |||
| 69 | OrePAN2::S3::Role::Inject - Role providing cmd_inject for OrePAN2::S3 | ||
| 70 | |||
| 71 | =head1 DESCRIPTION | ||
| 72 | |||
| 73 | Consumed by L<OrePAN2::S3>. Provides C<cmd_inject> which uploads a | ||
| 74 | tarball to S3 and updates the DarkPAN index in a single operation. | ||
| 75 | |||
| 76 | =cut |