| 1 | package App::DuckPAN::Config; | ||||||||||
| 2 | 5 | our $AUTHORITY = 'cpan:DDG'; | |||||||||
| 3 | # ABSTRACT: Configuration class of the duckpan client | ||||||||||
| 4 | 5 | $App::DuckPAN::Config::VERSION = '1021'; | |||||||||
| 5 | 5 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use File::HomeDir; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | ▶ | use Config::INI::Reader; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 5 | ▶ | use Config::INI::Writer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | has config_path => ( | ||||||||||
| 12 | is => 'ro', | ||||||||||
| 13 | lazy => 1, | ||||||||||
| 14 | 2 | ▶ | default => sub { _path_for('config') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 5 | ); | |||||||||
| 16 | has config_file => ( | ||||||||||
| 17 | is => 'ro', | ||||||||||
| 18 | lazy => 1, | ||||||||||
| 19 | 0 | ▶ | default => sub { shift->config_path->child('config.ini') }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 20 | 5 | ); | |||||||||
| 21 | has cache_path => ( | ||||||||||
| 22 | is => 'ro', | ||||||||||
| 23 | lazy => 1, | ||||||||||
| 24 | 0 | ▶ | default => sub { _path_for('cache') }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 25 | 5 | ); | |||||||||
| 26 | |||||||||||
| 27 | 2 | ▶ | sub _path_for { | ||||||||
|
Subroutine
_path_for: called CC=3 SCAR=11.0
| |||||||||||
| 28 | 2 | my $which = shift; | |||||||||
| 29 | |||||||||||
| 30 | 2 | my $from_env = $ENV{'DUCKPAN_' . uc $which . '_PATH'}; | |||||||||
| 31 | 2 | ▶ | my $path = ($from_env) ? path($from_env) : path(File::HomeDir->my_home, '.duckpan', lc $which); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 2 | ▶ | $path->mkpath unless $path->exists; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 2 | return $path; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub set_config { | ||||||||
|
Subroutine
set_config: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 37 | 0 | my ( $self, $config ) = @_; | |||||||||
| 38 | 0 | Config::INI::Writer->write_file($config,$self->config_file); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub get_config { | ||||||||
|
Subroutine
get_config: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 42 | 0 | my ( $self ) = @_; | |||||||||
| 43 | 0 | ▶ | return unless $self->config_file->is_file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | Config::INI::Reader->read_file($self->config_file); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 5 | 1; | |||||||||
| 48 | |||||||||||
| 49 | __END__ | ||||||||||