Tools/CLI/Config.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 51 CC 3 SCAR 12.8
CC
3
Cov
0%
option_value
6.0
_load_config
6.0
find_homedir
2.0
CRAP 3.6
1 #!/usr/bin/perl
2  
3 package Mail::Summary::Tools::CLI::Config;
4 use Moose;
5  
6 use File::Save::Home ();
7 use Path::Class;
8 use YAML::Syck;
9  
10 has homedir => (
11 isa => "Path::Class::Dir",
12 is => "rw",
13 lazy => 1,
14 default => sub { Path::Class::dir($_[0]->find_homedir) },
15 );
16  
17 has config_file => (
18 isa => "Path::Class::File",
19 is => "rw",
20 lazy => 1,
21 default => sub { $_[0]->homedir->file("config") },
22 );
23  
24 has config => (
25 isa => "HashRef",
26 is => "rw",
27 lazy => 1,
28 default => sub { $_[0]->_load_config },
29 );
30  
31 sub find_homedir {
32 my $self = shift;
33  
34 return File::Save::Home::make_subhome_directory(
35 File::Save::Home::get_subhome_directory_status(".mailsum"),
36 );
37 }
38  
39 sub defaults {
40 my $self = shift;
41 $self->config->{defaults} || {};
42 }
43  
44 sub option_value {
45 my ( $self, $command, $option ) = @_;
46 my $defaults = $self->defaults;
47  
48 for ( $command, "all" ) {
49 if ( exists $defaults->{$_}{$option} ) {
50 return $defaults->{$_}{$option};
51 }
52 }
53  
54 return;
55 }
56  
57 sub _load_config {
58 my $self = shift;
59  
60 if ( -e $self->config_file ) {
61 YAML::Syck::LoadFile( $self->config_file->stringify );
62 } else {
63 return {};
64 }
65 }
66  
67 1;