Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.
Some days I just get mental blocks. I had some ugly code which was trying to test which server I wanted to start and the code was filled with if/elsif/else blocks depending upon the server I wanted to launch. There's something about trying to work with servers and launch new processes which causes me to forget about robust language design. Then my boss asked my why I was doing it the way I was doing it and it took me a bit to realize I was being foolish. Now, my large, ungainly code has been reduced to this (pared down for readability):
my $command = lc shift @ARGV || '';
unless ( $command =~/^stop|start|restart$/ ) {
die localize("You must specify stop, start, or restart");
}
my $engine = ENGINE_CLASS; # loaded elsewhere
eval "use $engine";
if ( my $error = $@ ) {
die localize("Could not load [_1]: [_2]", $engine, $error);
}
$engine->$command;
Now, each engine class implements its own start, stop, and restart methods and all of the code is much cleaner. It bugs me when I get mental blocks like this.
classic Design Pattern (Score:1)
Re:classic Design Pattern (Score:1)
Re:classic Design Pattern (Score:2)
The localization is done via an in house module which subclasses from Locale::MakeText [cpan.org]. As for the "pattern", I was thinking more of the classic refactoring pattern of exchanging conditionals for polymorphism.
Regexp sillyness (Score:2)
You forgot to group the alternatives. Now you're saying "If this command starts with "stop", contains "start" or ends with "restart" (which also contains "start", BTW), then everything is alright.
To fix it:
Re:Regexp sillyness (Score:2)
Oh, sheesh. You're right. I feel silly and thanks for the catch :)