The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Config::Augeas - Edit configuration files through Augeas C library

SYNOPSIS

  use Config::Augeas;

  my $aug = Config::Augeas->new( root => $aug_root ) ;

  my $ret = $aug->get("/files/etc/hosts/1/ipaddr") ;
  $aug->set("/files/etc/hosts/2/ipaddr","192.168.0.1") ;

  my @a = $aug->match("/files/etc/hosts/") ;

  my $nb = $aug->count_match("/files/etc/hosts/") ;

  $aug->save ;

DESCRIPTION

Augeas is a library and command line tool that focuses on the most basic problem in handling Linux configurations programmatically: editing actual configuration files in a controlled manner.

To that end, Augeas exposes a tree of all configuration settings (well, all the ones it knows about) and a simple local API for manipulating the tree. Augeas then modifies underlying configuration files according to the changes that have been made to the tree; it does as little modeling of configurations as possible, and focuses exclusively on transforming the tree-oriented syntax of its public API to the myriad syntaxes of individual configuration files.

This module provides an object oriented Perl interface for Augeas configuration edition library with a more "perlish" API than Augeas C counterpart.

Constructor

new ( ... )

Creates a new Config::Augeas object. Optional parameters are:

loadpath

a colon-spearated list of directories that lenses should be searched in. This is in addition to the standard load path and the directories in specified AUGEAS_LENS_LIB environment variable.

root

Use root as the filesystem root. If not specified, use the value of the environment variable AUGEAS_ROOT. If that doesn't exist either, use "/".

save => backup | newfile

Specify how to save the configuration file. Either create a newfile (with extension .augnew, and do not overwrite the original file) or move the original file into a backup file (.augsave extension)

type_check => 1

Typecheck lenses; since it can be very expensive it is not done by default.

Methods

get( path )

Lookup the value associated with path. Returns the value associated with path if path matches exactly one node. If PATH matches no nodes or more than one node, returns undef.

set ( path, value )

Set the value associated with path to value. value is copied into Augeas internal data structure. Intermediate entries are created if they don't exist. Return 1 on success, 0 on error. It is an error if more than one node matches path.

insert ( label, before | after , path )

Create a new sibling label for path by inserting into the tree just before or just after path.

path must match exactly one existing node in the tree, and label must be a label, i.e. not contain a '/', '*' or end with a bracketed index '[N]'.

Return 1 on success, and 0 if the insertion fails.

remove ( path )

Remove path and all its children. Returns the number of entries removed. All nodes that match path, and their descendants, are removed.

match ( pattern )

Returns an array of the elements that match of the path expression pattern. The returned paths are sufficiently qualified to make sure that they match exactly one node in the current tree.

count_match ( pattern )

Same as match but return the number of matching element in manner more efficient than using scalar match( pattern )

save

Write all pending changes to disk. Return 0 if an error is encountered, 1 on success. Only files that had any changes made to them are written. save will follow backup files as specified with Config::Augeas::new backup parameter.

Print each node matching path and its descendants to the file descriptor.

SEE ALSO

  • http://augeas.net/ : Augeas project page

  • Config::Model : Another kind of configuration editor.

  • Augeas mailing list: http://augeas.net/developers.html

AUTHOR

Dominique Dumont, <ddumont at cpan dot org@<gt>

COPYRIGHT AND LICENSE

Copyright (C) 2008 by Dominique Dumont

This library is free software; you can redistribute it and/or modify it under the LGPL terms.