in reply to Handling cascading defaults
I was wondering whether you could do something using the __PACKAGE__ variable and a hash in the Err package, but I couldn't think of a way of reading your caller's package. I expect there is a way though. Then the err() function could read the callers package and read the default strings from a hash which the calling package had assigned.package Err; sub new { return bless { title => 'Really Bad Error', msg => 'Unknown', @_ }; } sub err { my %args = ( %{shift()}, @_ ); print "Error: $args{title}: $args{msg}\n"; } ########### package MyModule; $myerror = Err::new( title =>'My new default title for MyModule.pm', msg => 'MyModules generic error message' ); $myerror->err(); $myerror->err(title=>'Oops',msg=>'something went wrong');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE (tilly) 2: Handling cascading defaults
by tilly (Archbishop) on Aug 19, 2000 at 17:29 UTC | |
by merlyn (Sage) on Aug 19, 2000 at 19:31 UTC | |
by tilly (Archbishop) on Aug 19, 2000 at 19:44 UTC | |
|
OO vs. procedural style
by markjugg (Curate) on Aug 19, 2000 at 18:02 UTC | |
by tilly (Archbishop) on Aug 19, 2000 at 18:35 UTC |