Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved to K&R braces

  • Loading branch information...
commit 05b680a6bed97c012ee3a635e1f3b6b0c5b62e16 1 parent e00d210
@frodwith authored
View
4 Changes
@@ -2,6 +2,10 @@ Revision history for {{ $dist->name }}: {{ $dist->version }}
{{ $NEXT }}
+1.103340 2010-11-30 16:03:34 America/New_York
+ Moved the code to K&R brace style to work around a stupid MXD bug
+ under 5.12 perls. Oy ve.
+
1.103331 2010-11-29 10:18:00 America/New_York
Declare dependency on latest POEx::Role::TCPServer and use around for
BUILDARGS rather than method.
View
111 lib/POEx/Role/PSGIServer.pm
@@ -20,8 +20,7 @@ This Role has its roots firmly planted in POE::Component::Server::PSGI which pro
=cut
-role POEx::Role::PSGIServer
-{
+role POEx::Role::PSGIServer {
use aliased 'POEx::Role::Event';
use MooseX::Types::Moose(':all');
@@ -44,8 +43,7 @@ This attribute stores the PSGI application to be run from this server. A writer
=cut
- has psgi_app =>
- (
+ has psgi_app => (
is => 'ro',
isa => CodeRef,
writer => 'register_service',
@@ -64,14 +62,12 @@ This attribute stores coderefs to be called on a wheel's flush event
=cut
- has wheel_flushers =>
- (
+ has wheel_flushers => (
is => 'ro',
traits => ['Hash'],
isa => 'HashRef',
default => sub { {} },
- handles =>
- {
+ handles => {
has_wheel_flusher => 'exists',
get_wheel_flusher => 'get',
set_wheel_flusher => 'set',
@@ -88,8 +84,7 @@ BUILDARGS is wrapped to translate from the expected Plack::Handler interface to
=cut
- around BUILDARGS(ClassName $class: @args)
- {
+ around BUILDARGS(ClassName $class: @args) {
my $hash = $class->$orig(@args);
$hash->{listen_port} ||= delete $hash->{port} || 5000;
@@ -105,8 +100,7 @@ _start is advised to supply the proper input (HTTP::Parser) and output (Stream)
=cut
- after _start is Event
- {
+ after _start is Event {
$self->input_filter(POE::Filter::HTTP::Parser->new(type => 'server'));
$self->output_filter(POE::Filter::Stream->new());
}
@@ -119,15 +113,12 @@ write will alter the data if necessary for a chunked transfer encoded response a
=cut
- method write(PSGIServerContext $c, Str $data)
- {
- if($c->{chunked})
- {
+ method write(PSGIServerContext $c, Str $data) {
+ if($c->{chunked}) {
my $len = sprintf "%X", do { use bytes; length($data) };
$self->_write($c, "$len\r\n$data\r\n");
}
- else
- {
+ else {
$self->_write($c, $data);
}
@@ -141,8 +132,7 @@ _write accesses the proper wheel for this context and puts the supplied data int
=cut
- method _write(PSGIServerContext $c, Str $data)
- {
+ method _write(PSGIServerContext $c, Str $data) {
$c->{wheel}->put($data);
}
@@ -154,10 +144,8 @@ close will close the connection for the current context, but flushing the output
=cut
- method close(PSGIServerContext $c)
- {
- if($c->{chunked})
- {
+ method close(PSGIServerContext $c) {
+ if($c->{chunked}) {
$self->_write($c, "0\r\n\r\n");
}
@@ -174,8 +162,7 @@ handle_socket_error overridden from POEx::Role::TCPServer to delete the wheel wh
=cut
- method handle_socket_error(Str $action, Int $code, Str $message, WheelID $id) is Event
- {
+ method handle_socket_error(Str $action, Int $code, Str $message, WheelID $id) is Event {
$self->delete_wheel($id);
}
@@ -188,8 +175,7 @@ handle_listen_error is overridden from POEx::Role::TCPServer to die when the Soc
=cut
- method handle_listen_error(Str $action, Int $code, Str $message, WheelID $id) is Event
- {
+ method handle_listen_error(Str $action, Int $code, Str $message, WheelID $id) is Event {
die "Failed to '$action' to the specified port. Code: $code, Message: $message";
}
@@ -202,14 +188,11 @@ process_headers takes the headers from the PSGIResponse, and sends it to the out
=cut
- method process_headers(PSGIServerContext $c, PSGIResponse $response)
- {
+ method process_headers(PSGIServerContext $c, PSGIResponse $response) {
my $headers = $response->[1];
$headers->keys
- ->each
- (
- sub
- {
+ ->each(
+ sub {
my $index = shift;
return if $index == $#$headers;
my ($k, $v) = ($headers->[$index], $headers->[$index+1]) ;
@@ -230,8 +213,7 @@ http_preamble sends the first line of the HTTP response to the output buffer of
=cut
- method http_preamble(PSGIServerContext $c, PSGIResponse $response)
- {
+ method http_preamble(PSGIServerContext $c, PSGIResponse $response) {
$self->_write($c, "${\ $c->{protocol}} ${\ $response->[0] } ${ \status_message($response->[0]) }\r\n");
}
@@ -243,8 +225,7 @@ http_body_allowed checks the result code from the PSGIResponse to determine if a
=cut
- method http_body_allowed(PSGIServerContext $c, PSGIResponse $response) returns (Bool)
- {
+ method http_body_allowed(PSGIServerContext $c, PSGIResponse $response) returns (Bool) {
my $code = $response->[0];
my $no_body_allowed = ($c->{request}->method =~ /^head$/i)
@@ -269,8 +250,7 @@ respond processes the PSGIResponse to write out a valid HTTP response. If the bo
=cut
- method respond(PSGIServerContext $c, PSGIResponse $response) is Event
- {
+ method respond(PSGIServerContext $c, PSGIResponse $response) is Event {
$self->http_preamble($c, $response);
$self->process_headers($c, $response);
return unless ($self->http_body_allowed($c, $response));
@@ -280,25 +260,21 @@ respond processes the PSGIResponse to write out a valid HTTP response. If the bo
$self->_write($c, "\r\n");
my $body = $response->[2];
- if ($body)
- {
+ if ($body) {
# If we have a real filehandle, build a Streamer
- if (Plack::Util::is_real_fh($body))
- {
+ if (Plack::Util::is_real_fh($body)) {
# flush and destroy the old wheel, since the Streamer will build a new one
$c->{wheel}->flush();
$self->delete_wheel($c->{wheel}->ID);
my $handle = (delete $c->{wheel})->get_input_handle();
- my $streamer = POEx::Role::PSGIServer::Streamer->new
- (
+ my $streamer = POEx::Role::PSGIServer::Streamer->new(
input_handle => $body,
output_handle => $handle,
server_context => $c,
);
}
# If we don't just iterate the lines
- else
- {
+ else {
Plack::Util::foreach($body, sub{$self->write($c, @_)});
$self->close($c);
}
@@ -318,8 +294,7 @@ generate_push_writer by default constructs and returns a L<POEx::Role::PSGIServe
=cut
- method generate_push_writer(PSGIServerContext $c) returns (Object)
- {
+ method generate_push_writer(PSGIServerContext $c) returns (Object) {
return POEx::Role::PSGIServer::ProxyWriter->new(server_context => $c, proxied => $self);
}
@@ -331,10 +306,8 @@ generate_psgi_env returns a suitable HashRef as defined by L<PSGI> for applicati
=cut
- method generate_psgi_env(PSGIServerContext $c) returns (HashRef)
- {
- return req_to_psgi
- (
+ method generate_psgi_env(PSGIServerContext $c) returns (HashRef) {
+ return req_to_psgi(
$c->{request},
SERVER_NAME => $self->listen_ip,
SERVER_PORT => $self->listen_port,
@@ -353,15 +326,13 @@ build_server_context constructs and returns a L<POEx::Types::PSGIServer/PSGIServ
=cut
- method build_server_context(HTTPRequest $req, WheelID $wheel_id) returns (PSGIServerContext)
- {
+ method build_server_context(HTTPRequest $req, WheelID $wheel_id) returns (PSGIServerContext) {
my $version = $req->header('X-HTTP-Version') || '0.9';
my $protocol = "HTTP/$version";
my $connection = $req->header('Connection') || '';
my $keep_alive = ($version eq '1.1' && $connection ne 'close');
- my $context =
- {
+ my $context = {
request => $req,
wheel => $self->get_wheel($wheel_id),
version => $version,
@@ -382,18 +353,15 @@ handle_inbound_data implements the required method for POEx::Role::TCPServer. It
=cut
- method handle_inbound_data(HTTPRequest $req, WheelID $wheel_id) is Event
- {
+ method handle_inbound_data(HTTPRequest $req, WheelID $wheel_id) is Event {
my $context = $self->build_server_context($req, $wheel_id);
my $env = $self->generate_psgi_env($context);
my $response = Plack::Util::run_app($self->psgi_app, $env);
- if (ref($response) eq 'CODE')
- {
+ if (ref($response) eq 'CODE') {
$response->(sub { $self->respond($context, @_) });
}
- else
- {
+ else {
$self->yield('respond', $context, $response);
}
}
@@ -406,29 +374,24 @@ run is provided to complete the Plack::Handler interface and allow the server to
=cut
- method run(CodeRef $app)
- {
+ method run(CodeRef $app) {
$self->register_service($app);
POE::Kernel->run();
}
- method handle_on_flushed(WheelID $id) is Event
- {
+ method handle_on_flushed(WheelID $id) is Event {
if ($self->has_wheel_flusher($id)) {
$self->get_wheel_flusher($id)->();
}
1;
}
- after delete_wheel(WheelID $id)
- {
+ after delete_wheel(WheelID $id) {
$self->clear_wheel_flusher($id);
}
- with 'POEx::Role::TCPServer' =>
- {
- -excludes =>
- [
+ with 'POEx::Role::TCPServer' => {
+ -excludes => [
qw/handle_socket_error handle_listen_error handle_on_flushed/
]
};
View
18 lib/POEx/Role/PSGIServer/ProxyWriter.pm
@@ -3,8 +3,7 @@ package POEx::Role::PSGIServer::ProxyWriter;
#ABSTRACT: Provides a push writer for PSGI applications to use
use MooseX::Declare;
-class POEx::Role::PSGIServer::ProxyWriter
-{
+class POEx::Role::PSGIServer::ProxyWriter {
use MooseX::Types::Moose(':all');
use POEx::Types::PSGIServer(':all');
@@ -16,8 +15,7 @@ This is the server context from POEx::Role::PSGIServer. It is needed to determin
=cut
- has server_context =>
- (
+ has server_context => (
is => 'ro',
isa => PSGIServerContext,
required => 1
@@ -31,8 +29,7 @@ This is the actual object that consumes POEx::Role::PSGIServer. It is weakened t
=cut
- has proxied =>
- (
+ has proxied => (
is => 'ro',
isa => Object,
weak_ref => 1,
@@ -47,8 +44,7 @@ write proxies to the weakened PSGIServer consumer object passing along the L</se
=cut
- method write($data)
- {
+ method write($data) {
$self->proxied->write($self->server_context, $data);
}
@@ -58,8 +54,7 @@ close is proxied to the weakened PSGIServer consumer passing along L</server_con
=cut
- method close()
- {
+ method close() {
$self->proxied->close($self->server_context);
}
@@ -71,8 +66,7 @@ poll_cb is provided to complete the interface. The first argument to $coderef wi
=cut
- method poll_cb(CodeRef $coderef)
- {
+ method poll_cb(CodeRef $coderef) {
my $on_flush = sub { $self->$coderef() };
my $id = $self->server_context->{wheel}->ID;
$self->proxied->set_wheel_flusher($id => $on_flush);
View
24 lib/POEx/Role/PSGIServer/Streamer.pm
@@ -3,8 +3,7 @@ package POEx::Role::PSGIServer::Streamer;
#ABSTRACT: Provides streaming filehandle PSGI implementation
use MooseX::Declare;
-class POEx::Role::PSGIServer::Streamer
-{
+class POEx::Role::PSGIServer::Streamer {
use POE::Filter::Map;
use POE::Filter::Stream;
use MooseX::Types::Moose(':all');
@@ -38,15 +37,11 @@ _build_filter is overridden to return a L<POE::Filter::Map> filter if the curren
=cut
- method _build_filter
- {
- if($self->server_context->{chunked})
- {
- POE::Filter::Map->new
- (
+ method _build_filter {
+ if($self->server_context->{chunked}) {
+ POE::Filter::Map->new(
Get => sub { $_ },
- Put => sub
- {
+ Put => sub {
my $data = shift;
return $data if $data =~ /0\r\n\r\n/;
my $len = sprintf "%X", do { use bytes; length($data) };
@@ -54,8 +49,7 @@ _build_filter is overridden to return a L<POE::Filter::Map> filter if the curren
}
);
}
- else
- {
+ else {
return POE::Filter::Stream->new();
}
}
@@ -66,10 +60,8 @@ done_writing is advised to check if the context demands a chunked terminator and
=cut
- around done_writing
- {
- if($self->server_context->{chunked} && !$self->closed_chunk)
- {
+ around done_writing {
+ if($self->server_context->{chunked} && !$self->closed_chunk) {
$self->closed_chunk(1);
$self->put("0\r\n\r\n");
return;
View
15 lib/POEx/Types/PSGIServer.pm
@@ -4,8 +4,7 @@ package POEx::Types::PSGIServer;
use warnings;
use strict;
-use MooseX::Types -declare =>
-[qw/
+use MooseX::Types -declare => [qw/
PSGIServerContext
PSGIResponse
PSGIBody
@@ -39,8 +38,7 @@ The context is passed around to identify the current connection and what it is e
=cut
subtype PSGIServerContext,
- as Dict
- [
+ as Dict [
request => HTTPRequest,
wheel => Optional[Wheel],
version => Str,
@@ -68,8 +66,7 @@ This constraint uses HTTP::Status to check if the Int is a valid HTTP::Status co
subtype HTTPCode,
as Int,
- where
- {
+ where {
HTTP::Status::is_info($_)
|| HTTP::Status::is_success($_)
|| HTTP::Status::is_redirect($_)
@@ -84,8 +81,7 @@ The PSGIBody constraint covers two of the three types of body responses valid fo
subtype PSGIBody,
as Ref,
- where
- {
+ where {
Plack::Util::is_real_fh($_)
|| (Scalar::Util::blessed($_) && ($_->can('getline') && $_->can('close')))
};
@@ -97,8 +93,7 @@ This constraint checks responses from PSGI applications for a valid HTTPCode, an
=cut
subtype PSGIResponse,
- as Tuple
- [
+ as Tuple [
HTTPCode,
ArrayRef,
Optional[ArrayRef|PSGIBody]
Please sign in to comment.
Something went wrong with that request. Please try again.