| 1 | package App::lcpan::Cmd::gh_clone; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||
|
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 | 1 | ▶ | use Log::ger; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | require App::lcpan; | |||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | require App::lcpan::Cmd::dist_meta; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | our $DATE = '2022-03-27'; # DATE | |||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | our $DIST = 'App-lcpan-CmdBundle-gh'; # DIST | |||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.005'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | our %SPEC; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | $SPEC{handle_cmd} = { | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||||||||||||
| 20 | summary => 'Clone github repo of a module/dist', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | args => { | ||||||||||||||||||||||||||||||||||||||||||
| 22 | %App::lcpan::common_args, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | %App::lcpan::dist_args, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | as => { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | schema => 'dirname*', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | pos => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | deps => { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | prog => 'git', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub handle_cmd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_cmd: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $state = App::lcpan::_init(\%args, 'ro'); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $dbh = $state->{dbh}; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my ($dist, $file_id); | |||||||||||||||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # first find dist | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if (($file_id) = $dbh->selectrow_array( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | "SELECT id FROM file WHERE dist_name=? AND is_latest_dist", {}, $args{module_or_dist})) { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $dist = $args{module_or_dist}; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # try mod | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if (($file_id, $dist) = $dbh->selectrow_array("SELECT m.file_id, f.dist_name FROM module m JOIN file f ON m.file_id=f.id WHERE m.name=?", {}, $args{module_or_dist})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $file_id or return [404, "No such module/dist '$args{module_or_dist}'"]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $res = App::lcpan::Cmd::dist_meta::handle_cmd(%args, dist=>$dist); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return [412, $res->[1]] unless $res->[0] == 200; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $meta = $res->[2]; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | unless ($meta->{resources} && $meta->{resources}{repository} && $meta->{resources}{repository}{type} eq 'git') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$meta->{"resources"} and $meta->{"resources"}{"repository"} and $meta->{"resources"}{"repository"}{"type"} eq "git"
$meta->{"resources"} and $meta->{"resources"}{"repository"}
MC/DC0%0/3
$meta->{"resources"} and $meta->{"resources"}{"repository"} and $meta->{"resources"}{"repository"}{"type"} eq "git"
$meta->{"resources"}
$meta->{"resources"}{"repository"}
$meta->{"resources"}{"repository"}{"type"} eq "git"
Truth table0%0/4
A and B and C
A= $meta->{"resources"}B= $meta->{"resources"}{"repository"}C= $meta->{"resources"}{"repository"}{"type"} eq "git"
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return [412, "No git repository specified in the distmeta's resources"]; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $url = $meta->{resources}{repository}{url}; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | unless ($url =~ m!^https?://github\.com!i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | return [412, "Git repository is not on github ($url)"]; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | require IPC::System::Options; | |||||||||||||||||||||||||||||||||||||||||
| 67 | IPC::System::Options::system({log=>1, die=>1}, "git", "clone", $url, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | ( defined $args{as} ? ($args{as}) : ())); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | [200]; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 73 | # ABSTRACT: Clone github repo of a module/dist | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||||||||||||||||||||||