NAME
Config::Model::Itself - Model editor for Config::Model
VERSION
version 2.003
SYNOPSIS
# Itself constructor returns an object to read or write the data
# structure containing the model to be edited
my $meta_model = Config::Model::Itself -> new( ) ;
# now load the model to be edited
$meta_model -> read_all( ) ;
# For Curses UI prepare a call-back to write model
my $wr_back = sub { $meta_model->write_all(); }
# create Curses user interface
my $dialog = Config::Model::CursesUI-> new (
store => $wr_back,
) ;
# start Curses dialog to edit the mode
$dialog->start( $meta_model->config_root ) ;
# that's it. When user quits curses interface, Curses will call
# $wr_back sub ref to write the modified model.
DESCRIPTION
Config::Itself module and its model files provide a model of Config:Model (hence the Itself name).
Let's step back a little to explain. Any configuration data is, in essence, structured data. This data could be stored in an XML file. A configuration model is a way to describe the structure and relation of all items of a configuration data set.
This configuration model is also expressed as structured data. This structure data is structured and follow a set of rules which are described for humans in Config::Model.
The structure and rules documented in Config::Model are also expressed in a model in the files provided with Config::Model::Itself
.
Hence the possibity to verify, modify configuration data provided by Config::Model can also be applied on configuration models. Using the same user interface.
From a Perl point of view, Config::Model::Itself provides a class dedicated to read and write a set of model files.
Constructor
new ( [ cm_lib_dir => ... ] )
Creates a new read/write handler. If no model_object is passed, the required objects are created. cm_lib_dir
specifies where are the model files (defaults to ./lib/Config/Model
.
cm_lib_dir
is either a Path::Tiny
object or a string.
By default, this constructor will create all necessary Config::Model*
objects. If needed, you can pass already created object with options config_model
(Config::Model object), meta_instance
(Config::Model::Instance object) or meta_root
(Config::Model::Node object).
Methods
read_all ( [ root_model => ... ], [ force_load => 1 ] )
Load all the model files contained in model_dir
and all its subdirectories. root_model
is used to filter the classes read.
Use force_load
if you are trying to load a model containing errors.
read_all
returns a hash ref containing ( class_name => file_name , ...)
write_all
Will write back configuration model in the specified directory. The structure of the read directory is respected.
write_model_snippet( snippet_dir => foo, model_file => bar.pl )
Write snippet models in separate .d
directory. E.g. a snippet for class Foo::Bar
will be written in Foo/Bar.d/bar.pl
file. This file is to be used by augment_config_class '...', class_data )">
read_model_snippet( snippet_dir => foo, model_file => bar.pl )
To read model snippets, this methid will search recursively $snippet_dir
and load all bar.pl
files found in there.
list_class_element
Returns a string listing all the class and elements. Useful for debugging your configuration model.
get_dot_diagram
Returns a graphviz dot file that represents the structure of the configuration model:
include
relations are represented by solid linesClass usage (i.e.
config_class_name
parameter) is represented by dashed lines. The name of the element is attached to the dashed line.
SEE ALSO
Config::Model, Config::Model::Node, Path::Tiny
AUTHOR
Dominique Dumont
COPYRIGHT AND LICENSE
This software is Copyright (c) 2016 by Dominique Dumont.
This is free software, licensed under:
The GNU Lesser General Public License, Version 2.1, February 1999