NAME

OX::Application - base class for OX applications

VERSION

version 0.14

SYNOPSIS

package MyApp;
use Moose;
extends 'OX::Application';

sub build_app {
    return sub { [ 200, [], ["Hello world"] ] };
}

MyApp->new->to_app; # returns the PSGI coderef

DESCRIPTION

This class provides the base set of functionality for OX applications. OX::Application is a subclass of Bread::Board::Container, so all Bread::Board functionality is available through it.

By default, the container holds two services:

Middleware

This service provides an arrayref of middleware to be applied, in order, to the app (the first middleware in the array will be the outermost middleware in the final built app). It is built via the build_middleware and middleware_dependencies methods, described below.

Middleware can be specified as either a coderef (which is expected to accept an app coderef as an argument and return a new app coderef), the name of a subclass of Plack::Middleware, or a Plack::Middleware instance.

App

This service provides the actual PSGI coderef for the application. It is built via the build_app and app_dependencies methods described below, and applies the middleware from the Middleware service afterwards. It also applies Plack::Middleware::HTTPExceptions as the innermost middleware, so your app can throw HTTP::Throwable or HTTP::Exception objects and have them work properly.

You can add any other services or subcontainers you like, and can use them in the construction of your app by overriding build_middleware, middleware_dependencies, build_app, and app_dependencies.

METHODS

build_middleware($service)

This method can be overridden in your app to provide an arrayref of middleware to be applied to the final application. It is passed the Middleware service object, so that you can access the resolved dependencies you specify in middleware_dependencies.

middleware_dependencies

This method returns a hashref of dependencies, as described in Bread::Board. The arrayref form of dependency specification is not currently supported. These dependencies can be accessed in the build_middleware method.

build_app($service)

This method must be overridden by your app to return a PSGI coderef. It is passed the App service object, so that you can access the resolved dependencies you specify in app_dependencies.

app_dependencies

This method returns a hashref of dependencies, as described in Bread::Board. The arrayref form of dependency specification is not currently supported. These dependencies can be accessed in the build_app method.

to_app

This method returns the final PSGI application, after all middleware have been applied. This method is just a shortcut for $app->resolve(service => 'App').

AUTHORS

  • Stevan Little <stevan.little@iinteractive.com>

  • Jesse Luehrs <doy@tozt.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Infinity Interactive.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.