Skip to content
Browse files

use Plack as PSGI implementation

  • Loading branch information...
1 parent 70fc0aa commit 7d41efc0b253b5f94ba7b6a1c93dd143daabeb3a @dann committed
View
6 angelos-core/Makefile.PL
@@ -54,6 +54,7 @@ requires(
'Data::Util' => 0,
'Class::Singleton' => 0,
'CHI' => '0.10',
+ 'Plack' => 0,
# Angelos Plugins
'Text::SimpleTable' => 0,
@@ -92,11 +93,6 @@ requires(
'Locale::Maketext::Simple' => 0,
'Locale::Maketext::Extract' => 0,
- # testing
- 'HTTP::Request::Common' => 0,
- 'Test::Class' => 0,
- 'Test::Base' => 0,
-
# View Plugins (remove from core)
# Core Middleware
View
2 angelos-core/lib/Angelos.pm
@@ -168,6 +168,8 @@ 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
4 angelos-core/lib/Angelos/Config.pm
@@ -10,6 +10,8 @@ use base 'Class::Singleton';
sub _new_instance {
my $class = shift;
my $self = bless {}, $class;
+ use Data::Dumper;
+ warn $class;
$self->{config} = Angelos::Config::Loader->load( $self->config_file_path,
Angelos::Config::Schema->config );
return $self;
@@ -18,7 +20,7 @@ sub _new_instance {
sub config_file_path {
my ( $self, $environment ) = @_;
Angelos::Exception::AbstractMethod->throw(
- message => 'Sub class must implement config_file method' );
+ message => 'Sub class must implement config_file_path method' );
}
sub global {
View
3 angelos-core/lib/Angelos/Engine.pm
@@ -2,7 +2,6 @@ package Angelos::Engine;
use Angelos::Class;
use Carp ();
use Scalar::Util ();
-use HTTP::Engine::Response;
use Angelos::Dispatcher;
use Angelos::Middleware::Builder;
use Angelos::Exceptions;
@@ -51,6 +50,8 @@ sub handle_request {
if ( my $e = Exception::Class->caught() ) {
$self->HANDLE_EXCEPTION($e);
}
+ use Data::Dumper;
+ warn Dumper $self->app->res;
return $self->app->res;
}
View
36 angelos-core/lib/Angelos/Engine/Base.pm
@@ -1,14 +1,14 @@
package Angelos::Engine::Base;
use Angelos::Class;
use Carp ();
-use HTTP::Engine;
use Angelos::Exceptions;
+use Angelos::PSGI::Engine;
+use Angelos::Request;
with 'Angelos::Class::Loggable';
has 'engine' => (
is => 'rw',
- isa => 'HTTP::Engine',
handles => [qw(run)],
);
@@ -66,7 +66,7 @@ sub build_engine {
my $request_handler = $self->request_handler;
$request_handler ||= $self->build_request_handler;
- return HTTP::Engine->new(
+ return Angelos::PSGI::Engine->new(
interface => {
module => $self->server,
args => {
@@ -74,32 +74,34 @@ sub build_engine {
port => $self->port,
root => $self->root,
},
- request_handler => $request_handler,
+ psgi_handler => $request_handler,
},
+
);
}
-
sub build_request_handler {
my $self = shift;
- my $request_handler = Angelos::Middleware::Builder->new->build(
- sub { my $req = shift; $self->handle_request($req) } );
- my $request_handler_with_context = sub {
- my $req = shift;
- my $res = HTTP::Engine::Response->new;
+ # FIXME implement Angelos::Middleware::Builder
+ my $request_handler = sub {
+ my $env = shift;
+ my $req = Angelos::Request->new($env);
+ my $res = Angelos::Response->new;
my $c = $self->create_context( $req, $res );
-
- use Devel::MemUsed;
- my $memused = Devel::MemUsed->new;
-
no warnings 'redefine';
local *Angelos::Registrar::context = sub {$c};
- $self->log->info(sprintf( "MEMORY: %08s", $memused ) . "\n");
- $request_handler->($req);
+ $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] );
+ return $psgi_res;
};
- $request_handler_with_context;
+ return $request_handler;
}
sub handle_request {
View
15 angelos-core/lib/Angelos/PSGI/Engine.pm
@@ -0,0 +1,15 @@
+package Angelos::PSGI::Engine;
+use Mouse;
+use Angelos::Types qw( Interface );
+
+has 'interface' => (
+ is => 'ro',
+ isa => Interface,
+ handles => [qw(run)],
+ coerce => 1,
+);
+
+__PACKAGE__->meta->make_immutable( inline_destructor => 1 );
+1;
+
+
View
29 angelos-core/lib/Angelos/PSGI/ServerGatewayBuilder.pm
@@ -0,0 +1,29 @@
+package Angelos::PSGI::ServerGatewayBuilder;
+use strict;
+use warnings;
+
+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;
+ }
+}
+
+1;
+
+
View
3 angelos-core/lib/Angelos/Request.pm
@@ -0,0 +1,3 @@
+package Angelos::Request;
+use base qw/Plack::Request/;
+1;
View
4 angelos-core/lib/Angelos/Response.pm
@@ -0,0 +1,4 @@
+package Angelos::Response;
+use base qw(Plack::Response);
+
+1;
View
25 angelos-core/lib/Angelos/Types.pm
@@ -0,0 +1,25 @@
+package Angelos::Types;
+use Mouse;
+use Angelos::PSGI::ServerGatewayBuilder;
+use MouseX::Types - declare => [
+ qw(
+ Interface
+ )
+];
+use MouseX::Types::Mouse qw(HashRef);
+
+subtype Interface;
+
+coerce Interface, from HashRef, via {
+ my $module = $_->{module};
+ my $args = $_->{args};
+ $args->{psgi_handler} = $_->{psgi_handler};
+
+ use Data::Dumper;
+ warn $module;
+ warn Dumper $args;
+ my $server = Angelos::PSGI::ServerGatewayBuilder->build( $module, $args );
+ return $server;
+};
+
+1;

0 comments on commit 7d41efc

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