Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Data-driven Programming: fun with Perl, JSON, YAML, XML...

by LanX (Sage)
on Apr 19, 2015 at 11:47 UTC ( #1123954=note: print w/replies, xml ) Need Help??

in reply to Data-driven Programming: fun with Perl, JSON, YAML, XML...

Personally I'd prefer working with a Domain Specific Language for configuration, far more flexible!

Each entry must be a sub in your my_config package, action is a sub action (&) {...} taking a code block with options.

It's not only easy to read for non programmers, but also easy to validate (just add prototypes and do argument checking within the subs)

package my_config; action { id 'svninfo'; desc 'svn working copy information'; cmdline 'svn info'; workdir ''; logfile 'minbld_svninfo.log'; tee 1; prompt 0; run 1; }; action { id 'svnup'; desc 'Run full svn update'; cmdline 'svn update'; workdir ''; logfile 'minbld_svnupdate.log'; tee 1; prompt 0; run 1; }; # ...

(update: features which are only boolean could be handled without arguments with useful defaults, i.e. run 1 is simply run and run 0 is skipped)

DRY could be achieved with preloaded constants, nested structures or special commands to set defaults like

default workdir => ''; # or default { workdir ''; } # or just a top-level setting workdir ''; action { # workdir can be missing now }

The fact that you can insert arbitrary perlcode is a mixed bag, it might add extra flexibility but also be a source of bugs with non-hackers. Deactivating builtins in CORE might be an option...

Dunno if there is already an appropriate module on CPAN (?), otherwise I'd volunteer producing one for the comming GPW.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1123954]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2022-05-26 15:05 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (93 votes). Check out past polls.