Coder Social home page Coder Social logo

perl6-pluggable's Introduction

NAME

Pluggable - dynamically find modules or classes under a given namespace

This is a modified version orginally based on https://github.com/tony-o/perl6-pluggable.

SYNOPSIS

Given a set of plugins in your library search path:

a::Plugins::Plugin1
a::Plugins::Plugin2
a::Plugins::PluginClass1::PluginClass2::Plugin3

And an invocation of Pluggable like this:

use Pluggable; 

class a does Pluggable {
    method listplugins () {
        @($.plugins).map({.perl}).join("\n").say;
    }
}

a.new.listplugins;

The following output would be produced:

a::Plugins::Plugin1
a::Plugins::Plugin2
a::Plugins::PluginClass1::PluginClass2::Plugin3

FEATURES

  • Role as well as procedural interface

  • Custom module name matching

  • Finding plugins outside of the current modules namespace

DESCRIPTION

Object-Oriented Interface

When "doing" the Pluggable role, a class can use the "plugins" method:

$.plugins(:$base = Nil, :$plugins-namespace = 'Plugins', :$name-matcher = Nil)

:$base (optional)

The base namespace to look for plugins under, if not provided then the namespace from which pluggable is invoked is used.

:$plugins-namespace (default: 'Plugins')

The name of the namespace within $base that contains plugins.

:$name-matcher (optional)

If present, the name of any module found will be compared with this and only returned if they match.

Procedural Interface

In a similar fashion, the module can be used in a non-OO environment, it exports a single sub:

plugins($base, :$plugins-namespace = 'Plugins', :$name-matcher = Nil)

$base (required)

The base namespace to look for plugins under. Unlike in the OO case, this is required in the procedural interface.

:$plugins-namespace (default: 'Plugins')

The name of the namespace within $base that contains plugins.

:$name-matcher (optional)

If present, the name of any module found will be compared with this and only returned if they match.

DEBUGGING

If you're having trouble with an object you think should be loading but would like to find out what is bonking in require, set $*DEBUG-PLUGINS to a truthy value.

LICENSE

Released under the Artistic License 2.0 http://www.perlfoundation.org/artistic_license_2_0

AUTHORS

perl6-pluggable's People

Contributors

tony-o avatar robertlemmen avatar zoffixznet avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.