Amon2 6.13 documentation



Amon2 is constructed by the following modules.

Generic Context Object

The Generic context object MUST inherit

You can use it as a context object on CLI.

The context object bootstrapping with following statement:

package MyApp;
use parent qw/Amon2/;

package main;
my $c = MyApp->bootstrap;

You can get a context object via $Amon2::CONTEXT from everywhere.

The Generic context object MUST implement the following abstract methods:


This method returns configuration data. It MUST be a hashref. Normally, this method using Amon2::Config::Simple.

Web Context Object

The Web context object SHOULD inherit Amon2::Web and the Generic context object.

You can use it as follows:

package MyApp::Web;
use parent qw/MyApp Amon2::Web/;

package main;
my $app = MyApp::Web->to_app();

$app is a PSGI application. $app creates a new instance of MyApp::Web per request and sends it to $Amon2::CONTEXT.

The Web context object SHOULD have the following methods:


Creates a new instance of Web request object.

MyApp::Web->create_response($code, $headers, $content)

Creates a new instance of Web response object.


Creates a new instance of View object. It MUST support Tiffany protocol.


Dispatches the request to the real application.

Web request object creates MyApp::Web::Request. It inherits an Amon2::Web::Request and Plack::Request.

In theory, you can customize it. In practice, it is fequently left untouched.

Web response Object creates MyApp::Web::Response. It inherits an Amon2::Web::Response and Plack::Response.

Normally, you don’t need to touch it. But you can customize it.