| 1 | package App::lcpan::Cmd::extract_mod; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | require App::lcpan; | |||||||||
| 8 | |||||||||||
| 9 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 10 | 1 | our $DATE = '2023-09-26'; # DATE | |||||||||
| 11 | 1 | our $DIST = 'App-lcpan'; # DIST | |||||||||
| 12 | 1 | our $VERSION = '1.074'; # VERSION | |||||||||
| 13 | |||||||||||
| 14 | 1 | our %SPEC; | |||||||||
| 15 | |||||||||||
| 16 | 1 | $SPEC{'handle_cmd'} = { | |||||||||
| 17 | v => 1.1, | ||||||||||
| 18 | summary => "Extract a module's latest release file to current directory", | ||||||||||
| 19 | args => { | ||||||||||
| 20 | %App::lcpan::common_args, | ||||||||||
| 21 | %App::lcpan::mod_args, | ||||||||||
| 22 | }, | ||||||||||
| 23 | tags => ['write-to-fs'], | ||||||||||
| 24 | }; | ||||||||||
| 25 | 0 | ▶ | sub handle_cmd { | ||||||||
|
Subroutine
handle_cmd: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 26 | 0 | require Archive::Extract; | |||||||||
| 27 | |||||||||||
| 28 | 0 | my %args = @_; | |||||||||
| 29 | |||||||||||
| 30 | 0 | my $state = App::lcpan::_init(\%args, 'ro'); | |||||||||
| 31 | 0 | my $dbh = $state->{dbh}; | |||||||||
| 32 | |||||||||||
| 33 | 0 | my $mod = $args{module}; | |||||||||
| 34 | |||||||||||
| 35 | 0 | my $row = $dbh->selectrow_hashref("SELECT | |||||||||
| 36 | file.cpanid cpanid, | ||||||||||
| 37 | file.name name | ||||||||||
| 38 | FROM module | ||||||||||
| 39 | LEFT JOIN file ON module.file_id=file.id | ||||||||||
| 40 | WHERE module.name=? | ||||||||||
| 41 | ORDER BY version_numified DESC | ||||||||||
| 42 | ", {}, $mod); | ||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | return [404, "No release for module '$mod'"] unless $row; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | |||||||||||
| 46 | my $path = App::lcpan::_fullpath( | ||||||||||
| 47 | 0 | $row->{name}, $state->{cpan}, $row->{cpanid}); | |||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | (-f $path) or return [404, "File not found: $path"]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | |||||||||||
| 51 | 0 | my $ae = Archive::Extract->new(archive => $path); | |||||||||
| 52 | 0 | ▶ | $ae->extract or return [500, "Can't extract: " . $ae->error]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | |||||||||||
| 54 | 0 | [200, "OK", undef, {'func.release_path'=>$path}]; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | 1; | |||||||||
| 58 | # ABSTRACT: Extract a module's latest release file to current directory | ||||||||||
| 59 | |||||||||||
| 60 | __END__ | ||||||||||