The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Nephia::Core - Core Class of Nephia

DESCRIPTION

Core Class of Nephia, Object Oriented Interface Included.

SYNOPSIS

    my $v = Nephia::Core->new( 
        appname => 'YourApp::Web',
        plugins => ['JSON', 'HashHandler' => { ... } ],
    );
    $v->app(sub {
        my $req = req();
        [200, [], 'Hello, World'];
    });
    $v->run;

ATTRIBUTES

appname

Your Application Name. Default is caller class.

plugins

Nephia plugins you want to load.

app

Application as coderef.

METHODS

action_chain

Returns a Nephia::Chain object for specifying order of actions.

filter_chain

Returns a Nephia::Chain object for specifying order of filters.

builder_chain

Returns a Nephia::Chain object for specifying order of builders.

caller_class

Returns caller class name as string.

app

Accessor method for application coderef (ignore plugins, actions, filters, and builders).

export_dsl

Export DSL (see dsl method) into caller namespace.

loaded_plugins

Returns objects of loaded plugins.

dsl

Returns pairs of name and coderef of DSL as hashref.

run

Returns an application as coderef (include plugins, actions, filters, and builders).

If you specify some arguments, these will be stored as config into context.

Look at following example. This psgi application returns 'Nephia is so good!'.

    my $v = Nephia::Core->new(
        app => sub {
            my $c = shift;
            [200, ['Content-Type' => 'text/plain'], ['Nephia is '.$c->{config}{message}]];
        },
    );
    $v->run(message => 'so good!');
    

HOOK MECHANISM

Nephia::Core includes hook mechanism itself. These provided as Nephia::Chain object.

Nephia::Core has action_chain, filter_chain, and builder_chain.

First, Look following ASCII Art Image.

This AA presents relation of builder chain and application.

          /----------------------------------------------\
          |                                              |
          |                           /---------------\  |
          |                           |               |  |
          |                           |   /~\   /~\   |  |
          |                           |   |B|   |B|   |  |
          |  +---------------+        |   |u|   |u|   |  |     |\   +----------+
          |  |               |        |   |i|   |i|   |  |     | \  |          |
          |  |            +---------------|l|---|l|------------+  \ |          |
          |  | $v->run;   | application   |d|   |d|                \|   PSGI   |
          |  |            |               |e|   |e|                 >          |
          |  |            +---------------|r|---|r|------------+   /|    App.  |
          |  |               |        |   | |   | |   |  |     |  / |          |
          |  +---------------+        |   |1|   |2|   |  |     | /  |          |
          |                           |   \_/   \_/   |  |     |/   +----------+
          |  $v                       |               |  |
          |  Nephia::Core obj.        | builder_chain |  |
          |                           \---------------/  |
          \----------------------------------------------/

When execute run method of Nephia::Core instance, run method returns PSGI Application (coderef).

Then, Builders in builder_chain modifies PSGI Application.

Okay. Look following ASCII Art Image.

This AA presents relation of request, response, action chain, and filter chain.

        [HTTP Request]                              [HTTP Response]
           |                                                   A
   /-------|---------------------------------------------------|--------------\
   |       |       Your Application                            |              |
   |       |                                                   |              |
   |       v                                                   |              |
   |   /------------------------------------\    /---------------------\      |
   |   |                                    |    |                     |      |
   |   |           Nephia::Context          |--->|  Nephia::Response   |      |
   |   |                                    |    |                     |      |
   |   \------------------------------------/    \---------------------/      |
   |       |  A    |  A     |   A    |  A           |           A             |
   |       |  |    |  |     |   |    |  |        [Content]      |             |
   |   /---|--|----|--|-----|---|----|--|--\   /----|-----------|--------\    |
   |   |   |  |    |  |     |   |    |  |  |   |    |           |        |    |
   |   |   |  |    |  |     |   |    |  |  |   |    |           |        |    |
   |   |   v  |    v  |     v   |    v  |  |   |    v           |        |    |
   |   |  /~\ |   /~\ |   /~~~\ |   /~\ |  |   |   /~\    /~\   |        |    |
   |   |  |A| |   |A| |   | A | |   |A| |  |   |   |F|    |F|   |        |    |
   |   |  |c|-/   |c|-/   | p |-/   |c|-/  |   |   |i|--->|i|---+        |    |
   |   |  |t|     |t|     | p.|     |t|    |   |   |l|    |l|            |    |
   |   |  |i|     |i|     |   |     |i|    |   |   |t|    |t|            |    |
   |   |  |o|     |o|     \---/     |o|    |   |   |e|    |e|            |    |
   |   |  |n|     |n|               |n|    |   |   |r|    |r|            |    |
   |   |  | |     | |               | |    |   |   | |    | |            |    |
   |   |  |1|     |2|               |3|    |   |   |1|    |2|            |    |
   |   |  \_/     \_/               \_/    |   |   \_/    \_/            |    |
   |   |                                   |   |                         |    |
   |   | action_chain                      |   | filter_chain            |    |
   |   \-----------------------------------/   \-------------------------/    |
   \--------------------------------------------------------------------------/

Actions (and App) in action_chain affects context. Then, Nephia::Response object creates from context.

Afterwords, filters in filter_chain affects content string in Nephia::Response.

AUTHOR

ytnobody <ytnobody@gmail.com>

SEE ALSO

Nephia::Chain