More Xs
[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 }
0c6352ff 42 elsif ($old_engine eq 'PSGI') {
43 ## If we are running under plackup let the Catalyst::Engine::PSGI
44 ## continue to run, but warn.
45 warn <<"EOW";
46You are running Catalyst::Engine::PSGI, which is considered a legacy engine for
47this version of Catalyst. We will continue running and use your existing psgi
48file, but it is recommended to perform the trivial upgrade process, which will
49leave you with less code and a forward path.
50
51Please review Catalyst::Upgrading
52EOW
53 return 'Catalyst::Engine::' . $old_engine;
54 }
55 elsif ($old_engine =~ /^(CGI|FastCGI|HTTP|Apache.*)$/) {
1e5dad00 56 return 'Catalyst::Engine';
57 }
0ea8962d 58 else {
59 return 'Catalyst::Engine::' . $old_engine;
1e5dad00 60 }
61}
62
532f0516 63around guess => sub {
64 my ($orig, $self) = (shift, shift);
65 my $engine = $self->$orig(@_);
66 if ($engine eq 'Standalone') {
67 if ( $ENV{MOD_PERL} ) {
68 my ( $software, $version ) =
d7132282 69 $ENV{MOD_PERL} =~ /^(\S+)\/(\d+(?:[\.\_]\d+)+)/;
532f0516 70 $version =~ s/_//g;
d7132282 71 $version =~ s/(\.[^.]+)\./$1/g;
72
532f0516 73 if ( $software eq 'mod_perl' ) {
74 if ( $version >= 1.99922 ) {
75 $engine = 'Apache2';
76 }
77
78 elsif ( $version >= 1.9901 ) {
79 Catalyst::Exception->throw( message => 'Plack does not have a mod_perl 1.99 handler' );
80 $engine = 'Apache2::MP19';
81 }
82
83 elsif ( $version >= 1.24 ) {
84 $engine = 'Apache1';
85 }
86
87 else {
88 Catalyst::Exception->throw( message =>
89 qq/Unsupported mod_perl version: $ENV{MOD_PERL}/ );
90 }
91 }
92 }
93 }
d7132282 94
acbecf08 95 my $old_engine = Catalyst::Utils::env_value($self->application_name, 'ENGINE');
96 if (!defined $old_engine) { # Not overridden
97 }
7b841c03 98 elsif ($old_engine =~ /^(PSGI|CGI|Apache.*)$/) {
acbecf08 99 # Trust autodetect
100 }
7b841c03 101 elsif ($old_engine eq 'HTTP') {
102 $engine = 'Standalone';
103 }
cac8fd6e 104 elsif ($old_engine eq 'FastCGI') {
105 $engine = 'FCGI';
106 }
acbecf08 107 elsif ($old_engine eq "HTTP::Prefork") { # Too bad if you're customising, we don't handle options
108 # write yourself a script to collect and pass in the options
109 $engine = "Starman";
110 }
111 elsif ($old_engine eq "HTTP::POE") {
112 Catalyst::Exception->throw("HTTP::POE engine no longer works, recommend you use Twiggy instead");
113 }
114 elsif ($old_engine eq "Zeus") {
115 Catalyst::Exception->throw("Zeus engine no longer works");
116 }
117 else {
118 warn("You asked for an unrecognised engine '$old_engine' which is no longer supported, this has been ignored.\n");
119 }
120
532f0516 121 return $engine;
122};
123
acbecf08 124# Force constructor inlining
125__PACKAGE__->meta->make_immutable( replace_constructor => 1 );
df1fa879 126
532f0516 1271;
df1fa879 128
129__END__
130
131=head1 NAME
132
b1ededd4 133Catalyst::EngineLoader - The Catalyst Engine Loader
df1fa879 134
135=head1 SYNOPSIS
136
137See L<Catalyst>.
138
139=head1 DESCRIPTION
140
141Wrapper on L<Plack::Loader> which resets the ::Engine if you are using some
142version of mod_perl.
143
144=head1 AUTHORS
145
146Catalyst Contributors, see Catalyst.pm
147
148=head1 COPYRIGHT
149
150This library is free software. You can redistribute it and/or modify it under
151the same terms as Perl itself.
152
1085c936 153=begin Pod::Coverage
154
155needs_psgi_engine_compat_hack
156
157=end Pod::Coverage
158
df1fa879 159=cut