Ado::Plugin - base class for Ado specific plugins.
Create your plugin like this:
# CamelCase plugin name is recommended. package Ado::Plugin::MyPlugin; use Mojo::Base 'Ado::Plugin'; sub register { my ($self, $app, $conf) = shift->initialise(@_); # Your magic here!.. return $self; }
but better use Ado::Command::generate::adoplugin to generate all the files for you.
Ado::Plugin is a base class for Ado specific plugins. It provides some methods specific to Ado only.
Ado::Plugin inherits all attributes from Mojolicious::Plugin and provides the following for use by subclasses.
my $app = $self->app; $command = $self->app(MyApp->new);
Application for plugin, defaults to a Mojo::HelloWorld object.
Path to plugin directory.
my $config_dir = $self->config_dir; $self->config_dir($app->home->rel_dir('etc/plugins'));
Defaults to etc/plugins relative to the plugin base directory, see "home_dir". This works both while developing a plugin and after installing the plugin.
etc/plugins
Returns a hash reference containing file-extension => class pairs. Used to detect which configuration plugin to use depending on the file extension. The default mapping is:
file-extension => class
{ conf => 'Mojolicious::Plugin::Config', json => 'Mojolicious::Plugin::JSONConfig', pl => 'Mojolicious::Plugin::Config' };
This attribute allows you to use your own configuration plugin as far as it supports the Mojolicious::Plugin::Config API.
Extension used for the plugin specific configuration file. defaults to 'conf';
my $ext = $self->ext;
my $plugin_home = $self->home_dir;
The plugin base directory. This path works both while developing a plugin and after installing the plugin. Using the guessed value allows you to have Ado plugins installed at arbitrary paths, possibly not the same where Ado is installed. As noted elsewhere, Ado plugins can be distributed as separate Ado applications and used together with other plugins to create custom enterprise-grade systems.
The name - only the last word of the plugin's package name.
$self->name # MyPlugin
Ado::Plugin inherits all methods from Mojolicious::Plugin and provides the following for use by subclasses.
The configuration which is for the currently registering plugin only. In Ado every plugin can have its own configuration file. When calling this method for the first time it will parse and merge configuration files for the plugin. Options from mode specific configuration file will overwrite options found in the generic file. You usually do not need to invoke this method directly since it is invoked in "initialise".
# everything in $self->config_dir.'/$my_plugin.conf' # and/or $self->config_dir.'/$my_plugin.$mode.conf' my $config = $self->config; #get a config value my $value = $self->config('key'); #set my $config = $self->config(foo => 'bar');
Used to initialize you plugin and reduce boilerplate code.
sub register { my ($self, $app, $config) = shift->initialise(@_); # ...
This method should be the first invoked in your "register" in Mojolicious::Plugin method. If you need to do some very custom stuff, you are free to implement the initialisation yourself.
Currently this method does the following:
Merges configurations (invokes "config").
Pushes @{$conf->{namespaces}} to $app->routes->namespaces if additional namespaces are defined in configuration file.
@{$conf->{namespaces}}
$app->routes->namespaces
Loads routes if defined in configuration file.
Pushes the plugin templates directory to @{app->renderer->paths} (if it exists and is not the same as Ado's one) so the templates can be found by Ado while developing your plugin.
templates
@{app->renderer->paths}
Pushes the plugin public directory to @{app->static->paths} (if it exists and is not the same as Ado's one) so the templates can be found by Ado while developing your plugin.
public
@{app->static->paths}
Returns ($self, $app, $config).
($self, $app, $config)
Look at some of the configuration files of the plugins that come with Ado.
Ado::Manual::Plugins, Mojolicious::Plugin, Ado::Plugin::AdoHelpers, Ado::Plugin::Auth, Ado::Plugin::I18n, Ado::Plugin::MarkdownRenderer, Ado::Plugin::Routes, Ado::Command::generate::adoplugin.
Красимир Беров (Krasimir Berov)
Copyright 2013-2014 Красимир Беров (Krasimir Berov).
This program is free software, you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License v3 (LGPL-3.0). You may copy, distribute and modify the software provided that modifications are open source. However, software that includes the license may release under a different license.
See http://opensource.org/licenses/lgpl-3.0.html for more information.
To install Ado, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Ado
CPAN shell
perl -MCPAN -e shell install Ado
For more information on module installation, please visit the detailed CPAN module installation guide.