Audio-GtkGramofile
view release on metacpan or search on metacpan
GtkGramofile/Settings.pm view on Meta::CPAN
package Audio::GtkGramofile::Settings;
use strict;
use warnings;
use Carp;
use Glib 1.040, qw(TRUE FALSE);
use IO::File;
use Config::IniFiles;
use vars qw($VERSION);
$VERSION = do { my @r = (q$Revision: 1.3 $ =~ /\d+/g); shift @r; sprintf("0.%04d",@r) }; # must be all one line, for MakeMaker
sub new {
my $proto = shift;
my $args = shift;
my $class = ref($proto) || $proto;
my $self = {};
bless $self, $class;
return $self;
}
sub gui {
my $self = shift;
my $gui = shift;
$self->{gui} = $gui if defined $gui;
$self->{gui};
}
sub signals {
my $self = shift;
my $signals = shift;
$self->{signals} = $signals if defined $signals;
$self->{signals};
}
sub callbacks {
my $self = shift;
my $callbacks = shift;
$self->{callbacks} = $callbacks if defined $callbacks;
$self->{callbacks};
}
sub logic {
my $self = shift;
my $logic = shift;
$self->{logic} = $logic if defined $logic;
$self->{logic};
}
sub load_settings {
my $self = shift;
my $cfg_file = $ENV{HOME}."/.gtkgramofilerc";
my $handle;
if (-e $ENV{HOME}."/.gtkgramofilerc") {
$handle = IO::File->new($ENV{HOME}."/.gtkgramofilerc","r");
} else {
no strict 'refs';
my $data = __PACKAGE__ . '::DATA';
$handle = *$data;
}
my $cfg = Config::IniFiles->new(-file => $handle);
foreach my $section ($cfg->Sections) {
foreach my $parameter ($cfg->Parameters($section)) {
my $val = $cfg->val( $section, $parameter);
$self->{defaults}->{$section}->{$parameter} = $val;
$self->{settings}->{$section}->{$parameter} = $val; # only set this if it changes during the program
}
}
}
sub get_value {
my $self = shift;
my $section = shift;
my $parameter = shift;
return (defined $self->{settings}->{$section}->{$parameter}) ?
$self->{settings}->{$section}->{$parameter} :
$self->{defaults}->{$section}->{$parameter};
}
sub set_value {
my $self = shift;
my $section = shift;
my $parameter = shift;
my $value = shift;
$self->{settings}->{$section}->{$parameter} = $value;
}
sub get_defaults {
return shift->{defaults};
}
sub get_default {
my $self = shift;
my $section = shift;
my $parameter = shift;
( run in 0.718 second using v1.01-cache-2.11-cpan-c221a9de4ec )