Professional Web Applications Themes

config file: a) what Module ? b) conditionals in config (for multiple hosts) - PERL Beginners

Hi, a) I am looking for a module to handle config files. There are a number of these modules, like AppCconig. Any consensus about The Right Module for this? b) As I develop one one machine and test/deploy on another, I want constructs in my config file like: if (`hostname` eq 'dev_box') { mysql_dsn = 'foobar'; } elsif ((`hostname` eq 'test_box'} mysql_dsn = 'abracadabra'; ... Any support for that in your module of choice? I know of the use-just-perl-code approach (with 'do') in the Perl Cookbook, but I am wondering if new insights exist. TIA ~henq...

  1. #1

    Default config file: a) what Module ? b) conditionals in config (for multiple hosts)

    Hi,

    a) I am looking for a module to handle config files. There are a number of
    these modules, like AppCconig. Any consensus about The Right Module for
    this?


    b) As I develop one one machine and test/deploy on another, I want
    constructs in my config file like:

    if (`hostname` eq 'dev_box') {
    mysql_dsn = 'foobar';
    } elsif ((`hostname` eq 'test_box'}
    mysql_dsn = 'abracadabra';
    ...

    Any support for that in your module of choice?

    I know of the use-just-perl-code approach (with 'do') in the Perl Cookbook,
    but I am wondering if new insights exist.

    TIA

    ~henq


    Henq Guest

  2. #2

    Default Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)


    > Hi,
    >
    > a) I am looking for a module to handle config files. There are a number of
    > these modules, like AppCconig. Any consensus about The Right Module for
    > this?
    >
    Whichever module gets the job done the way you want it. I have used
    AppConfig with some success but it fails to handle overly complex
    structures (not its claim to fame either) some people (read: myself)
    have come to expect in a config file so I switched to using XML::Simple
    for more complex tasks. Since I started out in the web world that
    transition was obviously easy for me. I have found in general the
    module that is chosen is based more on the format of the config file,
    which is usually left up to the person editing it and how comfortable
    they are with doing so, or whether there will be an interface to editing
    it. If the config file changes a lot and non-developers will edit it go
    with something simple like AppConfig because it is relatively powerful
    without complex layout restrictions, if the config file changes in
    frequently, is updated by knowledgeable users, and/or has an interface
    for making updates then go with a module that is easily written back out
    and allows for arbitrarily complex data structures....
    >
    > b) As I develop one one machine and test/deploy on another, I want
    > constructs in my config file like:
    >
    > if (`hostname` eq 'dev_box') {
    > mysql_dsn = 'foobar';
    > } elsif ((`hostname` eq 'test_box'}
    > mysql_dsn = 'abracadabra';
    > ...
    >
    > Any support for that in your module of choice?
    >
    > I know of the use-just-perl-code approach (with 'do') in the Perl
    Cookbook,
    > but I am wondering if new insights exist.
    >
    Not that I know of, that is a rather complex deal, where is hostname? is
    it in the path? what about machines that may not supply it? If you
    want a dev/q-a/prod set of config files i have found it more appropriate
    to use the same structure in a set of 3 different config files, then
    migrate the unique config files to each of the environments. Granted
    when you change the structure you have to update 3 copies, but it
    simplifies the programming, which *should* be the expensive part.

    Just my $.02,

    [url]http://danconia.org[/url]

    Wiggins D Anconia Guest

  3. #3

    Default Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)

    From: "Wiggins d Anconia" <wigginsdanconia.org>
    > > b) As I develop one one machine and test/deploy on another, I want
    > > constructs in my config file like:
    > >
    > > if (`hostname` eq 'dev_box') {
    > > mysql_dsn = 'foobar';
    > > } elsif ((`hostname` eq 'test_box'}
    > > mysql_dsn = 'abracadabra';
    > > ...
    > >
    > > Any support for that in your module of choice?
    > >
    > > I know of the use-just-perl-code approach (with 'do') in the Perl
    > Cookbook,
    > > but I am wondering if new insights exist.
    > >
    >
    > Not that I know of, that is a rather complex deal, where is hostname?
    > is it in the path? what about machines that may not supply it? If
    > you want a dev/q-a/prod set of config files i have found it more
    > appropriate to use the same structure in a set of 3 different config
    > files, then migrate the unique config files to each of the
    > environments. Granted when you change the structure you have to update
    > 3 copies, but it simplifies the programming, which *should* be the
    > expensive part.
    To simplify this you may consider using two configs. One "global"
    that contains the settings that are the same everywhere (which will
    probably be most of them) and one "local" that will contain the
    specialties. And then read both the configs and merge them so that
    the "local" overwrites the "global".

    That was if you need to make the same change to all machines you can
    do it in the "global" config and then just copy the file.

    Jenda
    ===== [email]JendaKrynicky.cz[/email] === [url]http://Jenda.Krynicky.cz[/url] =====
    When it comes to wine, women and song, wizards are allowed
    to get drunk and croon as much as they like.
    -- Terry Pratchett in Sourcery

    Jenda Krynicky Guest

  4. #4

    Default Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)


    "Wiggins D Anconia" <wigginsdanconia.org> schreef in bericht
    news:200310301436.h9UEaDq18612residualselfimage.c om...
    > > Hi,
    > I have found in general the
    > module that is chosen is based more on the format of the config file,

    YAML is a rising star as formats go, I believe.



    > > where is hostname? is
    it's a system command (back ticks).


    Henq Guest

  5. #5

    Default Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)


    "Jenda Krynicky" <JendaKrynicky.cz> schreef in bericht
    news:3FA1332B.19987.48CF3554localhost...
    > From: "Wiggins d Anconia" <wigginsdanconia.org>
    > To simplify this you may consider using two configs. One "global"
    > that contains the settings that are the same everywhere (which will
    > probably be most of them) and one "local" that will contain the
    > specialties. And then read both the configs and merge them so that
    > the "local" overwrites the "global".


    yes, that sunds like the rigtht solution. Funny, It was right under my nose
    as this method is explained in the chapter of the Cookbook I mentioned...

    like: my %config = {%standard, %override};



    Henq Guest

  6. #6

    Default Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)

    From: "henq" <onion.perl.org henq _ replace 0 by o <hvtijenh0tmail.c0m>>
    > "Jenda Krynicky" <JendaKrynicky.cz> schreef in bericht
    > news:3FA1332B.19987.48CF3554localhost...
    > > From: "Wiggins d Anconia" <wigginsdanconia.org>
    >
    > > To simplify this you may consider using two configs. One "global"
    > > that contains the settings that are the same everywhere (which will
    > > probably be most of them) and one "local" that will contain the
    > > specialties. And then read both the configs and merge them so that
    > > the "local" overwrites the "global".
    >
    > yes, that sunds like the rigtht solution. Funny, It was right under my
    > nose as this method is explained in the chapter of the Cookbook I
    > mentioned...
    >
    > like: my %config = {%standard, %override};
    You want ( instead of { !

    Jenda
    ===== [email]JendaKrynicky.cz[/email] === [url]http://Jenda.Krynicky.cz[/url] =====
    When it comes to wine, women and song, wizards are allowed
    to get drunk and croon as much as they like.
    -- Terry Pratchett in Sourcery

    Jenda Krynicky Guest

  7. #7

    Default Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)


    >
    > "Wiggins D Anconia" <wigginsdanconia.org> schreef in bericht
    > news:200310301436.h9UEaDq18612residualselfimage.c om...
    > > > Hi,
    > > I have found in general the
    > > module that is chosen is based more on the format of the config file,
    >
    >
    > YAML is a rising star as formats go, I believe.
    >
    >
    >
    >
    > > > where is hostname? is
    >
    > it's a system command (back ticks).
    >
    You missed the point, *I* know what 'hostname' is, but you restrict
    yourself to platforms and environments that have it defined and open
    yourself to security issues by attempting to use it in the manner you
    stated.

    On my RH 9.0 box hostname is in, /bin, on solaris 8 it is in /usr/bin,
    other systems could put it in any of /usr/local/bin, /opt/bin,
    /usr/sbin, /sbin, /my/really/long/weird/location/bin, etc., who knows if
    windows even has 'hostname' and where it would be.... ok so you depend
    on it being in the path, is the path setup correctly? what happens when
    you put it in cron? how about under a chroot? What happens when someone
    throws, ~/bin in their path and wants to have a 'hostname' command that
    logs into their NAT box and updates an IP address, ok they chose a dumb
    name, but your script is now broke......

    [url]http://danconia.org[/url]
    Wiggins D Anconia Guest

Similar Threads

  1. j2ee config and virtual hosts
    By kylewright in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: June 7th, 06:42 PM
  2. Noob Q: Ways for module to find config file?
    By J Krugman in forum PERL Modules
    Replies: 3
    Last Post: March 3rd, 06:40 PM
  3. Req advice on new module to be uploaded: Config::Magic?
    By Rusty Phillips in forum PERL Modules
    Replies: 1
    Last Post: June 22nd, 12:33 PM
  4. Replies: 3
    Last Post: June 1st, 02:49 AM
  5. Replies: 9
    Last Post: October 1st, 10:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139