User::Config::DB - This defines the role, the database-backends are playing.
To store the value, a user set for a given option, User::Config uses a database-backend. These backends must live within the namespace User::Config::DB:: and consume this role.
The interface was held as simple as possible. To consume this role, the following methods have to be implemented.
<$db-
The set method has to be implemented. Whenever a user sets a speicific option to a new value, this method is called and has to take care of storing this piece of information.
set
The parameters are as following:
$package
Contains the package or namespace for the module in question. This usally is the package-name of the module, declaring the option.
$user
The name of the current contexts user.
$option_name
The name of the option to set ( within the package ).
$context
The current context.
$value
The new value to set.
The get method has to be implemented by the corresponding backend. It returns the previous set value or undef, if no value was set.
get
The parameters work are the same as for set.
Optionally, the backend can implement the isset-method. This will be called before get is called. If the user has set this option in advance, the method should return true. If not, false should be returned. Then get isn't called at all and the default value will be submitted to the caller.
isset
If this isn't implemented get is always called. The default value will then be returned, if get returns undef.
The following information aren't needed to write new code. There here for completness only.
While set is just checking, wether the user is valid, get is completly wrapped in this role. The wrapper checks wether the backend implements isset and returns the user-set value or the default, if the setting isn't stored.
The default value is given while the option is declared. If the default value is a code-reference, the code is called. The returned value is immediatly saved in the backend, so that it get's returned the next time the option is retrieved.
User::Config User::Config::DB::DBIC User::Config::DB::Ldap User::Config::DB::Keyed
Further backends are welcome.
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.