lib/Acme/Coinbase/Config.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 45 SCAR 24.8
CC
3
Cov
0%
read_config
6.0
get_param
6.0
dump
2.0
CRAP 12.0
1 package Acme::Coinbase::Config;
2 # vim: set ts=4 sw=4 expandtab showmatch
3 #
4 use strict;
5  
6 # FOR MOOSE
7 use Moose; # automatically turns on strict and warnings
8 #use Config::INI::Reader;
9 use Config::IniFiles;
10 use Data::Dumper;
11  
12 has 'config_file' => (is => 'rw', isa => 'Str');
13 has 'config_reader' => (is => 'rw');
14  
15 sub read_config {
16 my $self = shift;
17 die "$0: no config file" unless $self->config_file;
18 print "$0: Config file is " . $self->config_file . "\n";
19 #my $config_hash = Config::INI::Reader->read_file( $self->config_file );
20 my $config = Config::IniFiles->new(); # -file => $self->config_file);
21 $config->SetFileName( $self->config_file ) || die "$0: Can't set config filename\n";;
22 $config->ReadConfig();
23 #print "READ: " . $config->OutputConfig();
24 $self->config_reader( $config );
25 }
26 sub get_param {
27 my ($self, $section, $param) = @_;
28 return "" unless($self->config_reader) ;
29 return $self->config_reader->val( $section, $param ) || "";
30 }
31  
32 sub dump {
33 my $self = shift;
34  
35 my @sections = $self->config_reader->Sections();
36 return "Sections: " . Dumper( \@sections ) . "\n";
37 }
38  
39 # dummy data
40 #has 'api_key' => (is => 'rw', isa => 'Str', default=>"lmnop");
41 #has 'api_secret' => (is => 'rw', isa => 'Str', default=>"qwerty");
42  
43 #############################################
44 # we expect a config file, if used, to look like:
45 # [default]
46 # api_key = keyasdakjb34234kj
47 # api_secret = secretk3j4204h554j2h3409u34bn
48 #############################################
49  
50 1;
51  
52 =head1 NAME
53  
54 Acme::Coinbase::Config -- read a acmecoinbase config file
55  
56 =head1 SYNOPSIS
57  
58 Example of a usage goes here, such as
59  
60 my $conf = new Acme::Coinbase::Config( config_file=>$filename);
61 my $conf->read_config();
62 my $val = $conf->get_param( "section", "param" );
63  
64 =head1 DESCRIPTION
65  
66 Manages reading a config file.
67  
68 =head1 METHODS
69  
70 =over 4
71  
72 =item my $conf = Acme::Coinbase::Config->new( );
73  
74 returns a new object.
75  
76 =item conf->read_config()
77  
78 reads the config file
79  
80 =item conf->get_param( "section", "param")
81  
82 reads the given parameter from the given section.
83  
84 =back
85  
86 =head1 COPYRIGHT
87  
88 Copyright (c) 2018 Josh Rabinowitz, All Rights Reserved.
89  
90 =head1 AUTHORS
91  
92 Josh Rabinowitz
93  
94 =cut
95