Subject: | Use default_values to initialize |
I use Net::Server as base for a new SOAP server implementation
(XML::Compile::SOAP::Daemon). My XML modules use the Log::Report
infrastructure for translations and logging. I try to merge this with
Net::Server's way of logging.
Inside Net::Server you use a lot of defaults, for instance log_level=2
and syslog_indent='net_server'. When overruling some logging specific
things in my Net::Server based class, I now need to retype those
defaults. Of course with the danger that I miss changes in the future.
It would be much nicer if Net::Server itself uses its default_values()
infrastructure. So, instead of this:
### make sure it has been configured properly
sub post_configure {
...
### set the log level
if( !defined $prop->{log_level} || $prop->{log_level} !~ /^\d+$/ ){
$prop->{log_level} = 2;
}
$prop->{log_level} = 4 if $prop->{log_level} > 4;
### log to STDERR
if( ! defined($prop->{log_file}) ){
$prop->{log_file} = '';
### log to syslog
}elsif( $prop->{log_file} eq 'Sys::Syslog' ){
...
}
### any values to set if no configuration could be found
sub default_values { {} }
It could be written as
### make sure it has been configured properly
sub post_configure {
...
### set the log level
$prop->{log_level} =~ /^\d+$/ && $prop->{log_level} <= 4
or die;
### log to syslog
if( $prop->{log_file} eq 'Sys::Syslog' ){
...
}
### any values to set if no configuration could be found
sub default_values { +{log_level => 2, log_file => ''} }
This would improve the clarity of the code a lot, and simplify complex
extensions. I hope you see the benefits.