Changeset 468

Show
Ignore:
Timestamp:
01/19/02 19:29:58
Author:
miyagawa
Message:

0.12

Files:

Legend:

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

    r461 r468  
    11Revision history for Perl extension Log::Dispatch::Config. 
    22 
    3 0.11_02 Fri Jan 18 05:08:22 JST 2002 
    4         * [API change] 
    5           No check on config mtime by default 
     30.12  Fri Jan 18 05:08:22 JST 2002 
     4        * No check on config mtime by default 
    65          New class method: configure_and_watch() 
    76          (Thanks to Hiroyuki Oyama <oyama@cpan.org>) 
    8         - Modified configurator API 
    97        - Added documenttion for subclassing/wrapping 
    10  
    11 This release is a beta release. If you have trouble with this API 
    12 change or something, please let me know ASAP. 
     8        - Code clean up, revised configurator API docs 
    139 
    14100.11  Sun Jan  6 18:01:48 JST 2002 
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Config.pm

    r467 r468  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = 0.11_03
     5$VERSION = 0.12
    66 
    77use Log::Dispatch; 
     
    3232        $config = Log::Dispatch::Configurator::AppConfig->new($config); 
    3333    } 
    34     $config->_init; 
     34    $config->myinit; 
    3535    $class->__instance($config); 
    3636} 
     
    7070    my $class = ref $proto || $proto; 
    7171    my $instance = $class->__instance; 
    72  
    73     # reconfigure and recreate instance 
    74     my $meth = $instance->{config}->should_watch 
    75         ? \&configure_and_watch : \&configure; 
    76     $class->$meth($instance->{config}); 
     72    $instance->{config}->reload; 
    7773    $class->__instance($class->create_instance($instance->{config})); 
    7874} 
     
    8076sub create_instance { 
    8177    my($class, $config) = @_; 
    82     $config->parse; 
    83     $config->{_ctime} = time;   # creation time 
     78    $config->{LDC_ctime} = time;        # creation time 
    8479 
    8580    my $global = $config->get_attrs_global; 
     
    196191  $dispatcher->emergency('something *bad* happened!'); 
    197192 
     193  # automatic reloading conf file, when modified 
     194  Log::Dispatch::Config->configure_and_watch('/path/to/log.conf'); 
     195 
    198196  # or if you write your own config parser: 
    199197  use Log::Dispatch::Configurator::XMLSimple; 
     
    201199  my $config = Log::Dispatch::Configurator::XMLSimple->new('log.xml'); 
    202200  Log::Dispatch::Config->configure($config); 
    203  
    204   # automatic reloading conf file, when modified 
    205   Log::Dispatch::Config->configure_and_watch('/path/to/log.conf'); 
    206201 
    207202=head1 DESCRIPTION 
     
    370365 
    371366Or make wrapper for it. See L<POE::Component::Logger> implementation 
    372 by Matt
     367by Matt Sergeant
    373368 
    374369=head1 PLUGGABLE CONFIGURATOR 
     
    389384  package Log::Dispatch::Configurator::Hardwired; 
    390385  use base qw(Log::Dispatch::Configurator); 
     386 
     387Declare your own C<new> constructor. Stub C<new> method is defined in 
     388Configurator base class, but you want to put parsing method in your 
     389own constructor. In this example, we just bless reference. Note that 
     390your object should be blessed hash. 
     391 
     392  sub new { bless {}, shift } 
    391393 
    392394=item * 
     
    435437=item * 
    436438 
    437 Implement optional C<needs_reload> and C<parse
     439Implement optional C<needs_reload> and C<reload
    438440methods. C<needs_reload> should return boolean value if the object is 
    439441stale and needs reloading itself. This method will be triggered when 
     
    449451  } 
    450452 
    451 If you do not need I<singleton-ness at all>, always return true. 
     453If you do not need I<singleton-ness> at all, always return true. 
    452454 
    453455  sub needs_reload { 1 } 
    454456 
    455 C<parse> method should do parsing of the config file. This method is 
    456 called in the first parsing of the config file, and again when 
    457 C<needs_reload> returns true. Log::Dispatch::Configurator base class 
    458 has a null C<parse> method. 
     457C<reload> method should redo parsing of the config file. Configurator 
     458base class has a stub null C<reload> method, so you should better 
     459override it. 
     460 
     461See Log::Dispatch::Configurator::AppConfig source code for details. 
    459462 
    460463=item * 
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Configurator.pm

    r467 r468  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = 0.11_03
     5$VERSION = 0.12
    66 
    77sub new { 
     
    1010} 
    1111 
    12 sub _init { 
     12sub myinit { 
    1313    my $self = shift; 
    14     $self->{_ctime} = 0 unless defined $self->{_ctime}; 
    15     $self->{_watch} = 0 unless defined $self->{_watch}; 
     14    $self->{LDC_ctime} = 0 unless defined $self->{LDC_ctime}; 
     15    $self->{LDC_watch} = 0 unless defined $self->{LDC_watch}; 
    1616} 
    1717 
    18 # backward compatible code 
    19 sub parse { 
    20     my $self = shift; 
    21     my $class = ref $self; 
    22     %$self = (%$self, %{$class->new($self->{file})}); 
    23     $self->_init; 
    24 
     18sub reload { } 
    2519 
    2620sub needs_reload { 
    2721    my $self = shift; 
    28     return $self->{_ctime} < (stat($self->{file}))[9]; 
     22    return $self->{LDC_ctime} < (stat($self->{file}))[9]; 
    2923} 
    3024 
    3125sub should_watch { 
    3226    my $self = shift; 
    33     $self->{_watch} = shift if @_; 
    34     return $self->{_watch}; 
     27    $self->{LDC_watch} = shift if @_; 
     28    return $self->{LDC_watch}; 
    3529} 
    3630 
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Configurator/AppConfig.pm

    r467 r468  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = 0.11_03
     5$VERSION = 0.12
    66 
    77use Log::Dispatch::Configurator; 
     
    99use AppConfig; 
    1010 
    11 sub parse { 
     11sub new { 
     12    my($class, $file) = @_; 
     13    my $self = bless { file => $file }, $class; 
     14    $self->parse_file; 
     15    return $self; 
     16
     17 
     18sub parse_file { 
    1219    my $self = shift; 
    1320    my $config = AppConfig->new({ 
     
    2229 
    2330    $self->{_config} = $config; 
     31} 
     32 
     33sub reload { 
     34    my $self = shift; 
     35    $self->parse_file; 
    2436} 
    2537 
  • Log-Dispatch-Config/trunk/t/07_hardwired.t

    r465 r468  
    77    package Log::Dispatch::Configurator::Hardwired; 
    88    use base qw(Log::Dispatch::Configurator); 
     9 
     10    sub new { bless {}, shift } 
    911 
    1012    sub get_attrs_global {