The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Ado::Plugin - base class for Ado specific plugins.

SYNOPSIS

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.

DESCRIPTION

Ado::Plugin is a base class for Ado specific plugins. It provides some methods specific to Ado only.

ATTRIBUTES

Ado::Plugin provides the following attributes for use by subclasses.

app

  my $app  = $self->app;
  $command = $self->app(MyApp->new);

Application for plugin, defaults to a Mojo::HelloWorld object.

config_dir

Path to plugin directory.

  $self->config_dir($app->home->rel_dir('etc/plugins'));

Defaults to $ENV{MOJO_HOME}/etc/plugins.

config_classes

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:

    {   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.

ext

Extension used for the plugin specific configuration file. defaults to 'conf';

  my $ext  = $self->ext;

name

The name - only the last word of the plugin's package name.

  $self->name # MyPlugin

METHODS

Ado::Plugin provides the following methods for use by subclasses.

config

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');

initialise

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.

SEE ALSO

Ado::Manual::Plugins, Mojolicious::Plugin, Ado::Plugin::AdoHelpers, Ado::Plugin::Auth, Ado::Plugin::I18n, Ado::Plugin::MarkdownRenderer, Ado::Plugin::Routes, Ado::Command::generate::adoplugin.

AUTHOR

Красимир Беров (Krasimir Berov)

COPYRIGHT AND LICENSE

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.