Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

use PlackX::Engine

  • Loading branch information...
commit fe631efaebcd777492c074ca86157e837bc2be74 1 parent 8598024
Dann authored
1  angelos-core/Makefile.PL
@@ -55,6 +55,7 @@ requires(
55 55 'Class::Singleton' => 0,
56 56 'CHI' => '0.10',
57 57 'Plack' => 0,
  58 + 'PlackX::Engine' => 0,
58 59
59 60 # Angelos Plugins
60 61 'Text::SimpleTable' => 0,
4 angelos-core/lib/Angelos/Engine.pm
@@ -46,6 +46,10 @@ sub build_dispatcher {
46 46
47 47 sub handle_request {
48 48 my ( $self, $req ) = @_;
  49 + my $c = $self->create_context( $req, $res );
  50 + no warnings 'redefine';
  51 + local *Angelos::Registrar::context = sub {$c};
  52 +
49 53 eval { $self->DISPATCH($req); };
50 54 if ( my $e = Exception::Class->caught() ) {
51 55 $self->HANDLE_EXCEPTION($e);
54 angelos-core/lib/Angelos/Engine/Base.pm
@@ -4,6 +4,7 @@ use Carp ();
4 4 use Angelos::Exceptions;
5 5 use Angelos::PSGI::Engine;
6 6 use Angelos::Request;
  7 +use PlackX::Engine;
7 8
8 9 with 'Angelos::Class::Loggable';
9 10
@@ -62,54 +63,27 @@ sub BUILD {
62 63 sub SETUP { }
63 64
64 65 sub build_engine {
65   - my $self = shift;
66   - my $request_handler = $self->request_handler;
  66 + my $self = shift;
  67 + my $request_handler ||= $self->request_handler;
67 68 $request_handler ||= $self->build_request_handler;
68 69
69   - return Angelos::PSGI::Engine->new(
70   - interface => {
71   - module => $self->server,
72   - args => {
73   - host => $self->host,
74   - port => $self->port,
75   - root => $self->root,
  70 + my $engine = PlackX::Engine->new(
  71 + { server => {
  72 + module => $self->server,
  73 + args => {
  74 + port => $self->port,
  75 + host => $self->host,
  76 + },
76 77 },
77   - },
78   - psgi_handler => $request_handler,
  78 + request_handler => $request_handler,
  79 + }
79 80 );
80   -}
81   -
82   -sub build_request_handler {
83   - my $self = shift;
84 81
85   - # FIXME wrap application handler Angelos::Middleware::Builder
86   - my $app_handler = $self->create_application_handler;
87   - return $app_handler;
88 82 }
89 83
90   -sub create_application_handler {
  84 +sub build_request_handler {
91 85 my $self = shift;
92   - return sub {
93   - my $env = shift;
94   - my $req = Angelos::Request->new($env);
95   - my $res = Angelos::Response->new;
96   - my $c = $self->create_context( $req, $res );
97   - no warnings 'redefine';
98   - local *Angelos::Registrar::context = sub {$c};
99   -
100   - $res = $self->handle_request($req);
101   - my $psgi_res = $self->finalize_response($res);
102   - return $psgi_res;
103   - };
104   -}
105   -
106   -sub finalize_response {
107   - my ( $self, $res ) = @_;
108   - my $psgi_res = $res->finalize;
109   - $psgi_res->[1] = [ %{ $psgi_res->[1] } ]
110   - if ref( $psgi_res->[1] ) eq 'HASH';
111   - $psgi_res->[2] = [ $psgi_res->[2] ] unless ref( $psgi_res->[2] );
112   - $psgi_res;
  86 + return sub { my $req = shift; $self->handle_request($req) }
113 87 }
114 88
115 89 sub handle_request {
24 angelos-core/lib/Angelos/PSGI/Adapter.pm
... ... @@ -1,24 +0,0 @@
1   -package Angelos::PSGI::Adapter;
2   -use strict;
3   -use warnings;
4   -use UNIVERSAL::require;
5   -
6   -sub new {
7   - my ( $class, $app ) = @_;
8   - bless { app => $app }, $class;
9   -}
10   -
11   -sub handler {
12   - my $self = shift;
13   - my $app = $self->_new_app;
14   - return sub { $app->run };
15   -}
16   -
17   -sub _new_app {
18   - my $self = shift;
19   - my $app = $self->{app};
20   - $app->require;
21   - $app->new;
22   -}
23   -
24   -1;
20 angelos-core/lib/Angelos/PSGI/Engine.pm
... ... @@ -1,20 +0,0 @@
1   -package Angelos::PSGI::Engine;
2   -use Mouse;
3   -use Angelos::Types qw( ServerGateway );
4   -
5   -has 'interface' => (
6   - is => 'ro',
7   - isa => ServerGateway,
8   - coerce => 1,
9   -);
10   -
11   -has 'psgi_handler' => ( is => 'rw', );
12   -
13   -sub run {
14   - my $self = shift;
15   - $self->interface->run( $self->psgi_handler );
16   -}
17   -
18   -__PACKAGE__->meta->make_immutable( inline_destructor => 1 );
19   -1;
20   -
13 angelos-core/lib/Angelos/PSGI/ServerGatewayBuilder.pm
... ... @@ -1,13 +0,0 @@
1   -package Angelos::PSGI::ServerGatewayBuilder;
2   -use strict;
3   -use warnings;
4   -use Plack::Loader;
5   -
6   -sub build {
7   - my ( $class, $module, $args ) = @_;
8   - my $server_gateway = Plack::Loader->load( $module, %{$args} );
9   - $server_gateway;
10   -}
11   -
12   -1;
13   -
1  angelos-plugins/Angelos-Controller-Plugin-Dumper
... ... @@ -1 +0,0 @@
1   -Subproject commit 16e076c82a37511ad5113e4f73d5e913ee29b8ad
1  angelos-plugins/Angelos-Controller-Plugin-FillinForm
... ... @@ -1 +0,0 @@
1   -Subproject commit 234a80b47b772a8ecc49adc959dc3e943aa44052
1  angelos-plugins/Angelos-Controller-Plugin-FormValidator-Simple
... ... @@ -1 +0,0 @@
1   -Subproject commit 1b36282a51b6411c8e46f2cd241755aeece18810
1  angelos-tasks/Task-Angelos
... ... @@ -1 +0,0 @@
1   -Subproject commit dbda7637edc1ba9f91d6fc3a32e8ce05027b4663

0 comments on commit fe631ef

Please sign in to comment.
Something went wrong with that request. Please try again.