Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated implementation based on new PSGI::Impl api and used Plack::Lo…

…ader to build PSGI::Impl
  • Loading branch information...
commit bfb10fe652b030c05d0fb718ccc9ceac3acbc680 1 parent 6f9c983
@dann authored
View
2  angelos-core/lib/Angelos.pm
@@ -168,8 +168,6 @@ sub setup_config {
sub create_config {
my $self = shift;
my $config_class = join '::', ( ref $self, 'Config' );
- use Data::Dumper;
- warn Dumper $config_class;
$config_class->require;
$config_class->instance;
}
View
30 angelos-core/lib/Angelos/Engine/Base.pm
@@ -74,17 +74,22 @@ sub build_engine {
port => $self->port,
root => $self->root,
},
- psgi_handler => $request_handler,
},
-
+ psgi_handler => $request_handler,
);
}
sub build_request_handler {
my $self = shift;
- # FIXME implement Angelos::Middleware::Builder
- my $request_handler = sub {
+ # FIXME wrap application handler Angelos::Middleware::Builder
+ my $app_handler = $self->create_application_handler;
+ return $app_handler;
+}
+
+sub create_application_handler {
+ my $self = shift;
+ return sub {
my $env = shift;
my $req = Angelos::Request->new($env);
my $res = Angelos::Response->new;
@@ -93,15 +98,18 @@ sub build_request_handler {
local *Angelos::Registrar::context = sub {$c};
$res = $self->handle_request($req);
- my $psgi_res = $res->finalize;
-
- # hmmmmmmm
- $psgi_res->[1] = [ %{ $psgi_res->[1] } ]
- if ref( $psgi_res->[1] ) eq 'HASH';
- $psgi_res->[2] = [ $psgi_res->[2] ] unless ref( $psgi_res->[2] );
+ my $psgi_res = $self->finalize_response($res);
return $psgi_res;
};
- return $request_handler;
+}
+
+sub finalize_response {
+ my ( $self, $res ) = @_;
+ my $psgi_res = $res->finalize;
+ $psgi_res->[1] = [ %{ $psgi_res->[1] } ]
+ if ref( $psgi_res->[1] ) eq 'HASH';
+ $psgi_res->[2] = [ $psgi_res->[2] ] unless ref( $psgi_res->[2] );
+ $psgi_res;
}
sub handle_request {
View
17 angelos-core/lib/Angelos/PSGI/Engine.pm
@@ -1,15 +1,20 @@
package Angelos::PSGI::Engine;
use Mouse;
-use Angelos::Types qw( Interface );
+use Angelos::Types qw( ServerGateway );
has 'interface' => (
- is => 'ro',
- isa => Interface,
- handles => [qw(run)],
- coerce => 1,
+ is => 'ro',
+ isa => ServerGateway,
+ coerce => 1,
);
+has 'psgi_handler' => ( is => 'rw', );
+
+sub run {
+ my $self = shift;
+ $self->interface->run( $self->psgi_handler );
+}
+
__PACKAGE__->meta->make_immutable( inline_destructor => 1 );
1;
-
View
24 angelos-core/lib/Angelos/PSGI/ServerGatewayBuilder.pm
@@ -1,29 +1,13 @@
package Angelos::PSGI::ServerGatewayBuilder;
use strict;
use warnings;
+use Plack::Loader;
sub build {
- my ( $class, $module, $args ) = @_;
- if ( $module !~ s{^\+}{} ) { $module = join( '::', "Plack", "Impl", $module );
- }
- Mouse::load_class($module);
-
- # FIXME need to develop standalone Plack::Impl wrapper
- # looks ugly...
- # we need to wrap Plack::Impl or
- if ( $module eq 'Plack::Impl::ServerSimple' ) {
- my $server = $module->new( $args->{port} );
- $server->host( $args->{host} );
- $server->psgi_app( $args->{psgi_handler} );
- return $server;
- }
-
- if ( $module eq 'Plack::Impl::AnyEvent' ) {
- $module->new( port => $args->{port}, host => $args->{host} );
- return $module;
- }
+ my ( $class, $module, $args ) = @_;
+ my $server_gateway = Plack::Loader->load( $module, %{$args} );
+ $server_gateway;
}
1;
-
View
7 angelos-core/lib/Angelos/Types.pm
@@ -3,17 +3,16 @@ use Mouse;
use Angelos::PSGI::ServerGatewayBuilder;
use MouseX::Types - declare => [
qw(
- Interface
+ ServerGateway
)
];
use MouseX::Types::Mouse qw(HashRef);
-subtype Interface;
+subtype ServerGateway;
-coerce Interface, from HashRef, via {
+coerce ServerGateway, from HashRef, via {
my $module = $_->{module};
my $args = $_->{args};
- $args->{psgi_handler} = $_->{psgi_handler};
my $server = Angelos::PSGI::ServerGatewayBuilder->build( $module, $args );
return $server;
};
Please sign in to comment.
Something went wrong with that request. Please try again.