Debian Codegraph @

README

raw
1 NAME
2 Config::Auto - Magical config file parser
3
4 SYNOPSIS
5 use Config::Auto;
6
7 # Not very magical at all.
8 my $config = Config::Auto::parse("myprogram.conf", format => "colon");
9
10 # Considerably more magical.
11 my $config = Config::Auto::parse("myprogram.conf");
12
13 # Highly magical.
14 my $config = Config::Auto::parse();
15
16 DESCRIPTION
17 This module was written after having to write Yet Another Config File
18 Parser for some variety of colon-separated config. I decided "never
19 again".
20
21 When you call "Config::Auto::parse" with no arguments, we first look at
22 $0 to determine the program's name. Let's assume that's "snerk". We look
23 for the following files:
24
25 snerkconfig
26 ~/snerkconfig
27 /etc/snerkconfig
28 snerk.config
29 ~/snerk.config
30 /etc/snerk.config
31 snerkrc
32 ~/snerkrc
33 /etc/snerkrc
34 .snerkrc
35 ~/.snerkrc
36 /etc/.snerkrc
37
38 We take the first one we find, and examine it to determine what format
39 it's in. The algorithm used is a heuristic "which is a fancy way of
40 saying that it doesn't work." (Mark Dominus.) We know about colon
41 separated, space separated, equals separated, XML, Perl code, Windows
42 INI, BIND9 and irssi style config files. If it chooses the wrong one,
43 you can force it with the "format" option.
44
45 If you don't want it ever to detect and execute config files which are
46 made up of Perl code, set "$Config::Auto::DisablePerl = 1".
47
48 Then the file is parsed and a data structure is returned. Since we're
49 working magic, we have to do the best we can under the circumstances -
50 "You rush a miracle man, you get rotten miracles." (Miracle Max) So
51 there are no guarantees about the structure that's returned. If you have
52 a fairly regular config file format, you'll get a regular data structure
53 back. If your config file is confusing, so will the return structure be.
54 Isn't life tragic?
55
56 Here's what we make of some common Unix config files:
57
58 /etc/resolv.conf:
59
60 $VAR1 = {
61 'nameserver' => [ '163.1.2.1', '129.67.1.1', '129.67.1.180' ],
62 'search' => [ 'oucs.ox.ac.uk', 'ox.ac.uk' ]
63 };
64
65 /etc/passwd:
66
67 $VAR1 = {
68 'root' => [ 'x', '0', '0', 'root', '/root', '/bin/bash' ],
69 ...
70 };
71
72 /etc/gpm.conf:
73
74 $VAR1 = {
75 'append' => '""',
76 'responsiveness' => '',
77 'device' => '/dev/psaux',
78 'type' => 'ps2',
79 'repeat_type' => 'ms3'
80 };
81
82 /etc/nsswitch.conf:
83
84 $VAR1 = {
85 'netgroup' => 'nis',
86 'passwd' => 'compat',
87 'hosts' => [ 'files', 'dns' ],
88 ...
89 };
90
91 TODO
92 BIND9 and irssi file format parsers currently don't exist. It would be
93 good to add support for "mutt" and "vim" style "set"-based RCs.
94
95 AUTHOR
96 Simon Cozens, "[email protected]"
97
98 LICENSE
99 AL&GPL.
100