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 do everything for you.
Ado::Plugin is a base class for Ado specific plugins. It provides some methods specific to Ado only.
Ado::Plugin provides the following attributes 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.
$self->config_dir($app->home->rel_dir('etc/plugins'));
Defaults to $ENV{MOJO_HOME}/etc/plugins.
$ENV{MOJO_HOME}/etc/plugins
Returns a hash reference containing file-extension => class pairs. Used to decide 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' };
Using this attribute you can 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;
The name - only the last word of the plugin's package name.
$self->name # MyPlugin
Ado::Plugin provides the following methods 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 form the generic file. You usually do not need to invoke this method directly since it is invoked in "initialise".
# everything in '$ENV{MOJO_HOME}/etc/plugins/$my_plugin.conf' # and/or '$ENV{MOJO_HOME}/etc/plugins/$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 initialise you plugin and reduce boilerplate code.
* Merges configurations. * Adds new $app->routes->namespaces if defined in config. * Loads routes if defined in config * Returns ($self, $app, $config). sub register { my ($self, $app, $conf) = @_; $self->initialise($app, $conf); # ...
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.
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.