Net::ICQ - Pure Perl interface to an ICQ server
use Net::ICQ;
$icq = Net::ICQ->new($uin, $password);
$icq->connect();
$icq->add_handler('SRV_SYS_DELIVERED_MESS', \&on_msg);
$params = {
'type' => 1,
'text' => 'Hello world',
'receiver_uin' => 1234
};
$icq->send_event('CMD_SEND_MESSAGE', $params);
$icq->start();
Net::ICQ is a class implementing an ICQ client interface
in pure Perl.
All of the following methods are instance methods;
you must call them on a Net::ICQ object (for example, $icq->start).
- connect
Connects the Net::ICQ object to the server.
- disconnect
Disconnects the Net::ICQ object from the server.
- connected
Returns true if the Net::ICQ object is connected to the server,
and false if it is not.
- start
If you're writing a fairly simple application that doesn't need to
interface with other event-loop-based libraries, you can just call
start() to begin communicating with the server.
Note that start() will not return until the Net::ICQ object is
disconnected from the server, either by the server itself or by
your event-handler code calling disconnect().
- do_one_loop
If you don't want to (or can't) call the start() method, you must
continuously call do_one_loop when your Net::ICQ object
is connected to the server. It uses select() to wait for
data from the server and other ICQ clients, so it won't use
CPU power even if you call it in a tight loop. If you need
to do other processing, you could call do_one_loop as
infrequently as once every few seconds.
This method does one processing loop, which involves looking
for incoming data from the network, calling registered event
handlers, sending acknowledgements for received packets,
transmitting outgoing data over the network, and sending
keepalives to the server to tell it that we are still online.
If it is not called often enough, you will not be notified of
incoming events in a timely fashion, or the server might even
think you have disconnected and start to ignore you.
- add_handler(command_number, handler_ref)
Sets the handler function for a specific ICQ server event.
command_number specifies the event to handle. You may use
either the numeric code or the corresponding string code.
See the SERVER EVENTS section below for the numeric and
string codes for all the events, along with descriptions
of each event's function and purpose.
handler_ref is a code ref for the sub that you want to handle
the event. See the HANDLERS section for how a handler works
and what it needs to do.
- send_event(command_number, params)
Sends an event to the server.
command_number specifies the event to be sent. You may use
either the numeric code or the corresponding string code.
See the CLIENT EVENTS section below for the numeric and
string codes for all the events, along with descriptions
of each event's function and purpose.
params is a reference to a hash containing the parameters
for the event. See the CLIENT EVENTS section for an
explanation of the correct parameters for each event.
The parameters list is the second parameter to send_event(),
and it specifies the data for the event. Every event has
its own parameter list, but the general idea is the same.
The parameters list is stored as a hashref, where the hash
contains a key for each parameter. Almost all the events
utilize a regular 1-level hash where the values are plain
scalars, but a few events do require 2-level hash. The
CLIENT EVENT LIST section lists the parameters for every
client event.
For example: to send a normal text message with the text
'Hello world' to UIN 1234, the parameters would
look like this:
{
'type' => 1,
'text' => 'Hello world',
'receiver_uin' => 1234
}
Here is the complete code using send_event() to send the
message 'Hello world' to UIN 1234:
$params = {
'type' => 1,
'text' => 'Hello world',
'receiver_uin' => 1234
};
$icq->send_event('CMD_SEND_MESSAGE', $params);