Write out the pid file after double fork.
[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 }
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 1141;
df1fa879 115
116__END__
117
118=head1 NAME
119
b1ededd4 120Catalyst::EngineLoader - The Catalyst Engine Loader
df1fa879 121
122=head1 SYNOPSIS
123
124See L<Catalyst>.
125
126=head1 DESCRIPTION
127
128Wrapper on L<Plack::Loader> which resets the ::Engine if you are using some
129version of mod_perl.
130
131=head1 AUTHORS
132
133Catalyst Contributors, see Catalyst.pm
134
135=head1 COPYRIGHT
136
137This library is free software. You can redistribute it and/or modify it under
138the same terms as Perl itself.
139
1085c936 140=begin Pod::Coverage
141
142needs_psgi_engine_compat_hack
143
144=end Pod::Coverage
145
df1fa879 146=cut