Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 65 lines (53 sloc) 1.261 kb
0d9b0c15 »
2009-08-11 Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
1 #!/usr/bin/env perl
2
b811c714 »
2009-09-20 Give the fourth sortie a new name. It's 53% done now!
3 use warnings;
4 use strict;
9e56da91 »
2009-09-23 Add the examples to the distribution, and ensure they run in their ne…
5 use lib qw(../lib);
b811c714 »
2009-09-20 Give the fourth sortie a new name. It's 53% done now!
6
0d9b0c15 »
2009-08-11 Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
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
b811c714 »
2009-09-20 Give the fourth sortie a new name. It's 53% done now!
9 # Reflex::UdpPeer object rather than inheriting from that class.
0d9b0c15 »
2009-08-11 Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
10
11 {
08bafbd2 »
2010-06-26 Massive redoing of Reflex roles and some of the objects that use them.
12 package Reflex::Udp::Echo;
0d9b0c15 »
2009-08-11 Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
13 use Moose;
1f5ed273 »
2010-06-27 Rename Reflex::Role::Object to Reflex::Role::Reactive; Reflex::Object…
14 extends 'Reflex::Base';
b811c714 »
2009-09-20 Give the fourth sortie a new name. It's 53% done now!
15 use Reflex::UdpPeer;
6eae87cc »
2010-09-06 Add "emits" and "observes" attribute declarations.
16 use Reflex::Trait::Observed qw(observes);
0d9b0c15 »
2009-08-11 Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
17
30dfe8c3 »
2009-09-23 Add a quick round of documentation, and edit some code and examples f…
18 has port => (
19 isa => 'Int',
20 is => 'ro',
0d9b0c15 »
2009-08-11 Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
21 );
22
6eae87cc »
2010-09-06 Add "emits" and "observes" attribute declarations.
23 observes peer => (
08bafbd2 »
2010-06-26 Massive redoing of Reflex roles and some of the objects that use them.
24 isa => 'Maybe[Reflex::UdpPeer]',
30dfe8c3 »
2009-09-23 Add a quick round of documentation, and edit some code and examples f…
25 setup => sub {
26 my $self = shift;
08bafbd2 »
2010-06-26 Massive redoing of Reflex roles and some of the objects that use them.
27 Reflex::UdpPeer->new(
28 socket => IO::Socket::INET->new(
29 LocalPort => $self->port(),
30 Proto => 'udp',
31 )
32 )
30dfe8c3 »
2009-09-23 Add a quick round of documentation, and edit some code and examples f…
33 },
34 );
0d9b0c15 »
2009-08-11 Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
35
36 sub on_peer_datagram {
37 my ($self, $args) = @_;
38 my $data = $args->{datagram};
39
40 if ($data =~ /^\s*shutdown\s*$/) {
41 $self->peer(undef);
42 return;
43 }
44
45 $self->peer()->send(
46 datagram => $data,
47 remote_addr => $args->{remote_addr},
48 );
49 }
50
51 sub on_peer_error {
52 my ($self, $args) = @_;
08bafbd2 »
2010-06-26 Massive redoing of Reflex roles and some of the objects that use them.
53
0d9b0c15 »
2009-08-11 Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
54 warn "$args->{op} error $args->{errnum}: $args->{errstr}";
55 $self->peer(undef);
56 }
57 }
58
b811c714 »
2009-09-20 Give the fourth sortie a new name. It's 53% done now!
59 # Main.
60
7d73cabc »
2009-08-13 Replace the God structure of session watchers and observations with
61 my $port = 12345;
08bafbd2 »
2010-06-26 Massive redoing of Reflex roles and some of the objects that use them.
62 my $peer = Reflex::Udp::Echo->new( port => $port );
7d73cabc »
2009-08-13 Replace the God structure of session watchers and observations with
63 print "UDP echo service is listening on port $port.\n";
1f5ed273 »
2010-06-27 Rename Reflex::Role::Object to Reflex::Role::Reactive; Reflex::Object…
64 Reflex->run_all();
0d9b0c15 »
2009-08-11 Create a compositional verson of eg-04-inheritance.pl, and debug Stag…
65 exit;
Something went wrong with that request. Please try again.