MKDoc::Core::Plugin - Class for atomic MKDoc application functionality


The MKDoc::Core plugin system is a fundamental foundation for any application which uses the MKDoc::Core framework. Plugins are classes which are executed one after the other in a predefined order.

The plugin processor (MKDoc::process) executes a list of plugins until one (usually the one which handles the request) returns 'TERMINATE'.

Petal modifiers


Instanciates a plugin of class plugin_type and returns it. This is handy if you need to access the attributes methods of another plugin from the plugin you're on, e.g:

    petal:define="details flo::plugin::Account::Details"


Gives you access to any scalar variable stored in $::. For example:

    petal:define="site_dir global: MKD__SITE_DIR"


$self->equals ($otherplugin);

Returns TRUE if the class of $self is the same as the class of $otherplugin.

Since by default plugin objects do not have any data a class equivalence makes sense, however this behavior can be subclassed as necessary.


Returns TRUE if this plugin would activate if it was requested. Returns FALSE otherwise.

For example:

        petal:define="details flo::plugin::Account::Details"
    > ./.account.details can be accessed from here!</span>

For convenience, would_activate always returns FALSE if invoked on the same class of plugin that is currently being activated. This is because usually, hyperlinking to yourself is rather useless.

i.e. if you were using the piece of code above in the account details plugin itself, details/would_activate would always return false.


Returns the current plugin which is being executed.


Returns TRUE if $self is the plugin being currently executed, FALSE otherwise.


This class method is called by the MKDoc module. Unless overriden it instantiates the current plugin and checks to see if it should be activated. If so it processes the request by calling run(), otherwise it does nothing.

Returns 'TERMINATE' if the request was handled by this plugin, false if not, or undef on error.


Very basic constructor which instantiates a new object. Calls the _initialize method.


Initializes this object, called by new(). This is empty, and here to be overrided if necessary. Returns $self, or undef on failure.


Runs the current plugin. If the request is a POST, runs $self->http_post(). If it's a GET, runs $self->http_get().


Processes an HTTP GET request.


Processes an HTTP POST request. Defaults http_get() by default.


Returns TRUE if this plugin wants to be activated, FALSE otherwise.

By default it returns true if $self->location() equals the current PATH_INFO.


By default, returns the URI of the current plugin without any parameters. However, this behavior can be overriden as follows:

  $plugin->uri (foo => 'bar');
  $plugin->uri ('parameters');
  $plugin->uri ( 'parameters', foo => 'bar');

$self->uri_relative ($other);

Same this object's URI relative to $other. $other can be a URI object, a SCALAR representing a URI, or an object which MUST have a uri() method.


Returns a MKDoc::Language object which represents the preferred language to be used for this plugin. By order of preference:

new MKDoc::Language ('en')


Returns the content-type associated with this plugin. By default, returns "text/html; charset=UTF-8"


Returns TRUE if the current plugin object holds error that needs to be displayed, false otherwise.


Returns a list of errors, or an array ref in scalar context.

$self->add_error (@_);

Adds all the errors in @_ to the current plugin object.


Renders the current object with render(). Sets the response object.

Explores all the inherited HTTP_ methods and sets HTTP headers accordingly.


Recursively introspects $this and its base classes and find all methods which starts with HTTP_. Returns a list of methods found.

This little hack is written so that you can simply add HTTP headers by defining methods, e.g.

  sub HTTP_X_Bender { "Bite my shiny, metal ass!" }

Will set the following header:

  X-Bender: Bite my shiny, metal ass!

$self->render (%args);

Renders the current object, passing %args to the template being used. Intercepts '__input__' and '__output__' to set Petal processing vars.

Returns the rendered document on success, or undef on error. See template_path().


Returns the environment variables as a hash reference.


Returns the environment variables keys as an array or an array ref depending on the context.

$self->env_value ($key);

Returns the environment variable value for $key, i.e.

    my $path_info = $self->env_value ('PATH_INFO');


Returns the template path relative to Petal @BASE_DIR directories.

By default if your plugin is called something like:


It will return:


This method is subclassable.


Returns the location of the current plugin. By default, returns the current PATH_INFO.


Returns the MKDoc::Core::Request object singleton.


Returns the MKDoc::Core::Response object singleton.


Some plugins have a need to redirect to a return uri once they have finished processing. This is usually the case with POST request. This method tries to provide a sensible default:

it looks for a return_uri parameter
otherwise it looks in $ENV{HTTP_REFERER}
otherwise it returns the root of the website by setting path_info to '/'.


Copyright 2003 - MKDoc Holdings Ltd.

Author: Jean-Michel Hiver

This module is free software and is distributed under the same license as Perl itself. Use it at your own risk.


  L<Petal> TAL for perl

Help us open-source MKDoc. Join the mkdoc-modules mailing list: