Config-Model
view release on metacpan or search on metacpan
lib/Config/Model/Backend/PlainFile.pm view on Meta::CPAN
@v = map { "$_\n" } $obj->fetch_all_values;
}
else {
$logger->debug("PlainFile write skipped $type $elt");
next;
}
if (@v) {
$logger->trace("PlainFile write opening $file to write $elt");
$file->spew_utf8(@v);
$file->chmod($args{file_mode}) if $args{file_mode};
}
elsif ($file->exists) {
$logger->trace("PlainFile delete $file");
$file->remove;
}
}
return 1;
}
lib/Config/Model/Backend/PlainFile.pm view on Meta::CPAN
file => '&element(-).&element',
file_mode => 0644, # optional
}
If the configuration is loaded with C<example string_a=something
string_b=else>, this backend writes "C<something>" in file
C<example.string_a> and C<else> in file C<example.string_b>.
C<file_mode> parameter can be used to set the mode of the written
file. C<file_mode> value can be in any form supported by
L<Path::Tiny/chmod>.
=head1 Methods
=head2 read_leaf
Parameters: C<(obj, elt, check, file, args)>
Called by L<read> method to read the file of a leaf element. C<args>
contains the arguments passed to L<read> method.
lib/Config/Model/BackendMgr.pm view on Meta::CPAN
return unless defined $file_path;
if ($error) {
# restore backup and display error
$logger->warn("Error during write, restoring backup data in $file_path" );
$file_path->append_utf8({ truncate => 1 }, $self->file_backup );
$error->rethrow if ref($error) and $error->can('rethrow');
die $error;
}
# TODO: move chmod in a backend role
$file_path->chmod($file_mode) if $file_mode;
# TODO: move in a backend role
# check file size and remove empty files
$file_path->remove if -z $file_path and not -l $file_path;
}
sub is_auto_write_for_type {
my $self = shift;
my $type = shift;
return $self->{auto_write}{$type} || 0;
lib/Config/Model/BackendMgr.pm view on Meta::CPAN
service # hash element
foo # hash index
nodeA # values of nodeA are stored in service.foo.conf
bar # hash index
nodeB # values of nodeB are stored in service.bar.conf
=item file_mode
C<file_mode> parameter can be used to set the mode of the written
file(s). C<file_mode> value can be in any form supported by
L<Path::Tiny/chmod>. Example:
file_mode => 0664,
file_mode => '0664',
file_mode => 'g+w'
=item os_config_dir
Specify alternate location of a configuration directory depending on the OS
(as returned by C<$^O>, see L<perlport/PLATFORMS>).
For instance:
lib/Config/Model/FuseUI.pm view on Meta::CPAN
return 0;
}
sub statfs { return 255, 1, 1, 1, 1, 2 }
my @methods = map { ( $_ => __PACKAGE__ . "::$_" ) }
qw/getattr getdir open read write statfs truncate unlink mkdir rmdir/;
# FIXME: flush release
# maybe also: readlink mknod symlink rename link chmod chown utime
sub run_loop {
my ( $self, %args ) = @_;
my $debug = $args{debug} || 0;
Fuse::main(
mountpoint => $self->mountpoint,
@methods,
debug => $debug || 0,
threaded => 0,
( run in 0.287 second using v1.01-cache-2.11-cpan-496ff517765 )