Show
Ignore:
Timestamp:
05/17/08 00:29:44 (5 years ago)
Author:
tomyhero
Message:

lang/perl/Config-Muti : add POD.

Location:
lang/perl/Config-Multi/trunk
Files:
3 added
4 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Config-Multi/trunk/Makefile.PL

    r11667 r11708  
    66author 'Tomohiro Teranishi <tomohiro.teranishi@gmail.com>'; 
    77all_from 'lib/Config/Multi.pm'; 
    8 requires 'Test::More'            => 0; 
     8requires 'Test::Base'            => 0; 
    99requires 'Test::Spelling'        => 0; 
    1010requires 'DirHandle'             => 0; 
    1111requires 'Config::Any'           => 0; 
     12requires 'Class::Accessor'       => 0; 
    1213requires 'YAML::Syck'            => 0; # for testing 
    1314recommends 'Test::Pod::Coverage' => 0; 
  • lang/perl/Config-Multi/trunk/lib/Config/Multi.pm

    r11667 r11708  
    55use DirHandle; 
    66use File::Spec; 
    7 use YAML::Syck; 
    87use FindBin; 
    98use Config::Any ; 
     
    1514    my $self = shift; 
    1615    my @files = (); 
    17     my $app_files    = $self->find_files( $self->{app_name} ) ; 
    18     my $prefix_files = $self->find_files( $self->{prefix} . '_' . $self->{app_name} ); 
    19     my $local_files = $self->local_files; 
     16    $self->{extension} ||= 'yml'; 
     17    my $app_files    = $self->_find_files( $self->{app_name} ) ; 
     18    my $prefix_files = $self->_find_files( $self->{prefix} . '_' . $self->{app_name} ); 
     19    my $local_files = $self->_local_files; 
    2020 
    2121    my $config = {}; 
     
    4848 
    4949 
    50 sub local_files { 
     50sub _local_files { 
    5151    my $self = shift; 
    52     my $config_key_name = uc($self->{prefix}) . '_' . uc($self->{app_name}) . '_CONFIG_MULTI'; 
    53     if ( $ENV{ $config_key_name } ) { 
    54         return ( -e $ENV{ $config_key_name } ) ? [ $ENV{ $config_key_name } ] : [] ;  
    55     } 
    56     else { 
    57         my @files = (); 
    58         my $app_lcoal    = File::Spec->catfile( $self->dir ,  $self->{app_name} . '_local.' . $self->extension ) ; 
    59         my $prefix_local = File::Spec->catfile( $self->dir ,  $self->{prefix} . '_' . $self->{app_name} . '_local.' . $self->extension ); 
     52    my $env_app_key    = 'CONFIG_MULTI_' .uc($self->{app_name})  ; 
     53    my $env_prefix_key = 'CONFIG_MULTI_' . uc($self->{prefix}) . '_' . uc($self->{app_name})  ; 
     54    my @files = (); 
     55    my $app_lcoal    = $ENV{ $env_app_key } || File::Spec->catfile( $self->dir ,  $self->{app_name} . '_local.' . $self->extension ) ; 
     56    my $prefix_local = $ENV{ $env_prefix_key} || File::Spec->catfile( $self->dir ,  $self->{prefix} . '_' . $self->{app_name} . '_local.' . $self->extension ); 
    6057 
    61         push @files  , $app_lcoal if -e $app_lcoal; 
    62         push @files  , $prefix_local if -e $prefix_local; 
     58    push @files  , $app_lcoal if -e $app_lcoal; 
     59    push @files  , $prefix_local if -e $prefix_local; 
    6360 
    64         return \@files; 
    65     } 
     61    return \@files; 
    6662} 
    6763 
    68 sub find_files { 
     64sub _find_files { 
    6965    my $self = shift; 
    7066    my $path = $self->dir; 
     
    9086=head1 NAME 
    9187 
    92 Config::Multi - my module Config::Multi !! 
     88Config::Multi - load multiple config files. 
    9389 
    9490=head1 SYNOPSIS 
    9591 
     92 use Config::Multi; 
     93 use File::Spec; 
     94 use FindBin; 
     95  
     96 my $dir = File::Spec->catfile( $FindBin::Bin , 'conf' ); 
     97 my $cm =  Config::Multi->new({dir => $dir , app_name => 'myapp' , prefix => 'web' , extension => 'yml' }); 
     98 my $config = $cm->load(); 
     99 my $loaded_config_files = $cm->files; 
     100 
    96101=head1 DESCRIPTION 
     102 
     103 
     104 
     105=head1 METHODS 
     106 
     107=head2 new 
     108  
     109constructor SEE CONSTRUCTOR ARGUMENT section. 
     110 
     111=head2 load 
     112 
     113load config files and return config data. 
     114 
     115=head2 files 
     116 
     117get array references of loaded config files. You can use this method after call load() method. 
     118 
     119=head1 CONSTRUCTOR ARGUMENT 
     120 
     121=head2 app_name 
     122 
     123your application name. use [a-z]+ for format.  
     124 
     125=head2 prefix 
     126 
     127prefix name . use [a-z]+ for format. 
     128 
     129=head2 dir 
     130 
     131specify directory where your config files are located. 
     132 
     133=head2 extension 
     134 
     135you must specify extension for your config files. default is yml. 
    97136 
    98137=head1 AUTHOR 
  • lang/perl/Config-Multi/trunk/t/01-loadling.t

    r11667 r11708  
    1313run {  
    1414    my $block = shift; 
    15     my $config = Config::Multi->new({dir => $dir , app_name => 'myapp' , prefix => $block->prefix , extension => 'yml' }); 
     15    my $config = Config::Multi->new({dir => $dir , app_name => 'myapp' , prefix => $block->prefix }); 
    1616    $config->load(); 
    1717    my $paths = $config->files; 
  • lang/perl/Config-Multi/trunk/t/spelling.t

    r11665 r11708  
    1919 
    2020__END__ 
    21  
     21Teranishi 
     22Tomohiro 
     23dir 
     24yml