On Wed, Apr 24, 2002 at 10:40:09AM -0400, Dan McCormick wrote:
> Hi,
> 
> Does anyone have any advice for writing a POE object/session in such a
> way that the main program doesn't need to know all its states?
> 
> The problem is that if you write 20 programs that use one POE
> object/session, and then add an internal, private state to that
> object/session, it won't be able to call it without modifications to all
> 20 programs, assuming you've created the object/session in each of the
> 20 programs like...
> 
> POE::Session->create(
>       object_states => [ ... ]
> );
> 
> It looks like IKC handles this by exporting subroutines that create the
> sessions, which the main programs then call.  Are there any other
> approaches?

I do it the same way.  Basically, write a function that acts as the
Session's constructor or spawner.

If you'd rather have the create() constructor calls in the main
program, you can have your object export a list or hash for the value
of object_states.  The work-around looks like this:

  package Thingy;
  use Exporter;

  my @thingy_states = qw(_start _stop etc and so on);

  use vars qw(ISA EXPORT_OK);
  @ISA = qw(Exporter);
  @EXPORT_OK = qw(@thingy_states);

  ...;

  package main;

  use Thingy qw(@thingy_states);

  POE::Session->create(
    object_states => \@thingy_states,
  );

  ...;

Be sure to update @thingy_states when you change Thingy's states, and
you're all set.

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

Reply via email to