Nile::Plugin - Plugin base class for the Nile framework.



Nile::Plugin - Plugin base class for the Nile framework.

This module is the base class for plugins. You include it by using it which also makes itself as a parent class for the plugin and inherts the method setting which has the plugin setting loaded automatically from the config files.

Creating your first plugin Hello is simple like that, just create a module file called in the folder Nile/Plugin and put the following code in it:

    package Nile::Plugin::Hello;
    our $VERSION = '0.55';
    # this also extends Nile::Plugin, the plugin base class
    use Nile::Plugin;
    # optional our alternative for sub new {} called automaticall on object creation
    sub main {

        my ($self, $arg) = @_;
        # plugin settings from config files section
        my $setting = $self->setting();
        #same as
        #my $setting = $self->setting("hello");
        # get app context
        my $app = $self->app;

        # good to setup hooks here
        # run this hook after the "start" method
        $app->hook->after_start( sub { 
            my ($me, @args) = @_;
    sub welcome {
        my ($self) = @_;
        return "Hello world";


Then inside other modules or plugins you can access this plugin as

        # get the plugin object
        $hello = $app->plugin->hello;
        # or
        $hello = $app->plugin("Hello");
        # if plugin name has sub modules
        my $redis = $app->plugin("Cache::Redis");
        # call plugin method
    say $app->plugin->hello->welcome;

    # in general, you access plugins like this:

Plugins will be loaded automatically on the first time it is used and can be load on application startup in the init method:

        plugin  => [ qw(hello) ],

Plugins also can be loaded on application startup by setting the autoload variable in the plugin configuration in the config files.

Example of plugin configuration to auto load on application startup:




At the plugin load, the plugin optional method main will be called automatically if it exists, this is an alternative for the method new.

Inside the plugin methods, you access the application context by the injected method app and you use it in this way:

    my $app = $self->app;

Plugins that setup hooks must be set to autoload on startup for hooks to work as expected.


    # inside plugin classes, return current plugin class config settings
    my $setting = $self->setting();
    my %setting = $self->setting();

    # inside plugin classes, return specific plugin class config settings
    my $setting = $self->setting("email");
    my %setting = $self->setting("email");

Returns plugin class settings from configuration files loaded.

Helper plugin settings in config files must be in inside the plugin tag. The plugin class name can be lower case tag, so plugin Email can be email.

Exampler settings for email and cache plugins class below:



This project is available on github at


Please visit the project's homepage at


Source repository is at


See Nile for details about the complete framework.


Ahmed Amin Elsheshtawy, احمد امين الششتاوى <> Website:


Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى,,,

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.