File Coverage

blib/lib/Catalyst/EngineLoader.pm
Criterion Covered Total %
statement 19 22 86.3
branch 5 8 62.5
condition 1 3 33.3
subroutine 6 6 100.0
pod 0 1 0.0
total 31 40 77.5


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