Perinci/CmdLine/github/cmd.pm

filter: Statementstmt 33.3% 17 / 51 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 27.1% 22 / 81 CC 10 SCAR 43.0
CC
10
Cov
24%
hook_before_parse_argv
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 73.7
↑ Summary App/github/cmd.pm »
1 package Perinci::CmdLine::github::cmd;
2  
3 1 our $DATE = '2020-04-08'; # DATE
4 1 our $VERSION = '0.008'; # VERSION
5  
6 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use parent 'Perinci::CmdLine::Lite';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub hook_before_parse_argv {
Subroutine hook_before_parse_argv: not called CC=10 SCAR=47.0
Pod undocumented
14 0 my ($self, $r) = @_;
15  
16 # we want to run 'setup' when user runs 'github-cmd' the first time (without
17 # any subcommand) and without login/pass or token specified in the config
18 # file
19 RUN_SETUP:
20 {
21 0 $self->_parse_argv1($r);
22 0 ▶ last if $r->{subcommand_name};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"subcommand_name"} 0 0 0
23 0 ▶ $self->_read_config($r) unless $r->{config};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"config"} 0 0 0
24 last if defined($r->{config}{GLOBAL}{login}) &&
25 defined($r->{config}{GLOBAL}{pass}) ||
26 0 ▶ defined($r->{config}{GLOBAL}{access_token});
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"config"}{"GLOBAL"}{"login"} and defined $r->{"config"}{"GLOBAL"}{"pass"} or defined $r->{"config"}{"GLOBAL"}{"access_token"} 0 0 0
Condition0%0/6
defined $r->{"config"}{"GLOBAL"}{"login"} and defined $r->{"config"}{"GLOBAL"}{"pass"} or defined $r->{"config"}{"GLOBAL"}{"access_token"}
l!l&&r!l&&!r
000
defined $r->{"config"}{"GLOBAL"}{"login"} and defined $r->{"config"}{"GLOBAL"}{"pass"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $r->{"config"}{"GLOBAL"}{"login"} and defined $r->{"config"}{"GLOBAL"}{"pass"} or defined $r->{"config"}{"GLOBAL"}{"access_token"}
defined $r->{"config"}{"GLOBAL"}{"login"} defined $r->{"config"}{"GLOBAL"}{"pass"} defined $r->{"config"}{"GLOBAL"}{"access_token"}
Truth table0%0/5
A and B or C
A= defined $r->{"config"}{"GLOBAL"}{"login"}B= defined $r->{"config"}{"GLOBAL"}{"pass"}C= defined $r->{"config"}{"GLOBAL"}{"access_token"}
ABCresult
11X1
0X11
1011
0X00
1000
27 0 log_trace "User does not have defined login+pass or token in ".
28 "configuration, running setup ...";
29 0 require Term::ReadKey;
30 0 my ($login, $pass);
31 0 while (1) {
32 0 print "Setting up github-cmd. Please enter GitHub login: ";
33 0 chomp($login = <STDIN>);
34 0 ▶ last if $login =~ /\A\w+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $login =~ /\A\w+\z/ 0 0 0
35 }
36 0 while (1) {
37 0 print "Please enter GitHub password: ";
38 0 Term::ReadKey::ReadMode('noecho');
39 0 chomp($pass = <STDIN>);
40 0 Term::ReadKey::ReadMode('normal');
41 0 print "\n";
42 0 ▶ last if length $login;
Branch: 1 branch
BranchTrueFalseTotal
if length $login 0 0 0
43 }
44 0 require PERLANCAR::File::HomeDir;
45 0 my $path = PERLANCAR::File::HomeDir::get_my_home_dir() .
46 "/github-cmd.conf";
47 0 require Config::IOD;
48 0 my $iod = Config::IOD->new;
49 0 require Config::IOD::Document;
50 0 ▶ my $doc = (-f $path) ? $iod->read_file($path) :
Branch: 1 branch
BranchTrueFalseTotal
-f $path ? : 0 0 0
51 Config::IOD::Document->new;
52 0 $doc->insert_section({ignore=>1}, 'GLOBAL');
53 0 $doc->insert_key({replace=>1}, 'GLOBAL', 'login', $login);
54 0 $doc->insert_key({replace=>1}, 'GLOBAL', 'pass', $pass);
55 0 ▶ open my $fh, ">", $path or die "Can't write config '$path': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $path or die "Can't write config '${path}': $!" 0 0 0
56 0 print $fh $doc->as_string;
57 0 close $fh;
58  
59 # early exit
60 0 print "Setup done, please run 'github-cmd' again.\n";
61 0 exit 0;
62 } # RUN_SETUP
63 }
64  
65 1 1;
66 # ABSTRACT: Subclass for github-cmd
67  
68 __END__
↑ Summary App/github/cmd.pm »