Changeset 466

Show
Ignore:
Timestamp:
01/18/02 23:47:13
Author:
miyagawa
Message:

refactoring
backward compat
more test

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Config.pm

    r465 r466  
    1111# caller depth: can be changed from outside 
    1212$Log::Dispatch::Config::CallerDepth = 0; 
     13 
     14sub _croak { require Carp; Carp::croak(@_); } 
    1315 
    1416# accessor for symblic reference 
     
    2325sub configure { 
    2426    my($class, $config) = @_; 
    25     die "no config file or configurator supplied" unless $config; 
     27    _croak "no config file or configurator supplied" unless $config; 
    2628 
    2729    # default configurator: AppConfig 
     
    3032        $config = Log::Dispatch::Configurator::AppConfig->new($config); 
    3133    } 
    32  
     34    $config->_init; 
    3335    $class->__instance($config); 
    3436} 
     
    4749    my $class = shift; 
    4850 
    49     my $instance = $class->__instance; 
    50     unless (defined $instance) { 
    51         require Carp; 
    52         Carp::croak("Log::Dispatch::Config->configure not yet called."); 
    53     } 
    54  
     51    my $instance = $class->__instance or _croak "Log::Dispatch::Config->configure not yet called."; 
    5552    if (UNIVERSAL::isa($instance, 'Log::Dispatch::Config')) { 
    5653        # reload singleton on the fly 
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Configurator.pm

    r465 r466  
    77sub new { 
    88    my($class, $file) = @_; 
    9     bless { 
    10         file   => $file, 
    11         _ctime => 0, 
    12         _watch => 0, 
    13     }, $class; 
     9    bless { file   => $file }, $class; 
     10
     11 
     12sub _init { 
     13    my $self = shift; 
     14    $self->{_ctime} = 0 unless defined $self->{_ctime}; 
     15    $self->{_watch} = 0 unless defined $self->{_watch}; 
    1416} 
    1517 
     
    1820    my $self = shift; 
    1921    my $class = ref $self; 
    20     my %res = map { $_ => $self->{$_} } grep /^_/, keys %$self
    21     %{$self} = (%{$class->new($self->{file})}, %res)
     22    %$self = (%$self, %{$class->new($self->{file})})
     23    $self->_init
    2224} 
    2325