File: FileHandler.pm

package info (click to toggle)
libconfig-model-perl 2.155-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,172 kB
  • sloc: perl: 15,117; makefile: 19
file content (66 lines) | stat: -rw-r--r-- 1,533 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package Config::Model::Role::FileHandler;

# ABSTRACT: role to read or write configuration files

use strict;
use warnings;
use Carp;
use 5.10.0;

use Mouse::Util;
use Log::Log4perl qw(get_logger :levels);
use Path::Tiny;

use Mouse::Role;

use Config::Model::TypeConstraints;

my $logger = get_logger("FileHandler");

# used only for tests
sub _set_test_home {
    Config::Model::TypeConstraints::_set_test_home(shift) ;
    return;
}

# Configuration directory where to read and write files. This value
# does not override the configuration directory specified in the model
# data passed to read and write functions.
has config_dir => ( is => 'ro', isa => 'Config::Model::TypeContraints::Path', required => 0 );

sub get_tuned_config_dir {
    my ($self, %args) = @_;

    my $dir = $args{os_config_dir}{$^O} || $args{config_dir} || $self->config_dir || '';
    if ( $dir =~ /^~/ ) {
        # because of tests, we can't rely on Path::Tiny's tilde processing
        # TODO: should this be my_config ? May be once this is done:
        # https://github.com/perl5-utils/File-HomeDir/pull/5/files
        # beware of compat and migration issues
        my $home =  &Config::Model::TypeConstraints::_get_test_home || File::HomeDir->my_home;
        $dir =~ s/^~/$home/;
    }

    return $args{root} ? $args{root}->child($dir)
        : $dir ?  path($dir)
        :         path ('.');
}

1;

__END__

=head1 SYNOPSIS


=head1 DESCRIPTION

Role used to handle configuration files on the behalf of a backend.

=head1 METHODS




=cut