Container-Builder
view release on metacpan or search on metacpan
examples/fatpacked.plackup view on Meta::CPAN
PSGI middleware is a PSGI application that wraps an existing PSGI
application and plays both side of application and servers. From the
servers the wrapped code reference still looks like and behaves
exactly the same as PSGI applications.
L<Plack::Middleware> gives you an easy way to wrap PSGI applications
with a clean API, and compatibility with L<Plack::Builder> DSL.
=head2 Plack::Builder
L<Plack::Builder> gives you a DSL that you can enable Middleware in
C<.psgi> files to wrap existent PSGI applications.
=head2 Plack::Request, Plack::Response
L<Plack::Request> gives you a nice wrapper API around PSGI C<$env>
hash to get headers, cookies and query parameters much like
L<Apache::Request> in mod_perl.
L<Plack::Response> does the same to construct the response array
reference.
=head2 Plack::Test
L<Plack::Test> is a unified interface to test your PSGI application
using standard L<HTTP::Request> and L<HTTP::Response> pair with simple
callbacks.
=head2 Plack::Test::Suite
L<Plack::Test::Suite> is a test suite to test a new PSGI server backend.
=head1 CONTRIBUTING
=head2 Patches and Bug Fixes
Small patches and bug fixes can be either submitted via nopaste on IRC
L<irc://irc.perl.org/#plack> or L<the github issue
tracker|http://github.com/plack/Plack/issues>. Forking on
L<github|http://github.com/plack/Plack> is another good way if you
intend to make larger fixes.
See also L<http://contributing.appspot.com/plack> when you think this
document is terribly outdated.
=head2 Module Namespaces
Modules added to the Plack:: sub-namespaces should be reasonably generic
components which are useful as building blocks and not just simply using
Plack.
Middleware authors are free to use the Plack::Middleware:: namespace for
their middleware components. Middleware must be written in the pipeline
style such that they can chained together with other middleware components.
The Plack::Middleware:: modules in the core distribution are good examples
of such modules. It is recommended that you inherit from L<Plack::Middleware>
for these types of modules.
Not all middleware components are wrappers, but instead are more like
endpoints in a middleware chain. These types of components should use the
Plack::App:: namespace. Again, look in the core modules to see excellent
examples of these (L<Plack::App::File>, L<Plack::App::Directory>, etc.).
It is recommended that you inherit from L<Plack::Component> for these
types of modules.
B<DO NOT USE> Plack:: namespace to build a new web application or a
framework. It's like naming your application under CGI:: namespace if
it's supposed to run on CGI and that is a really bad choice and
would confuse people badly.
=head1 AUTHOR
Tatsuhiko Miyagawa
=head1 COPYRIGHT
The following copyright notice applies to all the files provided in
this distribution, including binary files, unless explicitly noted
otherwise.
Copyright 2009-2013 Tatsuhiko Miyagawa
=head1 CORE DEVELOPERS
Tatsuhiko Miyagawa (miyagawa)
Tokuhiro Matsuno (tokuhirom)
Jesse Luehrs (doy)
Tomas Doran (bobtfish)
Graham Knop (haarg)
=head1 CONTRIBUTORS
Yuval Kogman (nothingmuch)
Kazuhiro Osawa (Yappo)
Kazuho Oku
Florian Ragwitz (rafl)
Chia-liang Kao (clkao)
Masahiro Honma (hiratara)
Daisuke Murase (typester)
John Beppu
Matt S Trout (mst)
Shawn M Moore (Sartak)
Stevan Little
Hans Dieter Pearcey (confound)
examples/fatpacked.plackup view on Meta::CPAN
use Plack::Util;
use overload '&{}' => \&to_app_auto, fallback => 1;
sub new {
my $proto = shift;
my $class = ref $proto || $proto;
my $self;
if (@_ == 1 && ref $_[0] eq 'HASH') {
$self = bless {%{$_[0]}}, $class;
} else {
$self = bless {@_}, $class;
}
$self;
}
sub to_app_auto {
my $self = shift;
if (($ENV{PLACK_ENV} || '') eq 'development') {
my $class = ref($self);
warn "WARNING: Automatically converting $class instance to a PSGI code reference. " .
"If you see this warning for each request, you probably need to explicitly call " .
"to_app() i.e. $class->new(...)->to_app in your PSGI file.\n";
}
$self->to_app(@_);
}
# NOTE:
# this is for back-compat only,
# future modules should use
# Plack::Util::Accessor directly
# or their own favorite accessor
# generator.
# - SL
sub mk_accessors {
my $self = shift;
Plack::Util::Accessor::mk_accessors( ref( $self ) || $self, @_ )
}
sub prepare_app { return }
sub to_app {
my $self = shift;
$self->prepare_app;
return sub { $self->call(@_) };
}
sub response_cb {
my($self, $res, $cb) = @_;
Plack::Util::response_cb($res, $cb);
}
1;
__END__
=head1 NAME
Plack::Component - Base class for PSGI endpoints
=head1 SYNOPSIS
package Plack::App::Foo;
use parent qw( Plack::Component );
sub call {
my($self, $env) = @_;
# Do something with $env
my $res = ...; # create a response ...
# return the response
return $res;
}
=head1 DESCRIPTION
Plack::Component is the base class shared between L<Plack::Middleware>
and C<Plack::App::*> modules. If you are writing middleware, you should
inherit from L<Plack::Middleware>, but if you are writing a
Plack::App::* you should inherit from this directly.
=head1 REQUIRED METHOD
=over 4
=item call ($env)
You are expected to implement a C<call> method in your component. This
is where all the work gets done. It receives the PSGI C<$env> hash-ref
as an argument and is expected to return a proper PSGI response value.
=back
=head1 METHODS
=over 4
=item new (%opts | \%opts)
The constructor accepts either a hash or a hashref and uses that to
create the instance. It will call no other methods and simply return
the instance that is created.
=item prepare_app
This method is called by C<to_app> and is meant as a hook to be used to
prepare your component before it is packaged as a PSGI C<$app>.
=item to_app
This is the method used in several parts of the Plack infrastructure to
convert your component into a PSGI C<$app>. You should not ever need to
override this method; it is recommended to use C<prepare_app> and C<call>
instead.
=item response_cb
This is a wrapper for C<response_cb> in L<Plack::Util>. See
( run in 0.788 second using v1.01-cache-2.11-cpan-0d23b851a93 )