NAME
Jedi::App - to define your application
VERSION
version 1.004
DESCRIPTION
A Jedi::App is a Moo class with a 'jedi_app' method. This method is call directly by Jedi to mount your app in the required path.
REQUIRED METHOD
jedi_app
This method is automatically called by Jedi to initialize your app.
You have to define the relative route the app takes
sub jedi_app {
my ($app) = @_;
$app->get('/' => sub {
my ($app, $request, $response) = @_;
# ...
});
$app->post('/signin', $app->can('route_signin')),
}
sub route_signin {
my ($app, $request, $response) = @_;
# ...
}
The return will decide if Jedi need to continue to any other matching routes, or stop here.
If the return is true, the route continue.
If the return is false, the route stop here.
You can for instance :
sub jedi_app {
my ($app) = @_;
$app->get(qr{.*}, $app->can("check_auth"));
$app->get('/', $app->can("handle_index"));
}
sub check_app{
my ($app, $request, $response) = @_;
# check auth
if (!$auth_ok) {
$response->status('302');
$response->set_header('Location', '/auth');
return 0;
}
return 1;
}
DEFINE YOUR ROUTES
All routes will take ($app, $request, $response).
get
Define a GET method.
$app->get("/", sub{...});
post
Define a POST method.
$jedi->post("/", sub{...});
put
Define a PUT method.
$jedi->put("/", sub{...});
del
Define a DEL method.
$jedi->del("/", sub{...});
missing
If no route matches, all the missing method is executed.
$jedi->missing(sub{...});
CONFIG
The 'config' attribute of Jedi is passed to all your apps.
You can access to it with the 'jedi_config' attribute :
sub jedi_app {
my ($app) = @_;
my $admin_token = $app->jedi_config->{MyConf}{admin}{token};
# ...
}
THE REPONSE
Each route will call your method with : ($app, $request, $response).
'$app' is the 'self' of your package, a Jedi::App
'$request' is the request, a Jedi::Request
'$response' is the object you need to manipulate to prepare your response, a Jedi::Response
Checkout the documentation of each of them to get all the possibilities.
BUGS
Please report any bugs or feature requests on the bugtracker website https://github.com/celogeek/perl-jedi/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
AUTHOR
celogeek <me@celogeek.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by celogeek <me@celogeek.com>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.