Changeset 11708 for lang/perl/Config-Multi
- Timestamp:
- 05/17/08 00:29:44 (5 years ago)
- Location:
- lang/perl/Config-Multi/trunk
- Files:
-
- 3 added
- 4 modified
-
Makefile.PL (modified) (1 diff)
-
lib/Config/Multi.pm (modified) (4 diffs)
-
t/01-loadling.t (modified) (1 diff)
-
t/04-env.t (added)
-
t/conf/env-prefix.yml (added)
-
t/conf/env.yml (added)
-
t/spelling.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Config-Multi/trunk/Makefile.PL
r11667 r11708 6 6 author 'Tomohiro Teranishi <tomohiro.teranishi@gmail.com>'; 7 7 all_from 'lib/Config/Multi.pm'; 8 requires 'Test:: More' => 0;8 requires 'Test::Base' => 0; 9 9 requires 'Test::Spelling' => 0; 10 10 requires 'DirHandle' => 0; 11 11 requires 'Config::Any' => 0; 12 requires 'Class::Accessor' => 0; 12 13 requires 'YAML::Syck' => 0; # for testing 13 14 recommends 'Test::Pod::Coverage' => 0; -
lang/perl/Config-Multi/trunk/lib/Config/Multi.pm
r11667 r11708 5 5 use DirHandle; 6 6 use File::Spec; 7 use YAML::Syck;8 7 use FindBin; 9 8 use Config::Any ; … … 15 14 my $self = shift; 16 15 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; 20 20 21 21 my $config = {}; … … 48 48 49 49 50 sub local_files {50 sub _local_files { 51 51 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 ); 60 57 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; 63 60 64 return \@files; 65 } 61 return \@files; 66 62 } 67 63 68 sub find_files {64 sub _find_files { 69 65 my $self = shift; 70 66 my $path = $self->dir; … … 90 86 =head1 NAME 91 87 92 Config::Multi - my module Config::Multi !!88 Config::Multi - load multiple config files. 93 89 94 90 =head1 SYNOPSIS 95 91 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 96 101 =head1 DESCRIPTION 102 103 104 105 =head1 METHODS 106 107 =head2 new 108 109 constructor SEE CONSTRUCTOR ARGUMENT section. 110 111 =head2 load 112 113 load config files and return config data. 114 115 =head2 files 116 117 get 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 123 your application name. use [a-z]+ for format. 124 125 =head2 prefix 126 127 prefix name . use [a-z]+ for format. 128 129 =head2 dir 130 131 specify directory where your config files are located. 132 133 =head2 extension 134 135 you must specify extension for your config files. default is yml. 97 136 98 137 =head1 AUTHOR -
lang/perl/Config-Multi/trunk/t/01-loadling.t
r11667 r11708 13 13 run { 14 14 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 }); 16 16 $config->load(); 17 17 my $paths = $config->files; -
lang/perl/Config-Multi/trunk/t/spelling.t
r11665 r11708 19 19 20 20 __END__ 21 21 Teranishi 22 Tomohiro 23 dir 24 yml
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)