drewhead has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to be able to write an IRC bot using Net::IRC. The event framework of this module looks interesting and playing around with it a tad has shown it to be rather straight forward. However, my primary goal of the bot is to announce to a channel when a certian action happens in a third perl program that is runing as a daemon.

I am considering doing this through a socket with IO:Socket. From the Net::IRC documentation I think I should be able so simply create my socket

my $server = IO::Socket::INET->new( LocalPort => $listen_port, Blocking => 0, Listen => 5 ) or croak $@;
pass it to the addfh method (after creating my $irc object of course)
$irc->addfh($server, \&from_socket, "r" );
And then have &from_socket invoked everytime some data is written to the socket from my third parties' client connection (which likely will hold the socket open for weeks writing 20-40 times per day).

My problem is that I don't know what &from_socket should look like and have been unable to find any example code in the src, goole, SuperSearch. I've played with this off and on for a week and tried so many things I'm coding in circles now. I either seem to block or be unable to retrieve the data from the client.

Does anyone use addfh and have example code that they would be willing to share? Am I barking up the wrong tree and need to investigate another suggested plan of attack? Thanks Monks.

Replies are listed 'Best First'.
Re: Using addfh in Net::IRC with a socket (use POE instead)
by grinder (Bishop) on Oct 07, 2003 at 20:51 UTC

    I do have some code lying around that is based on Net::IRC. It was pretty nifty, based on coderefs. The code had a certain amount of introspection and if it saw that any of its source files had changed, it would reload them on the fly. If any of the code had problems, it could revert back to the previous version.

    I could dig it out if you're really stuck, but the general concensus these days is that IRC bots are better written using POE. The best plan of attack would probably be to investigate POE::Component::IRC.