Hook::Modular::Builder - Domain-specific language for building configurations
version 1.101050
use Hook::Modular::Builder; my $config = builder { global { log => { level => 'error' }, cache => { base => '/tmp/test-hook-modular' }, }; # or: # log_level 'error'; enable 'Some::Printer', indent => 4, indent_char => '*', text => 'this is some printer'; enable 'Another::Plugin', foo => 'bar' if $ENV{BAZ}; }; main->bootstrap(config => $config);
With this module you can use a domain-specific language (DSL) to build Hook::Modular configurations. The functions are exported automatically.
This package is also a class in disguise. The methods are not intended for public consumption, but they are documented nevertheless.
Creates a new object. This method is called by builder() so it can be used by functions like enable() and global().
builder()
enable()
global()
Does the actual work of the enable() function. It is called from enable() with the object constructed by builder().
Does the actual work of the global() function. It is called from global() with the object constructed by builder().
Does the actual work of the log_level() function. It is called from log_level() with the object constructed by builder().
log_level()
Does the actual work of the cache_base() function. It is called from cache_base() with the object constructed by builder().
cache_base()
Takes a block in which you can enable plugins and define global configuration. It is normal Perl code, so you could, for example, only enable a plugin if a certain environment variable is set:
my $config = builder { # ... enable 'Another::Plugin', foo => 'bar' if $ENV{BAZ}; };
It returns a configuration hash that can be passed to Hook::Modular objects.
Adds a plugin to the configuration. It takes as arguments the plugin name and an optional list of plugin configuration arguments. Plugins are added in the order in which they are defined in the builder() block.
Example:
my $config = builder { enable 'Some::Printer', indent => 4, indent_char => '*', text => 'this is some printer'; };
This is equivalent to having the following in a YAML configuration file:
plugins: - module: Some::Printer config: indent: 4 indent_char: '*' text: 'this is some printer'
If you call this function outside a builder() block, you will get an error.
Defines the global configuration. Takes as arguments a hash of options.
my $config = builder { global { log => { level => 'error' }, cache => { base => '/tmp/test-hook-modular' }; };
global: log: level: error cache: base: /tmp/test-hook-modular
Takes as an argument a log level string - for example, error - and sets the global log level configuration value; any other global configuration is left untouched.
error
my $config = builder { log_level 'error'; };
This is equivalent to the following global() call:
my $config = builder { global { log => { level => 'error' }, };
And it is equivalent to having the following in a YAML configuration file:
global: log: level: error
Takes as an argument a path string and sets the global cache base configuration value; any other global configuration is left untouched.
my $config = builder { cache_base '/tmp/test-hook-modular'; };
my $config = builder { global { cache => { base => 'error' }, };
global: cache: base: error
See perlmodinstall for information and options on installing Perl modules.
No bugs have been reported.
Please report any bugs or feature requests through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Hook-Modular.
The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you, or see http://search.cpan.org/dist/Hook-Modular/.
The development version lives at http://github.com/hanekomu/Hook-Modular/. Instead of sending patches, please fork this project using the standard git and github infrastructure.
Marcel Gruenauer <marcel@cpan.org> Tatsuhiko Miyagawa <miyagawa@bulknews.net>
This software is copyright (c) 2007 by Marcel Gruenauer.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Hook::Modular, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hook::Modular
CPAN shell
perl -MCPAN -e shell install Hook::Modular
For more information on module installation, please visit the detailed CPAN module installation guide.