modularize
1.0.0A modularization framework
Table of Contents
About Modularize
modularize
is an attempt at providing a common interface to segregate major application components. This is achieved by adding special treatment to packages. Each module is a package that is specially registered, which allows it to interact and co-exist with other modules in better ways. For instance, by adding module definition options you can introduce mechanisms to tie modules together in functionality, hook into each other, and so on.
How To
Each module should consist of a define-module
form and an ASDF system with the superclass modularize:module
. define-module
acts as a wrapper around defpackage
, so it will replace your usual defpackage
form. Any option you would use in defpackage
is also usable in define-module
, but the latter also allows for custom-defined options that perform specific actions upon module creation.
(modularize:define-module test-module
(:use #:cl #:modularize)
(:export #:greet))
If for some reason you absolutely do not want to use define-module
, you may define your package manually and call modularize
on it afterwards. Note though that you also need to manually perform all changes that additional module options may otherwise perform for you. If your module-name somehow differs from the ASDF system, you will need to specify this in your ASDF system definition:
(asdf:defsystem some-test-module
:class "modularize:virtual-module"
:defsystem-depends-on (:modularize)
:module-name "test-module"
...)
The main difference from packages is that each module has a central storage table, which you can access with module-storage
. This allows you to save metadata on modules to keep track of the different parts each module might play in your application.
Another function that might prove useful is delete-module
, which attempts to offer a mechanism to completely remove a module so as to revert its changes. Without any further additions, this will simply result in all symbols in the module package being makunbound
and fmakunbound
and the package getting deleted. Since a module might also cause changes outside of its own package, it is therefore advised to add deletion hooks through define-delete-hook
, so as to make sure other kinds of changes can be cleaned up as well.
Similarly, if you want to tack on functionality to initialize a module once it is defined, you can hook into that with define-modularize-hook
and define-option-expander
. The former works like define-delete-hook
, and is called once modularize
is called on a package after the package's storage has been set up. The latter allows you to declare custom forms that a define-module
call should expand to. Note that module options are only expanded after modularize
is called, so you may use the storage in your expansions.
If a component should extend the functionality of another, this can be more intuitively done through define-module-extension
. In looks and form it is the same as define-module
, with the difference that it won't create a new package, but use the one it is extending. Through this you can export new functions and other additions without running into a multiple-package mess.
If you would like to group multiple packages under a single module (probably the case if you use one package per file), then you must register the packages with the module. You can do this in your module definition with the :packages
option, or by module-packages
calls.
For a super small sample use of a module, have a look at modularize-test-module.asd and modularize-test-module.lisp. For extensions to the module system, have a gander at modularize-interfaces and modularize-hooks.
System Information
Definition Index
-
MODULARIZE
- ORG.SHIRAKUMO.RADIANCE.LIB.MODULARIZE
- RADIANCE-MODULARIZE
No documentation provided.-
EXTERNAL CLASS MODULE
ASDF System subclass that serves as the class for virtual modules. Deprecated-- use VIRTUAL-MODULE instead.
-
EXTERNAL CLASS VIRTUAL-MODULE
ASDF System subclass that serves as the class for virtual modules.
-
EXTERNAL CONDITION MODULE-NOT-FOUND
Condition signalled when a module is requested but not found.
-
EXTERNAL CONDITION NOT-A-MODULE
Condition signalled when a module is requested but only a package of the requested name exists.
-
EXTERNAL CONDITION VIRTUAL-MODULE-NOT-FOUND
Condition signalled when a virtual module was requested but could not be found.
-
EXTERNAL FUNCTION CALL-DELETE-HOOKS
- PACKAGE
- &REST
Calls all deletion hooks on the package.
-
EXTERNAL FUNCTION CALL-MODULARIZE-HOOKS
- PACKAGE
- &REST
Calls all modularization hooks on the package.
-
EXTERNAL FUNCTION DELETE-HOOK
- IDENTIFIER
- &REST
Accesses the deletion hook function associated with the identifier.
-
EXTERNAL FUNCTION (SETF DELETE-HOOK)
- FUNCTION
- IDENTIFIER
- &REST
No documentation provided. -
EXTERNAL FUNCTION DELETE-MODULE
- MODULE
- &REST
Attempts to completely delete the given module. This first calls the delete hooks, then demodularizes the package, unbinds all symbols in the package from values and functions, and finally deletes the package.
-
EXTERNAL FUNCTION DEMODULARIZE
- MODULE
- &REST
Removes the module from the module storage table. This essentially returning it back to a normal package. Any additional effects by module options or modularization hooks can of course not be undone by this.
-
EXTERNAL FUNCTION LIST-MODULES
Returns a list of all modules in no particular order.
-
EXTERNAL FUNCTION LOAD-MODULE
- IDENTIFIER
- &REST
Attempts to find the module named by identifier and load its ASDF system.
-
EXTERNAL FUNCTION MAP-MODULES
- FUNCTION
- &REST
Calls the function once with each module in no particular order.
-
EXTERNAL FUNCTION MODULARIZE
- &KEY
- PACKAGE
- NAME
- &REST
Turns the given package into one that is identified as a module. What this does is register the package on the module storage table, add the name and identifiers to it, and then call the modularize hooks.
-
EXTERNAL FUNCTION MODULARIZE-HOOK
- IDENTIFIER
- &REST
Accessor to the modularization hook function associated with the identifier.
-
EXTERNAL FUNCTION (SETF MODULARIZE-HOOK)
- FUNCTION
- IDENTIFIER
- &REST
No documentation provided. -
EXTERNAL FUNCTION MODULE
- &OPTIONAL
- IDENTIFIER
- &REST
Attempts to return the matching module package. If not possible, a condition of type MODULE-NOT-FOUND is signalled. You may pass a STRING, SYMBOL or PACKAGE as the identifier. If NIL is passed, the current *PACKAGE* is used instead.
-
EXTERNAL FUNCTION MODULE-IDENTIFIER
- MODULE
- &REST
Returns the identifier of the module.
-
EXTERNAL FUNCTION MODULE-NAME
- MODULE
- &REST
Returns the name of the module.
-
EXTERNAL FUNCTION MODULE-P
- OBJECT
- &REST
Returns non-NIL if the passed object is or resolves to a module package, otherwise NIL.
-
EXTERNAL FUNCTION MODULE-PACKAGES
- MODULE
- &REST
Accesses the packages that are sub-packages under the module. The list may contain package objects or package-names. You can only add packages that are not already registered as sub-packages to a module, and are not themselves a module.
-
EXTERNAL FUNCTION (SETF MODULE-PACKAGES)
- PACKAGES
- MODULE
- &REST
No documentation provided. -
EXTERNAL FUNCTION MODULE-STORAGE
- MODULE
- &OPTIONAL
- KEY
- &REST
Accesses the module storage table of the module or a field from it if a key is passed.
-
EXTERNAL FUNCTION (SETF MODULE-STORAGE)
- VALUE
- MODULE
- &OPTIONAL
- KEY
- &REST
No documentation provided. -
EXTERNAL FUNCTION MODULE-STORAGE-REMOVE
- MODULE
- KEY
- &REST
Removes a key from the module storage table.
-
EXTERNAL FUNCTION REGISTER-VIRTUAL-MODULE
- MODULE
- &REST
Registers the given module in the virtual module map.
-
EXTERNAL FUNCTION REMOVE-DELETE-HOOK
- IDENTIFIER
- &REST
Removes the deletion hook named by the identifier.
-
EXTERNAL FUNCTION REMOVE-MODULARIZE-HOOK
- IDENTIFIER
- &REST
Removes the modularization hook named by the identifier.
-
EXTERNAL GENERIC-FUNCTION EXPAND-OPTION
- TYPE
- PACKAGE
- ARGS
- &REST
Called to expand module options into forms.
-
EXTERNAL GENERIC-FUNCTION REMOVE-VIRTUAL-MODULE
- IDENTIFIER
- &REST
Removes the association of the name with a virtual module.
-
EXTERNAL GENERIC-FUNCTION VIRTUAL-MODULE
- IDENTIFIER
- &REST
Accesses the virtual module instance associated with the identifier if one was found, otherwise NIL.
-
EXTERNAL GENERIC-FUNCTION (SETF VIRTUAL-MODULE)
- MODULE
- IDENTIFIER
- &REST
No documentation provided. -
EXTERNAL GENERIC-FUNCTION VIRTUAL-MODULE-NAME
- OBJECT
- &REST
Returns the module name associated with this virtual module.
-
EXTERNAL GENERIC-FUNCTION (SETF VIRTUAL-MODULE-NAME)
- NEW-VALUE
- OBJECT
- &REST
No documentation provided. -
EXTERNAL MACRO CURRENT-MODULE
Macro that expands to the module in the current package. Useful to establish a module context.
-
EXTERNAL MACRO DEFINE-DELETE-HOOK
- MODULEVAR
- &OPTIONAL
- IDENTIFIER
- &REST
- &BODY
- BODY
- &REST
Defines a new deletion hook. The identifier is defaulted to a keyword representation of the current package name.
-
EXTERNAL MACRO DEFINE-MODULARIZE-HOOK
- MODULEVAR
- &OPTIONAL
- IDENTIFIER
- &REST
- &BODY
- BODY
- &REST
Defines a new modularization hook. The identifier is defaulted to a keyword representation of the current package name.
-
EXTERNAL MACRO DEFINE-MODULE
- NAME
- &BODY
- OPTIONS
- &REST
Defines a new module. This essentially defines a new package with the given name, calls MODULARIZE on it and then expands all options to extend the package/module.
-
EXTERNAL MACRO DEFINE-MODULE-EXTENSION
- MODULE-IDENTIFIER
- NAME
- &REST
- &BODY
- OPTIONS
- &REST
Defines a module extension. This gives the existing module new nicknames and expands the given options on it to add functionality.
-
EXTERNAL MACRO DEFINE-OPTION-EXPANDER
- NAME
- PACKAGE
- &REST
- ARGUMENTS
- &REST
- &BODY
- BODY
- &REST
Defines a new option expander that is called whenever the option is used in the module definition. This should run whatever is necessary to accomplish the desired option effect. The expanders are run AFTER the modularize call, so you can use the module storage in your expansions.
-
EXTERNAL MACRO WITH-MODULE
- VAR
- &OPTIONAL
- MODULE
- &REST
- &BODY
- BODY
- &REST
Binds the resolved MODULE to VAR.
-
ORG.SHIRAKUMO.RADIANCE.LIB.MODULARIZE.USER
- MODULARIZE-USER
No documentation provided.