Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hey arbingersys, tell me about it. I'm maintaining a number of loosely coupled, but interelated web site instances. In addition there are multiple development and test sites. A lot of the information is shared, but to give each it's own copy, that's a cut and paste nightmare.

Since you ask, here's how I've approached it:

  • I maintain a meta config file. This has knowledge about all the websites in the cluster.
  • At run time, when I load the meta-config, it conditionally extract just the config information required by this application, running on this host, in this working directory:

    A snippet from a typical (YAML) config file and Perl extraction code follow. The "about" clauses represent the conditional parts:

    --- timezone: Australia/Melbourne demo_url: http://someapponline.co.uk?logout=1&_client=8 support_url: /?_action=support::support some_root_id: 1272 # someapp_db: adaptor: mysql database: some_database host: localhost username: some_username password: some_password # otherapp_db: adaptor: mysql database: some_database host: localhost username: some_username password: some_password # about: host: somehost.com.au: about: server_root: /home/snoopy/merge/www_someapp: &1 prod_level: devl client_root: /var/www/devl/someapp someapp_url: http://devl.someapp.com.au demo_url: http://devl.someapp.com.au?logout=1&_client=14 otherapp_url: http://someapp.dowork.com.au /home/david/doitall: *1 someotherhost.com: about: server_root: # /home/wwwbaz/public_html: prod_level: prod otherapp_url: http://someapp.com.au/otherapp someapp_url: http://someapp.com.au demo_url: http://someapp.com.au?logout=1&_client=14 client_root: /home/wwwbaz/public_html # /home/wwwbazuk/public_html: prod_level: prod otherapp_url: http://mywebsite.com/otherapp someapp_url: http://mywebsite.com client_root: /home/wwwfoobar/public_html someapp_db: adaptor: mysql database: yet_another_database host: localhost username: yet_another_username password: yet_aother_password
    I'm using the host name and the working directory to build the actual run-time settings for this instance of the application.
    package SomeApp::Config; use warnings; use strict; use YAML; use Cwd; use Config::Auto; use Class::Autouse qw/Sys::Hostname/; our $Config; our $Host; our $Cwd; use Class::Struct ('Database' => { adaptor => '$', database => '$', host => '$', username => '$', password => '$', }); use Class::Struct ( client_root => '$', demo_url => '$', host => '$', someapp_db => 'Database', someapp_url => '$', prod_level => '$', server_root => '$', root_id => '$', support_url => '$', timezone => '$', otherapp_db => 'Database', otherapp_url => '$', ); { my $config = Config::Auto::parse('someapp.ini', format => 'yaml'); my @config = _load_config($config); $Config = __PACKAGE__->new( @config ); } sub _load_config { my $ config = shift; my @config = (); my $about = delete $config->{about}; push(@config, map{$_ => $config->{$_}} (keys %$config)); $Host ||= Sys::Hostname::hostname(); $Cwd ||= cwd(); if ($about) { die "malformed 'about' clause in config file" unless (ref $about eq 'HASH'); foreach (keys %$about) { if ($_ eq 'host') { my $about_hosts = $about->{'host'}; if (my $about_this_host = $about_hosts->{$Host}) { push (@config, _load_config ($about_this_host)); } } elsif ($_ eq 'server_root') { my $about_cwds = $about->{'server_root'}; foreach (sort keys %$about_cwds) { if (substr($Cwd, 0, length($_)) eq $_) { my $about_this_cwd = $about_cwds->{$_}; push (@config, _load_config ($about_this_cwd)) +; } } } else { die "don't know anything 'about' $_"; } } } push (@config, 'host', $Host); push (@config, 'server_root', $Cwd); return (@config); } sub config { return $Config; }; 1;

    In reply to Re: Single file oriented for different usage by snoopy
    in thread Single file oriented for different usage by arbingersys

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":



    • Are you posting in the right place? Check out Where do I post X? to know for sure.
    • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
      <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
    • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
    • Want more info? How to link or How to display code and escape characters are good places to start.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others about the Monastery: (3)
    As of 2024-04-25 17:37 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found