| 1 | package Labyrinth::PSGI; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 5 | our $VERSION = '1.01'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Labyrinth; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Labyrinth::Variables; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub new { | ||||||||||||||||||||||||||||
| 12 | 0 | ▶ | my ($class,$env,$cnf) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | my $lab = Labyrinth->new(); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # create an attributes hash | ||||||||||||||||||||||||||||
| 17 | 0 | my $atts = { | |||||||||||||||||||||||||||
| 18 | cnf => $cnf, | ||||||||||||||||||||||||||||
| 19 | lab => $lab | ||||||||||||||||||||||||||||
| 20 | }; | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # create the object | ||||||||||||||||||||||||||||
| 23 | 0 | bless $atts, $class; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | $settings{psgi}{env} = $env; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | return $atts; | |||||||||||||||||||||||||||
| 28 | }; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub run { | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my $cnf = shift || $self->{cnf}; | ||||||||||||||||||||||||||
|
Condition0%0/3
shift() || $self->{'cnf'}
MC/DC0%0/2
shift() || $self->{'cnf'}
shift()
$self->{'cnf'}
Truth table0%0/3
A || B
A= shift()B= $self->{'cnf'}
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return [ 500, 'text/html', [ '<html><head><title>Oops!</title></head><body>Oops, something went wrong</body></html>' ] ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cnf and -f $cnf
MC/DC0%0/2
$cnf and -f $cnf
$cnf
-f $cnf
Truth table0%0/3
A and B
A= $cnfB= -f $cnf
| |||||||||||||||||||||||||||||
| 35 | unless($cnf && -f $cnf); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | $self->{lab}->run( $cnf ); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | return [ $settings{psgi}{status}, $settings{psgi}{headers}, [ $settings{psgi}{body} ] ]; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 5 | 1; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | __END__ | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head1 NAME | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Labyrinth::PSGI - PSGI handler for Labyrinth | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Allow Labyrinth to run under Plack. Use the PSGI protocol to interface with | ||||||||||||||||||||||||||||
| 53 | a Plack web server to process web requests. | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Update your settings file to include the following lines. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | query-parser=PSGI | ||||||||||||||||||||||||||||
| 60 | writer-render=PSGI | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Then create a .psgi file for your application, containing the following: | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | use Labyrinth::PSGI; | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | my $app = sub { | ||||||||||||||||||||||||||||
| 67 | my $env = shift; | ||||||||||||||||||||||||||||
| 68 | my $lab = Labyrinth::PSGI->new( $env, '/var/www/<mywebsite>/cgi-bin/config/settings.ini' ); | ||||||||||||||||||||||||||||
| 69 | return $lab->run(); | ||||||||||||||||||||||||||||
| 70 | }; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | You may also need to add builder instructions. These should be added to your | ||||||||||||||||||||||||||||
| 73 | .psgi file, and may look something like: | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | use Plack::Builder; | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | builder { | ||||||||||||||||||||||||||||
| 78 | enable "Static", path => qr!^/images/!, root => '../html'; | ||||||||||||||||||||||||||||
| 79 | enable "Static", path => qr!^/(cs|j)s/!, root => '../html'; | ||||||||||||||||||||||||||||
| 80 | enable "Static", path => qr!^/favicon.ico!, root => '../html'; | ||||||||||||||||||||||||||||
| 81 | enable "Static", path => qr!^/robots.txt!, root => '../html'; | ||||||||||||||||||||||||||||
| 82 | $app; | ||||||||||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | The above lines allow static files to pass through and be retrieved from the | ||||||||||||||||||||||||||||
| 86 | file system, rather than through your application. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =head1 METHODS | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head2 new( $env [, $config ] ) | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | The constructor. Must be passed the environment variable from the PSGI server. | ||||||||||||||||||||||||||||
| 93 | You may optionally pass the Labyrinth configuration file as well, or via the | ||||||||||||||||||||||||||||
| 94 | run() method. | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head2 run( [ $config ] ) | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | CGI::PSGI | ||||||||||||||||||||||||||||
| 101 | Labyrinth | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | Barbie, <barbie@missbarbell.co.uk> for | ||||||||||||||||||||||||||||
| 106 | Miss Barbell Productions, L<http://www.missbarbell.co.uk/> | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | Copyright (C) 2013-2014 Barbie for Miss Barbell Productions | ||||||||||||||||||||||||||||
| 111 | All Rights Reserved. | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | This module is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||
| 114 | modify it under the Artistic License 2.0. | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||||||||||