blib/lib/Pinto/Remote/SelfContained/Util.pm

filter: Statementstmt 64.1% 34 / 53 Branchbran 0.0% 0 / 10 Conditioncond 71.4% 10 / 14 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 80.0% 12 / 15 Podpod 0.0% 0 / 5 totaltotal 55.8% 57 / 102 CC 11 SCAR 19.1
CC
11
Cov
57%
get_password
20.0
password_exec
12.0
current_username
6.7
CRAP 6.8
« blib/lib/Pinto/Remote/SelfContained/Request.pm ↑ Summary blib/lib/Pinto/Remote/SelfContained/Chrome.pm »
1 package
2 Pinto::Remote::SelfContained::Util; # hide from PAUSE
3 # ABSTRACT: various utility functions
4  
5 6 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶use Capture::Tiny qw(capture);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Time::Moment;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use IO::Interactive qw(is_interactive);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Term::ReadKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 6 our $VERSION = '1.999'; # TRIAL VERSION
18  
19 6 our @EXPORT_OK = qw(
20 current_time_offset
21 current_username
22 get_password
23 mask_uri_passwords
24 password_exec
25 );
26  
27 5 ▶sub current_time_offset { Time::Moment->now->offset }
Subroutine current_time_offset: called CC=1 SCAR=0.0
Pod undocumented
28  
29 2 ▶sub current_username {
Subroutine current_username: called CC=6 SCAR=19.0
Pod undocumented
30 return $ENV{PINTO_USERNAME} // $ENV{USER} // $ENV{LOGIN} // $ENV{USERNAME} // $ENV{LOGNAME}
31 2 ▶ // croak("Can't determine username; try setting \$PINTO_USERNAME");
Condition71%10/14
(((($ENV{"PINTO_USERNAME"} // $ENV{"USER"}) // $ENV{"LOGIN"}) // $ENV{"USERNAME"}) // $ENV{"LOGNAME"}) // croak("Can't determine username; try setting \$PINTO_USERNAME")
l!l
11
((($ENV{"PINTO_USERNAME"} // $ENV{"USER"}) // $ENV{"LOGIN"}) // $ENV{"USERNAME"}) // $ENV{"LOGNAME"}
l!l&&r!l&&!r
101
(($ENV{"PINTO_USERNAME"} // $ENV{"USER"}) // $ENV{"LOGIN"}) // $ENV{"USERNAME"}
l!l&&r!l&&!r
101
($ENV{"PINTO_USERNAME"} // $ENV{"USER"}) // $ENV{"LOGIN"}
l!l&&r!l&&!r
101
$ENV{"PINTO_USERNAME"} // $ENV{"USER"}
l!l&&r!l&&!r
101
MC/DC20%1/5
(((($ENV{"PINTO_USERNAME"} // $ENV{"USER"}) // $ENV{"LOGIN"}) // $ENV{"USERNAME"}) // $ENV{"LOGNAME"}) // croak("Can't determine username; try setting \$PINTO_USERNAME")
$ENV{"PINTO_USERNAME"} $ENV{"USER"} $ENV{"LOGIN"} $ENV{"USERNAME"} $ENV{"LOGNAME"}
Truth table33%2/6
A // B // C // D // E
A= $ENV{"PINTO_USERNAME"}B= $ENV{"USER"}C= $ENV{"LOGIN"}D= $ENV{"USERNAME"}E= $ENV{"LOGNAME"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
32 }
33  
34 0 ▶sub get_password {
Subroutine get_password: not called CC=4 SCAR=30.0
Pod undocumented
35 # Environment Set
36 0 ▶ return $ENV{PINTO_PASSWORD} if $ENV{PINTO_PASSWORD};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PINTO_PASSWORD"} 0 0 0
37  
38 # Try password exec
39 return password_exec($ENV{PINTO_PASSEXEC})
40 0 ▶ if $ENV{PINTO_PASSEXEC};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PINTO_PASSEXEC"} 0 0 0
41  
42 0 ▶ if( is_interactive() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_interactive()) 0 0 0
43 0 local $|=1;
44 0 printf "Pinto password: ";
45 0 ReadMode('noecho');
46 0 my $password = ReadLine();
47 0 ReadMode('normal');
48 0 chomp($password);
49 0 return $password;
50 }
51  
52 0 return;
53 }
54  
55 15 ▶sub mask_uri_passwords {
Subroutine mask_uri_passwords: called CC=1 SCAR=0.0
Pod undocumented
56 15 my ($uri) = @_;
57  
58 15 $uri =~ s{ (https?://[^:/@]+ :) [^@/]+@}{$1*password*@}gx;
59 15 return $uri;
60 }
61  
62 0 ▶sub password_exec {
Subroutine password_exec: not called CC=3 SCAR=24.8
Pod undocumented
63 0 my (@cmd) = @_;
64  
65 0 ▶ my ($out,$err,$rc) = capture { system @cmd };
Subroutine __ANON__: not called CC=1 SCAR=6.9
66  
67 0 ▶ if( $rc == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc == 0) 0 0 0
68 0 chomp($out);
69 0 ▶ warn sprintf "password_exec(%s) returned empty password", join(' ', @cmd)
Branch: 1 branch
BranchTrueFalseTotal
unless length $out 0 0 0
70 unless length $out;
71 0 return $out;
72 }
73  
74 # Unsuccesful
75 0 die sprintf "password_exec(%s) returned non-zero exit code: rc=%d, stderr='%s'",
76 $rc, $err;
77 }
78  
79 6 1;
80  
81 __END__
« blib/lib/Pinto/Remote/SelfContained/Request.pm ↑ Summary blib/lib/Pinto/Remote/SelfContained/Chrome.pm »