Description | A static content generator. |
Newcomen::Config::Backend - Base class for configuration backends.
package Newcomen::Config::MyBackend; use namespace::autoclean; use Moose; extends 'Newcomen::Config::Backend'; override '_do_config' => sub { my $self = shift; my $options = shift; my $config = {}; # Get configuration... return $config; }; __PACKAGE__ -> meta () -> make_immutable (); 1;
This is the base class to be extended by configuration backends. It does not define any attributes. It does define the methods config() and _do_config(). config() will call the _do_config() method, which has to be overridden by the actual backend implementation (see SYNOPSIS). The _do_config() method of the base class will simply die()!
my $backend = Newcomen::Config::MyBackend -> new ();
Constructor. new() will be called once for every (!) backend found when the configuration is first accessed. A backend does not have to be actually used to be instantiated! If it is actually used to load some user configuration, config() will be called (and in turn call _do_config()). Only this one backend instance will be used for every call for a specific backend. The constructor will be called without any parameters.
Toggle source: config
sub config { my $self = shift; my $opts = shift // Newcomen::Data -> new (); confess 'Usage: config($options)' unless is_a ($opts, 'Newcomen::Data') and not @_; my $config = $self -> _do_config ($opts); confess 'No hashref returned by configuration backend' unless $config and ref $config eq 'HASH'; return $config; }
my $config = $backend -> config ($backend_options);
The config() method of a backend will be called when Newcomen::Config's
add_config() method is called. See there for details on that method.
It will return a hashref that contains the user configuration to be added to the
Newcomen::Config instance. The backend options passed to
add_config() will be passed to the config() method as the only
parameter. This must be an Newcomen::Data instance or undef
. The config() method must not
be overridden by a backend implementation!
Toggle source: _do_config
sub _do_config { confess '_do_config() not implemented by backend' }
The actual backends must implement a _do_config() method, _do_config() of this base class will die(). The Newcomen::Data instance containing the options (or a newly created empty one, if no options were supplied) will be passed as the only parameter to this method. _do_config() has to return a hashref containing the user configuration to be added to the configuration instance (the hashref may be empty).
Newcomen::Config, Newcomen::Data
This is version 2014052501
.
Stefan Goebel - newcomen {at} subtype {dot} de
Copyright 2013-2014 Stefan Goebel.
This file is part of Newcomen.
Newcomen is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the license, or (at your option) any later version.
Newcomen is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Newcomen. If not, see <http://www.gnu.org/licenses/>.