0b81933c2f9c40d58a7650b213b1fee2cb8bd715
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / Loader.pm
1 package Catalyst::Engine::Loader;
2 use Moose;
3 use Catalyst::Exception;
4 use Catalyst::Utils;
5 use namespace::autoclean;
6
7 extends 'Plack::Loader';
8
9 has application_name => (
10     isa => 'Str',
11     is => 'ro',
12     required => 1,
13 );
14
15 around guess => sub {
16     my ($orig, $self) = (shift, shift);
17     my $engine = $self->$orig(@_);
18     if ($engine eq 'Standalone') {
19         if ( $ENV{MOD_PERL} ) {
20             my ( $software, $version ) =
21               $ENV{MOD_PERL} =~ /^(\S+)\/(\d+(?:[\.\_]\d+)+)/;
22             $version =~ s/_//g;
23             $version =~ s/(\.[^.]+)\./$1/g;
24
25             if ( $software eq 'mod_perl' ) {
26                 if ( $version >= 1.99922 ) {
27                     $engine = 'Apache2';
28                 }
29
30                 elsif ( $version >= 1.9901 ) {
31                     Catalyst::Exception->throw( message => 'Plack does not have a mod_perl 1.99 handler' );
32                     $engine = 'Apache2::MP19';
33                 }
34
35                 elsif ( $version >= 1.24 ) {
36                     $engine = 'Apache1';
37                 }
38
39                 else {
40                     Catalyst::Exception->throw( message =>
41                           qq/Unsupported mod_perl version: $ENV{MOD_PERL}/ );
42                 }
43             }
44         }
45     }
46
47     my $old_engine = Catalyst::Utils::env_value($self->application_name, 'ENGINE');
48     if (!defined $old_engine) { # Not overridden
49     }
50     elsif ($old_engine =~ /^(CGI|FCGI|HTTP|Apache.*)$/) {
51         # Trust autodetect
52     }
53     elsif ($old_engine eq "HTTP::Prefork") { # Too bad if you're customising, we don't handle options
54                                              # write yourself a script to collect and pass in the options
55         $engine = "Starman";
56     }
57     elsif ($old_engine eq "HTTP::POE") {
58         Catalyst::Exception->throw("HTTP::POE engine no longer works, recommend you use Twiggy instead");
59     }
60     elsif ($old_engine eq "Zeus") {
61         Catalyst::Exception->throw("Zeus engine no longer works");
62     }
63     else {
64         warn("You asked for an unrecognised engine '$old_engine' which is no longer supported, this has been ignored.\n");
65     }
66
67     return $engine;
68 };
69
70 # Force constructor inlining
71 __PACKAGE__->meta->make_immutable( replace_constructor => 1 );
72
73 1;
74
75 __END__
76
77 =head1 NAME
78
79 Catalyst::Engine::Loader - The Catalyst Engine Loader
80
81 =head1 SYNOPSIS
82
83 See L<Catalyst>.
84
85 =head1 DESCRIPTION
86
87 Wrapper on L<Plack::Loader> which resets the ::Engine if you are using some
88 version of mod_perl.
89
90 =head1 AUTHORS
91
92 Catalyst Contributors, see Catalyst.pm
93
94 =head1 COPYRIGHT
95
96 This library is free software. You can redistribute it and/or modify it under
97 the same terms as Perl itself.
98
99 =cut