PLACKUP(1p) | User Contributed Perl Documentation | PLACKUP(1p) |
plackup - Run PSGI application with Plack handlers
# read your app from app.psgi file plackup # choose .psgi file from ARGV[0] (or with -a option) plackup hello.psgi # switch server implementation with --server (or -s) plackup --server HTTP::Server::Simple --port 9090 --host 127.0.0.1 test.psgi # use UNIX socket to run FCGI daemon plackup -s FCGI --listen /tmp/fcgi.sock myapp.psgi # launch FCGI external server on port 9090 plackup -s FCGI --port 9090
plackup is a command line utility to run PSGI applications from the command line.
plackup automatically figures out the environment it is run in, and runs your application in that environment. FastCGI, CGI, AnyEvent and others can all be detected. See Plack::Loader for the authoritative list.
"plackup" assumes you have an "app.psgi" script in your current directory. The last statement of "app.psgi" should be a code reference that is a PSGI application:
#!/usr/bin/perl use MyApp; my $application = MyApp->new; my $app = sub { $application->run_psgi(@_) };
plackup --host 127.0.0.1 --port 9090 /path/to/app.psgi
The first non-option argument is used as a ".psgi" file path. You can also set this path with "-a" or "--app". If omitted, the default file path is "app.psgi" in the current directory.
plackup -e 'sub { my $env = shift; return [ ... ] }'
It is also handy when you want to run a custom application like Plack::App::*.
plackup -MPlack::App::File -e 'Plack::App::File->new(...)->to_app'
You can also specify "-e" option with ".psgi" file path to wrap the application with middleware configuration from the command line. You can also use Plack::Builder DSL syntax inside "-e" code. For example:
plackup -e 'enable "Auth::Basic", authenticator => ...;' myapp.psgi
is equivalent to the PSGI application:
use Plack::Builder; use Plack::Util; builder { enable "Auth::Basic", authenticator => ...; Plack::Util::load_psgi("myapp.psgi"); };
Note that when you use "-e" option to enable middleware, plackup doesn't assume the implicit "app.psgi" path. You must either pass the path to your ".psgi" file in the command line arguments or load the application inside "-e" after the "enable".
plackup # Runs app.psgi plackup -e 'enable "Foo"' # Doesn't work! plackup -e 'enable "Foo"' app.psgi # Works plackup -e 'enable "Foo"; sub { ... }' # Works
Note: default port 5000 may conflict with AirPlay server on MacOS 12 (Monterey) or later.
If no option is given, plackup will try to detect the best server implementation based on the environment variables as well as modules loaded by your application in %INC. See Plack::Loader for details.
In combination with "-r" or "-R" may not have the desired restart effect when the loaded module is changed in the development directory. To avoid this problem you need to load the module with the app code using "-e".
# These two are the same plackup -E deployment env PLACK_ENV=deployment plackup
Common values are "development", "deployment", and "test". The default value is "development", which causes "plackup" to load the middleware components: AccessLog, StackTrace, and Lint unless "--no-default-middleware" is set.
Reloading will delay the compilation of your application. Automatic server detection (see "-s" above) may not behave as you expect, if plackup needs to scan your application for the modules it uses. Avoid problems by specifying "-s" explicitly when using "-r" or "-R".
To avoid problems with changes to preloaded modules see documentation for "-M".
plackup -R /path/to/project/lib,/path/to/project/templates
To avoid problems with changes to preloaded modules see documentation for "-M".
See Plack::Loader::Delayed and Plack::Loader::Shotgun for more details.
plackup --path /foo app.psgi plackup -e 'mount "/foo" => Plack::Util::load_psgi("app.psgi")'
Other options that starts with "--" are passed through to the backend server. See each Plack::Handler backend's documentation for more details on their available options.
Plack::Runner Plack::Loader
2022-09-06 | perl v5.34.0 |