Fix bug stopping fastcgi script working
[catagits/Catalyst-Runtime.git] / lib / Catalyst / EngineLoader.pm
CommitLineData
b1ededd4 1package Catalyst::EngineLoader;
532f0516 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
a26a6adb 15has requested_engine => (
16 is => 'ro',
17 isa => 'Str',
18 predicate => 'has_requested_engine',
1085c936 19);
20
21sub needs_psgi_engine_compat_hack {
22 my ($self) = @_;
a26a6adb 23 return $self->has_requested_engine
24 && $self->requested_engine eq 'PSGI';
1085c936 25}
26
1e5dad00 27has catalyst_engine_class => (
28 isa => 'Str',
29 is => 'rw',
30 lazy => 1,
31 builder => '_guess_catalyst_engine_class',
32);
33
34sub _guess_catalyst_engine_class {
35 my $self = shift;
a26a6adb 36 my $old_engine = $self->has_requested_engine
37 ? $self->requested_engine
38 : Catalyst::Utils::env_value($self->application_name, 'ENGINE');
1e5dad00 39 if (!defined $old_engine) {
40 return 'Catalyst::Engine';
41 }
86c4012a 42 elsif ($old_engine =~ /^(PSGI|CGI|FastCGI|HTTP|Apache.*)$/) {
1e5dad00 43 return 'Catalyst::Engine';
44 }
0ea8962d 45 else {
46 return 'Catalyst::Engine::' . $old_engine;
1e5dad00 47 }
48}
49
532f0516 50around guess => sub {
51 my ($orig, $self) = (shift, shift);
52 my $engine = $self->$orig(@_);
53 if ($engine eq 'Standalone') {
54 if ( $ENV{MOD_PERL} ) {
55 my ( $software, $version ) =
d7132282 56 $ENV{MOD_PERL} =~ /^(\S+)\/(\d+(?:[\.\_]\d+)+)/;
532f0516 57 $version =~ s/_//g;
d7132282 58 $version =~ s/(\.[^.]+)\./$1/g;
59
532f0516 60 if ( $software eq 'mod_perl' ) {
61 if ( $version >= 1.99922 ) {
62 $engine = 'Apache2';
63 }
64
65 elsif ( $version >= 1.9901 ) {
66 Catalyst::Exception->throw( message => 'Plack does not have a mod_perl 1.99 handler' );
67 $engine = 'Apache2::MP19';
68 }
69
70 elsif ( $version >= 1.24 ) {
71 $engine = 'Apache1';
72 }
73
74 else {
75 Catalyst::Exception->throw( message =>
76 qq/Unsupported mod_perl version: $ENV{MOD_PERL}/ );
77 }
78 }
79 }
80 }
d7132282 81
acbecf08 82 my $old_engine = Catalyst::Utils::env_value($self->application_name, 'ENGINE');
83 if (!defined $old_engine) { # Not overridden
84 }
86c4012a 85 elsif ($old_engine =~ /^(PSGI|CGI|FastCGI|HTTP|Apache.*)$/) {
86>>>>>>> Fix bug stopping fastcgi script working
acbecf08 87 # Trust autodetect
88 }
89 elsif ($old_engine eq "HTTP::Prefork") { # Too bad if you're customising, we don't handle options
90 # write yourself a script to collect and pass in the options
91 $engine = "Starman";
92 }
93 elsif ($old_engine eq "HTTP::POE") {
94 Catalyst::Exception->throw("HTTP::POE engine no longer works, recommend you use Twiggy instead");
95 }
96 elsif ($old_engine eq "Zeus") {
97 Catalyst::Exception->throw("Zeus engine no longer works");
98 }
99 else {
100 warn("You asked for an unrecognised engine '$old_engine' which is no longer supported, this has been ignored.\n");
101 }
102
532f0516 103 return $engine;
104};
105
acbecf08 106# Force constructor inlining
107__PACKAGE__->meta->make_immutable( replace_constructor => 1 );
df1fa879 108
532f0516 1091;
df1fa879 110
111__END__
112
113=head1 NAME
114
b1ededd4 115Catalyst::EngineLoader - The Catalyst Engine Loader
df1fa879 116
117=head1 SYNOPSIS
118
119See L<Catalyst>.
120
121=head1 DESCRIPTION
122
123Wrapper on L<Plack::Loader> which resets the ::Engine if you are using some
124version of mod_perl.
125
126=head1 AUTHORS
127
128Catalyst Contributors, see Catalyst.pm
129
130=head1 COPYRIGHT
131
132This library is free software. You can redistribute it and/or modify it under
133the same terms as Perl itself.
134
1085c936 135=begin Pod::Coverage
136
137needs_psgi_engine_compat_hack
138
139=end Pod::Coverage
140
df1fa879 141=cut