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