Samn has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: Net::AIM
by tachyon (Chancellor) on May 10, 2002 at 01:20 UTC

    First here is some debugging code:

    #!/usr/bin/perl -w use CGI; use CGI::Carp qw(fatalsToBrowser); use lib '/home/samn/cgi-bin/lib/'; use Net::AIM; use Data::Dumper; # preove that the module is listening ;-) # print "Content-type: text/html\n\nNet::AIM Version: ", $Net::AIM::VE +RSION; # exit; $aim = new Net::AIM; $conn = $aim->newconn(Screenname => 'Robotskull', Password => 'passwor +d'); # check our objects using Data::Dumper (need to escape HTML, pre tag e +tc) #$q = new CGI; #my $data = Dumper ($aim , $conn); #$data = $q->escapeHTML($data); #print $q->header, "<pre>$data</pre>"; #exit; $conn->set_handler('im_in',\&on_im); $aim->start; sub on_im { my ($self, $event) = @_; my ($nick) = $event->from; print $event->dump; my @args = $event->args; $self->send_im($nick, "Hi $nick. You said: $args[2]"); }

    Note as I suggested you only need to use lib '/home/samn/cgi-bin/lib/' although you can be more explicit you don't need to be as @INC contains . /lib/site_perl/5.6.0 and /site/lib/site_perl/5.6.0 and will check all those paths. See my A Guide to Installing Modules tutorial for details.

    Uncomment the debugging code one bit at a time. The first bit proves you have the module as it can find the $VERSION but as I explained we know that because the error message comes from the module.

    Next uncomment the Dumper part

    Note that while $aim looks like an object $conn does not. It looks like a 1 to me. Hmmm methinks error in the newconn() method.

    Go to the newconn() sub in Net::AIM

    Note that instead of returning $conn it returns 1. This is a bug in the software and I have no idea how the author could have failed to notice because the module will not work until you fix it.

    Patch the sub like this:

    sub newconn { my $self = shift; my $conn = $self->{_conn} = Net::AIM::Connection->new($self, @_); return undef if $conn->error; # return 1; # bzzt, we need to return the object return $conn; }

    GOK if the rest of it works, it now hangs for me with no errors which I guess is good given the lack of code. Note that contrary to the advice above Net::AIM uses Net::AIM::Connection so you don't need to access it directly as suggested.

    Finally email the author with the patch being as rude as you feel like (depends if the rest of it works :-)

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Net::AIM
by JayBonci (Curate) on May 10, 2002 at 00:04 UTC
    There is no set_handler object in Net::AIM, but there is in Net::Aim::Connection. I haven't tested your code out, but that seems like a good place to start.
    use Net::AIM::Connection; my $conn = new Net::AIM::Connection({Screenname => 'Robotskull', Passw +ord => 'password'});
    Happy Hunting!

        --jb
    <rb> Update: Oops. Scratch that. Ignore me, this is wrong. Well we all make mistakes. Thanks for the tip tachyon.

      This is wrong. Consider this standard code:

      require LWP::UserAgent; $ua = LWP::UserAgent->new; $request = HTTP::Request->new('GET', 'file://localhost/etc/motd'); $response = $ua->request($request); # or

      How can we use HTTP::Request and the new method in it? - because LWP::UserAgent used it for us making it available.

      For the actual problem, how I found it, and how to fix it see below.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Net::AIM Can't call method 'set_handler'
by newrisedesigns (Curate) on May 10, 2002 at 19:40 UTC

    Try this first:

    $aim = new Net::AIM; $aim->debug(1); $aim->newconn( Screenname => $screenname, Password => $password ) or d +ie "Can't connect to AIM server.\n"; my $conn = $aim->getconn();

    Then go ahead with:

    $conn->set_handler('config', \&on_config); $conn->set_handler('im_in', \&on_im); $conn->set_handler('error', \&on_error); $conn->set_handler('eviled', \&on_evil); $aim->start;

    I'm pretty sure you must make "newconn" then "getconn".

    Also, in my scratchpad, there's a good template for building a AIM interface.

    Hope this helps.

    John J Reiser
    newrisedesigns.com