Plugin in Perl - buddy status

Gabor Szabo szabgab at gmail.com
Sun Mar 13 05:19:24 EDT 2011


Hi,

I hope the dev list is where I am supposed to ask
plugin development related questions. If not please,
direct me to the right place.

I am trying to write a plugin in Perl and have certain issues.
After some fight I managed to compile and setup Pidgin and
added a perl plugin.


I have two gmail accounts. One (szabgab.other) was added to Pidgin.
With the other one (szabgab) I am logged in to Gmail.
When I launch pidgin, after a while I see the icon next to my "buddy"
turn to green circle indicating it is online. Still the following code keeps
telling me the buddy is off-line.
I even tried to browse away from my gmail account and back again.
That changed the icon but the perl script kept telling me offline.

Any idea what am I doing incorrectly and how can I make this work?

#!/usr/bin/perl
use strict;
use warnings;
use 5.010;

# run the following before launching the script or pidgin:
# export LD_PRELOAD='/opt/pidgin/lib/libpurple.so
/opt/pidgin/lib/purple-2/perl.so'

use lib '/opt/pidgin/lib/purple-2/perl';

use Purple;

our %PLUGIN_INFO = (
    perl_api_version => 2,
    name => "Perl Test Plugin",
    version => "0.1",
    summary => "Test plugin for the Perl interpreter.",
    description => "Your description here",
    author => "John H. Kelm <johnhkelm\@gmail.com",
    url => "http://pidgin.im",
    load => "plugin_load",
#    unload => "plugin_unload"
#    plugin_action_sub => 'plugin_action_cb',
);

sub plugin_init {
    my $plugin = shift;
    say "plugin_init";
    return %PLUGIN_INFO;
}

sub timeout_cb {
    my $plugin = shift;
    say "timeout $plugin " . time;
    send_message();

    return 1;
}

sub send_message {

    my $account_name = 'szabgab.other at gmail.com/Home';
    my $protocol = 'prpl-jabber';
    my $acc = Purple::Accounts::find($account_name, $protocol);

    return if not $acc->is_connected;

    my $buddy = Purple::Find::buddy($acc, "szabgab");
    my $pres = $buddy->get_presence;
    my $online = $pres->is_online;
    say $online ? "online" : "offline";

    return 1;
}

sub plugin_load {
    my $plugin = shift;
    say "plugin_load";
    Purple::timeout_add($plugin, 2, \&timeout_cb, $plugin);

    return;
}



regards
   Gabor
http://szabgab.com/




More information about the Devel mailing list