Changeset 465

Show
Ignore:
Timestamp:
01/18/02 19:34:14
Author:
miyagawa
Message:

remove backward compatible comment

Files:

Legend:

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

    r459 r465  
    3131    } 
    3232 
    33     # records conf time 
    34     $config->conf_time(time); 
    3533    $class->__instance($config); 
    3634} 
     
    3937    my($class, $config) = @_; 
    4038    $class->configure($config); 
    41  
    42     # hack: __instance should return conf 
    43     $config = $class->__instance; 
    44  
    45     # tells conf to watch config file 
    46     $config->should_watch(1); 
     39    $config = $class->__instance; # XXX: __instance is now config 
     40    $config->should_watch(1);   # tells conf to watch config file 
    4741} 
    4842 
    4943# backward compatibility 
    50 sub Log::Dispatch::instance { 
    51     __PACKAGE__->instance; 
    52 
     44sub Log::Dispatch::instance { __PACKAGE__->instance; } 
    5345 
    5446sub instance { 
     
    6355    if (UNIVERSAL::isa($instance, 'Log::Dispatch::Config')) { 
    6456        # reload singleton on the fly 
    65         if ($instance->needs_reload) { 
    66             $class->reload; 
    67         } 
     57        $class->reload if $instance->needs_reload; 
    6858    } 
    6959    else { 
     
    8474    my $instance = $class->__instance; 
    8575 
    86     # reconfigure, and returns instance 
     76    # reconfigure and recreate instance 
    8777    my $meth = $instance->{config}->should_watch 
    8878        ? \&configure_and_watch : \&configure; 
    8979    $class->$meth($instance->{config}); 
    90     $class->__instance($class->instance); 
     80    $class->__instance($class->create_instance($instance->{config})); 
    9181} 
    9282 
     
    9484    my($class, $config) = @_; 
    9585    $config->parse; 
     86    $config->{_ctime} = time;   # creation time 
    9687 
    9788    my $global = $config->get_attrs_global; 
     
    235226dispatcher instance via C<Log::Dispatch::Config-E<gt>instance>. 
    236227 
    237 Formerly, C<configure> method declares C<instance> method in 
    238 Log::Dispatch namespace. Now it inherits from Log::Dispatch, so the 
    239 namespace pollution is not necessary. Currrent version still defines 
    240 one-liner shortcut: 
    241  
    242   sub Log::Dispatch::instance { Log::Dispatch::Config->instance } 
    243  
    244 so still you can call C<Log::Dispatch-E<gt>instance>, if you prefer, 
    245 or for backward compatibility. 
    246  
    247228=head1 CONFIGURATION 
    248229 
     
    373354C<configure_and_watch> method on Log::Dispatch::Config instead of 
    374355C<configure>. Then C<instance> call will check mtime of configuration 
    375 file, and compares it with last configuration time. If config file is 
    376 newer than last configuration, it will automatically reload object. 
     356file, and compares it with instanciation time of singleton object. If 
     357config file is newer than last instanciation, it will automatically 
     358reload object. 
    377359 
    378360=head1 NAMESPACE COLLISION 
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Configurator.pm

    r459 r465  
    1414} 
    1515 
    16 sub parse { } 
     16# backward compatible code 
     17sub parse { 
     18    my $self = shift; 
     19    my $class = ref $self; 
     20    my %res = map { $_ => $self->{$_} } grep /^_/, keys %$self; 
     21    %{$self} = (%{$class->new($self->{file})}, %res); 
     22
    1723 
    1824sub needs_reload { 
    1925    my $self = shift; 
    2026    return $self->{_ctime} < (stat($self->{file}))[9]; 
    21 } 
    22  
    23 sub conf_time { 
    24     my $self = shift; 
    25     $self->{_ctime} = shift if @_; 
    26     $self->{_ctime}; 
    2727} 
    2828 
  • Log-Dispatch-Config/trunk/t/03_reload.t

    r463 r465  
    11use strict; 
    2 use Test::More tests => 4
     2use Test::More tests => 5
    33 
    44use Log::Dispatch::Config; 
     
    2626    is $disp2->{outputs}->{foo}, undef; 
    2727    isnt "$disp", "$disp2", "$disp - $disp2"; 
     28 
     29    my $disp3 = Log::Dispatch::Config->instance; 
     30    is "$disp2", "$disp3", 'same one'; 
    2831} 
  • Log-Dispatch-Config/trunk/t/07_hardwired.t

    r454 r465  
    11use strict; 
    2 use Test::More tests => 5
     2use Test::More tests => 7
    33 
    44END { unlink 't/log.out' if -e 't/log.out' } 
     
    5656isnt "$disp", "$disp2", "$disp - $disp2"; 
    5757 
     58my $disp3 = Log::Dispatch::Config->instance; 
     59isnt "$disp", "$disp3", "$disp - $disp3"; 
     60isnt "$disp2", "$disp3", "$disp2 - $disp3"; 
    5861