dear Monks, once again I am in need of your infinite wisdom.
This is not so much a matter of not knowing how to do something, but more of how to do it properly from an OO point of view.
The situation is as follows: I'm writing a module that will allow the creation of 1 or more irc connections. I've decided to treat the connections themselves as the objects, and all the data and settings as properties of that specific object. So far so good. For each connection the calling script uses the ->new method, and as many connections as desired can be created, and the proper references are returned in classic OO fashion.
But it is at this point that my troubles begin. The very nature of such an irc connection requires a continuous loop. The easy solution is to simply keep an internal array of all the objects, and loop through them one at a time, directing data in and out as required, but somehow this approach *feels* wrong, not properly OO. What I'm doing right now is allow the calling script to call ->run directly on an object, meaning that irc connection gets placed in a loop, data flows happily in both ways, but any other connections just sit there and eventually perish, since from the moment the loop starts, the script is effectively frozen.
From what I can see, I have 3 options at this point:
- to make 1 global run method that kicks all connections into gear using an internal array of connections. it feels wrong somehow, but it does work. obviously this would have to be the last command in the calling script, since it's an endless loop.
- to make a run method that is not a loop, but instead handles all the buffered data at that time, and that's it. this would mean that the responsibility of looping through each of the connections again and again lies with the calling script. doesn't feel right somehow either.
- to somehow split off the connection once ->run has been called, perhaps even into a separate process(no idea how to do that, any tips would be greatly appreciated), thereby allowing the calling script to continue and eventually even finish.
Any pe(a)rls of wisdom thrown my way will be mightily appreciated.
Don't forget Rule One...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.