Cmd/gh_open.pm

filter: Statementstmt 46.5% 20 / 43 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 34.7% 25 / 72 CC 10 SCAR 43.7
CC
10
Cov
32%
handle_cmd
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 78.9
↑ Summary Cmd/gh_clone.pm »
1 package App::lcpan::Cmd::gh_open;
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 => 'Open the GitHub project page of a module/dist',
21 args => {
22 %App::lcpan::common_args,
23 %App::lcpan::mod_or_dist_args,
24 },
25 };
26 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=10 SCAR=47.0
Pod documented
27 0 my %args = @_;
28  
29 0 my $state = App::lcpan::_init(\%args, 'ro');
30 0 my $dbh = $state->{dbh};
31  
32 0 my ($dist, $file_id);
33 {
34 # first find dist
35 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
36 "SELECT id FROM file WHERE dist_name=? AND is_latest_dist", {}, $args{module_or_dist})) {
37 0 $dist = $args{module_or_dist};
38 0 last;
39 }
40 # try mod
41 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
42 0 last;
43 }
44 }
45 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
46  
47 0 my $res = App::lcpan::Cmd::dist_meta::handle_cmd(%args, dist=>$dist);
48 0 ▶ return [412, $res->[1]] unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
49 0 my $meta = $res->[2];
50  
51 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
52 0 return [412, "No git repository specified in the distmeta's resources"];
53 }
54 0 my $url = $meta->{resources}{repository}{web};
55 0 ▶ unless ($url =~ m!^https?://github\.com!i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($url =~ m[^https?://github\.com]i) 0 0 0
56 0 return [412, "Git repository web URL not on github ($url)"];
57 }
58  
59 0 require Browser::Open;
60 0 my $err = Browser::Open::open_browser($url);
61 0 ▶ return [500, "Can't open browser"] if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
62 0 [200];
63 }
64  
65 1 1;
66 # ABSTRACT: Open the GitHub project page of a module/dist
67  
68 __END__
↑ Summary Cmd/gh_clone.pm »