Changeset 2305

Show
Ignore:
Timestamp:
08/09/07 05:56:21
Author:
miyagawa
Message:

apply a patch from Ben H Kram

Files:

Legend:

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

    r626 r2305  
    11Revision history for Perl extension Log::Dispatch::Config. 
     2 
     31.02  Wed Aug  8 13:46:16 PDT 2007 
     4        - Added a functionality to reuse existing AppConfig object 
     5          (Thanks to Ben H Kram) 
    26 
    371.01  Tue Apr 30 14:06:06 JST 2002 
  • Log-Dispatch-Config/trunk/MANIFEST

    r528 r2305  
    2121t/13_do_reload.t 
    2222t/14_destroy.t 
     23t/15_appconfig.t 
    2324t/another.cfg 
    2425t/bar.cfg 
     
    2728t/log.cfg 
    2829t/log.ini 
     30t/section.ini 
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Config.pm

    r626 r2305  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = 1.01
     5$VERSION = "1.02"
    66 
    77use Log::Dispatch 2.00; 
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Configurator/AppConfig.pm

    r582 r2305  
    1010 
    1111sub new { 
    12     my($class, $file) = @_; 
    13     my $self = bless { file => $file }, $class; 
     12    my($class, $file, $section) = @_; 
     13    my $self = bless { section => ($section ? "${section}_" : '') }, $class; 
     14    if(ref $file && $file->isa('AppConfig')){ 
     15        $self->{config} = $file; 
     16    }else{ 
     17        $self->{file}   = $file; 
     18    } 
    1419    $self->parse_file; 
    1520    return $self; 
     
    1823sub parse_file { 
    1924    my $self = shift; 
    20     my $config = AppConfig->new({ 
     25 
     26    my $section = $self->{section}; 
     27    my $config; 
     28    if($self->{config}){ 
     29        $config = $self->{config}; 
     30    } 
     31    else{  
     32        $config = AppConfig->new({ 
    2133        CREATE => 1, 
    2234        GLOBAL => { 
     
    2436        }, 
    2537    }); 
    26     $config->define(dispatchers => { DEFAULT => '' }); 
    27     $config->define(format      => { DEFAULT => undef }); 
    28     $config->file($self->{file}); 
    29  
     38        $config->file($self->{file}); 
     39    } 
     40    $config->define("${section}dispatchers" => { DEFAULT => '' })    unless $config->varlist("^${section}dispatchers\$"); 
     41    $config->define("${section}format"      => { DEFAULT => undef }) unless $config->varlist("^${section}format\$"); 
     42     
    3043    $self->{_config} = $config; 
    3144} 
     
    4053sub get_attrs_global { 
    4154    my $self = shift; 
     55    my $section = $self->{section}; 
    4256    return { 
    43         format      => scalar $self->_config->get('format'), 
    44         dispatchers => [ split /\s+/, $self->_config->get('dispatchers') ], 
     57        format      => scalar $self->_config->get("${section}format"), 
     58        dispatchers => [ split /\s+/, $self->_config->get("${section}dispatchers") ], 
    4559    }; 
    4660} 
     
    4862sub get_attrs { 
    4963    my($self, $name) = @_; 
    50     my $regex = "^$name" . '[\._]'; 
     64    my $section = $self->{section}; 
     65    my $regex = "^$section$name" . '[\._]'; 
    5166    my %var = $self->_config->varlist($regex); 
    5267    my %param = map {