NAME

eris::role::pluggable - Implements the plumbing for an object to support plugins

VERSION

version 0.008

SYNOPSIS

Implements helpers around creating plugins to make things easier to plug.

package eris::schemas;

use Moo;
with qw(eris::role::pluggable);

sub _build_namespace { 'eris::schema' }

sub find {
    my ($self,$log) = @_;

    foreach my $p ($self->plugins) {
        return $p->name if $p->match_log($log);
    }
}

package main;

my $schemas = eris::schemas->new(
    search_path => [ qw( my::app::schema ) ],
    disabled    => [ qw( eris::schema::syslog ) ],
    config      => {
        access => { index_name => 'www-%Y.%m.%d' }
    }
);

ATTRIBUTES

namespace

Primary namespace for the plugins for this object. No default provided, you must implement _build_namespace in your plugin.

search_path

An ArrayRef of additional namespaces or directories to search to load our plugins. Default is an empty array.

disabled

An ArrayRef of explicitly disallowed package namespaces to prevent loading. Default is an empty array.

loader

An instance of Module::Pluggable::Object to use to locate plugins.

You shouldn't need this considering the options available, but always nice to have the option to override it with _build_loader.

This plugin class expects the loader's plugin() call to return a list of class names, not instantiated objects.

plugins_config

A HashRef of configs for passing along to our plugins. The init arg for this parameter is 'config' to simplify creation and config files.

Special considerations are taken when processing the hash. The namespace and search_path are automatically prepended to all keys to allow pretty config. This means I can pass a config like this:

my $schema = eris::schemas->new(
    search_path => [qw(my::app::schema)],
    config => {
        syslog               => { enabled => 0 },
        eris::schema::syslog => { enabled => 1 },
        access               => { enabled => 0 },
    },
);

This will expand the config to:

config => {
    my::app::schema::access => { enabled => 0 },
    eris::schema::access    => { enabled => 0 },
    my::app::schema::syslog => { enabled => 0 },
    eris::schema::syslog    => { enabled => 1 },
},

The explicit config for 'eris::schema::syslog' is retained.

plugins

The priority sorted list of plugin objects found by the loader. The plugins call expects the loader function to return a list of class names, not objects.

SEE ALSO

eris::role::plugin, eris::schemas, eris::log::contexts, eris::log::decoders

AUTHOR

Brad Lhotsky <brad@divisionbyzero.net>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2015 by Brad Lhotsky.

This is free software, licensed under:

The (three-clause) BSD License