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