Changeset 11786 for lang/perl/Config-Multi
- Timestamp:
- 05/17/08 21:58:55 (5 years ago)
- Location:
- lang/perl/Config-Multi
- Files:
-
- 8 modified
- 14 copied
-
tags/0.02 (copied) (copied from lang/perl/Config-Multi/trunk)
-
tags/0.02/Changes (copied) (copied from lang/perl/Config-Multi/trunk/Changes) (1 diff)
-
tags/0.02/MANIFEST (copied) (copied from lang/perl/Config-Multi/trunk/MANIFEST)
-
tags/0.02/Makefile.PL (copied) (copied from lang/perl/Config-Multi/trunk/Makefile.PL)
-
tags/0.02/lib/Config/Multi.pm (copied) (copied from lang/perl/Config-Multi/trunk/lib/Config/Multi.pm) (7 diffs)
-
tags/0.02/t/01-loadling.t (copied) (copied from lang/perl/Config-Multi/trunk/t/01-loadling.t) (1 diff)
-
tags/0.02/t/02-overwrite.t (copied) (copied from lang/perl/Config-Multi/trunk/t/02-overwrite.t) (1 diff)
-
tags/0.02/t/03-multi.t (copied) (copied from lang/perl/Config-Multi/trunk/t/03-multi.t) (1 diff)
-
tags/0.02/t/04-env.t (copied) (copied from lang/perl/Config-Multi/trunk/t/04-env.t) (1 diff)
-
tags/0.02/t/05-no-prefix.t (copied) (copied from lang/perl/Config-Multi/trunk/t/05-no-prefix.t) (1 diff)
-
tags/0.02/t/boilerplate.t (copied) (copied from lang/perl/Config-Multi/trunk/t/boilerplate.t)
-
tags/0.02/t/conf/env-prefix.yml (copied) (copied from lang/perl/Config-Multi/trunk/t/conf/env-prefix.yml)
-
tags/0.02/t/conf/env.yml (copied) (copied from lang/perl/Config-Multi/trunk/t/conf/env.yml)
-
tags/0.02/t/spelling.t (copied) (copied from lang/perl/Config-Multi/trunk/t/spelling.t) (1 diff)
-
trunk/Changes (modified) (1 diff)
-
trunk/lib/Config/Multi.pm (modified) (7 diffs)
-
trunk/t/01-loadling.t (modified) (1 diff)
-
trunk/t/02-overwrite.t (modified) (1 diff)
-
trunk/t/03-multi.t (modified) (1 diff)
-
trunk/t/04-env.t (modified) (1 diff)
-
trunk/t/05-no-prefix.t (modified) (1 diff)
-
trunk/t/spelling.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Config-Multi/tags/0.02/Changes
r11709 r11786 1 1 Revision history for Config::Multi 2 3 0.02 2008-05-17/21:53 4 - remove use FindBin::libs; 5 - fix POD indent 2 6 3 7 0.01 2008-05-17/01:17 -
lang/perl/Config-Multi/tags/0.02/lib/Config/Multi.pm
r11710 r11786 6 6 use File::Spec; 7 7 use FindBin; 8 use Config::Any ;8 use Config::Any; 9 9 use Carp; 10 10 11 11 use base qw/Class::Accessor/; 12 12 13 our $VERSION = '0.0 1';13 our $VERSION = '0.02'; 14 14 15 15 __PACKAGE__->mk_accessors(qw/app_name prefix dir files extension/); 16 16 17 17 sub load { 18 my $self = shift;18 my $self = shift; 19 19 my @files = (); 20 20 $self->{extension} ||= 'yml'; 21 croak( 'you must set dir' )unless $self->{dir};22 croak( 'you must set app_name') unless $self->{app_name};21 croak('you must set dir') unless $self->{dir}; 22 croak('you must set app_name') unless $self->{app_name}; 23 23 24 24 my $config = {}; 25 25 26 my $app_files = $self->_find_files( $self->{app_name} );26 my $app_files = $self->_find_files( $self->{app_name} ); 27 27 my $app = Config::Any->load_files( { files => $app_files } ); 28 for ( @{$app} ){ 29 my ($filename, $data) = %$_; 30 push @files , $filename; 31 $config = { %{$config}, %{$data} } ; 32 } 33 34 if( $self->{prefix} ) { 35 my $prefix_files = $self->_find_files( $self->{prefix} . '_' . $self->{app_name} ); 36 my $prefix = Config::Any->load_files( { files => $prefix_files } ); 37 for ( @{$prefix} ){ 38 my ($filename, $data) = %$_; 39 push @files , $filename; 40 $config = { %{$config}, %{$data} } ; 28 for ( @{$app} ) { 29 my ( $filename, $data ) = %$_; 30 push @files, $filename; 31 $config = { %{$config}, %{$data} }; 32 } 33 34 if ( $self->{prefix} ) { 35 my $prefix_files 36 = $self->_find_files( $self->{prefix} . '_' . $self->{app_name} ); 37 my $prefix = Config::Any->load_files( { files => $prefix_files } ); 38 for ( @{$prefix} ) { 39 my ( $filename, $data ) = %$_; 40 push @files, $filename; 41 $config = { %{$config}, %{$data} }; 41 42 } 42 43 } 43 44 44 45 my $local_files = $self->_local_files; 45 my $local = Config::Any->load_files( { files => $local_files } );46 for ( @{$local} ) {47 my ( $filename, $data) = %$_;48 push @files , $filename;49 $config = { %{$config}, %{$data} } ;46 my $local = Config::Any->load_files( { files => $local_files } ); 47 for ( @{$local} ) { 48 my ( $filename, $data ) = %$_; 49 push @files, $filename; 50 $config = { %{$config}, %{$data} }; 50 51 } 51 52 … … 55 56 } 56 57 57 58 58 sub _local_files { 59 my $self = shift; 60 my $env_app_key = 'CONFIG_MULTI_' .uc($self->{app_name}) ; 61 my $env_prefix_key = 'CONFIG_MULTI_' . uc($self->{prefix}) . '_' . uc($self->{app_name}) ; 62 my @files = (); 63 my $app_lcoal = $ENV{ $env_app_key } || File::Spec->catfile( $self->dir , $self->{app_name} . '_local.' . $self->extension ) ; 64 push @files , $app_lcoal if -e $app_lcoal; 65 66 if( $self->{prefix}) { 67 my $prefix_local = $ENV{ $env_prefix_key} || File::Spec->catfile( $self->dir , $self->{prefix} . '_' . $self->{app_name} . '_local.' . $self->extension ); 68 push @files , $prefix_local if -e $prefix_local; 59 my $self = shift; 60 my $env_app_key = 'CONFIG_MULTI_' . uc( $self->{app_name} ); 61 my $env_prefix_key 62 = 'CONFIG_MULTI_' 63 . uc( $self->{prefix} ) . '_' 64 . uc( $self->{app_name} ); 65 my @files = (); 66 my $app_lcoal = $ENV{$env_app_key} 67 || File::Spec->catfile( $self->dir, 68 $self->{app_name} . '_local.' . $self->extension ); 69 push @files, $app_lcoal if -e $app_lcoal; 70 71 if ( $self->{prefix} ) { 72 my $prefix_local = $ENV{$env_prefix_key} || File::Spec->catfile( 73 $self->dir, 74 $self->{prefix} . '_' 75 . $self->{app_name} 76 . '_local.' 77 . $self->extension 78 ); 79 push @files, $prefix_local if -e $prefix_local; 69 80 } 70 81 … … 73 84 74 85 sub _find_files { 75 my $self = shift;76 my $path = $self->dir;77 my $label = shift;86 my $self = shift; 87 my $path = $self->dir; 88 my $label = shift; 78 89 my $extension = $self->extension; 79 90 80 91 my @files; 81 my $dh = DirHandle->new( $path ) or croak "Could not Open " . $path;92 my $dh = DirHandle->new($path) or croak "Could not Open " . $path; 82 93 83 94 while ( my $file = $dh->read() ) { 84 95 next if $file =~ /local\.$extension$/; 85 if( $file =~ /^$label\.yml$/ || $file =~ /^$label\_(\w+)\.$extension$/ ) { 86 push @files , "$path/$file"; 96 if ( $file =~ /^$label\.yml$/ 97 || $file =~ /^$label\_(\w+)\.$extension$/ ) 98 { 99 push @files, File::Spec->catfile( $path, $file ); 87 100 } 88 101 } … … 90 103 return \@files; 91 104 } 92 93 105 94 106 1; … … 107 119 108 120 # prefix and extension is optional. 109 my $cm = Config::Multi->new({dir => $dir , app_name => 'myapp' , prefix => 'web' , extension => 'yml' }); 121 my $cm 122 = Config::Multi->new({ 123 dir => $dir , 124 app_name => 'myapp' , 125 prefix => 'web' , 126 extension => 'yml' 127 }); 110 128 my $config = $cm->load(); 111 129 my $loaded_config_files = $cm->files; … … 121 139 =head2 your configuration files 122 140 123 This is under your ~/myapp/conf/ and have sone yaml configuration in each files. you can specify the directory 124 using dir option. 141 This is under your ~/myapp/conf/ and have yaml configuration in each files. you can specify the directory using dir option. 125 142 126 143 . … … 184 201 185 202 instead of ${prefix}_${app_name}_local.yml , you can specify the path with $ENV{CONFIG_MULTI_PREFIX_MYAPP} 203 186 204 instead of ${app_name}_local.yml , you can specify the path with $ENV{CONFIG_MULTI_MYAPP} 187 205 -
lang/perl/Config-Multi/tags/0.02/t/01-loadling.t
r11708 r11786 1 use FindBin::libs;2 1 use Test::Base; 3 2 use Config::Multi; -
lang/perl/Config-Multi/tags/0.02/t/02-overwrite.t
r11667 r11786 1 use FindBin::libs;2 1 use Test::Base; 3 2 use Config::Multi; -
lang/perl/Config-Multi/tags/0.02/t/03-multi.t
r11667 r11786 1 use FindBin::libs;2 1 use Test::Base; 3 2 use Config::Multi; -
lang/perl/Config-Multi/tags/0.02/t/04-env.t
r11708 r11786 1 use FindBin::libs;2 1 use Test::Base; 3 2 use Config::Multi; -
lang/perl/Config-Multi/tags/0.02/t/05-no-prefix.t
r11710 r11786 1 use FindBin::libs;2 1 use Test::Base; 3 2 use Config::Multi; -
lang/perl/Config-Multi/tags/0.02/t/spelling.t
r11709 r11786 27 27 jobqueue 28 28 myapp 29 # configration 30 # jobqueue 31 # myapp 32 # overwrited 29 yaml -
lang/perl/Config-Multi/trunk/Changes
r11709 r11786 1 1 Revision history for Config::Multi 2 3 0.02 2008-05-17/21:53 4 - remove use FindBin::libs; 5 - fix POD indent 2 6 3 7 0.01 2008-05-17/01:17 -
lang/perl/Config-Multi/trunk/lib/Config/Multi.pm
r11710 r11786 6 6 use File::Spec; 7 7 use FindBin; 8 use Config::Any ;8 use Config::Any; 9 9 use Carp; 10 10 11 11 use base qw/Class::Accessor/; 12 12 13 our $VERSION = '0.0 1';13 our $VERSION = '0.02'; 14 14 15 15 __PACKAGE__->mk_accessors(qw/app_name prefix dir files extension/); 16 16 17 17 sub load { 18 my $self = shift;18 my $self = shift; 19 19 my @files = (); 20 20 $self->{extension} ||= 'yml'; 21 croak( 'you must set dir' )unless $self->{dir};22 croak( 'you must set app_name') unless $self->{app_name};21 croak('you must set dir') unless $self->{dir}; 22 croak('you must set app_name') unless $self->{app_name}; 23 23 24 24 my $config = {}; 25 25 26 my $app_files = $self->_find_files( $self->{app_name} );26 my $app_files = $self->_find_files( $self->{app_name} ); 27 27 my $app = Config::Any->load_files( { files => $app_files } ); 28 for ( @{$app} ){ 29 my ($filename, $data) = %$_; 30 push @files , $filename; 31 $config = { %{$config}, %{$data} } ; 32 } 33 34 if( $self->{prefix} ) { 35 my $prefix_files = $self->_find_files( $self->{prefix} . '_' . $self->{app_name} ); 36 my $prefix = Config::Any->load_files( { files => $prefix_files } ); 37 for ( @{$prefix} ){ 38 my ($filename, $data) = %$_; 39 push @files , $filename; 40 $config = { %{$config}, %{$data} } ; 28 for ( @{$app} ) { 29 my ( $filename, $data ) = %$_; 30 push @files, $filename; 31 $config = { %{$config}, %{$data} }; 32 } 33 34 if ( $self->{prefix} ) { 35 my $prefix_files 36 = $self->_find_files( $self->{prefix} . '_' . $self->{app_name} ); 37 my $prefix = Config::Any->load_files( { files => $prefix_files } ); 38 for ( @{$prefix} ) { 39 my ( $filename, $data ) = %$_; 40 push @files, $filename; 41 $config = { %{$config}, %{$data} }; 41 42 } 42 43 } 43 44 44 45 my $local_files = $self->_local_files; 45 my $local = Config::Any->load_files( { files => $local_files } );46 for ( @{$local} ) {47 my ( $filename, $data) = %$_;48 push @files , $filename;49 $config = { %{$config}, %{$data} } ;46 my $local = Config::Any->load_files( { files => $local_files } ); 47 for ( @{$local} ) { 48 my ( $filename, $data ) = %$_; 49 push @files, $filename; 50 $config = { %{$config}, %{$data} }; 50 51 } 51 52 … … 55 56 } 56 57 57 58 58 sub _local_files { 59 my $self = shift; 60 my $env_app_key = 'CONFIG_MULTI_' .uc($self->{app_name}) ; 61 my $env_prefix_key = 'CONFIG_MULTI_' . uc($self->{prefix}) . '_' . uc($self->{app_name}) ; 62 my @files = (); 63 my $app_lcoal = $ENV{ $env_app_key } || File::Spec->catfile( $self->dir , $self->{app_name} . '_local.' . $self->extension ) ; 64 push @files , $app_lcoal if -e $app_lcoal; 65 66 if( $self->{prefix}) { 67 my $prefix_local = $ENV{ $env_prefix_key} || File::Spec->catfile( $self->dir , $self->{prefix} . '_' . $self->{app_name} . '_local.' . $self->extension ); 68 push @files , $prefix_local if -e $prefix_local; 59 my $self = shift; 60 my $env_app_key = 'CONFIG_MULTI_' . uc( $self->{app_name} ); 61 my $env_prefix_key 62 = 'CONFIG_MULTI_' 63 . uc( $self->{prefix} ) . '_' 64 . uc( $self->{app_name} ); 65 my @files = (); 66 my $app_lcoal = $ENV{$env_app_key} 67 || File::Spec->catfile( $self->dir, 68 $self->{app_name} . '_local.' . $self->extension ); 69 push @files, $app_lcoal if -e $app_lcoal; 70 71 if ( $self->{prefix} ) { 72 my $prefix_local = $ENV{$env_prefix_key} || File::Spec->catfile( 73 $self->dir, 74 $self->{prefix} . '_' 75 . $self->{app_name} 76 . '_local.' 77 . $self->extension 78 ); 79 push @files, $prefix_local if -e $prefix_local; 69 80 } 70 81 … … 73 84 74 85 sub _find_files { 75 my $self = shift;76 my $path = $self->dir;77 my $label = shift;86 my $self = shift; 87 my $path = $self->dir; 88 my $label = shift; 78 89 my $extension = $self->extension; 79 90 80 91 my @files; 81 my $dh = DirHandle->new( $path ) or croak "Could not Open " . $path;92 my $dh = DirHandle->new($path) or croak "Could not Open " . $path; 82 93 83 94 while ( my $file = $dh->read() ) { 84 95 next if $file =~ /local\.$extension$/; 85 if( $file =~ /^$label\.yml$/ || $file =~ /^$label\_(\w+)\.$extension$/ ) { 86 push @files , "$path/$file"; 96 if ( $file =~ /^$label\.yml$/ 97 || $file =~ /^$label\_(\w+)\.$extension$/ ) 98 { 99 push @files, File::Spec->catfile( $path, $file ); 87 100 } 88 101 } … … 90 103 return \@files; 91 104 } 92 93 105 94 106 1; … … 107 119 108 120 # prefix and extension is optional. 109 my $cm = Config::Multi->new({dir => $dir , app_name => 'myapp' , prefix => 'web' , extension => 'yml' }); 121 my $cm 122 = Config::Multi->new({ 123 dir => $dir , 124 app_name => 'myapp' , 125 prefix => 'web' , 126 extension => 'yml' 127 }); 110 128 my $config = $cm->load(); 111 129 my $loaded_config_files = $cm->files; … … 121 139 =head2 your configuration files 122 140 123 This is under your ~/myapp/conf/ and have sone yaml configuration in each files. you can specify the directory 124 using dir option. 141 This is under your ~/myapp/conf/ and have yaml configuration in each files. you can specify the directory using dir option. 125 142 126 143 . … … 184 201 185 202 instead of ${prefix}_${app_name}_local.yml , you can specify the path with $ENV{CONFIG_MULTI_PREFIX_MYAPP} 203 186 204 instead of ${app_name}_local.yml , you can specify the path with $ENV{CONFIG_MULTI_MYAPP} 187 205 -
lang/perl/Config-Multi/trunk/t/01-loadling.t
r11708 r11786 1 use FindBin::libs;2 1 use Test::Base; 3 2 use Config::Multi; -
lang/perl/Config-Multi/trunk/t/02-overwrite.t
r11667 r11786 1 use FindBin::libs;2 1 use Test::Base; 3 2 use Config::Multi; -
lang/perl/Config-Multi/trunk/t/03-multi.t
r11667 r11786 1 use FindBin::libs;2 1 use Test::Base; 3 2 use Config::Multi; -
lang/perl/Config-Multi/trunk/t/04-env.t
r11708 r11786 1 use FindBin::libs;2 1 use Test::Base; 3 2 use Config::Multi; -
lang/perl/Config-Multi/trunk/t/05-no-prefix.t
r11710 r11786 1 use FindBin::libs;2 1 use Test::Base; 3 2 use Config::Multi; -
lang/perl/Config-Multi/trunk/t/spelling.t
r11709 r11786 27 27 jobqueue 28 28 myapp 29 # configration 30 # jobqueue 31 # myapp 32 # overwrited 29 yaml
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)