Alexis Sukrieh > Dancer-1.9999_01 > Dancer::Core::Server::PSGI

Download:
Dancer-1.9999_01.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 1.9999_01   Source   Latest Release: Dancer-2.0000_01

NAME ^

Dancer::Core::Server::PSGI - TODO

VERSION ^

version 1.9999_01

SYNOPSIS ^

        sub start {
        my $self = shift;
            my $app  = $self->psgi_app();

            foreach my $setting (qw/plack_middlewares plack_middlewares_map/) {
                if (Dancer::Config::setting($setting)) {
                    my $method = 'apply_'.$setting;
                    $app = $self->$method($app);
                }
            }
        return $app;
        }

        sub apply_plack_middlewares_map {
            my ($self, $app) = @_;

            my $mw_map = Dancer::Config::setting('plack_middlewares_map');

            foreach my $req (qw(Plack::App::URLMap Plack::Builder)) {
                croak "$req is needed to use apply_plack_middlewares_map"
                  unless Dancer::ModuleLoader->load($req);
            }

            my $urlmap = Plack::App::URLMap->new;

            while ( my ( $path, $mw ) = each %$mw_map ) {
                my $builder = Plack::Builder->new();
                map { $builder->add_middleware(@$_) } @$mw;
                $urlmap->map( $path => $builder->to_app($app) );
            }

            $urlmap->map('/' => $app) unless $mw_map->{'/'};
            return $urlmap->to_app;
        }

        sub apply_plack_middlewares {
            my ($self, $app) = @_;

            my $middlewares = Dancer::Config::setting('plack_middlewares');
        
            croak "Plack::Builder is needed for middlewares support"
              unless Dancer::ModuleLoader->load('Plack::Builder');
        
            my $builder = Plack::Builder->new();
        
            ref $middlewares eq "ARRAY"
              or croak "'plack_middlewares' setting must be an ArrayRef";

            map {
                Dancer::Logger::core "add middleware " . $_->[0];
                $builder->add_middleware(@$_)
            } @$middlewares;

            $app = $builder->to_app($app);
        
            return $app;
        }

        sub init_request_headers {
            my ($self, $env) = @_;
            my $plack = Plack::Request->new($env);
            Dancer::SharedData->headers($plack->headers);
        }

DESCRIPTION ^

This is a server implementation for PSGI. It contains all the code to handle a PSGI request.

METHODS ^

name

The server's name: PSGI.

start

Starts the server.

AUTHOR ^

Dancer Core Developers

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2012 by Alexis Sukrieh.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: