My Advice to Anyone Working with Net::Jabber
Posted on August 30th, 2004
Lately I've been doing some work with Perl and PubSub. One of the ways PubSub can deliver messages about new content is over XMPP (details are available) -- actually XMPP with some extra stuff mixed in. I went with Perl because the Net::Jabber module available from CPAN is really extensive, and seems to be under relatively active development unlike other libraries that were all the rage in 2002. But underneath it all, XMPP is just XML. Don't do what I did, and forget that building an application that understands XMPP is really an application that reads XML.
To some extent that distinction shouldn't matter, because Net::Jabber should take care of all the XML-related details and free you up to think about higher-level problems. Not quite, at least not yet. It's the documentation that's the problem. I'm not especially fond of Net::Jabber's documentation because it's the kind of thing you have to read a dozen or more times before it makes sense. It's mostly documentation about what, with relatively little in the how or why departments. Once you understand what's going on it's not so bad. A prime example of that is Net::Jabber's support for namespaces. In theory, it should be possible to build arbitrary IQ and message blocks however suits you, following the outline for the DefineNamespace method specified in Net::Jabber's documentation. But there's not much sample code to show you the way. When you're in a situation like that, what do you do?
I took the stubborn approach and willed myself to make it work. Many hours later, it still did not. I started to think Net::Jabber was crap. Then I started reading the O'Reilly book on Perl and XML. Then I read about Twig. Then I started using Twig where I had previously been trying to shoehorn Net::Jabber's DefineNamespace method. It worked. I was happy.
My application is still using Net::Jabber for the really Jabber-based parts like logging into the server, authenticating, and responding to the presence of others. If you're looking at doing something with Jabber in Perl, draw a line there and handle everything that comes after as what it really is-- XML.