Magpie/Config.pm

filter: Statementstmt 67.5% 25 / 37 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 63.6% 7 / 11 Podpod 100% 3 / 3 totaltotal 62.5% 35 / 56 CC 2 SCAR 7.3
CC
2
Cov
62%
_build__config
6.0
dump
2.0
get
2.0
CRAP 2.1
« Magpie/Logger.pm ↑ Summary Magpie/App/Command/update.pm »
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
l!l&&r!l&&!r
000
MC/DC0%0/2
$config //= "Config::Tiny"->new
$config "Config::Tiny"->new
Truth table0%0/3
A //= B
A= $configB= "Config::Tiny"->new
ABresult
1X1
011
000
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__
« Magpie/Logger.pm ↑ Summary Magpie/App/Command/update.pm »