views:

54

answers:

1

I want to have my Perl program support both Win32 Registry and the similar feature in Linux.

GConf maybe a good idea, but it's too heavy. Is there some lightweight user preference support in CPAN?

+2  A: 

Why not use YAML (and YAML::XS)?

Now the main thing that suggests YAML to me is that it supports nested structures. Thus, you could still keep the concept of Key.subkey.subkey.... from the Windows registry and thus keep the concept structure similar.

You would need to create an object that reads the YAML file and then handles requests and storage via paths. In the YAML, you could even create HKEY_CURRENT_USER sections or something.

---
HKEY_LOCAL_MACHINE:
  Software:
    Brand A:
      Product P:
        Items: 
          - One
          - Two
          - Three

And you would read this by turning '/HKEY_LOCAL_MACHINE/Software/Brand A/Product P/Items' into

$yaml_reg->{HKEY_LOCAL_MACHINE}{Software}{'Brand A'}{'Product P'}{Items}
Axeman
`YAML` is great, but I hate to code win32 registry keys in Linux.
谢继雷
@谢继雷, How were you thinking of mapping the paths then? All I was thinking of was a uniform high-level way of referring to keys. In that case you would need to code a wrapper around the registry object which maps keys to registry paths.
Axeman
YAML is too general and low-level, if I code a wrapper around, I don't think there's too much difference between manipulating a config file. I can put the config file under `~/.xyz/config` or `/usr/share/xyz/def` or somewhere. In `GConf`, all config goes into `~/.gconf2/*`. The problem of `YAML` is it requires me to define a specific config file, but not uniformly well defined by Perl policy or somewhat.
谢继雷