Hi all.

I would desperately love to use POE. All of the introductory material makes it sound like just the sort of thing I need.

A bit of background. I'm writing a simple IRC chatbot script as a favor to a friend, and as a learning experience. The requirements are simple - get a bot into a channel and have it react appropriately to private messages. Also, we want to be able to run more than one bot at a time.

Originally, I did a multi-threading script which works fairly well. However, I'm having trouble with keeping the bot up in the channel. I'm currently using Net::IRC, which is no longer supported. It has trouble connecting to a server, and drops connections after a few hours. POE seems to have a thriving community, and my friend, after asking around on mailing lists and in IRC, got a lot of suggestions for POE::Component::IRC.

So: CPAN -- install POE, et al.

The limited documentation at CPAN (which is, according to poe.perl.org, the best place to look for documentation) was enough for me to get a simple script up and running. The system seems fairly intuitive, and some copy and modifying of Randal Shwartz' example code helped to get me started.

Now, I want to be able to read in an XML configuration file for my bots. CPAN -- install POE::Filter::XML. Check out the POD. To the author's credit, he does admit that the documentation is as clear as mud. Does anyone have any working example code to get a document tree from an XML file with this module? :) The example in the synopsis of the module's POD does not work, and an hour or so of playing around with it hasn't gotten me any closer. I've tried to figure out what Wheels do, especially ReadWrite, mostly by poring through the source, but I just don't have my brain around the system enough to be able to figure it out.

Is there documentation out there that I'm missing? I find it hard to believe that such a useful system could have so little documentation. I'm sure I've missed a link on poe.perl.org. Could someone point me in the right direction.

Here's what I've got so far:

======================================================================================
use strict;
use warnings;

use POE qw(Component::IRC Filter::XML);

my $sConfigPath = shift || "chatbot.xml";

POE::Session->new
   (
   main => [ qw(_start _stop input_event) ],
   );

POE::Kernel->run();
exit;

sub _start
   {
   print "starting...\n";

open(XML, $sConfigPath) || die("Can't open config file (looking for $sConfigPath): $!");

   my $fltXML = POE::Filter::XML->new();

my $whlXML = POE::Wheel::ReadWrite->new
(
Handle => \*XML, # this isn't in POE::Filter::XML POD, but Wheel complains if it isn't here (which, after all makes sense, otherwise, what are you parsing?)
Filter => $fltXML, # verbatim (almost) from Filter::XML
InputEvent => 'input_event', # verbatim (almost) from Filter::XML
);


   close XML; # is this the place to do this?
   }

sub _stop
   {
   print "done\n";
   }

sub input_event
{
print "got an input event!"; # assuming later we'll shift() interesting things off of @_ or something
}


======================================================================================

Output from this script looks like this:
======================================================================================
C:\perl>perl chatbot.pl
starting...
done
<rc> LOOP VECTOR LEAK: MODE_RD = 00010000
!!! Leaked fileno: 3 (total refcnt=2)
!!!     Read:
!!!             refcnt  = 1
!!!             ev cnt  = 0
!!!             session = POE::Session=ARRAY(0x1ba1b88)
!!!                     handle  = GLOB(0x1a6b724)
!!!                     session = POE::Session=ARRAY(0x1ba1b88)
!!!                     event   = POE::Wheel::ReadWrite(2) -> select read
!!!     Write:
!!!             refcnt  = 1
!!!             ev cnt  = 0
!!!             session = POE::Session=ARRAY(0x1ba1b88)
!!!                     handle  = GLOB(0x1a6b724)
!!!                     session = POE::Session=ARRAY(0x1ba1b88)
!!!                     event   = POE::Wheel::ReadWrite(2) -> select write
!!!     Exception:
!!!             refcnt  = 0
!!!             ev cnt  = 0
======================================================================================
It blocks after printing "done"

The !!! stuff gets printed after <ctrl-C>

Observant readers will now understand I'm on a Windows maching, 2k to be precise. Perl is 5.8.3. I won't include -V output here, but will send it later, if that seems necessary.

Ok, I think I've used enough bandwidth for now.

Thanks for the help.


-- Aaron Craig BID s.n.c. tel: +39 329 714 1865 fax: +39 055 202 0503 email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>


The miserable have no other medicine but only hope. -- Measure for Measure



Reply via email to