| 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 $self->config_reader->val( $section, $param ) || ""; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub dump { | ||
| 32 | my $self = shift; | ||
| 33 | |||
| 34 | my @sections = $self->config_reader->Sections(); | ||
| 35 | return "Sections: " . Dumper( \@sections ) . "\n"; | ||
| 36 | } | ||
| 37 | |||
| 38 | # dummy data | ||
| 39 | #has 'api_key' => (is => 'rw', isa => 'Str', default=>"lmnop"); | ||
| 40 | #has 'api_secret' => (is => 'rw', isa => 'Str', default=>"qwerty"); | ||
| 41 | |||
| 42 | 1; |