I'm sure I'm missing something simple here, so bare with me.  I realize that 
POE is a multitasking environment, and I realize that this is part of the 
beauty of it, but I can't seem to figure out the best way to utilize this.

Basically, I have a wrapper(sort of) for POE::Component::IRC.  The program has 
a configuration file, using Config::General.  The constructor for my wrapper 
module handles all the needed options, like the server name, port, nick, etc.  
Now, what I need to do is make a connection for each server listed in the 
config file.  Sounds simple enough, right?  I worked out a way to do it using a 
loop and fork, but I'm already daemonizing the process, so that makes things 
seem a bit wonky to me.  I was hoping to do it in a more POE'ish way.  The 
problem is figuring out how to do it.  My code is a bit jacked up right now, 
since I've been trying to make this work, but I'll give you a basic idea:



~code~

    my $conf = Config::General->new("servers.conf");
    my %config = $conf->getall();

    foreach (keys %{$config{server}}) {

    # Where I was using fork(), didn't seem right.
    # my $pid;               
    # if (!($pid = fork)) {

      my $bot = Bot->new(
                             Debug    => 0,
                             Nick     => $config{'server'}{$_}{'nick'},
                             Server   => $_,
                             Pass     => $config{'server'}{$_}{'pass'},
                             Port     => $config{'server'}{$_}{'port'},
                             Username => $config{'server'}{$_}{'username'},
                             Ircname  => $config{'server'}{$_}{'ircname'},
                             Admin    => 'admin',
                             Apass    => 'changeme',
                             Channels => $config{'server'}{$_}{'channel'},
                             LogPath  => $config{'server'}{$_}{'logpath'},
                          );
        $bot->run();     # Actuall calls POE::Session->create()
        $bot->daemon();  # Daemonize

    #}

    }

~/code~

Here's the config file: 

~code~

<server irc.newirc1.org>
  nick poeB
  pass
  port 6667
  username poeB
  ircname poeB
  channel \#test
  logpath /home/mydir/irc1log/
</server>

<server irc.newirc2.org>
  nick poeB
  pass
  port 6667
  username poeB
  ircname poeB
  channel \#test
  logpath /home/mydir/irc2log/
</server>

~/code~

Once again, I'm sure I've overlooked something simple.  If so, break it to me 
easily =).

Thanks,

Ben

Reply via email to