PSGI-Handy

 view release on metacpan or  search on metacpan

lib/PSGI/Handy.pm  view on Meta::CPAN


=item C<new: a PSGI env hash reference is required>

C<PSGI::Handy::Request::new> was called without a PSGI environment hash
reference.

=item C<add: method is required>

C<PSGI::Handy::Router::add> was called without an HTTP method.

=item C<add: pattern is required>

C<PSGI::Handy::Router::add> was called without a path pattern.

=item C<add: handler must be a code reference>

The handler passed to C<PSGI::Handy::Router::add> was not a CODE reference.

=item C<add: pattern must begin with '/' (got '$pattern')>

The path pattern passed to C<PSGI::Handy::Router::add> did not begin with
a slash.

=item C<match: method is required>

C<PSGI::Handy::Router::match> was called without an HTTP method.

=item C<match: path is required>

C<PSGI::Handy::Router::match> was called without a path.

=item C<redirect: location is required>

C<PSGI::Handy::Response::redirect> was called without a target location.

=item C<json: body must be a pre-encoded JSON string, not a reference>

C<PSGI::Handy::Response::json> was given a reference (array or hash). The
body must be a JSON string that the caller has already encoded (for
example with C<mb::JSON>).

=item C<cookie: name is required>

C<PSGI::Handy::Response::cookie> was called without a cookie name.

=item C<render: no renderer configured (pass renderer => ... to PSGI::Handy->new)>

C<render> was called but no renderer was injected into the application.

=item C<render: renderer must be a code reference or an object with a render() method>

The configured renderer is neither a CODE reference nor an object with a
C<render> method.

=back

=head1 LIMITATIONS

The C<$app> returned by C<to_app> always produces the buffered,
three-element PSGI response C<[ $status, \@headers, \@body ]>. The PSGI
delayed-response form (the streaming "responder" callback) is not
generated; this is what "PSGI-subset" means throughout this distribution.

Concurrency and the HTTP version depend on the PSGI server you choose.
No multipart uploads or WebSocket in this version. C<HEAD> requests are
served by the matching C<GET> route with the body removed.

=head1 PSGI::Handy::Router

A tiny PSGI route dispatcher. It resolves an incoming request, expressed
as an HTTP method and a C<PATH_INFO> string, to a previously registered
handler.

=head2 Pattern syntax

=over 4

=item * Literal segments match exactly. A dot is a literal dot, not a
regular-expression wildcard (C</feed.xml> does not match C</feedaxml>).

=item * C<:name> matches a single non-empty path segment (C<[^/]+>) and
stores it in C<params> under C<name>.

=item * A C<*> used as the final segment matches the remainder of the
path, including slashes, and is stored under C<splat>.

=back

Matching is exact (anchored), so a trailing slash is significant:
C</a> and C</a/> are different routes.

=head2 Router methods

=over 4

=item new

Returns a new, empty router.

=item add($method, $pattern, $handler)

Registers a route. C<$handler> must be a code reference. C<$pattern>
must begin with C</>. Returns the router for chaining.

=item match($method, $path)

Returns a hash reference C<{ handler =E<gt> ..., params =E<gt> ... }> on
success, C<{ allowed =E<gt> [...] }> when the path is known but the
method is not (HTTP 405), or C<undef> when nothing matched (HTTP 404).
The first registered matching route wins.

=item routes

Returns the internal array reference of route records. For introspection
and testing.

=back

Path parameters rely on positional captures paired with a name list
because named captures were not available until Perl 5.10.



( run in 0.472 second using v1.01-cache-2.11-cpan-140bd7fdf52 )