Sawyer X > Dancer2-0.150000 > Dancer2::Core::App

Download:
Dancer2-0.150000.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.150000   Source   Latest Release: Dancer2-0.157001

NAME ^

Dancer2::Core::App - encapsulation of Dancer2 packages

VERSION ^

version 0.150000

DESCRIPTION ^

Everything a package that uses Dancer2 does is encapsulated into a Dancer2::Core::App instance. This class defines all that can be done in such objects.

Mainly, it will contain all the route handlers, the configuration settings and the hooks that are defined in the calling package.

Note that with Dancer2, everything that is done within a package is scoped to that package, thanks to that encapsulation.

ATTRIBUTES ^

with_return

Used to cache the coderef from Return::MultiLevel within the dispatcher.

destroyed_session

We cache a destroyed session here; once this is set we must not attempt to retrieve the session from the cookie in the request. If no new session is created, this is set (with expiration) as a cookie to force the browser to expire the cookie.

plugins

runner_config

default_config

METHODS ^

has_session

Returns true if session engine has been defined and if either a session object has been instantiated or if a session cookie was found and not subsequently invalidated.

destroy_session

Destroys the current session and ensures any subsequent session is created from scratch and not from the request session cookie

redirect($destination, $status)

Sets a redirect in the response object. If $destination is not an absolute URI, then it will be made into an absolute URI, relative to the URI in the request.

halt

Flag the response object as 'halted'.

If called during request dispatch, immediatly returns the response to the dispatcher and after hooks will not be run.

pass

Flag the response object as 'passed'.

If called during request dispatch, immediatly returns the response to the dispatcher.

forward

Create a new request which is a clone of the current one, apart from the path location, which points instead to the new location. This is used internally to chain requests using the forward keyword.

Note that the new location should be a hash reference. Only one key is required, the to_url, that should point to the URL that forward will use. Optional values are the key params to a hash of parameters to be added to the current request parameters, and the key options that points to a hash of options about the redirect (for instance, method pointing to a new request method).

register_plugin

lexical_prefix

Allow for setting a lexical prefix

    $app->lexical_prefix('/blog', sub {
        ...
    });

All the route defined within the callback will have a prefix appended to the current one.

add_route

Register a new route handler.

    $app->add_route(
        method  => 'get',
        regexp  => '/somewhere',
        code    => sub { ... },
        options => $conditions,
    );

route_exists

Check if a route already exists.

    my $route = Dancer2::Core::Route->new(...);
    if ($app->route_exists($route)) {
        ...
    }

routes_regexps_for

Sugar for getting the ordered list of all registered route regexps by method.

    my $regexps = $app->routes_regexps_for( 'get' );

Returns an ArrayRef with the results.

app

Returns itself. This is simply available as a shim to help transition from a previous version in which hooks were sent a context object (originally Dancer2::Core::Context) which has since been removed.

    # before
    hook before => sub {
        my $ctx = shift;
        my $app = $ctx->app;
    };

    # after
    hook before => sub {
        my $app = shift;
    };

This meant that $app->app would fail, so this method has been provided to make it work.

    # now
    hook before => sub {
        my $WannaBeCtx = shift;
        my $app        = $WannaBeContext->app; # works
    };

AUTHOR ^

Dancer Core Developers

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2014 by Alexis Sukrieh.

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

syntax highlighting: