<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># NAME

Nephia::Plugin::Dispatch - Dispatcher Plugin for Nephia

# DESCRIPTION

This plugin provides dispatcher feature to Nephia.

# SYNOPSIS

    package My::NephiaApp;
    use Nephia plugins =&gt; ['Dispatch'];
    

    {   ### External Controller Class
        package My::NephiaApp::C::External;
        sub index {
            my $c = shift;             # Nephia::Core object
            my $id = $c-&gt;param('id');  # You may call param method via Nephia::Core object
            [200, [], ["id = $id"]];
        }
    };

    my $users = {};
    

    app {
        get '/' =&gt; sub { [200, [], 'Hello, World!'] };
        get '/user/:id' =&gt; sub {
            my $id = path_param('id');
            my $user = $users-&gt;{$id};
            $user ? 
                [200, [], sprintf('name = %s', $user-&gt;{name}) ]
                [404, [], 'no such user']
            ;
        };
        post '/user/:id' =&gt; sub {
            my $id = path_param('id');
            my $name = param('name'); 
            $users-&gt;{$id} = { name =&gt; $name };
            [200, [], 'registered!'];
        };
        get '/external/' =&gt; Nephia-&gt;call('C::External#index');
    };
    



# DSL

## get post put del

    get $path =&gt; sub { ... };

Add action for $path. You may use [Router::Simple](http://search.cpan.org/perldoc?Router::Simple) syntax in $path.

## path\_param

    get '/user/:id' =&gt; sub {
        my $id = path_param('id');
        ### or 
        my $path_params = path_param;
        $id = $path_params-&gt;{id};
        ...
    };

Fetch captured parameter from PATH\_INFO.

# LICENSE

Copyright (C) ytnobody.

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

# AUTHOR

ytnobody &lt;ytnobody@gmail.com&gt;
</pre></body></html>