blob: 3ba7771e6f8f568385cc5a73f03e44272d26e5cb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
package Plack::Client::Backend;
use strict;
use warnings;
# ABSTRACT: turns a Plack::Request into a PSGI app
use Carp;
use Scalar::Util qw(weaken);
use overload '&{}' => sub { shift->as_code(@_) }, fallback => 1;
=head1 SYNOPSIS
package My::Backend;
use base 'Plack::Client::Backend';
sub app_from_request {
my $self = shift;
my ($req) = @_;
return sub { ... }
}
=head1 DESCRIPTION
This is a base class for L<Plack::Client> backends. These backends are handlers
for a particular URL scheme, and translate a L<Plack::Request> instance into a
PSGI application coderef.
=cut
=method new
Creates a new backend instance. Takes no parameters by default, but may be
overridden in subclasses.
=cut
sub new {
my $class = shift;
bless {}, $class;
}
=method app_from_request
This method is called with an argument of a L<Plack::Request> object, and
should return a PSGI application coderef. The Plack::Request object it receives
contains the actual env hash that will be passed to the application, so
backends can modify that too, if they need to.
=cut
sub app_from_request {
croak "Backends must implement app_from_request";
}
=method as_code
Returns a coderef which will call L</app_from_request> as a method.
=cut
sub as_code {
my $self = shift;
return sub { $self->app_from_request(@_) };
}
1;
|