Changeset 528

Show
Ignore:
Timestamp:
02/26/02 12:27:38
Author:
miyagawa
Message:

doc

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Log-Dispatch-Config/trunk/Changes

    r468 r528  
    11Revision history for Perl extension Log::Dispatch::Config. 
     2 
     30.13 
     4        - Fixed doc 
     5        - Code cleanup (refactoring, s/die/croak/g etc.) 
     6        * now requires Log::Dispatch 2.00 
    27 
    380.12  Fri Jan 18 05:08:22 JST 2002 
     
    510          New class method: configure_and_watch() 
    611          (Thanks to Hiroyuki Oyama <oyama@cpan.org>) 
    7         - Added documenttion for subclassing/wrapping 
     12        - Added documentation for subclassing/wrapping 
    813        - Code clean up, revised configurator API docs 
    914 
  • Log-Dispatch-Config/trunk/MANIFEST

    r464 r528  
    2020t/12_inherit.t 
    2121t/13_do_reload.t 
     22t/14_destroy.t 
    2223t/another.cfg 
    2324t/bar.cfg 
  • Log-Dispatch-Config/trunk/Makefile.PL

    r454 r528  
    44eval q{require Log::Dispatch::Config}; 
    55unless ($@) { 
    6     print <<WARN if ${Log::Dispatch::Config::VERSION} <= $LAST_API_CHANGE; 
     6    print <<WARN if ${Log::Dispatch::Config::VERSION} < $LAST_API_CHANGE; 
    77 
    88NOTE: There have been API changes between this version and any older 
     
    1919    'PREREQ_PM' => { 
    2020        Test::More => 0.32, 
    21         Log::Dispatch => 1.79
     21        Log::Dispatch => 2.00
    2222        AppConfig => 1.52, 
    2323        IO::Scalar => 0, 
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Config.pm

    r468 r528  
    2323} 
    2424 
     25sub _configurator_for { 
     26    my($class, $stuff) = @_; 
     27    return $stuff if UNIVERSAL::isa($stuff, 'Log::Dispatch::Configurator'); 
     28    require Log::Dispatch::Configurator::AppConfig; 
     29    return Log::Dispatch::Configurator::AppConfig->new($stuff); 
     30} 
     31 
    2532sub configure { 
    26     my($class, $config) = @_; 
    27     _croak "no config file or configurator supplied" unless $config; 
    28  
    29     # default configurator: AppConfig 
    30     unless (UNIVERSAL::isa($config, 'Log::Dispatch::Configurator')) { 
    31         require Log::Dispatch::Configurator::AppConfig; 
    32         $config = Log::Dispatch::Configurator::AppConfig->new($config); 
    33     } 
     33    my($class, $stuff) = @_; 
     34    _croak "no config file or configurator supplied" unless $stuff; 
     35    my $config = $class->_configurator_for($stuff); 
    3436    $config->myinit; 
    3537    $class->__instance($config); 
     
    3739 
    3840sub configure_and_watch { 
    39     my($class, $config) = @_; 
    40     $class->configure($config); 
    41     $config = $class->__instance; # XXX: __instance is now config 
    42     $config->should_watch(1);   # tells conf to watch config file 
     41    my $class = shift; 
     42    $class->configure(@_); 
     43    $class->__instance->should_watch(1); # tells conf to watch config file 
    4344} 
    4445 
     
    4950    my $class = shift; 
    5051 
    51     my $instance = $class->__instance or _croak "Log::Dispatch::Config->configure not yet called."; 
    52     if (UNIVERSAL::isa($instance, 'Log::Dispatch::Config')) { 
     52    my $instance = $class->__instance or _croak "configure not yet called."; 
     53    if ($instance->isa('Log::Dispatch::Config')) { 
    5354        # reload singleton on the fly 
    5455        $class->reload if $instance->needs_reload; 
     
    100101    } 
    101102 
    102     # config info 
    103103    $instance->{config} = $config; 
    104  
    105104    return $instance; 
    106105} 
     
    109108    my($class, $disp, $var) = @_; 
    110109 
    111     my $dispclass = $var->{class} 
    112         or die "class param missing for $disp"; 
     110    my $dispclass = $var->{class} or _croak "class param missing for $disp"; 
    113111 
    114112    eval qq{require $dispclass}; 
    115     die $@ if $@ && $@ !~ /locate/; 
     113    _croak $@ if $@ && $@ !~ /locate/; 
    116114 
    117115    if (exists $var->{format}) { 
     
    443441 
    444442Stub config file mtime based C<needs_reload> method is declared in 
    445 Log::Dispatch::Configurator as below, so if your config class is based 
    446 on filesystem files, you do not need to reimplement this. 
    447  
    448   sub needs_reload { 
    449       my($self, $obj) = @_; 
    450       return $obj->{ctime} < (stat($self->{file}))[9]; 
    451   } 
     443Log::Dispatch::Configurator, so if your config class is based on 
     444filesystem files, you do not need to reimplement this. 
    452445 
    453446If you do not need I<singleton-ness> at all, always return true. 
     
    467460object to C<configure> method call instead of config file name. 
    468461 
    469   use Log::Dispatch
     462  use Log::Dispatch::Config
    470463  use Log::Dispatch::Configurator::Hardwired; 
    471464 
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Configurator.pm

    r468 r528  
    5454 
    5555  # optional 
    56   sub parse        { } 
     56  sub reload       { } 
    5757  sub needs_reload { } 
    5858