Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Try to resolve on_my_foo not looking right. See eg 35 for newness.

  • Loading branch information...
commit 5c01112efcfeec3e5adead1fa3bb21bb9465e04c 1 parent 6c37951
@rcaputo authored
View
4 eg/eg-04-inheritance.pl
@@ -13,7 +13,7 @@
use Moose;
extends 'Reflex::UdpPeer';
- sub on_my_datagram {
+ sub on_udppeer_datagram {
my ($self, $args) = @_;
my $data = $args->{datagram};
@@ -28,7 +28,7 @@
);
}
- sub on_my_error {
+ sub on_udppeer_error {
my ($self, $args) = @_;
warn "$args->{op} error $args->{errnum}: $args->{errstr}";
$self->destruct();
View
4 eg/eg-06-moose-roles.pl
@@ -14,7 +14,7 @@
extends 'Reflex::Object';
with 'Reflex::Role::UdpPeer';
- sub on_my_datagram {
+ sub on_udppeer_datagram {
my ($self, $args) = @_;
my $data = $args->{datagram};
@@ -29,7 +29,7 @@
);
}
- sub on_my_error {
+ sub on_udppeer_error {
my ($self, $args) = @_;
warn "$args->{op} error $args->{errnum}: $args->{errstr}";
$self->destruct();
View
2  eg/eg-13-irc-bot.pl
@@ -62,7 +62,7 @@
sub on_poco_irc_public {
my ($self, $args) = @_;
- my ($who, $where, $what) = @$args;
+ my ($who, $where, $what) = @$args{0,1,2};
my $nick = (split /!/, $who)[0];
my $channel = $where->[0];
View
2  eg/eg-15-handle.pl
@@ -36,7 +36,7 @@
undef;
};
- sub on_remote_read {
+ sub on_remote_readable {
my ($self, $args) = @_;
my $remote_address = recv(
View
2  eg/eg-16-timer-inheritance.pl
@@ -9,7 +9,7 @@
use Moose;
extends 'Reflex::Timer';
- sub on_my_tick {
+ sub on_timer_tick {
print "tick at ", scalar(localtime), "...\n";
}
}
View
2  eg/eg-17-inheritance-no-moose.pl
@@ -11,7 +11,7 @@
use Reflex::Timer;
use base qw(Reflex::Timer);
- sub on_my_tick {
+ sub on_timer_tick {
print "tick at ", scalar(localtime), "...\n";
}
}
View
16 eg/eg-34-tcp-server-echo.pl
@@ -1,25 +1,25 @@
# A TCP echo server.
# Strawman use cases for Reflex::Stream and Reflex::Listener.
-use lib qw(./lib ../lib);
+use lib qw(../lib);
{
package TcpEchoSession;
use Moose;
extends 'Reflex::Stream';
- sub on_my_stream {
+ sub on_stream_data {
my ($self, $args) = @_;
$self->put($args->{data});
}
- sub on_my_fail {
+ sub on_stream_fail {
my ($self, $args) = @_;
warn "$args->{errfun} error $args->{errnum}: $args->{errstr}\n";
$self->emit( event => "shutdown", args => {} );
}
- sub on_my_close {
+ sub on_stream_close {
my ($self, $args) = @_;
$self->emit( event => "shutdown", args => {} );
}
@@ -38,7 +38,7 @@
default => sub { {} },
);
- sub on_my_accepted {
+ sub on_listener_accepted {
my ($self, $args) = @_;
# TODO - We're developing a pattern here:
@@ -60,7 +60,7 @@
$self->clients()->{$client} = $client;
}
- sub on_my_fail {
+ sub on_listener_fail {
my ($self, $args) = @_;
warn "$args->{errfun} error $args->{errnum}: $args->{errstr}\n";
}
@@ -71,10 +71,12 @@
}
}
+my $port = 12345;
+print "Setting up TCP echo server on localhost:$port...\n";
TcpEchoServer->new(
handle => IO::Socket::INET->new(
LocalAddr => '127.0.0.1',
- LocalPort => 12345,
+ LocalPort => $port,
Listen => 5,
Reuse => 1,
),
View
6 eg/eg-35-tcp-client.pl
@@ -1,19 +1,19 @@
# A TCP echo client.
# Strawman use cases for Reflex::Stream and Reflex::Connector.
-use lib qw(./lib ../lib);
+use lib qw(../lib);
{
package TcpEchoClient;
use Moose;
extends 'Reflex::Client';
- after on_my_connected => sub {
+ after on_connector_connected => sub {
my ($self, $args) = @_;
$self->connection()->put("Hello, world!\n");
};
- sub on_connection_stream {
+ sub on_connection_data {
my ($self, $args) = @_;
# Not chomped.
View
4 lib/Reflex/Client.pm
@@ -22,7 +22,7 @@ has connection => (
traits => ['Reflex::Trait::Observer'],
);
-sub on_my_connected {
+sub on_connector_connected {
my ($self, $args) = @_;
$self->stop();
@@ -35,7 +35,7 @@ sub on_my_connected {
);
}
-sub on_my_fail {
+sub on_connector_fail {
my ($self, $args) = @_;
warn "$args->{errfun} error $args->{errnum}: $args->{errstr}\n";
$self->stop();
View
2  lib/Reflex/Connector.pm
@@ -64,7 +64,7 @@ sub BUILD {
}
}
-sub on_my_writable {
+sub on_handle_writable {
my ($self, $args) = @_;
# Not watching anymore.
View
2  lib/Reflex/Listener.pm
@@ -6,7 +6,7 @@ extends 'Reflex::Handle';
has '+rd' => ( default => 1 );
-sub on_my_readable {
+sub on_handle_readable {
my ($self, $args) = @_;
my $peer = accept(my ($socket), $args->{handle});
View
2  lib/Reflex/POE/Session.pm
@@ -36,7 +36,7 @@ sub deliver {
foreach my $self (values %{$session_id_to_object{$sender_id}}) {
$self->emit(
event => $event,
- args => [ @$args ],
+ args => { map { $_ => $args->[$_] } (0..$#$args) },
);
}
}
View
29 lib/Reflex/Role/Object.pm
@@ -157,10 +157,18 @@ has watched_objects => (
default => sub { {} },
);
-has role => (
- isa => 'Str',
- is => 'ro',
-);
+# TODO - Needs to be class, not object based!
+#has role => (
+# is => 'ro',
+# isa => 'Str',
+# default => sub {
+# my $self = shift;
+# my $role = ref($self);
+# $role =~ s/^Reflex:://;
+# $role =~ tr[a-zA-Z0-9][_]cs;
+# return lc $role;
+# },
+#);
has observers => (
isa => 'ArrayRef',
@@ -349,15 +357,22 @@ sub emit {
# TODO - Needs consideration:
# TODO - Weaken?
# TODO - Underscores for Reflex parameters?
+ # TODO - Must be a hash reference. Would be nice if non-hashref
+ # errors were pushed to the caller.
$callback_args->{_sender} = $self;
# Look for self-handling of the event.
# TODO - can() calls are also candidates for caching.
# (AKA: Cache as cache can()?)
- if ($self->can("on_my_$event")) {
- my $method = "on_my_$event";
- $self->$method($callback_args);
+ my $caller_role = caller();
+ $caller_role =~ s/^Reflex::(?:Role::)?//;
+ $caller_role =~ tr[a-zA-Z0-9][_]cs;
+
+ my $self_method = "on_" . lc($caller_role) . "_" . $event;
+ #warn $self_method;
+ if ($self->can($self_method)) {
+ $self->$self_method($callback_args);
return;
}
View
4 lib/Reflex/Role/UdpPeer.pm
@@ -102,7 +102,7 @@ Reflex::Role::UdpPeer - Turn an object into a UDP network peer.
use Moose;
with 'Reflex::Role::UdpPeer';
- sub on_my_datagram {
+ sub on_udppeer_datagram {
my ($self, $args) = @_;
my $data = $args->{datagram};
@@ -117,7 +117,7 @@ Reflex::Role::UdpPeer - Turn an object into a UDP network peer.
);
}
- sub on_my_error {
+ sub on_udppeer_error {
my ($self, $args) = @_;
warn "$args->{op} error $args->{errnum}: $args->{errstr}";
$self->destruct();
View
6 lib/Reflex/Stream.pm
@@ -61,7 +61,7 @@ sub put {
return;
}
-sub on_my_readable {
+sub on_handle_readable {
my ($self, $args) = @_;
my $in_buffer = "";
@@ -84,7 +84,7 @@ sub on_my_readable {
}
$self->emit(
- event => "stream",
+ event => "data",
args => {
data => $in_buffer
},
@@ -93,7 +93,7 @@ sub on_my_readable {
return;
}
-sub on_my_writable {
+sub on_handle_writable {
my ($self, $args) = @_;
my $out_buffer = $self->out_buffer();
View
4 lib/Reflex/UdpPeer.pm
@@ -23,7 +23,7 @@ Inherit it.
use Moose;
extends 'Reflex::UdpPeer';
- sub on_my_datagram {
+ sub on_udppeer_datagram {
my ($self, $args) = @_;
my $data = $args->{datagram};
@@ -38,7 +38,7 @@ Inherit it.
);
}
- sub on_my_error {
+ sub on_udppeer_error {
my ($self, $args) = @_;
warn "$args->{op} error $args->{errnum}: $args->{errstr}";
$self->destruct();
Please sign in to comment.
Something went wrong with that request. Please try again.