Net::Async::IRC::Protocol - send and receive IRC messages
This subclass of IO::Async::Protocol::LineStream implements an established IRC connection that has already completed its inital login sequence and is ready to send and receive IRC messages. It handles base message sending and receiving, and implements ping timers.
Objects of this type would not normally be constructed directly. For IRC clients, see Net::Async::IRC which is a subclass of it. All the events, parameters, and methods documented below are relevant there.
Returns a new instance of a
This object represents a IRC connection to a peer.
As it is a subclass of
IO::Async::Protocol::LineStream its constructor takes any arguments for that class,
in addition to the parameters named below.
The following named parameters may be passed to
A CODE reference to the generic message handler; see
MESSAGE HANDLING below.
Any parameter whose name starts with
on_message_ can be installed as a handler for a specific message,
in preference to the generic handler.
Amount of quiet time,
after a message is received from the peer,
PING will be sent to check it is still alive.
after sending a
to wait for a
A CODE reference to invoke if the peer fails to respond to a
PING message within the given timeout.
$on_ping_timeout->( $irc )
A CODE reference to invoke when the peer successfully sends a
PONG in response of a
$on_pong_reply->( $irc, $lag )
$lag is the response time in (fractional) seconds.
If supplied, sets an encoding to use to encode outgoing messages and decode incoming messages.
Returns true if a connection to the peer is established. Note that even after a successful connection, the connection may not yet logged in to. See also the
Returns true if the full login sequence has been performed on the connection and it is ready to use.
Sends a message to the peer from the given
Sends a message to the peer directly from the given arguments.
Shortcut to sending a CTCP message. Sends a PRIVMSG to the given target, containing the given verb and argument string.
Shortcut to sending a CTCP reply. As
send_ctcp but using a NOTICE instead.
The following methods are controlled by the server information given in the
As well as the actual
ISUPPORT values set by the server, a number of derived values are also calculated. Their names are all lowercase and contain underscores, to distinguish them from the uppercase names without underscores that the server usually sets.
The mode characters from
The flag characters from
A precompiled regexp that matches any of the prefix flags
A map from mode characters to flag characters
A map from flag characters to mode characters
A 4-element array containing the split portions of
[ $listmodes, $argmodes, $argsetmodes, $boolmodes ]
True if the
CASEMAPPING parameter is not
ascii; i.e. it is some form of RFC 1459 mapping
True if the
CASEMAPPING parameter is exactly
Returns an item of information from the server's
005 ISUPPORT lines. Traditionally IRC servers use all-capital names for keys.
Compares two channel occupant prefix flags, and returns a signed integer to indicate which of them has higher priviledge, according to the server's ISUPPORT declaration. Suitable for use in a
sort() function or similar.
cmp_prefix_flags, but compares channel occupant
MODE command flags.
Converts a channel occupant
MODE flag (such as
o) into a name prefix flag (such as
The inverse of
$name, folded in case according to the server's
ISUPPORT. Such a folded name will compare using
eq according to whether the server would consider it the same name.
Useful for use in hash keys or similar.
channel if the given name matches the pattern of names allowed for channels according to the server's
user if not.
Returns the current nick in use by the connection.
Returns the current nick in use by the connection, folded by
casefold_name for convenience.
Returns true if the given nick refers to that in use by the connection.
Every incoming message causes a sequence of message handling to occur. First, the message is parsed, and a hash of data about it is created; this is called the hints hash. The message and this hash are then passed down a sequence of potential handlers.
Each handler indicates by return value, whether it considers the message to have been handled. Processing of the message is not interrupted the first time a handler declares to have handled a message. Instead, the hints hash is marked to say it has been handled. Later handlers can still inspect the message or its hints, using this information to decide if they wish to take further action.
A message with a command of
COMMAND will try handlers in following places:
$on_message_COMMAND->( $irc, $message, \%hints )
$irc->on_message_COMMAND( $message, \%hints )
$on_message->( $irc, 'COMMAND', $message, \%hints )
$irc->on_message( 'COMMAND', $message, \%hints )
Certain commands are handled internally by methods on the base
Net::Async::IRC::Protocol class itself. These may cause other hints hash keys to be created, or to invoke other handler methods. These are documented below.
The following keys will be present in any message hint hash:
Initially false. Will be set to true the first time a handler returns a true value.
Values split from the message prefix; see the
Usually the prefix nick, or the hostname in case the nick isn't defined (usually on server messages).
True if the nick mentioned in the prefix refers to this connection.
Added to this set, will be all the values returned by the message's
named_args method. Some of these values may cause yet more values to be generated.
If the message type defines a
user, as returned by
True if the target name is a user and refers to this connection.
Finally, any key whose name ends in
_name will have a corresponding key added with
_folded suffixed on its name, containing the value casefolded using
casefold_name. This is for the convenience of string comparisons, hash keys, etc..
PRIVMSG are so similar, they are handled together by synthesized events called
ctcpreply. Depending on the contents of the text, and whether it was supplied in a
PRIVMSG or a
NOTICE, one of these three events will be created.
In all cases, the hints hash will contain a
is_notice key being true or false, depending on whether the original messages was a
NOTICE or a
target_name key containing the message target name, a case-folded version of the name in a
target_name_folded key, and a classification of the target type in a
user target type, it will contain a boolean in
target_is_me to indicate if the target of the message is the user represented by this connection.
channel target type, it will contain a
restriction key containing the channel message restriction, if present.
text messages, it will contain a key
text containing the actual message text.
For either CTCP message type, it will contain keys
ctcp_args with the parsed message. The
ctcp_verb will contain the first space-separated token, and
ctcp_args will be a string containing the rest of the line, otherwise unmodified. This type of message is also subject to a special stage of handler dispatch, involving the CTCP verb string. For messages with
VERB as the verb, the following are tried.
CTCP may stand for either
$on_message_CTCP_VERB->( $irc, $message, \%hints )
$irc->on_message_CTCP_VERB( $message, \%hints )
$on_message_CTCP->( $irc, 'VERB', $message, \%hints )
$irc->on_message_CTCP( 'VERB', $message, \%hintss )
$on_message->( $irc, 'CTCP VERB', $message, \%hints )
$irc->on_message( 'CTCP VERB', $message, \%hints )
Paul Evans <email@example.com>