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.


In reply to Using addfh in Net::IRC with a socket by drewhead

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.