Plack (software)
{{primary sources|date=February 2013}}
{{Infobox software
| name = Plack
| author = Tatsuhiko Miyagawa
| developer = Tatsuhiko Miyagawa, Tokuhiro Matsuno, Jesse Luehrs, Tomas Doran, Graham Knop and others.
| released =
| latest release version =
| latest release date =
| latest preview version =
| latest preview date =
| programming language = Perl
| license = Perl license (Artistic License v2 + GNU General Public License v1)
| website = {{URL|https://plackperl.org}}
}}
File:Mod_perl_plack.png using Perl, Plack and PSGI.]]
Plack is a Perl web application programming framework inspired by Rack for Ruby and WSGI for Python,{{cite book |last1=Poe |first1=Curtis |title=Beginning Perl |date=2012 |publisher=John Wiley & Sons |isbn=9781118235638 |page=484 |url=https://books.google.com/books?id=0qe1JQbqz8AC&q=plack&pg=PA484 |access-date=29 October 2018 |language=en}}{{Cite web |title=PSGI/Plack - Perl Superglue for Web Frameworks and Web Servers |url=https://plackperl.org/ |access-date=2023-09-09 |website=plackperl.org}} and it is the project behind the PSGI specification used by other frameworks such as Catalyst and Dancer.{{cite book |last1=Quigley |first1=Ellie |title=Perl by Example |date=2014 |publisher=Pearson Education |isbn=9780133760811 |page=586 |url=https://books.google.com/books?id=f6DfBQAAQBAJ&q=plack&pg=PA586 |access-date=29 October 2018 |language=en}} Plack allows for testing of Perl web applications without a live web server.{{cite book |last1=Chromatic |title=Modern Perl |date=2015 |publisher=The Pragmatic Programmers, LLC |isbn=978-1-68050-088-2 |page=134 |edition=Fourth |url=https://pragprog.com/book/swperl/modern-perl-fourth-edition}}
Plackup is a command line utility to run PSGI applications from the command line.{{Cite web|title = plackup - metacpan.org|url = https://metacpan.org/dist/Plack/view/script/plackup | website = metacpan.org|access-date = 2023-05-30}}
PSGI
PSGI or Perl Web Server Gateway Interface is an interface between web servers and web applications and frameworks written in the Perl programming language that allows writing portable applications that can be run as standalone servers or using CGI, FastCGI, mod_perl, et al.{{cite web |last1=chromatic |title=Web Application Development with Modern Perl |url=http://modernperlbooks.com/whitepapers/developers/web-application-development.html |website=modernperlbooks.com |language=en}} It is inspired by the Web Server Gateway Interface for Python, Rack for Ruby and JSGI for JavaScript. A PSGI application is a Perl subroutine that accepts arguments as a single hash reference and returns a reference to an array of three elements: an HTTP status code, a reference to an array of HTTP headers and a reference to an array of HTTP body lines (usually a generated HTML document) or a filehandle-like object.
Supported backends
{{As of|2023|05}}[https://metacpan.org/search?q=Plack::Handler Plack::Handler modules on CPAN] Plack supports the following server backends:
- CGI
- SCGI
- FastCGI
- mod_perl under Apache 1.3 and 2.0
- [https://metacpan.org/module/Plack::Handler::Standalone Standalone] HTTP server included in Plack
- [https://metacpan.org/module/HTTP::Server::Simple HTTP::Server::Simple]
- [https://metacpan.org/module/Corona Corona]
- [https://metacpan.org/module/Starman Starman]
- [https://metacpan.org/module/Twiggy Twiggy]
- [https://metacpan.org/module/AnyEvent::HTTPD AnyEvent::HTTPD]
- [https://metacpan.org/module/AnyEvent::ReverseHTTP AnyEvent::ReverseHTTP]
Examples
Using the default standalone HTTP server:
$ plackup app.psgi
HTTP::Server::PSGI: Accepting connections at http://0:5000/
Running as a FastCGI daemon listening on a Unix socket, ready to be used by any Web server with FastCGI support:
$ plackup -s FCGI -listen /tmp/fcgi.sock app.psgi
FastCGI: manager (pid 3336): initialized
FastCGI: manager (pid 3336): server (pid 3337) started
FastCGI: server (pid 3337): initialized
A working Hello world application run as a one-liner:
$ plackup -e 'sub { [200, ["Content-Type" => "text/plain"], ["Hello, world!"]] }'
HTTP::Server::PSGI: Accepting connections at http://0:5000/
The command above starts an HTTP server listening on port 5000 of every local interface (IP address) and returns this 200 OK response to every HTTP request:
HTTP/1.0 200 OK
Date: Fri, 19 Mar 2010 23:34:10 GMT
Server: HTTP::Server::PSGI
Content-Type: text/plain
Content-Length: 13
Hello, world!
References
{{Reflist}}
External links
- [https://plackperl.org/ PSGI and Plack website]
- [https://metacpan.org/module/Plack Plack documentation]
- [https://metacpan.org/module/plackup
plackup
manual]
{{Perl}}
{{Use dmy dates|date=May 2019}}