Subject: | Improved clarity in ex/serial_watcher.pl |
The example serves to introduce MX::POE to the new user. In it,
attributes and their builders are shown, and then LATER, the events
referenced in the builders are set.
The attached patch re-orders the event declarations to immediately
follow the place where they're first mentioned (e.g. InputHandler =>
"got_console" is followed by event got_console). This follows the
principal of least surprise, and groups relevant info together.
Subject: | reordered.patch |
--- serial_orig/serial_watcher.pl 2009-06-26 08:35:13.000000000 -0700
+++ serial_watcher.pl 2009-08-18 19:57:34.000000000 -0700
@@ -65,6 +65,22 @@
);
}
+event got_port => sub { # wheel gave us some data:
+ my ( $self, $data ) = @_; # [OBJECT, ARG0];
+ $self->console->put($data);
+};
+
+event got_error => sub {
+ my ( $self, @args) = @_; # [OBJECT, ARG0...$#_ ];
+
+ $self->console->put("$args[0] error $args[1]: $args[2]");
+ $self->console->put("Bye!");
+
+ $self->clear_device;
+ $self->clear_console;
+
+};
+
has console => (
is => 'ro',
isa => 'POE::Wheel::ReadLine',
@@ -78,19 +94,6 @@
POE::Wheel::ReadLine->new( InputEvent => "got_console" );
}
-sub START {
- my $self = shift;
-
- # make sure our wheels are started up *in the session*
- $self->device;
- $self->console;
-}
-
-event got_port => sub { # wheel gave us some data:
- my ( $self, $data ) = @_; # [OBJECT, ARG0];
- $self->console->put($data);
-};
-
event got_console => sub {
my ( $self, $input ) = @_; # [OBJECT, ARG0];
if ( defined $input ) {
@@ -111,16 +114,13 @@
$self->clear_console;
};
-event got_error => sub {
- my ( $self, @args) = @_; # [OBJECT, ARG0...$#_ ];
-
- $self->console->put("$args[0] error $args[1]: $args[2]");
- $self->console->put("Bye!");
-
- $self->clear_device;
- $self->clear_console;
+sub START {
+ my $self = shift;
-};
+ # make sure our wheels are started up *in the session*
+ $self->device;
+ $self->console;
+}
no MooseX::POE;