NAME

Hook::Modular - making pluggable applications easy

SYNOPSIS

# some_config.yaml

global:
  log:
    level: error
  cache:
    base: /tmp/test-hook-modular
  # plugin_namespace: My::Test::Plugin

plugins:
  - module: Some::Printer
    config:
      indent: 4
      indent_char: '*'
      text: 'this is some printer'

# some_app.pl

use base 'Hook::Modular';

use constant PLUGIN_NAMESPACE => 'My::Test::Plugin';

sub run {
  my $self = shift;
  $self->SUPER::run(@_);
  ...
  $self->run_hook('output.print', ...);
  ...
}

main->bootstrap(config => $config_filename);

DESCRIPTION

Hook::Modular makes writing pluggable applications easy. Use a config file to specify which plugins you want and to pass options to those plugins. The program to support those plugin then subclasses Hook::Modular and bootstraps itself. This causes the plugins to be loaded and registered. This gives each plugin the chance to register callbacks for any or all hooks the program offers. The program then runs the hooks in the order it desires. Each time a hook is run, all the callbacks the plugins have registered with this particular hook are run in order.

METHODS

new(%opt)

Creates a new object and initializes it. The arguments are passed as a named hash. Valid argument keys:

config

Reads or sets the global configuration.

If the value is a simple string, it is interpreted as a filename. If the file is readable, it is loaded as YAML. If the filename is -, the configuration is read from STDIN.

If the value is a scalar reference, the dereferenced value is assumed to be YAML and is loaded.

If the value is a hash reference, the configuration is cloned from that hash reference.

For example:

Hook::Modular->new(config => 'some_config.yaml');
context(), set_context($context)

Gets and sets (respectively) the global context. It is singular; each program has only one context. Thie can be used to communicate between the plugins.

conf([$conf])

TO BE WRITTEN

plugins_path([$path])

TO BE WRITTEN

cache([$cache])

TO BE WRITTEN

PLUGIN_NAMESPACE

A constant that specifies the namespace that is prepended to plugin names found in the configuration. Defaults to Hook::Modular::Plugin. Subclasses can and probably should override this value. For example, if the plugin namespace is set to My::Test::Plugin and the config file specifies a plugin with the name Some::Printer, we will try to load My:::Test::Plugin::Some::Printer.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to bug-hook-modular@rt.cpan.org, or through the web interface at http://rt.cpan.org.

INSTALLATION

See perlmodinstall for information and options on installing Perl modules.

AVAILABILITY

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://www.perl.com/CPAN/authors/id/M/MA/MARCEL/>.

AUTHOR

Marcel Grünauer, <marcel@cpan.org>

The code is almost completely lifted from Plagger, so really Tatsuhiko Miyagawa <miyagawa@bulknews.net> deserves all the credit.

COPYRIGHT AND LICENSE

Copyright 2007 by Marcel Grünauer

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.