creating new events without catching through POE::Component::Client::TCP?

2003-06-13 Thread Bruno Boettcher
Hello!

again i am stuck in a surely trivial and stupid problem, showing again
that i didn't understand a single thing about POE

(thus the general POE questions at the end of this mail, you might want
 ot jump directly there searching for 'GENERAL QUESTIONS')

anyways...

i am trying to move a service actually based on a script run amidst
xchat to a client server type setup (that's why i needed the ssl
layer...)

actually it works without the ssl stuff since i decided to continue
setting the thing up without that lib, to see if its possible to get it
actually working...

i took the client server example from the cook book and began to extend
it... worked quite nicely until i decided to integrade a Term::ReadLine
to the client...

the first thing i noticed was that it completely blocked the POE
system... thus i tryed to get it running through the event system of
POE

for this i created a new class, which starts an own session (listening
to 'shell' events) and starting on the runShell event a new
instance of Term::ReadLine 

unfortunately that event is gobbled up somewhere by some other
session i suppose the POE::Component::Client::TCP thing is
responsible for that...

i have put the stuff up on http://bboett.dyndns.org/~bboett/leve.tgz

the interesting parts are: POE::Component::Leve::leveShell
and search for runShell (3 occurences: set up of the session, sending
the runshell event, and the actual thing that set ups the shell)

the thing gots called from patternQuery.pl, CTOR of
POE::Component::Client::TCP under the event Connected (shell-init)

