Personally creating a class would be my method of choice.
Depending on how you read them, plain config files can lead to all sorts of messy namespace pollution with incautious Exporting. Keeping things in a class tightens things up a bit and keeps it all clean. Much easier to keep things under the obligatory use strict as well :)
| [reply] [d/l] [select] |
| [reply] |
And what is the naughties way of dealing with config files?
Tongue in cheek: clearly it must be XML-derived, have well-defined DTDs, written up as a RFC, have provable and hashed content to avoid contaminations, and signed by a trusted certificate authority. Being able to fetch an initial local config from an https repository is a plus.
I think things are often over-designed, even in the Perl world. Think of effective design, not capable design.
It's not bad to use something simple and "old-fashioned" that works, as long as you isolate your design decisions so they can be improved later. Keep a mind on the possible security implications (such as how someone can inject new code into a string that gets eval treatment).
P.S. -- this is my 600th post on perlmonks.org
-- [ e d @ h a l l e y . c c ]
| [reply] [d/l] |
If you can trust your users (or if you can trust them to secure their machines properly), a clean way to do this is to let your application have a "plugins" directory full of simple Perl modules all adhering to a common interface, and then require each of these modules. Each plugin module could have a method called "make_callback" (or equivalent), and they would be all properly namespaced and sorted.
Then you will need some way to instantiate them and add them to a list of active plugins, but this should be left as an exercise to the reader (it's simple enough).
But in general, unless you are writing something like the GIMP or PhotoShop or an Application Server, it might be best to not have users write code to modify the way your program works. Depends what you are doing, of course, there may be moer usable/friendly ways. Meanwhile, if I'm installing a Wiki or something, I have no problem editing perl config files, it's just horrific if you mess one up because you'd get a syntax error or some obscure runtime error rather than the application telling you what's up as part of a config file verification process. So avoid making users write code if you can help it (some don't even know what '$' means!)
| [reply] |