Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 67 lines (54 sloc) 1.284 kB
0d9b0c1 @rcaputo Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
authored
1 #!/usr/bin/env perl
2
b811c71 @rcaputo Give the fourth sortie a new name. It's 53% done now!
authored
3 use warnings;
4 use strict;
9e56da9 @rcaputo Add the examples to the distribution, and ensure they run in their ne…
authored
5 use lib qw(../lib);
b811c71 @rcaputo Give the fourth sortie a new name. It's 53% done now!
authored
6
0d9b0c1 @rcaputo Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
authored
7 # An object's emitted events can also trigger methods in the subclass.
8 # This example is a direct port of eg-04-inheritance.pl, but it uses a
b811c71 @rcaputo Give the fourth sortie a new name. It's 53% done now!
authored
9 # Reflex::UdpPeer object rather than inheriting from that class.
0d9b0c1 @rcaputo Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
authored
10
11 {
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
12 package Reflex::Udp::Echo;
0d9b0c1 @rcaputo Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
authored
13 use Moose;
b811c71 @rcaputo Give the fourth sortie a new name. It's 53% done now!
authored
14 extends 'Reflex::Object';
15 use Reflex::UdpPeer;
0d9b0c1 @rcaputo Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
authored
16
30dfe8c @rcaputo Add a quick round of documentation, and edit some code and examples f…
authored
17 has port => (
18 isa => 'Int',
19 is => 'ro',
0d9b0c1 @rcaputo Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
authored
20 );
21
30dfe8c @rcaputo Add a quick round of documentation, and edit some code and examples f…
authored
22 has peer => (
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
23 isa => 'Maybe[Reflex::UdpPeer]',
30dfe8c @rcaputo Add a quick round of documentation, and edit some code and examples f…
authored
24 is => 'rw',
28ec466 @rcaputo Rename uses of Reflex::Trait::Observer to Reflex::Trait::Observed.
authored
25 traits => ['Reflex::Trait::Observed'],
30dfe8c @rcaputo Add a quick round of documentation, and edit some code and examples f…
authored
26 setup => sub {
27 my $self = shift;
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
28 Reflex::UdpPeer->new(
29 socket => IO::Socket::INET->new(
30 LocalPort => $self->port(),
31 Proto => 'udp',
32 )
33 )
30dfe8c @rcaputo Add a quick round of documentation, and edit some code and examples f…
authored
34 },
35 );
0d9b0c1 @rcaputo Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
authored
36
37 sub on_peer_datagram {
38 my ($self, $args) = @_;
39 my $data = $args->{datagram};
40
41 if ($data =~ /^\s*shutdown\s*$/) {
42 $self->peer(undef);
43 return;
44 }
45
46 $self->peer()->send(
47 datagram => $data,
48 remote_addr => $args->{remote_addr},
49 );
50 }
51
52 sub on_peer_error {
53 my ($self, $args) = @_;
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
54
0d9b0c1 @rcaputo Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
authored
55 warn "$args->{op} error $args->{errnum}: $args->{errstr}";
56 $self->peer(undef);
57 }
58 }
59
b811c71 @rcaputo Give the fourth sortie a new name. It's 53% done now!
authored
60 # Main.
61
7d73cab @rcaputo Replace the God structure of session watchers and observations with
authored
62 my $port = 12345;
08bafbd @rcaputo Massive redoing of Reflex roles and some of the objects that use them.
authored
63 my $peer = Reflex::Udp::Echo->new( port => $port );
7d73cab @rcaputo Replace the God structure of session watchers and observations with
authored
64 print "UDP echo service is listening on port $port.\n";
b811c71 @rcaputo Give the fourth sortie a new name. It's 53% done now!
authored
65 Reflex::Object->run_all();
0d9b0c1 @rcaputo Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
authored
66 exit;
Something went wrong with that request. Please try again.