Jedi::App - to define your application
version 1.008
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.
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; }
All routes will take ($app, $request, $response).
Define a GET method.
$app->get("/", sub{...});
Define a POST method.
$jedi->post("/", sub{...});
Define a PUT method.
$jedi->put("/", sub{...});
Define a DEL method.
$jedi->del("/", sub{...});
If no route matches, all the missing method is executed.
$jedi->missing(sub{...});
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}; # ... }
To get the server host ip, use the method 'jedi_host_ip' :
sub jedi_app { my ($app) = @_; say "Server Host IP : ", $app->jedi_host_ip; }
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.
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.
celogeek <me@celogeek.com>
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.
To install Jedi, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Jedi
CPAN shell
perl -MCPAN -e shell install Jedi
For more information on module installation, please visit the detailed CPAN module installation guide.