Cmd/gh_clone.pm

filter: Statementstmt 47.6% 20 / 42 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 35.2% 25 / 71 CC 10 SCAR 43.7
CC
10
Cov
32%
handle_cmd
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 78.9
« Cmd/gh_open.pm ↑ Summary CmdBundle/gh.pm »
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
BranchTrueFalseTotal
if (($file_id) = $dbh->selectrow_array("SELECT id FROM file WHERE dist_name=? AND is_latest_dist", {}, $args{"module_or_dist"})) 0 0 0
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
BranchTrueFalseTotal
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"})) 0 0 0
49 0 last;
50 }
51 }
52 0 ▶ $file_id or return [404, "No such module/dist '$args{module_or_dist}'"];
Branch: 1 branch
BranchTrueFalseTotal
$file_id or return [404, qq[No such module/dist '$args{"module_or_dist"}']] 0 0 0
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
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
56 0 my $meta = $res->[2];
57  
58 0 ▶ unless ($meta->{resources} && $meta->{resources}{repository} && $meta->{resources}{repository}{type} eq 'git') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta->{"resources"} and $meta->{"resources"}{"repository"} and $meta->{"resources"}{"repository"}{"type"} eq "git") 0 0 0
Condition0%0/6
$meta->{"resources"} and $meta->{"resources"}{"repository"} and $meta->{"resources"}{"repository"}{"type"} eq "git"
!ll&&!rl&&r
000
$meta->{"resources"} and $meta->{"resources"}{"repository"}
!ll&&!rl&&r
000
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"
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
unless ($url =~ m[^https?://github\.com]i) 0 0 0
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
BranchTrueFalseTotal
defined $args{'as'} ? : 0 0 0
69 0 [200];
70 }
71  
72 1 1;
73 # ABSTRACT: Clone github repo of a module/dist
74  
75 __END__
« Cmd/gh_open.pm ↑ Summary CmdBundle/gh.pm »