The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Kelp::Module::Symbiosis::Base - Base class for symbiotic modules


        package Kelp::Module::MyModule;

        use Kelp::Base qw(Kelp::Module::Symbiosis::Base);

        sub psgi
                # write code that returns psgi application without middlewares

        sub build
                my ($self, %args) = @_;

                # write initialization code as usual
                $self->register(some_method => sub { ... });


This class serves as a base for a Kelp module that is supposed to be ran as a standalone Plack application (mounted separately). It takes care of middleware management, mounting into Symbiosis manager and some basic initialization chores. To write a new module that introduces a standalone Plack application as a Kelp module, simply extend this class and override methods: psgi build name (see below for details).


It is a base for Kelp modules that are meant to be used with Symbiosis - it inherits from Kelp::Module. It can also come very handy because of the built in middleware handling and access to Kelp application's configuration.



        sig: run($self)

Calls psgi() and wraps its contents in middlewares. Returns a Plack application.


        sig: psgi($self, @more_data)

By default, this method will throw an exception. It has to be replaced with an actual application producing code in the child class. The resulting application will be wrapped in middlewares from config in run().

Must be reimplemented in a module.


        sig: build($self, %args)

Standard Kelp module building method. When reimplementing it's best to call parent's implementation, as middleware initialization happens in base implementation.

Should be reimplemented in a module. If it isn't, no extra methods will be added to the Kelp instance, but all the middleware and module registration in Symbiosis will happen anyway.


        sig: name($self)

new in 1.10

Returns a name of a module - a string. This name will be available in "loaded" in Kelp::Module::Symbiosis hash as a key, containing the module instance as a value.

Should be reimplemented in a module. If it isn't, it will return the name of the package.


        sig: middleware($self)

Returns an array containing all the middlewares in format: [ middleware_class, { middleware_config } ]. By default, this config comes from module configuration.


example configuration could look like this (for Kelp::Module::WebSocket::AnyEvent):

        modules => [qw/JSON Symbiosis WebSocket::AnyEvent/],
        modules_init => {
                Symbiosis => {
                        mount => undef, # kelp will be mounted manually under different path
                "WebSocket::AnyEvent" => {
                        serializer => "json",
                        middleware => [qw/Recorder/],
                        middleware_init => {
                                Recorder => { output => "~/recorder.out" },

middleware, middleware_init

Middleware specs for this application - see above example. Every module basing on this class can specify its own set of middlewares. They are configured exactly the same as middlewares in Kelp. There's currently no standarized way to retrieve middleware configurations from Kelp into another application (to wrap that application in the same middleware as Kelp), so custom code is needed if such need arise.


        modules_init => {
                "Symbiotic::Module" => {
                        mount => '/path',

new in 1.10

Should be a string value. If specified, the module will be automatically mounted under that path - there will be no need to call that explicitly, and it will work like: $kelp->symbiosis->mount($path => $module);.