Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 62 lines (49 sloc) 1.077 kB
78b77ad @rcaputo Convert Stage and UdpPeer into roles, and then compose them into conc…
authored
1 #!/usr/bin/env perl
5b0127b @rcaputo Remove emit() from roles.
authored
2 # vim: ts=2 sw=2 noexpandtab
78b77ad @rcaputo Convert Stage and UdpPeer into roles, and then compose them into conc…
authored
3
b811c71 @rcaputo Give the fourth sortie a new name. It's 53% done now!
authored
4 use warnings;
5 use strict;
9e56da9 @rcaputo Add the examples to the distribution, and ensure they run in their ne…
authored
6 use lib qw(../lib);
b811c71 @rcaputo Give the fourth sortie a new name. It's 53% done now!
authored
7
78b77ad @rcaputo Convert Stage and UdpPeer into roles, and then compose them into conc…
authored
8 # This example creates a UDP echo server using a role rather than
9 # inheritance.
10
11 {
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
12 package Reflex::Udp::Echo;
78b77ad @rcaputo Convert Stage and UdpPeer into roles, and then compose them into conc…
authored
13 use Moose;
1f5ed27 @rcaputo Rename Reflex::Role::Object to Reflex::Role::Reactive; Reflex::Object…
authored
14 extends 'Reflex::Base';
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
15 use IO::Socket::INET;
5b0127b @rcaputo Remove emit() from roles.
authored
16 use Reflex::Callbacks qw(make_error_handler);
78b77ad @rcaputo Convert Stage and UdpPeer into roles, and then compose them into conc…
authored
17
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
18 has socket => (
19 is => 'ro',
20 isa => 'FileHandle',
21 required => 1,
22 );
78b77ad @rcaputo Convert Stage and UdpPeer into roles, and then compose them into conc…
authored
23
5b0127b @rcaputo Remove emit() from roles.
authored
24 has active => (
25 is => 'ro',
26 isa => 'Bool',
27 default => 1,
28 );
29
30 make_error_handler("on_socket_error");
31
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
32 with 'Reflex::Role::Recving' => {
5b0127b @rcaputo Remove emit() from roles.
authored
33 att_handle => 'socket',
34 att_active => 'active',
a19c6c8 @rcaputo Replace -alias/-excludes with the method_send role parameter.
authored
35 method_send => 'send',
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
36 };
37
38 sub on_socket_datagram {
5c57d49 @rcaputo !!! Experiment with Reflex events being objects.
authored
39 my ($self, $datagram) = @_;
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
40
5c57d49 @rcaputo !!! Experiment with Reflex events being objects.
authored
41 if ($datagram->octets() =~ /^\s*shutdown\s*$/) {
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
42 $self->stop_socket_readable();
78b77ad @rcaputo Convert Stage and UdpPeer into roles, and then compose them into conc…
authored
43 return;
44 }
45
5c57d49 @rcaputo !!! Experiment with Reflex events being objects.
authored
46 $self->send($datagram->_body());
78b77ad @rcaputo Convert Stage and UdpPeer into roles, and then compose them into conc…
authored
47 }
48 }
49
b811c71 @rcaputo Give the fourth sortie a new name. It's 53% done now!
authored
50 # Main.
51
7d73cab @rcaputo Replace the God structure of session watchers and observations with
authored
52 my $port = 12345;
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
53 my $peer = Reflex::Udp::Echo->new(
54 socket => IO::Socket::INET->new(
55 LocalPort => $port,
56 Proto => 'udp',
57 )
58 );
7d73cab @rcaputo Replace the God structure of session watchers and observations with
authored
59 print "UDP echo service is listening on port $port.\n";
1f5ed27 @rcaputo Rename Reflex::Role::Object to Reflex::Role::Reactive; Reflex::Object…
authored
60 Reflex->run_all();
78b77ad @rcaputo Convert Stage and UdpPeer into roles, and then compose them into conc…
authored
61 exit;
Something went wrong with that request. Please try again.