The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


Net::YahooMessenger - Interface to the Yahoo!Messenger IM protocol


        use Net::YahooMessenger;

        my $yahoo = Net::YahooMessenger->new(
                id       => 'your_yahoo_id',
                password => 'your_password',
        $yahoo->login or die "Can't login Yahoo!Messenger";
        $yahoo->send('recipient_yahoo_id', 'Hello World!');



This module is not in active maintenance now. Thus it doesn't play well with recent Yahoo! protocol updates. If you are interested in taking over this module on CPAN, please let me know your CPAN author ID to me at miyagawa[at]


Net::YahooMessenger is a client class for connecting with the Yahoo!Messenger server, and transmitting and receiving a message.

Since implement of a protocol is the result of analyzing and investigating a packet, it has an inadequate place. However, it is working as expected usually.


This section documents method of the Net::YahooMessenger class.


It should be called with following arguments (items with default value are optional):

        id            => yahoo id
        password      => password
        pre_login_url => url which refers to setting information.
        hostname      => server hostname
                         (default '

Returns a blessed instantiation of Net::YahooMessenger.

Note: If you plan to connect with Yahoo!Japan(, it sets up as follows.

        my $yahoo_japan = Net::YahooMessenger->new(
                pre_login_url => '',
                hostname      => '',

Since it connects with Yahoo!(, this procedure is unnecessary in almost all countries.


This method gets or sets the present Yahoo Id.


This method gets or sets the present password.


Call this after new() to logon the Yahoo!Messenger service.

$yahoo->send($yahoo_id, $message)

This method send an Instant-Message $message to the user specified by $yahoo_id. A kanji code is Shift_JIS when including Japanese in $message.

$yahoo->change_state($busy, $status_message)

This method sets the status messages for the current user. 'Status message' is set by $status_message. 'Busy icon' is set by the numerical value of $busy.

The $busy should be called with following arguments:

        0 - I'm Available
        1 - Busy
        2 - Sleep


This method reads the message from a server socket and returns a corresponding Event object. The Event object which will be returned is as follows:

        Net::YahooMessenger::InvalidLogin     - Invalid Login
        Net::YahooMessenger::Login            - Succeeded in Login.
        Net::YahooMessenger::GoesOnline       - Buddy has logged in.
        Net::YahooMessenger::ReceiveMessage   - Message was received.
        Net::YahooMessenger::ChangeState      - Buddy has change status.
        Net::YahooMessenger::GoesOffline      - Buddy logged out.
        Net::YahooMessenger::NewFriendAlert   - New Friend Alert.
        Net::YahooMessenger::UnImplementEvent - Un-implemented event was received.

All event objects have the following attributes:


Yahoo id which invoked the event.


Yahoo id which should receive an event.


The contents of an event. The message and state which were transmitted.


The event number on Yahoo Messenger Protocol.


This method returns a raw server socket. When connection has already ended, the socket is returned, and when not connecting, it connects newly.


This method sets the Event handler for a specific Yahoo!Messenger server event. $event_handler is the sub class of Net::YahooMessenger::EventHandler.

Note: The event which can be overwritten should look at the method signature of Net::YahooMessenger::EventHandler.

$yahoo->add_event_source($file_handle, $code_ref, $flag)

This method adds the file handle (event sauce) to supervise. The file handle to add is specified by $file_handle. The code reference to the processing to perform is specified by $code_ref.

        C<$flag> eq 'r' - set when the file handle to add is an object for read.
        C<$flag> eq 'w' - set when the file handle to add is an object for write.

By adding another handle (for example, STDIN), processing can be performed based on those inputs. Usually, the server socket of 'Yahoo!Messenger server' is set as a candidate for surveillance.

                # The input of STDIN is transmitted to 'EXAMPLE_YAHOO_ID'.
                $yahoo->add_event_source(\*STDIN, sub {
                        my $message = scalar <STDIN>;
                        chomp $message;
                        $yahoo->send('EXAMPLE_YAHOO_ID', $message);
                }, 'r');


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.


Send message

        use Net::YahooMessenger;
        use strict;

        my $yahoo = Net::YahooMessenger->new;
        $yahoo->login or die "Can't login Yahoo!Messenger";

        $yahoo->send('recipient_yahoo_id', 'Hello World!');

Change Status message

        use Net::YahooMessenger;
        use strict;
        use constant IN_BUSY => 1;

        my $yahoo = Net::YahooMessenger->new(
                id       => 'yahoo_id',
                password => 'password',
        $yahoo->login or die "Can't login Yahoo!Messenger";;

        $yahoo->change_state(IN_BUSY, q{I'm very busy now!});
        sleep 5;

Received message output to STDOUT

        use Net::YahooMessenger;
        use strict;

        my $yahoo = Net::YahooMessenger->new(
                id       => 'yahoo_id',
                password => 'password',
        $yahoo->set_event_handler(new ToStdoutEventHandler);
        $yahoo->login or die "Can't login Yahoo!Messenger";

        package ToStdoutEventHandler;
        use base 'Net::YahooMessenger::EventHandler';
        use strict;

        sub ChangeState {}
        sub GoesOffline {}
        sub GoesOnline {}
        sub UnImplementEvent {}

        sub ReceiveMessage
                my $self = shift;
                my $event = shift;
                printf "%s: %s\n", $event->from, $event->body;

Connect to Yahoo!Japan Messege server

        use Net::YahooMessenger;
        use strict;

        my $yahoo = Net::YahooMessenger->new(
                pre_login_url => '',
                hostname      => '',
        $yahoo->login or die "Can't login Yahoo!Messenger";

        $yahoo->send('recipient_yahoo_id', 'Konnitiwa Sekai!');


Hiroyuki OYAMA <>

From October 2003, this module is taken over and maintained by Tatsuhiko Miyagawa ltmiyagawa@bulknews.netgt


<>, <>


Copyright (C) 2001 Hiroyuki OYAMA. Japan. All righits reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itsefl.

Please refer to the use agreement of Yahoo! about use of the Yahoo!Messenger service.