Skip to content

role for finding loaded modules in global scope that 'does' some role or class, useful for modules that want to support hot swapping modules with minimal end user code

zoffixznet/perl6-module-does

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Module::Does

Build Status

This module is built for module authors that want to allow the module's audience to 'hot swap' modules with minimal code on their end. This module gathers specified types from the GLOBAL scope upon object creation and then makes them available to the module.

#Usage

use Module::Does;

class A does Module::Does[HTTP::Server] {
  method listen {
    $.server = %!base-types<HTTP::Server>.new(:$.localhost, :$.localport, :listen);
  }
}

##IDGI.

When A is instantiated, the private variable %!base-types is populated with anything in the global scope that does HTTP::Server.

##Yea, but I want extra sauce, bro.

I got you.

use Module::Does;

class A does Module::Does[@(HTTP::Server => HTTP::Server::Async, CSV::Parser)] {
# ...
}

If a Pair is passed in, then the .key is sought in the global scope and only if nothing is found, then .value is used.

Notice in the second value that an array is given, this module lets you pass in multiple types to look for and can consist of class|Str|Pair.

About

role for finding loaded modules in global scope that 'does' some role or class, useful for modules that want to support hot swapping modules with minimal end user code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Other 100.0%