What is POE in the first place?
If you've been following perl.com lately I'm sure you've seen the article there about it. If not I'll quote from the introduction to POE article by Dennis Taylor with Jeff Goff.
"POE is a framework for building Perl programs that lends itself naturally to tasks which involve reacting to external data, such as network
communications or user interfaces. Programs written in POE are completely non-linear; you set up a bunch of small subroutines and define how they all call each other, and POE will automatically
switch between them while it's handling your program's input and output."
POE provides us with a tremendous
amount of power. We can create multiple "sessions" with it, which is similar to threading. It allows us to use Components which can do anything from pull HTTP pages to get on IRC.
P::C::I (as it's referred to in short) is a POE Component. POE Components are essentially preprogrammed sessions that can be controlled by other sessions. In the case of POE::Component::IRC we can connect to an IRC server. In many ways a P::C::I program is similar to a Net::IRC based program which Sandy told you about tonight. And in fact both modules are written by Dennis Taylor and a lot of the code of P::C::I was recycled from Net::IRC!
Why use P::C::I then?
There are several reasons why P::C::I should be preferred over the Net::IRC module.
- My personal top issue with Net::IRC is that it is not taint safe. By that you can not run Perl in Taint mode. I personally feel that any network program should be written in Taint mode. It forces me to think about what I'm doing and what type of input should be allowed. This thought can help ensure the security of your program. Which considering recent events on IRC isn't a bad idea. For those wondering why Net::IRC isn't taint safe it's because it uses the Sys::Hostname module
which is not taint safe. And if you try writing
a Net::IRC program with Taint mode you'll get an unusual message that says that it can't get your host name.
- It's no longer being updated/maintained. Dennis Taylor is spending his time updating P::C::I not Net::IRC. P::C::I was last updated on the January 14th, 2001. Not very long ago. While Net::IRC was last updated on May 29, 2000. Almost a year old.
- It's possible to create sub modules under P::C::I that will automatically do some or all of the work of writing
the program. CPAN already has one such module POE::Component::IRC::Onjoin, which in 3 lines of code allows you to setup a bot that tells people a message on joining a channel.
- Complex bot features like querying web sites for information on someone saying something. Take for instance the foreign exchange features of the infobots that given an amount and a currency
and the currency you want to convert to will tell you at the current exchange rates. Normally, you have to be careful not to block your IRC I/O while you are doing the web query. Because then you might cause your bot to be disconnected or at a minimum to be unresponsive. POE handles this for you. Rather than having to fork processes and use IPC to communicate. POE does that for you. It makes it very easy to add these features.
Why wouldn't you want to use P::C::I
- POE can be difficult to learn. It is a different paradigm since the program is not procedural.
- It's new so it could have bugs in it. I found a serious one myself that has since been fixed.
- There's a limited amount of sample code out there and the documentation isn't the greatest. Fortunately, it does come with a sample program.
Demo LiMuBai If Possible
LiMuBai is the bot that I've been writing
in P::C::I. A copy of the current source is viewable here.
If time allows...
P.S. I know this is rather rough and unpolished. I threw this together with 2 days notice.