added Engine::PSGI instructions
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / Loader.pm
CommitLineData
532f0516 1package Catalyst::Engine::Loader;
2use Moose;
3use Catalyst::Exception;
acbecf08 4use Catalyst::Utils;
532f0516 5use namespace::autoclean;
6
7extends 'Plack::Loader';
8
acbecf08 9has application_name => (
10 isa => 'Str',
11 is => 'ro',
12 required => 1,
13);
14
532f0516 15around guess => sub {
16 my ($orig, $self) = (shift, shift);
17 my $engine = $self->$orig(@_);
18 if ($engine eq 'Standalone') {
19 if ( $ENV{MOD_PERL} ) {
20 my ( $software, $version ) =
d7132282 21 $ENV{MOD_PERL} =~ /^(\S+)\/(\d+(?:[\.\_]\d+)+)/;
532f0516 22 $version =~ s/_//g;
d7132282 23 $version =~ s/(\.[^.]+)\./$1/g;
24
532f0516 25 if ( $software eq 'mod_perl' ) {
26 if ( $version >= 1.99922 ) {
27 $engine = 'Apache2';
28 }
29
30 elsif ( $version >= 1.9901 ) {
31 Catalyst::Exception->throw( message => 'Plack does not have a mod_perl 1.99 handler' );
32 $engine = 'Apache2::MP19';
33 }
34
35 elsif ( $version >= 1.24 ) {
36 $engine = 'Apache1';
37 }
38
39 else {
40 Catalyst::Exception->throw( message =>
41 qq/Unsupported mod_perl version: $ENV{MOD_PERL}/ );
42 }
43 }
44 }
45 }
d7132282 46
acbecf08 47 my $old_engine = Catalyst::Utils::env_value($self->application_name, 'ENGINE');
48 if (!defined $old_engine) { # Not overridden
49 }
50 elsif ($old_engine =~ /^(CGI|FCGI|HTTP|Apache.*)$/) {
51 # Trust autodetect
52 }
53 elsif ($old_engine eq "HTTP::Prefork") { # Too bad if you're customising, we don't handle options
54 # write yourself a script to collect and pass in the options
55 $engine = "Starman";
56 }
57 elsif ($old_engine eq "HTTP::POE") {
58 Catalyst::Exception->throw("HTTP::POE engine no longer works, recommend you use Twiggy instead");
59 }
60 elsif ($old_engine eq "Zeus") {
61 Catalyst::Exception->throw("Zeus engine no longer works");
62 }
63 else {
64 warn("You asked for an unrecognised engine '$old_engine' which is no longer supported, this has been ignored.\n");
65 }
66
532f0516 67 return $engine;
68};
69
acbecf08 70# Force constructor inlining
71__PACKAGE__->meta->make_immutable( replace_constructor => 1 );
df1fa879 72
532f0516 731;
df1fa879 74
75__END__
76
77=head1 NAME
78
79Catalyst::Engine::Loader - The Catalyst Engine Loader
80
81=head1 SYNOPSIS
82
83See L<Catalyst>.
84
85=head1 DESCRIPTION
86
87Wrapper on L<Plack::Loader> which resets the ::Engine if you are using some
88version of mod_perl.
89
90=head1 AUTHORS
91
92Catalyst Contributors, see Catalyst.pm
93
94=head1 COPYRIGHT
95
96This library is free software. You can redistribute it and/or modify it under
97the same terms as Perl itself.
98
99=cut