blib/lib/CatalystX/PSGIApp.pm

filter: Statementstmt 100% 20 / 20 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 96.7% 30 / 31 CC 3 SCAR 5.6
CC
3
Cov
96%
psgi_app
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
↑ Summary
1 package CatalystX::PSGIApp;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $CatalystX::PSGIApp::VERSION = '0.01';
4 }
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Catalyst ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 CatalystX::PSGIApp - Get a psgi_app in a unified way across different Catalyst versions
13  
14 =head1 VERSION
15  
16 version 0.01
17  
18 =head1 DESCRIPTION
19  
20 Provides a psgi_app via ->psgi_app if it's available, or via Catalyst::Engine::PSGI if it's not
21  
22 =head1 OVERVIEW
23  
24 To use Catalyst with PSGI on Catalyst versions pre 5.9 requires the use of
25 L<Catalyst::Engine::PSGI>. Version 5.9 (and presumably above) of Catalyst
26 have PSGI baked in, and provide a C<psgi_app> method.
27  
28 If your Catalyst app is being run on versions on both side of this divide -
29 which is a weird use-case you probably shouldn't have - this module allows you
30 a unified way of getting the PSGI app back.
31  
32 =head1 WARNINGS
33  
34 You'll need to use L<Catalyst::Engine::PSGI> installed for this to work with
35 older Catalysts, but it's not listed as a dependency.
36  
37 If you need this module, your developers are using different Catalyst versions
38 to develop against, which is pretty weird.
39  
40 As per L<Catalyst::PSGI>, Catalyst using the default .psgi file will add
41 several default middlewares - as we use the C<app_psgi> method explicitly, these
42 will not be added. See L<Catalyst::PSGI> for details.
43  
44 =head1 SYNOPSIS
45  
46 use CatalystX::PSGIApp;
47 my $app = CatalystX::PSGIApp->psgi_app( 'Your::App::Here' );
48  
49 =head1 METHODS
50  
51 =head2 psgi_app
52  
53 Returns a PSGI app, either via C<<->psgi_app>> if your version of Catalyst
54 supports it, or using L<Catalyst::Engine::PSGI>.
55  
56 =cut
57  
58 2 ▶sub psgi_app {
Subroutine psgi_app: called CC=3 SCAR=11.0
Pod documented
59 2 my $class = shift;
60 2 my $target = shift;
61  
62 2 eval "require $target";
63 2 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
64  
65 2 ▶ if ( $target->can('psgi_app') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target->can('psgi_app')) { } 1 1 2
66 1 return $target->psgi_app;
67 } else {
68 1 $target->setup_engine('PSGI');
69 1 ▶ return sub { $target->run(@_) }
Subroutine __ANON__: called CC=1 SCAR=0.0
70 1 }
71 }
72  
73 =head1 AUTHOR
74  
75 Peter Sergeant C<pete@clueball.com>, while at
76 L<http://www.net-a-porter.com|NET-A-PORTER>.
77  
78 =cut
79  
80 1 1;
↑ Summary