Net::Async::IRC::Protocol - send and receive IRC messages
Net::Async::IRC::Protocol
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 Net::Async::IRC::Protocol object. 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.
IO::Async::Protocol::LineStream
The following named parameters may be passed to new or configure:
new
configure
A CODE reference to the generic message handler; see MESSAGE HANDLING below.
MESSAGE HANDLING
Any parameter whose name starts with on_message_ can be installed as a handler for a specific message, in preference to the generic handler. See MESSAGE HANDLING.
on_message_
Amount of quiet time, in seconds, after a message is received from the peer, until a PING will be sent to check it is still alive.
PING
Timeout, in seconds, after sending a PING message, to wait for a PONG response.
PONG
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 PING message.
$on_pong_reply->( $irc, $lag )
Where $lag is the response time in (fractional) seconds.
$lag
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 is_loggedin method.
is_loggedin
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 Protocol::IRC::Message object.
Protocol::IRC::Message
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.
send_ctcp
The following methods are controlled by the server information given in the ISUPPORT settings.
ISUPPORT
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 PREFIX (e.g. @%+)
PREFIX
@%+
The flag characters from PREFIX (e.g. ohv)
ohv
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 CHANMODES;
CHANMODES
[ $listmodes, $argmodes, $argsetmodes, $boolmodes ]
True if the CASEMAPPING parameter is not ascii; i.e. it is some form of RFC 1459 mapping
CASEMAPPING
ascii
True if the CASEMAPPING parameter is exactly strict-rfc1459
strict-rfc1459
Returns an item of information from the server's 005 ISUPPORT lines. Traditionally IRC servers use all-capital names for keys.
005 ISUPPORT
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.
sort()
Similar to cmp_prefix_flags, but compares channel occupant MODE command flags.
cmp_prefix_flags
MODE
Converts a channel occupant MODE flag (such as o) into a name prefix flag (such as @).
o
@
The inverse of prefix_mode2flag.
prefix_mode2flag
Returns the $name, folded in case according to the server's CASEMAPPING ISUPPORT. Such a folded name will compare using eq according to whether the server would consider it the same name.
$name
eq
Useful for use in hash keys or similar.
Returns channel if the given name matches the pattern of names allowed for channels according to the server's CHANTYPES ISUPPORT. Returns user if not.
channel
CHANTYPES
user
Returns the current nick in use by the connection.
Returns the current nick in use by the connection, folded by casefold_name for convenience.
casefold_name
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:
COMMAND
A CODE ref in a parameter called on_message_COMMAND
on_message_COMMAND
$on_message_COMMAND->( $irc, $message, \%hints )
A method called on_message_COMMAND
$irc->on_message_COMMAND( $message, \%hints )
A CODE ref in a parameter called on_message
on_message
$on_message->( $irc, 'COMMAND', $message, \%hints )
A method called on_message
$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 Protocol::IRC::Message prefix_split method.
prefix_split
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.
named_args
If the message type defines a target_name:
target_name
target_type => STRING
Either channel or user, as returned by classify_name.
classify_name
target_is_me => BOOL
True if the target name is a user and refers to this connection.
Finally, any key whose name ends in _nick or _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..
_nick
_name
_folded
Because NOTICE and PRIVMSG are so similar, they are handled together by synthesized events called text, ctcp and 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.
NOTICE
PRIVMSG
text
ctcp
ctcpreply
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 PRIVMSG, 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 target_type key.
is_notice
target_name_folded
target_type
For the 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.
target_is_me
For the channel target type, it will contain a restriction key containing the channel message restriction, if present.
restriction
For normal text messages, it will contain a key text containing the actual message text.
For either CTCP message type, it will contain keys ctcp_verb and 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 ctcp or ctcpreply.
ctcp_verb
ctcp_args
VERB
CTCP
A CODE ref in a parameter called on_message_CTCP_VERB
on_message_CTCP_VERB
$on_message_CTCP_VERB->( $irc, $message, \%hints )
A method called on_message_CTCP_VERB
$irc->on_message_CTCP_VERB( $message, \%hints )
A CODE ref in a parameter called on_message_CTCP
on_message_CTCP
$on_message_CTCP->( $irc, 'VERB', $message, \%hints )
A method called on_message_CTCP
$irc->on_message_CTCP( 'VERB', $message, \%hintss )
$on_message->( $irc, 'CTCP VERB', $message, \%hints )
$irc->on_message( 'CTCP VERB', $message, \%hints )
Paul Evans <leonerd@leonerd.org.uk>
To install Net::Async::IRC, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Async::IRC
CPAN shell
perl -MCPAN -e shell install Net::Async::IRC
For more information on module installation, please visit the detailed CPAN module installation guide.