|No such thing as a small change|
Bundling unrelated classesby redlemon (Hermit)
|on Dec 18, 2004 at 14:25 UTC||Need Help??|
redlemon has asked for the
wisdom of the Perl Monks concerning the following question:
I don't know whether to post this as a request for wisdom or as a meditation. I chose for the first because it has a question at the end.
Anyway. I'm writing an chatbot. My design is modular: The bot has a connnection (aim/jabber/irc), a config, a brain, a scheduler, events, etc. All based on plugins so I can change parts while it is running.
The problem is that connections are callback based, and each callback only gets the connection object passed to it.
But the brain and the config need to be accessed from the callbacks.
The naive solution is to use globals, but I want to be able to use a test and a production bot at the same time. The other naive solution is to inherit the ChatBot class from Net::OSCAR (which is what I'm using for AIM) and stick the other objects into it. But that makes it hard to have both AIM and Jabber connections at the same time.
Hence I came up with Class::Bundle. The code is not really important here, if someone's interested let me know and I'll post it.
Class::Bundle is to be used as a base class.
So, now the im_in() callback from Net::OSCAR gets the connection object ($oscar) passed to it and I can find my config by doing $oscar->config; and my parent node by $oscar->parent; (or $oscar->whatever_name_I_passed_to_new();) etc.
This means that Class::Bundle is effectively grouping unrelated classes into a cooperating bundle.
Now, for the promised question(s):