On Sun, Mar 24, 2002 at 04:49:09PM -0800, Jason W. May wrote:
> Forgot to mention - I did get Spread::Session working with POE, and
> have included an example with the distribution.  However, it uses the
> Event.pm compatibility feature of POE.  I'd prefer a pure-POE implementation;
> if anyone can provide some pointers for this (should this be a Wheel?) I'd
> appreciate it.

Good morning!

I tried to install Spread::Session, but I've never been able to get
Spread itself working.  However, I did take a look at your POE and
Event examples, and I think I managed to port event.pl to plain POE.

Here's what I wrote.  It's not tested at all, but it should be pretty
straightforward.

-- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sf.net

#!/usr/bin/perl
# Using Spread::Session with POE
#

use warnings;
use strict;

use Spread::Session;
use POE;

use Log::Channel;
enable Log::Channel "Spread::Session";

my $group = shift @ARGV || "example";

POE::Session->create
  ( inline_states =>
    { _start => sub {
        my ($kernel, $heap) = @_[KERNEL, HEAP];

        $heap->{spread} = Spread::Session->new();
        $heap->{spread}->callbacks
          ( message => sub {
              my ($sender, $groups, $message) = @_;

              print "THE SENDER IS $sender\n";
              print "GROUPS: [", join(",", @$groups), "]\n";
              print "MESSAGE:\n", $message, "\n\n";

              $session->publish($sender, "the response!");
            },
          );
        $heap->{spread}->subscribe($group);

        # $kernel->select_read( $heap->{spread}->{MAILBOX} ); to stop.
        $kernel->select_read( $heap->{spread}->{MAILBOX}, "read_spread" );

        # $kernel->delay( "timer_spread" ); to stop the timer.
        $kernel->delay( timer_spread => 5 );
      },

      read_spread => sub {
        my $heap = $_[HEAP];
        $heap->{spread}->receive(0);
      },

      timer_spread => sub {
        print STDERR "(5 second timer)\n";
        $_[KERNEL]->delay( timer_spread => 5 );
      },
    }
  );

$poe_kernel->run();

Reply via email to