Mojo-IRC

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

# NAME

Mojo::IRC - IRC Client for the Mojo IOLoop

# VERSION

0.46

# SYNOPSIS

    my $irc = Mojo::IRC->new(
                nick => 'test123',
                user => 'my name',
                server => 'irc.perl.org:6667',
              );

    $irc->on(irc_join => sub {
      my($self, $message) = @_;
      warn "yay! i joined $message->{params}[0]";
    });

    $irc->on(irc_privmsg => sub {
      my($self, $message) = @_;
      say $message->{prefix}, " said: ", $message->{params}[1];
    });

    $irc->connect(sub {
      my($irc, $err) = @_;
      return warn $err if $err;
      $irc->write(join => '#mojo');
    });

    Mojo::IOLoop->start;

# DESCRIPTION

[Mojo::IRC](https://metacpan.org/pod/Mojo%3A%3AIRC) is a non-blocking IRC client using [Mojo::IOLoop](https://metacpan.org/pod/Mojo%3A%3AIOLoop) from the
wonderful [Mojolicious](https://metacpan.org/pod/Mojolicious) framework.

It features IPv6 and TLS, with additional optional modules:
[IO::Socket::IP](https://metacpan.org/pod/IO%3A%3ASocket%3A%3AIP) and [IO::Socket::SSL](https://metacpan.org/pod/IO%3A%3ASocket%3A%3ASSL).

By default this module will only emit standard IRC events, but by
settings ["parser"](#parser) to a custom object it will also emit CTCP events.
Example:

    my $irc = Mojo::IRC->new;
    $irc->parser(Parse::IRC->new(ctcp => 1);
    $irc->on(ctcp_action => sub {
      # ...
    });

It will also set up some default events: ["ctcp\_ping"](#ctcp_ping), ["ctcp\_time"](#ctcp_time),
and ["ctcp\_version"](#ctcp_version).

This class inherits from [Mojo::EventEmitter](https://metacpan.org/pod/Mojo%3A%3AEventEmitter).

# TESTING

The module [Test::Mojo::IRC](https://metacpan.org/pod/Test%3A%3AMojo%3A%3AIRC) is useful if you want to write tests without
having a running IRC server.

[MOJO\_IRC\_OFFLINE](https://metacpan.org/pod/MOJO_IRC_OFFLINE) (from v0.20) is now DEPRECATED in favor of
[Test::Mojo::IRC](https://metacpan.org/pod/Test%3A%3AMojo%3A%3AIRC).

# EVENTS

## close

    $self->on(close => sub { my ($self) = @_; });

Emitted once the connection to the server closes.

## error

    $self->on(error => sub { my ($self, $err) = @_; });

Emitted once the stream emits an error.

## message

    $self->on(message => sub { my ($self, $msg) = @_; });

Emitted when a new IRC message arrives. Will dispatch to a default handler,
which will again emit ["err\_event\_name"](#err_event_name) ["ctcp\_event\_name"](#ctcp_event_name) and
["irc\_event\_name"](#irc_event_name) below.

Here is an example `$msg`:

    {
      command  => "PRIVMSG",
      event    => "privmsg",
      params   => ["#convos", "hey!"],
      prefix   => "jan_henning",
      raw_line => ":jan_henning PRIVMSG #convos :hey",
    }

## err\_event\_name

Events that start with "err\_" are emitted when there is an IRC response that
indicates an error. See [Mojo::IRC::Events](https://metacpan.org/pod/Mojo%3A%3AIRC%3A%3AEvents) for sample events.



( run in 2.792 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )