lib/Wcpancover/Command/config.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 47 CC 2 SCAR 12.0
CC
2
Cov
0%
run
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.3
1 package Wcpancover::Command::config;
2 use Mojo::Base 'Mojolicious::Command';
3  
4 use Data::Dumper;
5 use Term::Prompt qw/prompt/;
6 use Getopt::Long;
7  
8 has description =>
9 "Write an optional configuration file for your application.\n";
10 has usage => "usage: $0 config\n";
11  
12 sub run {
13  
14 my $self = shift;
15 local @ARGV = @_;
16  
17 my $force = 0;
18 GetOptions("force" => \$force);
19  
20 my $file = $self->app->config_file;
21  
22 if (-e $file and not $force) {
23 die "Configuration file $file exists, use '--force' to proceed anyway.\n";
24 }
25  
26 my $config = $self->app->config;
27 local $config->{secret} = prompt('x', 'Application Secret: ', '', '');
28  
29 open my $fh, '>', $file
30 or die "Could not open file $file for writing: $!\n";
31  
32 local $Data::Dumper::Terse = 1;
33 local $Data::Dumper::Sortkeys = 1;
34  
35 print $fh Dumper $config
36 or die "Write to $file failed\n";
37  
38 print "Configuration file $file written sucessfully\n";
39 }
40  
41 1;
42