NAME
PAGI::Nano::Context - Shared behavior for the contexts PAGI::Nano vends
DESCRIPTION
A mixin inherited by PAGI::Nano::Context::HTTP, PAGI::Nano::Context::WebSocket, and PAGI::Nano::Context::SSE alongside the stock PAGI context class for each scope type. It provides "uri_for" and "service", both available to handlers of every protocol.
METHODS
uri_for
my $url = $c->uri_for($name);
my $url = $c->uri_for($name, \%path_params);
my $url = $c->uri_for($name, \%path_params, \%query_params);
Builds the URL for a route named with "name" in PAGI::Nano. Path placeholders (:id, {id}, {id:regex}, *splat) are filled from %path_params. Pass decoded Perl strings, not pre-encoded URL components. Ordinary placeholders represent one path segment and percent-encode inserted values as UTF-8 bytes; they croak if a value contains /. Use *splat for a path-valued parameter: its slash separators are preserved while each segment is encoded separately. This distinction is required because PAGI decodes percent-encoded paths, including %2F, before routing. Literal route text preserves RFC 3986 path characters and slash separators. %query_params (if any) is appended in sorted key order with UTF-8 percent encoding and %20 for spaces. Resolution is against the flat name registry PAGI::Nano injects on the scope, so names defined anywhere in the app — including across a mount, in either direction — are reachable, with mount prefixes applied. Dies if the name is unknown.
service
my $value = $c->service($name);
Resolves a service declared with "service" in PAGI::Nano. Whether this returns the same app-scoped value every time, a per-request object built and memoized on first access, or a fresh object on every call, is decided by what the service's builder returned — see "SERVICES" in PAGI::Nano for the full scoping rule. Dies if $name was never declared.
AUTHOR
John Napiorkowski <jjnapiork@cpan.org>
COPYRIGHT & LICENSE
Copyright 2026, John Napiorkowski. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.