Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

tokuhirom (7396)

tokuhirom
  (email not shown publicly)
http://d.hatena.ne.jp/tokuhirom/

Journal of tokuhirom (7396)

Thursday November 02, 2006
12:22 AM

Sledge::Config to YAML::Load

[ #31483 ]

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
    -

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.