From 4dcae463a99d85c05d2cb03356bb721e3c84fc3a Mon Sep 17 00:00:00 2001 From: Rocco Caputo Date: Tue, 31 May 2011 01:10:20 -0400 Subject: [PATCH] Whitespace fixes. --- eg/RunnerRole.pm | 238 +++++++++++++++++----------------- eg/eg-02-encoding.pl | 14 +- eg/eg-41-signal-twice.pl | 6 +- eg/eg-42-reflex-in-poe.pl | 8 +- eg/ttl/Ttl/HexDecoder.pm | 10 +- eg/ttl/Ttl/Nand.pm | 14 +- eg/ttl/Ttl/Nor.pm | 14 +- eg/ttl/Ttl/TriAnd.pm | 12 +- eg/ttl/Ttl/TriNand.pm | 12 +- lib/Reflex/Callbacks.pm | 2 +- lib/Reflex/Collection.pm | 12 +- lib/Reflex/POE/Event.pm | 34 ++--- lib/Reflex/Role/PidCatcher.pm | 60 ++++----- t/300-run-all-twice.t | 2 +- 14 files changed, 219 insertions(+), 219 deletions(-) diff --git a/eg/RunnerRole.pm b/eg/RunnerRole.pm index aae470f..c8954f1 100644 --- a/eg/RunnerRole.pm +++ b/eg/RunnerRole.pm @@ -17,56 +17,56 @@ callback_parameter cb_stdout_error => qw( on att_stdout error ); method_parameter method_put => qw( put att_stdin _ ); role { - my $p = shift; + my $p = shift; - with 'Reflex::Role::OutStreaming' => { - att_handle => $p->att_stdin(), - method_put => $p->method_put(), - }; + with 'Reflex::Role::OutStreaming' => { + att_handle => $p->att_stdin(), + method_put => $p->method_put(), + }; - my $m_stdout_stop = "stop_" . $p->att_stdout(); - my $cb_stdout_closed = $p->cb_stdout_closed(); + my $m_stdout_stop = "stop_" . $p->att_stdout(); + my $cb_stdout_closed = $p->cb_stdout_closed(); - requires( + requires( map { $p->$_() } qw( - att_pid att_stderr att_stdin att_stdout - cb_exit - cb_stderr_closed cb_stderr_data cb_stderr_data - cb_stdout_closed cb_stdout_data cb_stdout_data - ) - ); - - after $cb_stdout_closed => sub { - my ($self, $args) = @_; - $self->$m_stdout_stop(); - }; - - with 'Reflex::Role::InStreaming' => { - att_handle => $p->att_stdout(), - cb_data => $p->cb_stdout_data(), - cb_error => $p->cb_stdout_error(), - cb_closed => $cb_stdout_closed, - }; - - my $m_stderr_stop = "stop_" . $p->att_stderr(); - my $cb_stderr_closed = $p->cb_stderr_closed(); - - after $cb_stderr_closed => sub { - my ($self, $args) = @_; - $self->$m_stderr_stop(); - }; - - with 'Reflex::Role::InStreaming' => { - att_handle => $p->att_stderr(), - cb_data => $p->cb_stderr_data(), - cb_error => $p->cb_stderr_error(), - cb_closed => $cb_stderr_closed, - }; - - with 'Reflex::Role::PidCatcher' => { - att_pid => $p->att_pid(), - cb_exit => $p->cb_exit(), - }; + att_pid att_stderr att_stdin att_stdout + cb_exit + cb_stderr_closed cb_stderr_data cb_stderr_data + cb_stdout_closed cb_stdout_data cb_stdout_data + ) + ); + + after $cb_stdout_closed => sub { + my ($self, $args) = @_; + $self->$m_stdout_stop(); + }; + + with 'Reflex::Role::InStreaming' => { + att_handle => $p->att_stdout(), + cb_data => $p->cb_stdout_data(), + cb_error => $p->cb_stdout_error(), + cb_closed => $cb_stdout_closed, + }; + + my $m_stderr_stop = "stop_" . $p->att_stderr(); + my $cb_stderr_closed = $p->cb_stderr_closed(); + + after $cb_stderr_closed => sub { + my ($self, $args) = @_; + $self->$m_stderr_stop(); + }; + + with 'Reflex::Role::InStreaming' => { + att_handle => $p->att_stderr(), + cb_data => $p->cb_stderr_data(), + cb_error => $p->cb_stderr_error(), + cb_closed => $cb_stderr_closed, + }; + + with 'Reflex::Role::PidCatcher' => { + att_pid => $p->att_pid(), + cb_exit => $p->cb_exit(), + }; }; 1; @@ -88,46 +88,46 @@ __END__ watches process => ( isa => 'Maybe[Reflex::PID]', is => 'rw' ); has [qw(stdin stdout stderr)] => ( - isa => 'Maybe[FileHandle]', - is => 'rw', + isa => 'Maybe[FileHandle]', + is => 'rw', ); has ipc_run => ( isa => 'IPC::Run', is => 'rw' ); has cmd => ( - isa => 'ArrayRef', - is => 'ro', - required => 1, + isa => 'ArrayRef', + is => 'ro', + required => 1, ); ### Reap the child process. sub on_process_exit { - my ($self, $args) = @_; - $self->emit(event => 'exit', args => $args); + my ($self, $args) = @_; + $self->emit(event => 'exit', args => $args); } sub kill { - my ($self, $signal) = @_; - croak "no process to kill" unless $self->process(); - $signal ||= 'TERM'; - kill $signal, $self->process()->pid(); + my ($self, $signal) = @_; + croak "no process to kill" unless $self->process(); + $signal ||= 'TERM'; + kill $signal, $self->process()->pid(); } ### Write to standard input. sub on_stdin_error { - my ($self, $args) = @_; - $self->emit(event => 'stdin_error', args => $args); + my ($self, $args) = @_; + $self->emit(event => 'stdin_error', args => $args); } with 'Reflex::Role::Writing' => { att_handle => 'stdin' }; sub on_stdin_writable { - my ($self, $arg) = @_; - my $octets_left = $self->flush_stdin(); - return if $octets_left; - $self->flush_stdin(); + my ($self, $arg) = @_; + my $octets_left = $self->flush_stdin(); + return if $octets_left; + $self->flush_stdin(); } with 'Reflex::Role::Writable' => { att_handle => 'stdin' }; @@ -135,88 +135,88 @@ with 'Reflex::Role::Writable' => { att_handle => 'stdin' }; ### Read from standard output. sub on_stdout_readable { - my ($self, $arg) = @_; - my $octets_read = $self->read_stdout($arg); - warn $octets_read; - return if $octets_read; - if (defined $octets_read) { - warn 111; - $self->pause_stdout_readable(); - return; - } - $self->stop_stdout_readable(); + my ($self, $arg) = @_; + my $octets_read = $self->read_stdout($arg); + warn $octets_read; + return if $octets_read; + if (defined $octets_read) { + warn 111; + $self->pause_stdout_readable(); + return; + } + $self->stop_stdout_readable(); } sub on_stdout_error { - my ($self, $args) = @_; - $self->emit(event => 'stdout_error', args => $args); - $self->stop_stdout_readable(); + my ($self, $args) = @_; + $self->emit(event => 'stdout_error', args => $args); + $self->stop_stdout_readable(); } with 'Reflex::Role::Reading' => { - att_handle => 'stdout', - cb_data => make_emitter(on_stdout => "stdout"), + att_handle => 'stdout', + cb_data => make_emitter(on_stdout => "stdout"), }; with 'Reflex::Role::Readable' => { - att_handle => 'stdout', - cb_ready => 'on_stdout_readable', + att_handle => 'stdout', + cb_ready => 'on_stdout_readable', }; ### Read from standard error. sub on_stderr_error { - my ($self, $args) = @_; - $self->emit(event => 'stderr_error', args => $args); - $self->stop_stderr_readable(); + my ($self, $args) = @_; + $self->emit(event => 'stderr_error', args => $args); + $self->stop_stderr_readable(); } sub on_stderr_readable { - my ($self, $arg) = @_; - my $octets_read = $self->read_stderr($arg); - warn $octets_read; - return if $octets_read; - if (defined $octets_read) { - warn 111; - $self->pause_stderr_readable(); - return; - } - $self->stop_stderr_readable(); + my ($self, $arg) = @_; + my $octets_read = $self->read_stderr($arg); + warn $octets_read; + return if $octets_read; + if (defined $octets_read) { + warn 111; + $self->pause_stderr_readable(); + return; + } + $self->stop_stderr_readable(); } with 'Reflex::Role::Reading' => { - att_handle => 'stderr', - cb_data => make_emitter(on_stderr => "stderr"), + att_handle => 'stderr', + cb_data => make_emitter(on_stderr => "stderr"), }; with 'Reflex::Role::Readable' => { - att_handle => 'stderr', - cb_ready => 'on_stderr_readable', + att_handle => 'stderr', + cb_ready => 'on_stderr_readable', }; sub BUILD { - my $self = shift; - - my ($fh_in, $fh_out, $fh_err) = (gensym(), gensym(), gensym()); - - $self->ipc_run( - start( - $self->cmd(), - 'pipe', $fh_out, - '2>pipe', $fh_err, - ) - ) or die "IPC::Run start() failed: $? ($!)"; - - $self->process( - Reflex::PID->new( - pid => $self->ipc_run->{KIDS}[0]{PID} - ) - ); - - $self->att_stdin($fh_in); - $self->att_stdout($fh_out); - $self->att_stderr($fh_err); + my $self = shift; + + my ($fh_in, $fh_out, $fh_err) = (gensym(), gensym(), gensym()); + + $self->ipc_run( + start( + $self->cmd(), + 'pipe', $fh_out, + '2>pipe', $fh_err, + ) + ) or die "IPC::Run start() failed: $? ($!)"; + + $self->process( + Reflex::PID->new( + pid => $self->ipc_run->{KIDS}[0]{PID} + ) + ); + + $self->att_stdin($fh_in); + $self->att_stdout($fh_out); + $self->att_stderr($fh_err); } 1; diff --git a/eg/eg-02-encoding.pl b/eg/eg-02-encoding.pl index 6cb28f5..620be42 100644 --- a/eg/eg-02-encoding.pl +++ b/eg/eg-02-encoding.pl @@ -29,13 +29,13 @@ % perl -I../lib eg-02-encoding.pl --- !!perl/hash:Reflex::Decoder::Line messages: - - !!perl/hash:Reflex::Codec::Message::Stream - is_combinable: 1 - octets: 'test line onetest line twotest line threetest line four' - priority: 500 - - !!perl/hash:Reflex::Codec::Message::Eof - is_combinable: 0 - priority: 500 + - !!perl/hash:Reflex::Codec::Message::Stream + is_combinable: 1 + octets: 'test line onetest line twotest line threetest line four' + priority: 500 + - !!perl/hash:Reflex::Codec::Message::Eof + is_combinable: 0 + priority: 500 newline: '' --- !!perl/hash:Reflex::Codec::Message::Datagram is_combinable: 0 diff --git a/eg/eg-41-signal-twice.pl b/eg/eg-41-signal-twice.pl index b70b549..e01135c 100644 --- a/eg/eg-41-signal-twice.pl +++ b/eg/eg-41-signal-twice.pl @@ -11,11 +11,11 @@ eg_say("Process $$ is waiting for SIGUSR1 twice."); my $usr1_a = Reflex::Signal->new( - signal => "USR1", - on_signal => sub { eg_say("Got SIGUSR1 callback.") }, + signal => "USR1", + on_signal => sub { eg_say("Got SIGUSR1 callback.") }, ); my $usr1_b = Reflex::Signal->new( signal => "USR1" ); while ($usr1_b->next()) { - eg_say("Got SIGUSR1 from promise."); + eg_say("Got SIGUSR1 from promise."); } diff --git a/eg/eg-42-reflex-in-poe.pl b/eg/eg-42-reflex-in-poe.pl index 11781ca..3c4fd6c 100644 --- a/eg/eg-42-reflex-in-poe.pl +++ b/eg/eg-42-reflex-in-poe.pl @@ -140,7 +140,7 @@ 17:18 kthakore : dngor: right .. 17:18 kthakore : but how do I plug it into Bot::BasicBot 17:19 dngor : When you get the trigger from Bot::BasicBot, open a - socket, send a request, and wait for a response. + socket, send a request, and wait for a response. 17:19 dngor : You could use IO::Socket::INET and $poe_kernel->select_read(), or something higher level. 17:19 kthakore : http://github.com/PerlGameDev/SDL/blob/master/tools/SDLBot.pl @@ -148,12 +148,12 @@ 17:20 dngor : If the server is localhost, the connect() will tend to pass or fail pretty quickly... unless your firewall is interfering with localhost. So blocking is generally not - a problem. + a problem. 17:20 kthakore : I mean I know BasicBot uses Poe 17:20 dngor : Presumably Bot::BasicBot passes it to you, in the - standard POE way. If not, POE::Kernel exports it. + standard POE way. If not, POE::Kernel exports it. 17:21 dngor : Hm. There's an excellent exercise. Using Reflex INSIDE - POE components. + POE components. 17:21 dngor : Bot::BasicBot + Reflex::Client 17:22 kthakore : dngor: whut is reflex ... and how do I use it? 17:23 dngor : It's neither here nor there. I'm just brainstorming aloud. diff --git a/eg/ttl/Ttl/HexDecoder.pm b/eg/ttl/Ttl/HexDecoder.pm index cb83fbb..d4d4f61 100644 --- a/eg/ttl/Ttl/HexDecoder.pm +++ b/eg/ttl/Ttl/HexDecoder.pm @@ -19,13 +19,13 @@ sub on_my_change { my $self = shift; my $decimal = ( - ($self->ones() || 0) * 1 + - ($self->twos() || 0) * 2 + - ($self->fours() || 0) * 4 + - ($self->eights() || 0) * 8 + ($self->ones() || 0) * 1 + + ($self->twos() || 0) * 2 + + ($self->fours() || 0) * 4 + + ($self->eights() || 0) * 8 ); - $self->out( ("0".."9","a".."f")[$decimal] ); + $self->out( ("0".."9","a".."f")[$decimal] ); } 1; diff --git a/eg/ttl/Ttl/Nand.pm b/eg/ttl/Ttl/Nand.pm index 2d019cf..96fce93 100644 --- a/eg/ttl/Ttl/Nand.pm +++ b/eg/ttl/Ttl/Nand.pm @@ -16,24 +16,24 @@ use Ttl::And; use Reflex::Trait::Watched qw(watches); watches and => ( - isa => 'Ttl::And', - handles => [qw(a b)], + isa => 'Ttl::And', + handles => [qw(a b)], setup => sub { Ttl::And->new() }, ); watches not => ( - isa => 'Ttl::Not', + isa => 'Ttl::Not', setup => sub { Ttl::Not->new() }, ); sub on_and_out { - my ($self, $args) = @_; - $self->not->in($args->{value}); + my ($self, $args) = @_; + $self->not->in($args->{value}); } sub on_not_out { - my ($self, $args) = @_; - $self->out($args->{value}); + my ($self, $args) = @_; + $self->out($args->{value}); } 1; diff --git a/eg/ttl/Ttl/Nor.pm b/eg/ttl/Ttl/Nor.pm index 78a67a7..02c34f9 100644 --- a/eg/ttl/Ttl/Nor.pm +++ b/eg/ttl/Ttl/Nor.pm @@ -20,19 +20,19 @@ watches or => ( isa => 'Ttl::Or', handles => [qw(a b)] ); watches not => ( isa => 'Ttl::Not' ); sub BUILD { - my $self = shift; - $self->or( Ttl::Or->new() ); - $self->not( Ttl::Not->new() ); + my $self = shift; + $self->or( Ttl::Or->new() ); + $self->not( Ttl::Not->new() ); } sub on_or_out { - my ($self, $args) = @_; - $self->not->in($args->{value}); + my ($self, $args) = @_; + $self->not->in($args->{value}); } sub on_not_out { - my ($self, $args) = @_; - $self->out($args->{value}); + my ($self, $args) = @_; + $self->out($args->{value}); } 1; diff --git a/eg/ttl/Ttl/TriAnd.pm b/eg/ttl/Ttl/TriAnd.pm index af02ebe..1812ce8 100644 --- a/eg/ttl/Ttl/TriAnd.pm +++ b/eg/ttl/Ttl/TriAnd.pm @@ -30,19 +30,19 @@ emits out => ( isa => 'Bool' ); sub BUILD { my $self = shift; - $self->and_ab( Ttl::And->new() ); - $self->and_c( Ttl::And->new() ); + $self->and_ab( Ttl::And->new() ); + $self->and_c( Ttl::And->new() ); } sub on_and_ab_out { - my ($self, $args) = @_; - $self->and_c->a($args->{value}); + my ($self, $args) = @_; + $self->and_c->a($args->{value}); } sub on_and_c_out { - my ($self, $args) = @_; + my ($self, $args) = @_; warn $args->{value}; - $self->out($args->{value}); + $self->out($args->{value}); } 1; diff --git a/eg/ttl/Ttl/TriNand.pm b/eg/ttl/Ttl/TriNand.pm index e8f539c..f94a5d8 100644 --- a/eg/ttl/Ttl/TriNand.pm +++ b/eg/ttl/Ttl/TriNand.pm @@ -30,18 +30,18 @@ emits out => ( isa => 'Bool' ); sub BUILD { my $self = shift; - $self->tri_and( Ttl::TriAnd->new() ); - $self->not( Ttl::Not->new() ); + $self->tri_and( Ttl::TriAnd->new() ); + $self->not( Ttl::Not->new() ); } sub on_tri_and_out { - my ($self, $args) = @_; - $self->not->in($args->{value}); + my ($self, $args) = @_; + $self->not->in($args->{value}); } sub on_not_out { - my ($self, $args) = @_; - $self->out($args->{value}); + my ($self, $args) = @_; + $self->out($args->{value}); } 1; diff --git a/lib/Reflex/Callbacks.pm b/lib/Reflex/Callbacks.pm index 708133f..5bb9154 100644 --- a/lib/Reflex/Callbacks.pm +++ b/lib/Reflex/Callbacks.pm @@ -331,7 +331,7 @@ Reflex::Callback::Method to invoke the corresponding object method. my $object = bless {}; my @cbs = cb_object($object, "event"); - # ... is equivalent to: + # ... is equivalent to: use Reflex::Callback::Method; my $object = bless {}; diff --git a/lib/Reflex/Collection.pm b/lib/Reflex/Collection.pm index c429b51..7518de7 100644 --- a/lib/Reflex/Collection.pm +++ b/lib/Reflex/Collection.pm @@ -121,13 +121,13 @@ Reflex::Collection - Autmatically manage a collection of collectible objects ); } - sub broadcast { - my ($self, $message) = @_; + sub broadcast { + my ($self, $message) = @_; - foreach my $handle ($self->get_objects) { - $handle->put($message); - } - } + foreach my $handle ($self->get_objects) { + $handle->put($message); + } + } 1; diff --git a/lib/Reflex/POE/Event.pm b/lib/Reflex/POE/Event.pm index 7726438..615eaa5 100644 --- a/lib/Reflex/POE/Event.pm +++ b/lib/Reflex/POE/Event.pm @@ -64,23 +64,23 @@ This BUILD method is from eg-12-poco-event.pl in Reflex's eg directory. It's for an App (application) class that must request service from a POE component by posting an event. - sub BUILD { - my $self = shift; - $self->component( PoCoEvent->new() ); - - # Make sure it runs within the object's POE::Session. - $self->run_within_session( - sub { - $self->component->request( - Reflex::POE::Event->new( - object => $self, - method => "on_component_result", - context => { cookie => 123 }, - ), - ); - } - ); - } + sub BUILD { + my $self = shift; + $self->component( PoCoEvent->new() ); + + # Make sure it runs within the object's POE::Session. + $self->run_within_session( + sub { + $self->component->request( + Reflex::POE::Event->new( + object => $self, + method => "on_component_result", + context => { cookie => 123 }, + ), + ); + } + ); + } App's constructor runs within its creator's session, which may not be the correct one to be sending the event. run_within_session() diff --git a/lib/Reflex/Role/PidCatcher.pm b/lib/Reflex/Role/PidCatcher.pm index e74f36b..39ab4c6 100644 --- a/lib/Reflex/Role/PidCatcher.pm +++ b/lib/Reflex/Role/PidCatcher.pm @@ -137,8 +137,8 @@ role { unless (scalar keys %$sw) { delete $callbacks{$pid_value}->{$self->session_id()}; delete $callbacks{$pid_value} unless ( - scalar keys %{$callbacks{$pid_value}} - ); + scalar keys %{$callbacks{$pid_value}} + ); $self->$method_pause(); } }; @@ -152,34 +152,34 @@ Reflex::Role::PidCatcher - add async process reaping behavior to a class =head1 SYNOPSIS - package Reflex::PID; - - use Moose; - extends 'Reflex::Base'; - - has pid => ( - is => 'ro', - isa => 'Int', - required => 1, - ); - - has active => ( - is => 'ro', - isa => 'Bool', - default => 1, - ); - - with 'Reflex::Role::PidCatcher' => { - pid => 'pid', - active => 'active', - cb_exit => 'on_exit', - method_start => 'start', - method_stop => 'stop', - method_pause => 'pause', - method_resume => 'resume', - }; - - 1; + package Reflex::PID; + + use Moose; + extends 'Reflex::Base'; + + has pid => ( + is => 'ro', + isa => 'Int', + required => 1, + ); + + has active => ( + is => 'ro', + isa => 'Bool', + default => 1, + ); + + with 'Reflex::Role::PidCatcher' => { + pid => 'pid', + active => 'active', + cb_exit => 'on_exit', + method_start => 'start', + method_stop => 'stop', + method_pause => 'pause', + method_resume => 'resume', + }; + + 1; =head1 DESCRIPTION diff --git a/t/300-run-all-twice.t b/t/300-run-all-twice.t index cdf1bcf..96dcd66 100644 --- a/t/300-run-all-twice.t +++ b/t/300-run-all-twice.t @@ -12,7 +12,7 @@ is => 'rw', isa => 'ScalarRef', ); - + has wheel => ( isa => 'Reflex::POE::Wheel::Run|Undef', is => 'rw',