Just a litte fun:

Ok, it needs a lot more, p.e. you could code the reading part in a thread to loose the blocking.

Irc.pm
package Irc; use strict; use warnings; use Carp; use IO::Socket; sub new { my $class = shift; my $server = shift; my $self = { SERVER => $server, MYSOCKET => undef, }; my $closure = sub { my $field = shift; if (@_) { $self->{$field} = shift; } return $self->{$field}; }; bless ($closure, $class); return $closure; } # a public getter for the SERVER variable sub server { &{ $_[0] }("SERVER") } # a private getter/setter for the SOCKET variable sub socket { caller(0) eq __PACKAGE__ || confess "socket is a private method"; &{ $_[0] }( "MYSOCKET", @_[1..$#_] ); } # log on sub connect { my $self = shift; my $socket = IO::Socket::INET->new( $self->server() ); $self->socket($socket); } # logoff sub disconnect { my $self = shift; my $sock = $self->socket; print $sock "exit\r"; close $sock; } # send (and automatically append \r) sub send { my $self = shift; my $text = shift; my $sock = $self->socket; print $text . "\n"; print $sock $text . "\r"; } # receive something from the server sub read { my $self = shift; my $sock = $self->socket; PINGPONG: while (<$sock>) { print "$_"; # break after receiving PING if (/^PING :(.+)\r$/) { $self->send("PONG :$1"); last PINGPONG; } # break after receiving MOTD if (/ 376/) { last PINGPONG; } } } 1;
irc.pl
#!/usr/bin/perl use strict; use warnings; use Irc; my $session = Irc->new("localhost:6667"); $session->connect(); $session->send("nick whatever"); $session->read(); $session->send("user whatever ignored v1.0 :perl hack"); $session->read(); $session->send("join #room1"); # now keep on reading until receiving the special logoff code ;) $session->read(); $session->disconnect();

In reply to Re^3: A Quick OO Module for parsing lines from an IRC connection by gargle
in thread A Quick OO Module for parsing lines from an IRC connection by SoupNazi

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.