NAME

PAGI::Server::AppNormalizer - Normalizes PAGI 0.4 application providers to a coderef

SYNOPSIS

use PAGI::Server::AppNormalizer ();

my $app = PAGI::Server::AppNormalizer::normalize_app($candidate, 'app');

DESCRIPTION

Note: This is a PAGI::Server internal module, not part of the public PAGI::Server API, and is not indexed on CPAN.

PAGI 0.4 allows an application source (an app file, a module constructor, an -e expression, direct PAGI::Server construction, or configure(app = ...)>) to hand PAGI::Server either a native PAGI coderef or an instantiated application-provider object exposing a to_app method. This module is the single normalization point every one of those sources calls through, so a provider is normalized to its coderef exactly once regardless of which source produced it. A blessed coderef is returned as-is (native-app precedence); a package-name string is never treated as a provider.

FUNCTIONS

normalize_app($candidate, $source)

my $app = PAGI::Server::AppNormalizer::normalize_app($candidate, $source);

Returns $candidate unchanged if it is already a coderef (including a blessed one). Otherwise $candidate must be a blessed object providing to_app; that method is called once and its coderef return value is returned. $source is a human-readable label (e.g. 'App file', '-e code') used only to identify the origin in die messages; it defaults to 'Application'.

Dies if $candidate is neither a coderef nor a blessed object, if the object has no to_app method, if to_app raises, or if to_app's return value is not itself a coderef.

SEE ALSO

PAGI::Server, PAGI::Server::Runner