Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Created July 16, 2010 14:44
Show Gist options
  • Save jjn1056/478439 to your computer and use it in GitHub Desktop.
Save jjn1056/478439 to your computer and use it in GitHub Desktop.
In my Catalyst.pm:
if ($ENV{MOD_PERL}) {
use Catalyst::Engine::Loader;
my $apache = Catalyst::Engine::Loader->auto;
# FIXME - Immutable
$class->meta->add_method(handler => sub {
my $r = shift;
my $app = $class->psgi_app;
$apache->call_app($r, $app);
});
}
and here's the Catalyst::Engine::Loader code:
package Catalyst::Engine::Loader;
use Moose;
use Catalyst::Exception;
use namespace::autoclean;
extends 'Plack::Loader';
around guess => sub {
my ($orig, $self) = (shift, shift);
my $engine = $self->$orig(@_);
if ($engine eq 'Standalone') {
if ( $ENV{MOD_PERL} ) {
my ( $software, $version ) =
$ENV{MOD_PERL} =~ /^(\S+)\/(\d+(?:[\.\_]\d+)+)/;
$version =~ s/_//g;
$version =~ s/(\.[^.]+)\./$1/g;
if ( $software eq 'mod_perl' ) {
if ( $version >= 1.99922 ) {
$engine = 'Apache2';
}
elsif ( $version >= 1.9901 ) {
Catalyst::Exception->throw( message => 'Plack does not have a mod_perl 1.99 handler' );
$engine = 'Apache2::MP19';
}
elsif ( $version >= 1.24 ) {
$engine = 'Apache1';
}
else {
Catalyst::Exception->throw( message =>
qq/Unsupported mod_perl version: $ENV{MOD_PERL}/ );
}
}
}
}
return $engine;
};
__PACKAGE__->meta->make_immutable( inline_constructor => 0 );
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment