diff options
author | Angelo Naselli <anaselli@linux.it> | 2015-12-26 22:00:44 +0100 |
---|---|---|
committer | Angelo Naselli <anaselli@linux.it> | 2015-12-26 22:00:44 +0100 |
commit | f428879ec78ce46c6cfdad84db0a18e2e0bf88d3 (patch) | |
tree | e26378a102d26d2a0b4c965664b5ee7e865f1aee /lib | |
parent | 05915024363336c2f4098fdf3b231d1017bf5324 (diff) | |
download | manatools-f428879ec78ce46c6cfdad84db0a18e2e0bf88d3.tar manatools-f428879ec78ce46c6cfdad84db0a18e2e0bf88d3.tar.gz manatools-f428879ec78ce46c6cfdad84db0a18e2e0bf88d3.tar.bz2 manatools-f428879ec78ce46c6cfdad84db0a18e2e0bf88d3.tar.xz manatools-f428879ec78ce46c6cfdad84db0a18e2e0bf88d3.zip |
Added ConfigDirRole to be used in modules as a single configuration dir
position
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ManaTools/ConfigDirRole.pm | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/lib/ManaTools/ConfigDirRole.pm b/lib/ManaTools/ConfigDirRole.pm new file mode 100644 index 00000000..8211bdee --- /dev/null +++ b/lib/ManaTools/ConfigDirRole.pm @@ -0,0 +1,102 @@ +# vim: set et ts=4 sw=4: +package ManaTools::ConfigDirRole; +#============================================================= -*-perl-*- + +=head1 NAME + + Manatools::ConfigDirRole - Role to manage configuration directory + +=head1 SYNOPSIS + + package Foo; + + use Moose; + + has 'configDir' => ( + ... + ); + + has 'configName' => ( + ... + ); + with 'Manatools::ConfigDirRole'; + + 1; + +=head1 DESCRIPTION + + ConfigDirRole just define a role in which the config dir is defined in a single point + for all the module that uses it. + +=head1 SUPPORT + + You can find documentation for this module with the perldoc command: + + perldoc Manatools::ConfigDirRole + +=head1 SEE ALSO + +=head1 AUTHOR + +Angelo Naselli <anaselli@linux.it> + +=head1 COPYRIGHT and LICENSE + +Copyright (C) 2015, Angelo Naselli. + +This module is free software. You can redistribute it and/or +modify it under the terms of the Artistic License 2.0. + +This program is distributed in the hope that it will be +useful, but without any warranty; without even the implied +warranty of merchantability or fitness for a particular purpose + +=cut + +use Moose::Role; + +=head2 requires + +=head3 definitions + + configDir: a root directory for configuration, e.g. a path + configName: a name under configDir in which to find configuration file + +=cut +#============================================================= + +requires 'configDir'; +requires 'configName'; + +has 'defaultConfigDir' => ( + is => 'ro', + isa => 'Str', + init_arg => undef, + default => '/etc/manatools', +); + +#============================================================= + +=head2 configPathName + +=head3 INPUT + + $self: this object + +=head3 DESCRIPTION + + return the path name, e.g. configDir/configName + +=cut + +#============================================================= +sub configPathName { + my $self = shift; + + my $dir = $self->configDir() || $self->defaultConfigDir(); + chop $dir if substr($dir, -1) eq '/'; + + return $dir . "/" . $self->configName(); +} + +1; |