billyak has asked for the wisdom of the Perl Monks concerning the following question:
Here is the general idea and the implementation (or my excuse of one).
Monitor port ###
Get packet
Parse packet
Compare packet information with hash (or maybe an external DB later)
** Send packet out, do other things, general action based on packet content
(It looks so much simpler when I type it out ;-)
Thats the goal. So here is the clencher. I want it to be a somewhat modular system for adding new events (at the **'s part.) Right now I've got a Monitor package that I would like to have run things, and a Function package to hold all of the "functions" (the ** code.) Here is some relevant code (constructors and other vital code omitted):
Then I would get packets, loop through the $FUNC keys, applying the regexes and sending the data to the appropriate subs when the regex was a match.my $monitor = new Monitor; $monitor->add_function("3","blah"); package Function; sub blah { if(wantarray){return(qr{blah ?(.+)?})} # Useful code will eventually go here } package Monitor; sub add_function { my($self,$access,$name) = @_; my $ref = \&{"Function::$name"}; my($regexp) = $ref->(); $FUNC{$regexp}{access} = $access; $FUNC{$regexp}{code} = $ref; }
For some reason, I think there is a much better way to do this. The name space is also really messy. Ideally, I'd want several hashes and a few object refs to be globally accessible across packages; no doubt that is an obvious sign of bad code.
Hopefully I have done an adequate job at showing what I am trying to achieve. I would really appreciate any suggestions or comments anyone could contribute. Thanks.
-billyak
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A Not-as-Clumsy OOP Implementation?
by bikeNomad (Priest) on Aug 25, 2001 at 18:46 UTC | |
|
Re: A Not-as-Clumsy OOP Implementation?
by Aighearach (Initiate) on Aug 25, 2001 at 18:49 UTC | |
|
Re: A Not-as-Clumsy OOP Implementation?
by jepri (Parson) on Aug 25, 2001 at 20:54 UTC |