http://www.perlmonks.org?node_id=28627

markjugg has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'd like some advice on good perl style. I wrote a module for CGI error handling that I like the functionality of, but I think the interface needs some refinement.

The issue is this: The module needs to have some intelligent defaults, but these can be overridden by a module that calls it. For a given module that calls my error module (let's say Err.pm), it has it's own defaults, which can in turn be overridden a per-script basis.

Right now I have a routine in MyModule.pm which basically collects the values from the calling script, adds in defaults for abstent variables and returns Err::err.pm

It seems like there should be a slicker way than writing this wrapper routine to call the module though. Perhaps there is an answer somewhere in OO I can use?

I'll create some sample peusdo-code here in case someone wants to rework it for an example.

package Err.pm sub err { my %args = ( title =>'Really Bad Error', msg => undef, @_ ); # do something with %args here. } ########### package MyModule.pm; use Err.pm; sub err { my %args = ( title =>'My new default title for MyModule.pm', msg => 'MyModules generic error message', @_ ); return Err::err(%args); } ################## ### my script.cgi package MyModule; do_the_right_thing() || err(title=>'Oops',msg=>'something went wrong') +;

I hope that made sense. Thanks for any suggestions.

-mark