Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 91 lines (64 sloc) 2.305 kb
#!/usr/bin/perl
use strict;
use lib "lib";
use Cwd;
use Getopt::Long;
use Plack::Loader;
use Pod::Usage;
GetOptions(\my %opts, "app=s", "impl=s", "help");
pod2usage(0) if $opts{help};
# If there is an explicit implementation mentioned, use it, otherwise leave $ENV{PLACK_IMPL} alone.
$ENV{PLACK_IMPL} = $opts{impl} if $opts{impl};
my $file = $opts{app} || "app.psgi";
my $handler = load_handler($opts{app} || Cwd::cwd . "/app.psgi");
unless ($handler) {
die $@ if $@;
die "$file not found: $!\n" if $!;
unless ($handler && ref $handler eq 'CODE') {
die "$file does not return an application code reference.\n";
}
}
my @args = map { s/^--//; $_ } @ARGV;
my $impl = Plack::Loader->auto(@args);
$impl->run($handler);
$impl->run_loop if $impl->can('run_loop'); # run event loop
sub load_handler {
my $file = shift;
return unless -e $file;
return do $file;
}
__END__
=head1 NAME
plackup -- a useful tool for running Plack applications
=head1 SYNOPSIS
# read your app from app.psgi file
plackup
# can be passed with --app option (Or -a)
plackup --app hello.psgi
# switch implementations
env PLACK_IMPL=Standalone::Prefork plackup -- --port 9999
# Or, --impl (or -i)
plackup --impl AnyEvent
=head1 DESCRIPTION
plackup is a command line utility to run PSGI application from the command line.
plackup automatically figures out the environment it is run in, and
runs your application in that environment. mod_perl, FastCGI, CGI,
AnyEvent and others can all be detected. See L<Plack::Loader> for the
authorative list.
C<plackup> assumes you have an C<app.psgi> script in your current
directory, that would looke like:
#!/usr/bin/perl
use MyApp;
my $app = MyApp->new;
my $handler = sub { $app->run_psgi(@_) };
The last statement of C<app.psgi> should be a code reference that is a
PSGI application.
You can also use the C<--app> option to locate a C<.psgi> script with a
different name in a different path. (Actually the path doesn't need to
end in C<.psgi>: it's just there for convention)
You may also select a specific implementation to run on using the
C<PLACK_IMPL> environment variable or use the C<-i> or C<--impl> flag
which will be prefered over the environment variable if present.
=head1 SEE ALSO
L<Plack::Loader>
=cut
Jump to Line
Something went wrong with that request. Please try again.