|
|
| There's more than one way to do things | |
| PerlMonks |
RE (tilly) 1: OO vs. procedural styleby tilly (Archbishop) |
| on Aug 19, 2000 at 14:35 UTC ( [id://28638]=note: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.
The trick that CGI uses is all in the following sub:
They preprocess the args to every function this way, and as long as the first arg is 'CGI' or an object that inherits from CGI they leave the arguments alone. Otherwise they prepend a global to the list. This is nice but imposes quite a bit of overhead. Another way of doing the same thing is to make the procedural interface be in a different package, and have a well thought-out AUTOLOAD sub that creates needed procedural wrappers at run-time. More complex but probably more efficient than what CGI does. Another solution that I have used is to think functionally. There you actually have your error handler be an anon sub. By default it is your default, but it can be anything you want. In this case you would leave your package alone and in your CGI script say: If $handler is left alone, well you get the default. But anyone who wants can change it. I have often found that this functional approach is a more efficient way to implement optional hooks. YMMV.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||