Commit | Line | Data |
b1ededd4 |
1 | package Catalyst::EngineLoader; |
532f0516 |
2 | use Moose; |
3 | use Catalyst::Exception; |
acbecf08 |
4 | use Catalyst::Utils; |
532f0516 |
5 | use namespace::autoclean; |
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 | } |
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 |
50 | around 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 | } |
7b841c03 |
85 | elsif ($old_engine =~ /^(PSGI|CGI|Apache.*)$/) { |
acbecf08 |
86 | # Trust autodetect |
87 | } |
7b841c03 |
88 | elsif ($old_engine eq 'HTTP') { |
89 | $engine = 'Standalone'; |
90 | } |
cac8fd6e |
91 | elsif ($old_engine eq 'FastCGI') { |
92 | $engine = 'FCGI'; |
93 | } |
acbecf08 |
94 | elsif ($old_engine eq "HTTP::Prefork") { # Too bad if you're customising, we don't handle options |
95 | # write yourself a script to collect and pass in the options |
96 | $engine = "Starman"; |
97 | } |
98 | elsif ($old_engine eq "HTTP::POE") { |
99 | Catalyst::Exception->throw("HTTP::POE engine no longer works, recommend you use Twiggy instead"); |
100 | } |
101 | elsif ($old_engine eq "Zeus") { |
102 | Catalyst::Exception->throw("Zeus engine no longer works"); |
103 | } |
104 | else { |
105 | warn("You asked for an unrecognised engine '$old_engine' which is no longer supported, this has been ignored.\n"); |
106 | } |
107 | |
532f0516 |
108 | return $engine; |
109 | }; |
110 | |
acbecf08 |
111 | # Force constructor inlining |
112 | __PACKAGE__->meta->make_immutable( replace_constructor => 1 ); |
df1fa879 |
113 | |
532f0516 |
114 | 1; |
df1fa879 |
115 | |
116 | __END__ |
117 | |
118 | =head1 NAME |
119 | |
b1ededd4 |
120 | Catalyst::EngineLoader - The Catalyst Engine Loader |
df1fa879 |
121 | |
122 | =head1 SYNOPSIS |
123 | |
124 | See L<Catalyst>. |
125 | |
126 | =head1 DESCRIPTION |
127 | |
128 | Wrapper on L<Plack::Loader> which resets the ::Engine if you are using some |
129 | version of mod_perl. |
130 | |
131 | =head1 AUTHORS |
132 | |
133 | Catalyst Contributors, see Catalyst.pm |
134 | |
135 | =head1 COPYRIGHT |
136 | |
137 | This library is free software. You can redistribute it and/or modify it under |
138 | the same terms as Perl itself. |
139 | |
1085c936 |
140 | =begin Pod::Coverage |
141 | |
142 | needs_psgi_engine_compat_hack |
143 | |
144 | =end Pod::Coverage |
145 | |
df1fa879 |
146 | =cut |