NAME
App::DrivePlayer::Config - Load, persist and query DrivePlayer configuration
SYNOPSIS
use App::DrivePlayer::Config;
my $cfg = App::DrivePlayer::Config->new(); # default path
my $cfg = App::DrivePlayer::Config->new(config_file => $path); # explicit path
# Read settings
my $auth = $cfg->auth_config; # hashref for Google::RestApi->new
my @folders = @{ $cfg->music_folders };
# Manage music folders
$cfg->add_music_folder($drive_id, 'My Music');
$cfg->remove_music_folder($drive_id);
$cfg->save; # write changes back to disk
$cfg->ensure_dirs; # create parent directories for db, log, token
DESCRIPTION
Reads a YAML configuration file and provides typed accessors for every setting. Missing files are silently replaced by built-in defaults so the application works out of the box before the user runs the setup wizard.
Tilde (~) at the start of any path value is expanded to $HOME.
ATTRIBUTES
config_file
is: ro, isa: Str
Path to the YAML configuration file. Defaults to ~/.config/drive_player/config.yaml.
METHODS
new
my $cfg = App::DrivePlayer::Config->new(%args);
Constructor. Accepts config_file as an optional named argument.
auth_config
my $hashref = $cfg->auth_config;
Returns the auth stanza from the config file as a plain hashref. Pass this directly to Google::RestApi->new(auth => ...).
music_folders
my $aref = $cfg->music_folders;
$cfg->music_folders(\@folders); # replace all
Getter/setter for the list of configured music folders. Each element is a hashref with id (Google Drive folder ID) and name keys.
add_music_folder
$cfg->add_music_folder($drive_id, $name);
Appends a new folder to the music folder list.
remove_music_folder
$cfg->remove_music_folder($drive_id);
Removes the folder with the given Drive ID from the list.
db_path
my $path = $cfg->db_path;
Absolute path to the SQLite database file.
log_level
my $level = $cfg->log_level; # e.g. 'WARN', 'DEBUG'
Log4perl log level string. Defaults to WARN.
log_file
my $path = $cfg->log_file;
Absolute path to the application log file.
token_file
my $path = $cfg->token_file;
Absolute path to the OAuth2 token storage file.
save
$cfg->save;
Serialises the current configuration to config_file, creating parent directories as needed.
ensure_dirs
$cfg->ensure_dirs;
Creates the parent directories for db_path, log_file, and token_file if they do not already exist.