File Coverage

blib/lib/App/DuckPAN/Cmd/Env.pm
Criterion Covered Total %
statement 9 27 33.3
branch 0 12 0.0
condition n/a
subroutine 3 8 37.5
pod 0 4 0.0
total 12 51 23.5


line stmt bran cond sub pod time code
1             package App::DuckPAN::Cmd::Env;
2             our $AUTHORITY = 'cpan:DDG';
3             # ABSTRACT: Env command class
4             $App::DuckPAN::Cmd::Env::VERSION = '1017';
5 1     1   981 use Moo;
  1         1  
  1         5  
6 1     1   190 use MooX::Cmd;
  1         1  
  1         10  
7              
8             with qw( App::DuckPAN::Cmd );
9              
10 1     1   1870 use Config::INI;
  1         84  
  1         263  
11              
12             has env_ini => (
13             is => 'ro',
14             lazy => 1,
15             builder => 1,
16             );
17              
18             sub _build_env_ini {
19 0     0     my ( $self ) = @_;
20 0           $self->command_chain->[0]->root->cfg->config_path->child('env.ini')
21             }
22              
23             sub load_env_ini {
24 0     0 0   my ( $self ) = @_;
25 0 0         if ($self->env_ini->is_file) {
26 0           my $data = Config::INI::Reader->read_file($self->env_ini)->{_};
27 0 0         defined $data ? $data : {}
28             }
29             else {
30             {}
31 0           }
32             }
33              
34             sub save_env_ini {
35 0     0 0   my ( $self, $data ) = @_;
36 0           Config::INI::Writer->write_file({ _ => $data }, $self->env_ini);
37             }
38              
39             sub help {
40 0     0 0   my ( $self, $cmd_input ) = @_;
41 0           my $help_msg = "Available Commands:\n\t get: duckpan env get <name>\n\t help: duckpan env help\n\t ".
42             "list: duckpan env list\n\t rm: duckpan env rm <name>\n\t set: duckpan env set <name> <value>";
43              
44 0 0         if($cmd_input) {
45 0 0         $self->command_chain->[0]->root->emit_and_exit(1, "Missing arguments!\n\t Usage:\tduckpan env ". $self->command_name ." ". $cmd_input) if $self->command_name;
46 0           $self->app->emit_and_exit(1, "Command '". $cmd_input ."' not found\n". $help_msg);
47             }
48              
49 0 0         $self->command_name ? $self->command_chain->[0]->root->emit_info($help_msg) : $self->app->emit_info($help_msg);
50             }
51              
52             sub run {
53 0     0 0   my ( $self, $name ) = @_;
54 0 0         $self->help($name) if !$self->command_name;
55 0           exit 0;
56             }
57              
58             1;
59              
60             __END__
61              
62             =pod
63              
64             =head1 NAME
65              
66             App::DuckPAN::Cmd::Env - Env command class
67              
68             =head1 VERSION
69              
70             version 1017
71              
72             =head1 AUTHOR
73              
74             DuckDuckGo <open@duckduckgo.com>, Zach Thompson <zach@duckduckgo.com>, Zaahir Moolla <moollaza@duckduckgo.com>, Torsten Raudssus <torsten@raudss.us> L<https://raudss.us/>
75              
76             =head1 COPYRIGHT AND LICENSE
77              
78             This software is Copyright (c) 2013 by DuckDuckGo, Inc. L<https://duckduckgo.com/>.
79              
80             This is free software, licensed under:
81              
82             The Apache License, Version 2.0, January 2004
83              
84             =cut