File Coverage

blib/lib/App/PAIA/Command/config.pm
Criterion Covered Total %
statement 38 39 97.4
branch 12 12 100.0
condition 3 3 100.0
subroutine 7 8 87.5
pod 3 3 100.0
total 63 65 96.9


line stmt bran cond sub pod time code
1             package App::PAIA::Command::config;
2 4     4   1583 use strict;
  4         8  
  4         122  
3 4     4   74 use v5.10;
  4         8  
  4         98  
4 4     4   13 use parent 'App::PAIA::Command';
  4         4  
  4         14  
5              
6 4     4   171 use App::PAIA::JSON;
  4         4  
  4         1119  
7              
8             sub description {
9             <
10             This command shows or modifies the current configuration. Configuration
11             is printed as JSON object or in INI-sytle as sorted key-value-pairs.
12             MSG
13 0     0 1 0 }
14              
15             sub usage_desc {
16 14     14 1 60644 "%c config %o [ key [value] ]"
17             }
18              
19             sub opt_spec {
20 14     14 1 66 ['ini|i' => 'list configuration in sorted ini-style'],
21             ['delete|d=s' => 'remove a key from the configuration file'];
22             }
23              
24             sub _execute {
25 14     14   21 my ($self, $opt, $args) = @_;
26              
27 14 100       27 if (defined $opt->delete) {
28 1         7 $self->config->load;
29 1         4 $self->config->delete($opt->delete);
30 1         3 $self->config->store;
31 1         2 return;
32             }
33              
34 13 100       87 if (@$args) {
35 7         14 my ($key, $value) = @$args;
36              
37 7 100       18 if (defined $value) {
    100          
38 5 100 100     18 if (defined $self->config->file and -e $self->config->file) {
39 1         3 $self->config->load;
40             }
41 5         17 $self->config->set( $key => $value );
42 5         10 $self->config->store;
43 5         27 return;
44             } elsif( defined ($value = $self->config->get($key)) ) {
45 1         3 say $value;
46 1         7 return;
47             } else {
48 1         5 exit 1;
49             }
50             }
51            
52 6         20 $self->config->load;
53              
54 5 100       16 if ($opt->ini) {
55 2         6 foreach ( sort keys %{$self->config->{data}} ) {
  2         5  
56 2         14 say "$_=".$self->config->get($_);
57             }
58             } else {
59 3         15 return $self->config->{data};
60             }
61            
62 2         10 return;
63             }
64              
65             1;
66             __END__