Changeset 4243

Show
Ignore:
Timestamp:
01/09/08 03:42:45 (5 years ago)
Author:
cho45
Message:

lang/perl/Config-Pit/trunk/t/01_basic.t,
lang/perl/Config-Pit/trunk/lib/Config/Pit.pm:

Append switch tests.

Location:
lang/perl/Config-Pit/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Config-Pit/trunk/lib/Config/Pit.pm

    r4227 r4243  
    7272        $YAML::Syck::SingleQuote    = 1; 
    7373 
     74        $name ||= "default"; 
     75 
    7476        $profile_file = File::Spec->catfile($directory, "$name.yaml"); 
    7577 
    7678        my $config = _config(); 
     79        my $ret = $config->{profile}; 
    7780        $config->{profile} = $name; 
    7881        YAML::Syck::DumpFile($config_file, $config); 
     82        return $ret; 
    7983} 
    8084 
     
    164168=back 
    165169 
     170=item Config::Pit::set(setting_name, opts) 
     171 
     172Set setting named C<setting_name> to current profile. 
     173 
     174  Config::Pit::set("twitter.com"); #=> will open setting with $EDITOR 
     175 
     176opts: 
     177 
     178=over 
     179 
     180=item data 
     181 
     182  Config::Pit::set("twitter.com", data => { 
     183    username => "foobar", 
     184    password => "barbaz", 
     185  }); 
     186 
     187When C<data> specified, will not open C<$EDITOR> and set the data directly. 
     188 
     189=over 
     190 
     191=item config 
     192 
     193 
     194  Config::Pit::set("twitter.com", config => { 
     195    username => "config description or default value", 
     196    password => "same as above", 
     197  }); 
     198 
     199Open C<$EDITOR> with merged setting with specified config. 
     200 
     201=back 
     202 
     203=item Config::Pit::switch(profile_name); 
     204 
     205Switch profile to C<profile_name>. 
     206 
     207Profile is setting set: 
     208 
     209  $ pit get foobar 
     210  # foo bar... 
     211 
     212  $ pit switch devel 
     213  Switch profile to devel 
     214 
     215  $ pit get foobar 
     216  # bar baz 
     217 
     218  $ pit switch 
     219  Switch profile to default 
     220 
     221  $ pit get foobar 
     222  # foo bar... 
     223 
     224=back 
     225 
    166226=back 
    167227 
  • lang/perl/Config-Pit/trunk/t/01_basic.t

    r4238 r4243  
    22use warnings; 
    33 
    4 use Test::More tests => 11; 
     4use Test::More tests => 17; 
    55use File::Temp; 
    66use Path::Class; 
     
    1515$Config::Pit::directory = dir($dir->dirname); 
    1616 
    17 my $config; 
     17my ($config, $p); 
    1818 
    1919$config = Config::Pit::get("test"); 
     
    3636is($config->{bar}, "baz", "get returned value (exported sub)"); 
    3737 
     38$p = Config::Pit::switch("profile"); 
     39is($p, "default", "switch profile"); 
     40$config = pit_get("test"); 
     41is($config->{foo}, undef, "switch profile get value"); 
     42is($config->{bar}, undef, "switch profile get value"); 
     43 
     44$p = Config::Pit::switch(); 
     45is($p, "profile", "switch profile"); 
     46$config = pit_get("test"); 
     47is($config->{foo}, "bar", "switch profile get value"); 
     48is($config->{bar}, "baz", "switch profile get value"); 
    3849 
    3950# EDITOR