package Net::IRC3; use strict; use AnyEvent; use IO::Socket::INET; our $ConnectionClass = 'Net::IRC3::Connection'; =head1 NAME Net::IRC3 - An IRC Protocol module which is event system independend =head1 VERSION Version 0.21 =cut our $VERSION = '0.21'; =head1 SYNOPSIS use Net::IRC3; my $irc3 = new Net::IRC3; my $con = $irc3->connect ("test.not.at.irc.net", 6667); ... =head1 DESCRIPTION L itself is a simple building block for an IRC client. It manages connections and parses and constructs IRC messages. L is I simple, if you don't want to care about all the other things that a client still has to do (like replying to PINGs and remembering who is on a channel), I recommend to read the L page instead. Note that this module uses AnyEvent as it's IO event subsystem. You can integrate Net::IRC3 into any application with a event system that AnyEvent has support for (eg. L or L). =head1 METHODS =over 4 =item B This just creates a L object, which is a management class for creating and managing connections. =cut sub new { my $this = shift; my $class = ref($this) || $this; my $self = { }; bless $self, $class; return $self; } =item B Tries to open a socket to the host C<$host> and the port C<$port>. If successfull it will return a L object. If an error occured it will die (use eval to catch the exception). =cut sub connect { my ($self, $host, $port) = @_; defined $self->{connections}->{"$host:$port"} and return; my $sock = IO::Socket::INET->new ( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Blocking => 0 ) or die "couldn't connect to irc server '$host:$port': $!\n";; eval "require $ConnectionClass"; my $con = $ConnectionClass->new ($self, $sock, $host, $port); $con->{rw} = AnyEvent->io (poll => 'r', fh => $sock, cb => sub { my $l = sysread $sock, my $data, 1024; $con->feed_irc_data ($data); unless ($l) { if (defined $l) { $con->disconnect ("EOF from IRC server '$host:$port'"); return; } else { $con->disconnect ("Error while reading from IRC server '$host:$port': $!"); return; } } }); return $con; } =item B Returns a key value list, where the key is C<"$host:$port"> and the value is the connection object. Only 'active' connections are returned. That means, if a connection is terminated somehow, it will also disappear from this list. =cut sub connections { my ($self) = @_; return %{$self->{connections}}; } =item B or B Returns the L object for the C<$host> C<$port> pair. If no such connection exists, undef is returned. =cut sub connection { my ($self, $host, $port) = @_; if ($host =~ m/^[^:]+:(\d+)$/) { return $self->{connections}->{$host} } else { return $self->{connections}->{$host.':'.$port} } } =back =head1 EXAMPLES See the samples/ directory for some examples on how to use Net::IRC3. =head1 AUTHOR Robin Redeker, C<< >> =head1 SEE ALSO L L L RFC 2812 - Internet Relay Chat: Client Protocol =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Net::IRC3 You can also look for information at: =over 4 =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * RT: CPAN's request tracker L =item * Search CPAN L =back =head1 ACKNOWLEDGEMENTS Thanks to Marc Lehmann for the new AnyEvent module! =head1 COPYRIGHT & LICENSE Copyright 2006 Robin Redker, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1;