Command/credentials.pm

filter: Statementstmt 53.4% 31 / 58 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 9 / 12 Podpod 100% 1 / 1 totaltotal 38.6% 41 / 106 CC 18 SCAR 53.6
CC
18
Cov
34%
run
342.0
__ANON__
2.0
__ANON__
1.1
CRAP 212.7
↑ Summary Plugin/Credentials.pm »
1 package Mojolicious::Command::credentials;
2 1 $Mojolicious::Command::credentials::VERSION = '0.007';
3 1 ▶use Mojo::Base 'Mojolicious::Command', -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Env '$EDITOR';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Slurper qw/read_binary write_binary/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Temp 'tempfile';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Getopt::Long 'GetOptionsFromArray';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use IPC::Cmd 'can_run';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Text::ParseWords 'shellwords';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use YAML::PP 'LoadFile';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 has description => 'Edit the applications credentials';
15  
16 0 ▶has usage => sub { shift->extract_usage };
Subroutine __ANON__: not called CC=1 SCAR=1.2
17  
18 0 ▶sub run($self, $command, @args) {
Subroutine run: not called CC=18 SCAR=58.3
Pod documented
19 0 ▶ die $self->usage unless defined $command;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $command 0 0 0
20  
21 0 my $credentials = $self->app->credentials;
22  
23 0 ▶ if ($command eq 'edit') {
Branch: 5 branches
BranchTrueFalseTotal
if ($command eq 'edit') { } 0 0 0
elsif ($command eq 'show') { } 0 0 0
elsif ($command eq 'list') { } 0 0 0
elsif ($command eq 'remove') { } 0 0 0
elsif ($command eq 'recode') { } 0 0 0
24 0 ▶ my $editor = $EDITOR // first { can_run($_) } qw/editor vi nano/;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$Mojolicious::Command::credentials::EDITOR // &first(sub { can_run($_); } , "editor", "vi", "nano")
l!l&&r!l&&!r
000
MC/DC0%0/2
$Mojolicious::Command::credentials::EDITOR // &first(sub { can_run($_); } , "editor", "vi", "nano")
$Mojolicious::Command::credentials::EDITOR &first(sub { can_run($_); } , "editor", "vi", "nano")
Truth table0%0/3
A // B
A= $Mojolicious::Command::credentials::EDITORB= &first(sub { can_run($_); } , "editor", "vi", "nano")
ABresult
1X1
011
000
25 0 ▶ die 'Could not find an editor' if not defined $editor;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $editor 0 0 0
26 0 ▶ GetOptionsFromArray(\@args, 'yaml' => \my $yaml, 'editor=s' => \$editor) or die "Invalid arguments";
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray(\@args, "yaml", \my $yaml, "editor=s", \$editor) or die "Invalid arguments" 0 0 0
27 0 ▶ my $name = shift @args or die 'No credential name given';
Branch: 1 branch
BranchTrueFalseTotal
my $name = shift @args or die "No credential name given" 0 0 0
28  
29 0 ▶ my $suffix = $yaml ? '.yaml' : undef;
Branch: 1 branch
BranchTrueFalseTotal
$yaml ? : 0 0 0
30 0 my ($fh, $filename) = tempfile(UNLINK => 1, SUFFIX => $suffix);
31 0 ▶ write_binary($filename, $credentials->get($name)) if $credentials->has($name);
Branch: 1 branch
BranchTrueFalseTotal
if $credentials->has($name) 0 0 0
32  
33 0 ▶ system shellwords($editor), $filename and die 'Could not save file';
Branch: 1 branch
BranchTrueFalseTotal
system shellwords($editor), $filename and die "Could not save file" 0 0 0
34  
35 0 my $data = read_binary($filename);
36 0 write_binary($filename, scalar('\0' x length $data));
37 0 ▶ YAML::PP->new->load_string($data) if $yaml; # YAML validity check
Branch: 1 branch
BranchTrueFalseTotal
if $yaml 0 0 0
38 0 $credentials->put($name, $data);
39 } elsif ($command eq 'show') {
40 0 ▶ my $name = shift @args or die 'No credential name given';
Branch: 1 branch
BranchTrueFalseTotal
my $name = shift @args or die "No credential name given" 0 0 0
41 0 print $credentials->get($name);
42 } elsif ($command eq 'list') {
43 0 say for $credentials->list;
44 } elsif ($command eq 'remove') {
45 0 ▶ my $name = shift @args or die 'No credential name given';
Branch: 1 branch
BranchTrueFalseTotal
my $name = shift @args or die "No credential name given" 0 0 0
46 0 $credentials->remove($name);
47 } elsif ($command eq 'recode') {
48 0 print 'Please input new key in hex form: ';
49 0 chomp(my $encoded_key = <>);
50 0 my $key = pack "H*", $encoded_key;
51 0 $credentials->recode($key);
52 } else {
53 0 die "Unknown subcommand $command"
54 }
55 }
56  
57 1 1;
58  
59 # ABSTRACT: Manage your app's credentials
60  
61 __END__
↑ Summary Plugin/Credentials.pm »