Robin Smidsrød > Plack-App-Apache-ActionWrapper-0.31.0 > Plack::App::Apache::ActionWrapper

Download:
Plack-App-Apache-ActionWrapper-0.31.0.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.31.0   Source  

NAME ^

Plack::App::Apache::ActionWrapper - Wrapper for Apache2 Action directive for running PSGI apps on shared hosting with FastCGI

VERSION ^

version 0.31.0

SYNOPSIS ^

    ------------- .htaccess -----------------
    AddHandler fcgid-script .fcgi
    # Enable this instead if server is using mod_fastcgi instead of mod_fcgid
    #AddHandler fastcgi-script .fcgi
    Action psgi-script /cgi-bin/psgi.fcgi
    AddHandler psgi-script .psgi

    DirectoryIndex index.psgi

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.psgi/$1 [QSA,L]

    ------------- psgi.fcgi -----------------
    #!/usr/bin/env perl

    use strict;
    use warnings;

    # Some shared hosting providers don't even provide you
    # with a pointer to your files
    BEGIN {
        $ENV{HOME} = '/home/someuser' unless $ENV{HOME};
    }

    # Enable this if you're unable to get output to STDERR
    # in your normal log file
    #use IO::Handle;
    #close STDERR;
    #open STDERR, ">>", "$ENV{HOME}/fcgi-error.log";
    #STDERR->autoflush(1);

    # Change this line if you use local::lib or need
    # specific libraries loaded for your application
    use lib '/home/robin/perl5/lib/perl5';

    use Plack::App::Apache::ActionWrapper;
    my $app = Plack::App::Apache::ActionWrapper->new->enable_debug->to_app;

    # Run the actual app
    use Plack::Handler::FCGI;
    Plack::Handler::FCGI->new->run($app);

    1;

    ------------- index.psgi -----------------
    #!/usr/bin/env plackup

    use strict;
    use warnings;

    my $app = sub {
        my $env = shift;
        return [
            200,
            [ 'Content-Type' => 'text/plain' ],
            [
                "This is the index.\n",
                'PATH_INFO=' . $env->{'PATH_INFO'} . "\n",
                'PATH_TRANSLATED=' . $env->{'PATH_TRANSLATED'} . "\n",
            ],
        ];
    };

DESCRIPTION ^

The PSGI web application specification is awesome. Plack is awesome as well. Running PSGI apps using plackup in development is super easy.

But what do you do when you want to deploy your PSGI app on shared hosting? You can deploy it using traditional CGI, but if you're dealing with something like Moose or Catalyst-based apps it's bound to be slow.

So your shared hosting provider has provided you with FastCGI support to mitigate that problem. But because FastCGIExternalServer cannot be defined in .htaccess you can only run dynamic FastCGI applications.

Your immediate reaction is to define AddHandler fcgid-script .psgi in your .htaccess and use plackup on the shebang line to run your PSGI app. But that doesn't work if you use local::lib, because @INC is not setup properly.

By using a wrapper as specified in the synopsis you can avoid having to type in use lib 'XXX' in every one of your .psgi files. Another benefit is that you can preload modules to benefit from copy-on-write on operating systems that provide it to diminish the memory usage.

METHODS ^

call

The main handler that will be returned by the to_app method inherited from Plack::Component.

enable_debug

Mutator to enable debug output if no path was found in PATH_TRANSLATED. Allows chaining.

disable_debug

Mutator to disable debug output if no path was found in PATH_TRANSLATED. Allows chaining.

is_debug_enabled

Accessor to determine if debug is enabled or not. Debug is disabled by default.

SUPPORT ^

Perldoc

You can find documentation for this module with the perldoc command.

  perldoc Plack::App::Apache::ActionWrapper

Websites

The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.

Bugs / Feature Requests

Please report any bugs or feature requests by email to bug-plack-app-apache-actionwrapper at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Plack-App-Apache-ActionWrapper. You will be automatically notified of any progress on the request by the system.

Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :)

http://github.com/robinsmidsrod/Plack-App-Apache-ActionWrapper

  git clone git://github.com/robinsmidsrod/Plack-App-Apache-ActionWrapper.git

AUTHOR ^

Robin Smidsrød <robin@smidsrod.no>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2012 by Robin Smidsrød.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: