User::Config - Handling the per-user configuration in multi-user applications
use User::Config; has_option foo => ( isa => 'String', documentation => 'a sample option', default => 'foobar', dataclass => 'myclass', presets => { "Use this" => "value", "or this" => "another value", custom => undef, }, ); has_option bar => ( isa => 'Integer', default => sub { return 28; }, hidden => 1, ); ... $setting = $self->foo;
This primaly documents this modules interface. Please see User::Config::Manual for an in-depth discussion of the concepts.
has_option is the way to declare new user-configurable options. To specify the behaviour of this modul, the extended syntax with parameters can be used. The following parameters are currently supported:
has_option
<anon_default =
Will be used as default, but only if no user logged in. If this isn't given, default is used.
default
<coerce =
Use coercion. See "has" in Moose
<dataclass =
this entry might be used by the database-backend to decide how or where to save the entry
<default =
defines the default value for a given entry. If defined this either might be a scalar, which will be used as value for this option, as long as the user didn't set it to something else. Or it might be a CODE-ref. In this case the code will be executed the first time this option is read for a certain user. On this first time it automaticly will be set in the backend.
<documentation =
Document the option. This will be accessable as $self->item->documentation and may be used by UI-Generators.
<hidden =
If this set to a true value, the corresponding item will be ignored by the UI-Generator.
<isa =
set up runtime constrain checking for this option using "has" in Moose.
<lazy =
See "has" in Moose
<noset =
If set to something true, a value set to this value will silently be ignored. This implies hidden. This might be useful in conjunction with default/anon_default, if a database-connection night not be available.
hidden
anon_default
<range =
if this is set, the UI-Generator will assure, that the user didn't set a value outside.
<references =
this tells User::Config to access the option_name of the Modul Path::To::Modul, when this option is accessed. Thus both options always will have the same value. The UI-Generator will silently ignore this option and do not a display a corresponding entry to the user.
option_name
Path::To::Modul
<trigger =
triggers the following code every time the option is set. See "has" in Moose for details.
<ui_type =
this will be used by the UI-Generator to provide a suitable element.
<validate =
a code that will be executed, if the user set's a new value.
<weak_ref =
This can be used to set the global or module-wide context. See User::Config::Manual for more details.
instance will always return a handle to the global over-all object handling with the database-backend and storing references to all configuration items
instance
To set the database used to make any user-configuration persistent, the database should be set using this method. The first argument specifies the interface to be used, the second contains arguments for this interface to initialize.
For a list of valid Interfaces see User::Config::DB
This will return a new instance for generating a userinterface. There might be multiple interfaces supported. To choose one of them, provide the name of the Interface as first parameter. Valid names are any modules within User::Config::UI. The parameters to supply will depend on the interface in use, so please refer to it's documentation.
This will return a hash-ref containing all currently registered options. The content will look like the following example. The reference of a given option will be the same as used in has_option.
$ perl ... -e "print Dumper $uc->options" $VAR1 = { My::Namespace => { option1 => { }, option2 => { hidden => 1, }, };
User::Config::Manual - a introduction into the concept behind User::Config
User::Config::DB - for a Overview over the database-backends
User::Config::UI - for more information on generating User-Interfaces
Benjamin Tietz, <benjamin@micronet24.de>
Copyright (C) 2011 by Benjamin Tietz
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.
To install User::Config, copy and paste the appropriate command in to your terminal.
cpanm
cpanm User::Config
CPAN shell
perl -MCPAN -e shell install User::Config
For more information on module installation, please visit the detailed CPAN module installation guide.