Nephia::Plugin::Dispatch - Dispatcher Plugin for Nephia
This plugin provides dispatcher feature to Nephia.
package My::NephiaApp;
use Nephia plugins => ['Dispatch'];
{ ### External Controller Class
package My::NephiaApp::C::External;
sub index {
my $c = shift; # Nephia::Core object
my $id = $c->param('id'); # You may call param method via Nephia::Core object
[200, [], ["id = $id"]];
}
};
my $users = {};
app {
get '/' => sub { [200, [], 'Hello, World!'] };
get '/user/:id' => sub {
my $id = path_param('id');
my $user = $users->{$id};
$user ?
[200, [], sprintf('name = %s', $user->{name}) ]
[404, [], 'no such user']
;
};
post '/user/:id' => sub {
my $id = path_param('id');
my $name = param('name');
$users->{$id} = { name => $name };
[200, [], 'registered!'];
};
get '/external/' => Nephia->call('C::External#index');
};
get $path => sub { ... };
Add action for $path. You may use Router::Simple syntax in $path.
get '/user/:id' => sub {
my $id = path_param('id');
### or
my $path_params = path_param;
$id = $path_params->{id};
...
};
Fetch captured parameter from PATH_INFO.
Copyright (C) ytnobody.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
ytnobody [email protected]