Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: OT: Design question

by Joost (Canon)
on Sep 30, 2004 at 18:33 UTC ( [id://395443]=note: print w/replies, xml ) Need Help??


in reply to Re^2: OT: Design question
in thread OT: Design question

Ok, well in that case you could have a Handler::Colors that has returns those 80 objects from its new() method (though I would probably call it something else, then, like init()):

package Handler::Colors; use YAML qw(Load); # or some other module to handle config-like files # set up a bunch of event handlers that # send email depending on colour sub init { my $colors = Load('/color/config'); my @handlers; while (my ($color,$email) = each %$colors) { @handlers = Handler::Colors->new( { color => $color, email => $email } ); } return @handlers; #update: added this line! } # create handler object sub new { my $class = shift; return bless { @_ },$class; } # check for my color and send email if found. sub handle { my ($self,$event) = @_; if ($self->{color} eq $event->color()) { send_mail($self->{email}); } }
updated: added return @handlers line

update2: To clarify: this code plugs into the code in my post above, so you can have more of these classes for each different type of action you need to perform. All that's changed there is that the

push @event_handlers,"Handler::$_";
line needs to be replaced by
push @event_handlers,"Handler::$_"->init();

Replies are listed 'Best First'.
Re^4: OT: Design question
by dragonchild (Archbishop) on Sep 30, 2004 at 19:05 UTC
    Ok. That's the design twist I was looking for - different config files for each kind of event handler. THANK YOU! :-)

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://395443]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-25 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found