Sledge::Config to YAML::Load

tokuhirom on 2006-11-02T05:22:10

Long time ago, Sledge's config is written in codes, likes old version of Catalyst.

I want to write the config in YAML.YAML is cool, that is human readable and writable.

current style of Sledge::Config :

package Proj::Config;
use strict;
use warnings;
use base qw(Sledge::Config Class::Singleton);

sub case_sensitive { 0 }

sub _new_instance { my $class = shift; unless (defined $ENV{SLEDGE_CONFIG_NAME}) { do '/etc/proj-conf.pl' or warn $!; } $class->SUPER::new($ENV{SLEDGE_CONFIG_NAME}); }

1;

package Proj::Config::_common; use strict; use vars qw(%C); *Config = \%C;

$C{TMPL_PATH} = '/path/to/tmpl_dir'; $C{COOKIE_NAME} = 'sledge_sid'; $C{COOKIE_PATH} = '/'; $C{COOKIE_DOMAIN} = undef;

1;

package Proj::Config::_development; use strict; use vars qw(%C); *Config = \%C;

$C{DATASOURCE} = [ 'dbi:mysql:sledge','root', '' ];

1; package Proj::Config::_product; use strict; use vars qw(%C); *Config = \%C;

$C{DATASOURCE} = [ 'dbi:mysql:sledge;host=192.168.1.30','root', '' ];

1;


If you use the Sledge::Config::YAML, written by precuredaisuki, you can write config by YAML.

package Your::Config;
use basei qw(Sledge::Config::YAML Class::Singleton);

sub _new_instance { my $class = shift;

$class->SUPER::new($ENV{SLEDGE_CONFIG_NAME}, $ENV{SLEDGE_CONFIG_FILE}); }

1;


and, your yaml is:
common:
  tmpl_path: /path/to/tmpl_dir
  cookie_name: sledge_sid
  cookie_path: /
  cookie_domain: ~
product:
  datasource:
    - dbi:mysql:sledge;host=192.168.1.30
    - root
    - 
development:
  datasource:
    - dbi:mysql:sledge
    - root
    -