to start the whole system, run in one shell patternServer.pl, in another
patternQuery.pl (that's the client...)

so if someone could be kind enough and look through my messed up code
and tell my what's going wrong, why and how to correct it...


GENERAL QUESTIONS:

This shuffled up again the fact that i still have problems understanding
POE


- i have several objects, they might start up their own sessions, since
POE is somehow a global thing, i need to call the kernel run method only
once somewhere, right?

- events are generated and distributed randlomly to the listeners, once
one listener claims the event, it isn't propsed to the other sessions,
  right? or is there some sort of telling that the events should be
  proposed also to the other sessions?

- to the above question addendum, i didn't get the difference between
post and signal, when should i use which one? in all the code i see only
the use of post, never signal, should i use signal this time??

- sessions like the TCP stuff and the IRC module register an alias iwth
which it is possible to get it later on globally from the heap, how do i
setup such a mechanism? alias isn't a recognized var of session?

- i have a job that is returning only when the wholething closes down
(= a shell) with very slow input (a human user) that qualifies as a long
running task...  actually i run it inside a POE event handler, but
should i use the ::Run object instead? do i cause some havoc somewhere
by blocking the return of that event processing or doesn't it matter??

if you got this far, my gratefulness and sympathy, ethernal adoration to
you if you manage to help me on that :D 
sorry for the long post...
and if stuff isn't very clear: please keep in mind that i am not a
native english speaker


  
-- 
ciao bboett
==
[EMAIL PROTECTED]
http://inforezo.u-strasbg.fr/~bboett
===


Re: creating new events without catching through POE::Component::Client::TCP?

2003-06-13 Thread Rocco Caputo
On Fri, Jun 13, 2003 at 04:19:57PM +0200, Bruno Boettcher wrote:
 Hello!
 
 again i am stuck in a surely trivial and stupid problem, showing again
 that i didn't understand a single thing about POE

[...]

 unfortunately that event is gobbled up somewhere by some other
 session i suppose the POE::Component::Client::TCP thing is
 responsible for that...

If messages are being sent but not received, you can easily find them
by setting POE::Kernel::ASSERT_EVENTS, like so:

  sub POE::Kernel::ASSERT_EVENTS () { 1 }
  use POE;

It's important to set ASSERT_EVENTS before using POE.pm (or POE::Kernel)
so that the module will see the value when it loads.

[...]

 GENERAL QUESTIONS:
 
 This shuffled up again the fact that i still have problems understanding
 POE

Also see http://poe.perl.org/?POE_Documentation/Beginners_Guide

 - i have several objects, they might start up their own sessions, since
 POE is somehow a global thing, i need to call the kernel run method only
 once somewhere, right?

Yes.  I usually call POE::Kernel-run() after setting up the initial
objects for a program.  Several of my bot programs look like this:

  #!/usr/bin/perl -w
  # $Id: pastebot.perl,v 1.4 2003/02/03 04:50:17 rcaputo Exp $

  use strict;

  use POE;
  use Server::Web;
  use Client::IRC;

  $poe_kernel-run();
  exit 0;

Server::Web and Client::IRC read configuration options and create their
objects and sessions.  The configuration includes aliases for each
module, and the modules are designed to talk to each-other using those
aliases.

It's an interesting way to write programs, and I need to document it,
but the programs themselves are very bad examples of coding style.

 - events are generated and distributed randlomly to the listeners, once
 one listener claims the event, it isn't propsed to the other sessions,
   right? or is there some sort of telling that the events should be
   proposed also to the other sessions?

The English of this question is very bad.  Because I can't quite
understand it, I will answer every question I think it may be.

Events are generated as real-world things happen.  This file has input
waiting.  At the event, the time will be 16:00 UTC.  The user is
vainly attempting to suspend the program with ^Z.  This child process
has closed its output filehandles.

Events also are generated when you call POE::Kernel's post(), yield(),
or signal() methods.

The post() method sends events to a session.  That session may be
different from the one that calls post().

The yield() method sends events to the session that called it.

Events are queued very deterministically.  They are stored in what is
essentially an array, in due-time order.  Alarms and delays are usually
due in the future, so they reside later in the queue.  Events
representing immediate conditions are enqueued for time(), so they
happen in more-or-less FIFO (first in, first out) order.

 - to the above question addendum, i didn't get the difference between
 post and signal, when should i use which one? in all the code i see only
 the use of post, never signal, should i use signal this time??

The signal() call is for simulating signals without using kill() or
involving the operating system.

Signals are broadcast to every session that has used sig() to listen for
them.  Currently they are also broadcast to every other session, under
the _signal event, but that is deprecated and will go away soon.

Signals may be used to broadcast one event to many sessions at once.
Posted events are more point-to-point.

 - sessions like the TCP stuff and the IRC module register an alias iwth
 which it is possible to get it later on globally from the heap, how do i
 setup such a mechanism? alias isn't a recognized var of session?

Aliases are not stored in the heap.  You may retrieve the aliases for a
session with $kernel-alias_list($session) but there isn't a global
registry of them.

It's assumed that you assigned the aliases to ecah session, so you know
what they are.

 - i have a job that is returning only when the wholething closes down
 (= a shell) with very slow input (a human user) that qualifies as a long
 running task...  actually i run it inside a POE event handler, but
 should i use the ::Run object instead? do i cause some havoc somewhere
 by blocking the return of that event processing or doesn't it matter??

You should use POE::Wheel::ReadLine or Term::Visual.  Both work without
blocking your program.  Term::Visual is especially nice.

-- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/


Re: creating new events without catching through POE::Component::Client::TCP?

2003-06-13 Thread Rocco Caputo
On Fri, Jun 13, 2003 at 06:40:07PM +0200, Bruno Boettcher wrote:
 On Fri, Jun 13, 2003 at 11:22:44AM -0400, Rocco Caputo wrote:
  If messages are being sent but not received, you can easily find them
  by setting POE::Kernel::ASSERT_EVENTS, like so:
  
sub POE::Kernel::ASSERT_EVENTS () { 1 }
use POE;
  
  It's important to set ASSERT_EVENTS before using POE.pm (or POE::Kernel)
  so that the module will see the value when it loads.
 uhm what's that supposed to do? doens't change anything in my script?

It makes the attempted delivery of a message to a non-existent session
an error.

You may also want to set $session-option(default = 1) in your
sessions, to make the attempt to deliver a message to a non-existent
handler an error.

  Server::Web and Client::IRC read configuration options and create their
  objects and sessions.  The configuration includes aliases for each
  module, and the modules are designed to talk to each-other using those
  aliases.
 and how do you set up those aliases?

Either through Alias parameters for component constructors or by calling
$kernel-alias_set(alias) in _start.

[...]

  It's assumed that you assigned the aliases to ecah session, so you know
  what they are.
 ??? when i try to add an Alias = somename to the create method of
 session, i get a compile error?

See above.

  You should use POE::Wheel::ReadLine or Term::Visual.  Both work without
  blocking your program.  Term::Visual is especially nice.
 ok! switched to POE::Wheel::ReadLine (installed by default...)
 
 in the meantime another problem arouse
 
 the heap is different for each session, right?
 now, i have on one side a TCP connection and on another a session with
 the shell implementation that needs to send the info through that
 pipe... is it safe to exchange the ref to the server ?

It is possible, but it is not very safe.  If you do not clean up
session references properly, your program will leak memory (and probably
other things).

It's better to pass around $session-ID instead.  These are like weak
session references.  You can use them as destinations for post() and
other things.

 hmmm now on:
 my $task = POE::Wheel::Run-new
   (·
 »···   #Program = runShell(@_),
 »···   #Program = runShell,
 »···   Program = POE::Component::Leve::leveShell::runShell,

You are saying that the Program is the return value of the function
POE::Component::Leve::leveShell::runShell().  Really you want it to be a
reference to the function:

  Program = \runShell,
  Program = \POE::Component::Leve::leveShell::runShell,

 and how do i pass the runshell call its args? i need the usual
 @_[OBJECT, KERNEL etc] input

The child program is not run like the rest of POE.  It is called only
once, with the parameters given in POE::Wheel::Run's ProgramArgs, and
the child process will exit when it returns.

-- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/


Re: creating new events without catching through POE::Component::Client::TCP?

2003-06-13 Thread Bruno Boettcher
On Fri, Jun 13, 2003 at 06:40:07PM +0200, Bruno Boettcher wrote:
 »···   #program = runshell,
  ok.. silly me found out myself that i was lacking a \ 

  hmmm so far so good...
  but now the progeam issues a prompt, and blocks irremediably after the
  first char typed in.

  besides the POE::Wheel::ReadLine syntax is quite strange...

  there's a $heap-{wheel} = POE::Wheel::ReadLine-new( InputEvent =
  got_input );

  no package name, no object name. i am unsure if this will call the
  correct method...

  later on in the manpage is defined:
  sub got_input_handler

  different name but as it seems that's what it expected?
  i did the same thing... in one method i instantiated the shell object,
  and my object possesses the got_input_handler method

  at least there's no error message at compile time...

  but due to the readline the output to the console is strange, seems as
  if the carriage return codes are swallowed some where elaving a
  staircase effect to the prints

  anyway, how do i debug this now that it comes to a grinding halt? no
  error messages nothing... i have no idea where it blocks now... :(

-- 
ciao bboett
==
[EMAIL PROTECTED]
http://inforezo.u-strasbg.fr/~bboett
===


Re: creating new events without catching through POE::Component::Client::TCP?

2003-06-13 Thread Bruno Boettcher
On Fri, Jun 13, 2003 at 01:03:59PM -0400, Rocco Caputo wrote:
 It makes the attempted delivery of a message to a non-existent session
 an error.
ok! hmm but since the messages are caught, there's no error...

 You may also want to set $session-option(default = 1) in your
 sessions, to make the attempt to deliver a message to a non-existent
 handler an error.
ok!

 Either through Alias parameters for component constructors or by calling
 $kernel-alias_set(alias) in _start.
argh.. sorry... read that indeed somewhere...

 It is possible, but it is not very safe.  If you do not clean up
 session references properly, your program will leak memory (and probably
 other things).
awww uncool...

 It's better to pass around $session-ID instead.  These are like weak
 session references.  You can use them as destinations for post() and
 other things.
ok! also for the TCP intrinseque put method? those methods doesn't seem
to be attached as session methods... anyway will give it a try...

ok, since i passed on to use a POE readline i dropped the run stuff
still 

the whole thing stops as soon as i type in the first char
in case someone want's to give this mess a look:
http://bboett.dyndns.org/~bboett/leve.tgz

-- 
ciao bboett
==
[EMAIL PROTECTED]
http://inforezo.u-strasbg.fr/~bboett
===


definitely a POE::Wheel::ReadLine understanding problem....

2003-06-13 Thread Bruno Boettcher
ok,
  sorry bothering so much and beeing too dumb as it seems

  just to test (and maybe that would be a better code snippet (once
commented..) for the man page script is at the bottom of this
  mail...

set up the smallest possible sample program that uses readline...

but here too, as soon as i run it, it blocks on the first char i type...
  so seems i missed something somewhere

this example is surely easier to parse than the other stuff...

- cut here  readLine.pl --
#!/usr/bin/perl

use warnings;
use strict;

use POE;
use POE::Filter::Reference;
use POE::Wheel::ReadLine;

POE::Session-create( 
  #Alias = leveShell,
  inline_states =
  {  _start = \_start,
  _stop  = \_stop,
  got_input  = \got_input_handler,
  },

);
$poe_kernel-run();
# Input handler.  If $input is defined, then it contains a line of
# input.  Otherwise $exception contains a word describing some kind
# of user exception.  Currently these are 'interrupt' and 'cancel'.
sub got_input_handler {
  my ($heap, $input, $exception) = @_[HEAP, ARG0, ARG1];
  if (defined $input) {
$heap-{wheel}-addhistory($input);
$heap-{wheel}-put(\tGot: $input);
$heap-{wheel}-get('Prompt: '); # get another line
  }
  else {
$heap-{wheel}-put(\tException: $exception);
  }
}


##
=pod

=item start of the poe session


=cut

##
sub _start 
{
  my ($this, $kernel, $heap, $dsn, $queries,$session) = @_[OBJECT, KERNEL, HEAP, ARG0, 
ARG1,SESSION];
  $kernel-alias_set(leveShell);
# Create the wheel.
  $heap-{wheel} = POE::Wheel::ReadLine-new( InputEvent = got_input );

# Trigger the wheel to read a line of input.
  $heap-{wheel}-get( 'Prompt: ' );

}#sub _start
##
=pod

=item stop of the poe session


=cut

##
sub _stop 
{
  my ($this, $kernel, $heap) = @_[OBJECT, KERNEL, HEAP];
# Clear the terminal.
  $heap-{wheel}-clear();
}#sub _stop 
- cut here  --


-- 
ciao bboett
==
[EMAIL PROTECTED]
http://inforezo.u-strasbg.fr/~bboett
===


RE: definitely a POE::Wheel::ReadLine understanding problem....

2003-06-13 Thread Erick Calder
Bruno,

just as a side comment, the

inline_states = { method = \method }

can also be expressed as:

package_states = [ method ]

which allows for something like:

package_states = [ qw/_start _stop got_input/ ]

-Original Message-
From: Bruno Boettcher [mailto:[EMAIL PROTECTED]
Sent: Friday, June 13, 2003 11:01 AM
To: [EMAIL PROTECTED]
Subject: definitely a POE::Wheel::ReadLine understanding problem


ok,
  sorry bothering so much and beeing too dumb as it seems

  just to test (and maybe that would be a better code snippet (once
commented..) for the man page script is at the bottom of this
  mail...

set up the smallest possible sample program that uses readline...

but here too, as soon as i run it, it blocks on the first char i type...
  so seems i missed something somewhere

this example is surely easier to parse than the other stuff...

- cut here  readLine.pl --
#!/usr/bin/perl

use warnings;
use strict;

use POE;
use POE::Filter::Reference;
use POE::Wheel::ReadLine;

POE::Session-create(
  #Alias = leveShell,
  inline_states =
  {  _start = \_start,
  _stop  = \_stop,
  got_input  = \got_input_handler,
  },

);
$poe_kernel-run();
# Input handler.  If $input is defined, then it contains a line of
# input.  Otherwise $exception contains a word describing some kind
# of user exception.  Currently these are 'interrupt' and 'cancel'.
sub got_input_handler {
  my ($heap, $input, $exception) = @_[HEAP, ARG0, ARG1];
  if (defined $input) {
$heap-{wheel}-addhistory($input);
$heap-{wheel}-put(\tGot: $input);
$heap-{wheel}-get('Prompt: '); # get another line
  }
  else {
$heap-{wheel}-put(\tException: $exception);
  }
}



##
=pod

=item start of the poe session


=cut

##
sub _start
{
  my ($this, $kernel, $heap, $dsn, $queries,$session) = @_[OBJECT, KERNEL,
HEAP, ARG0, ARG1,SESSION];
  $kernel-alias_set(leveShell);
# Create the wheel.
  $heap-{wheel} = POE::Wheel::ReadLine-new( InputEvent = got_input );

# Trigger the wheel to read a line of input.
  $heap-{wheel}-get( 'Prompt: ' );

}#sub _start

##
=pod

=item stop of the poe session


=cut

##
sub _stop
{
  my ($this, $kernel, $heap) = @_[OBJECT, KERNEL, HEAP];
# Clear the terminal.
  $heap-{wheel}-clear();
}#sub _stop
- cut here  --


--
ciao bboett
==
[EMAIL PROTECTED]
http://inforezo.u-strasbg.fr/~bboett
===