| 1 | # | ||||||||||||||||||||
| 2 | # This file is part of App-Magpie | ||||||||||||||||||||
| 3 | # | ||||||||||||||||||||
| 4 | # This software is copyright (c) 2011 by Jerome Quelin. | ||||||||||||||||||||
| 5 | # | ||||||||||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 8 | # | ||||||||||||||||||||
| 9 | 20 | ▶ | use 5.012; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 20 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 20 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | package App::Magpie::Config; | ||||||||||||||||||||
| 14 | # ABSTRACT: magpie configuration storage & retrieval | ||||||||||||||||||||
| 15 | 20 | $App::Magpie::Config::VERSION = '2.010'; | |||||||||||||||||||
| 16 | 20 | ▶ | use Config::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 20 | ▶ | use File::HomeDir::PathClass; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 20 | ▶ | use MooseX::Singleton; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 20 | ▶ | use MooseX::Has::Sugar; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 20 | my $CONFIGDIR = File::HomeDir::PathClass->my_dist_config( "App-Magpie", {create=>1} ); | |||||||||||||||||||
| 22 | 20 | my $config_file = $CONFIGDIR->file( "config.ini" ); | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 20 | has _config => ( ro, isa => "Config::Tiny", lazy_build ); | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | sub _build__config { | ||||||||||||||||||
|
Subroutine
_build__config: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 27 | 0 | my $self = shift; | |||||||||||||||||||
| 28 | 0 | my $config = Config::Tiny->read( $config_file ); | |||||||||||||||||||
| 29 | 0 | ▶ | $config //= Config::Tiny->new; | ||||||||||||||||||
|
Condition0%0/3
$config //= "Config::Tiny"->new
MC/DC0%0/2
$config //= "Config::Tiny"->new
$config
"Config::Tiny"->new
Truth table0%0/3
A //= B
A= $configB= "Config::Tiny"->new
| |||||||||||||||||||||
| 30 | 0 | return $config; | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | # -- public methods | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 0 | ▶ | sub dump { | ||||||||||||||||||
|
Subroutine
dump: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||||||||
| 38 | 0 | return $config_file->slurp; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | ▶ | sub get { | ||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 44 | 0 | my ($self, $section, $key) = @_; | |||||||||||||||||||
| 45 | 0 | return $self->_config->{ $section }->{ $key }; | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | ▶ | sub set { | ||||||||||||||||||
|
Subroutine
set: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 51 | 0 | my ($self, $section, $key, $value) = @_; | |||||||||||||||||||
| 52 | 0 | my $config = $self->_config; | |||||||||||||||||||
| 53 | 0 | $config->{ $section }->{ $key } = $value; | |||||||||||||||||||
| 54 | 0 | $config->write( $config_file ); | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 20 | 1; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||