Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Config::GitLike.3pm
CommitLineData
3fea05b9 1.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.10)
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sp \" Vertical space (when we can't use .PP)
6.if t .sp .5v
7.if n .sp
8..
9.de Vb \" Begin verbatim text
10.ft CW
11.nf
12.ne \\$1
13..
14.de Ve \" End verbatim text
15.ft R
16.fi
17..
18.\" Set up some character translations and predefined strings. \*(-- will
19.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20.\" double quote, and \*(R" will give a right double quote. \*(C+ will
21.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
22.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
23.\" nothing in troff, for use with C<>.
24.tr \(*W-
25.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26.ie n \{\
27. ds -- \(*W-
28. ds PI pi
29. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
31. ds L" ""
32. ds R" ""
33. ds C` ""
34. ds C' ""
35'br\}
36.el\{\
37. ds -- \|\(em\|
38. ds PI \(*p
39. ds L" ``
40. ds R" ''
41'br\}
42.\"
43.\" Escape single quotes in literal strings from groff's Unicode transform.
44.ie \n(.g .ds Aq \(aq
45.el .ds Aq '
46.\"
47.\" If the F register is turned on, we'll generate index entries on stderr for
48.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
49.\" entries marked with X<> in POD. Of course, you'll have to process the
50.\" output yourself in some meaningful fashion.
51.ie \nF \{\
52. de IX
53. tm Index:\\$1\t\\n%\t"\\$2"
54..
55. nr % 0
56. rr F
57.\}
58.el \{\
59. de IX
60..
61.\}
62.\"
63.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
64.\" Fear. Run. Save yourself. No user-serviceable parts.
65. \" fudge factors for nroff and troff
66.if n \{\
67. ds #H 0
68. ds #V .8m
69. ds #F .3m
70. ds #[ \f1
71. ds #] \fP
72.\}
73.if t \{\
74. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
75. ds #V .6m
76. ds #F 0
77. ds #[ \&
78. ds #] \&
79.\}
80. \" simple accents for nroff and troff
81.if n \{\
82. ds ' \&
83. ds ` \&
84. ds ^ \&
85. ds , \&
86. ds ~ ~
87. ds /
88.\}
89.if t \{\
90. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
91. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
92. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
93. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
94. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
95. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
96.\}
97. \" troff and (daisy-wheel) nroff accents
98.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
99.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
100.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
101.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
102.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
103.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
104.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
105.ds ae a\h'-(\w'a'u*4/10)'e
106.ds Ae A\h'-(\w'A'u*4/10)'E
107. \" corrections for vroff
108.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
109.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
110. \" for low resolution devices (crt and lpr)
111.if \n(.H>23 .if \n(.V>19 \
112\{\
113. ds : e
114. ds 8 ss
115. ds o a
116. ds d- d\h'-1'\(ga
117. ds D- D\h'-1'\(hy
118. ds th \o'bp'
119. ds Th \o'LP'
120. ds ae ae
121. ds Ae AE
122.\}
123.rm #[ #] #H #V #F C
124.\" ========================================================================
125.\"
126.IX Title "Config::GitLike 3"
127.TH Config::GitLike 3 "2010-04-03" "perl v5.8.8" "User Contributed Perl Documentation"
128.\" For nroff, turn off justification. Always turn off hyphenation; it makes
129.\" way too many mistakes in technical documents.
130.if n .ad l
131.nh
132.SH "NAME"
133Config::GitLike \- git\-compatible config file parsing
134.SH "SYNOPSIS"
135.IX Header "SYNOPSIS"
136This module parses git-style config files, which look like this:
137.PP
138.Vb 10
139\& [core]
140\& repositoryformatversion = 0
141\& filemode = true
142\& bare = false
143\& logallrefupdates = true
144\& [remote "origin"]
145\& url = spang.cc:/srv/git/home.git
146\& fetch = +refs/heads/*:refs/remotes/origin/*
147\& [another\-section "subsection"]
148\& key = test
149\& key = multiple values are OK
150\& emptyvalue =
151\& novalue
152.Ve
153.PP
154Code that uses this config module might look like:
155.PP
156.Vb 1
157\& use Config::GitLike;
158\&
159\& my $c = Config::GitLike\->new(confname => \*(Aqconfig\*(Aq);
160\& $c\->load;
161\&
162\& $c\->get( key => \*(Aqsection.name\*(Aq );
163\& # make the return value a Perl true/false value
164\& $c\->get( key => \*(Aqcore.filemode\*(Aq, as => \*(Aqbool\*(Aq );
165\&
166\& # replace the old value
167\& $c\->set(
168\& key => \*(Aqsection.name\*(Aq,
169\& value => \*(Aqval1\*(Aq,
170\& filename => \*(Aq/home/user/.config\*(Aq,
171\& );
172\&
173\& # make this key have multiple values rather than replacing the
174\& # old value
175\& $c\->set(
176\& key => \*(Aqsection.name\*(Aq,
177\& value => \*(Aqval2\*(Aq,
178\& filename => \*(Aq/home/user/.config\*(Aq,
179\& multiple => 1,
180\& );
181\&
182\& # replace all occurrences of the old value for section.name with a new one
183\& $c\->set(
184\& key => \*(Aqsection.name\*(Aq,
185\& value => \*(Aqval3\*(Aq,
186\& filename => \*(Aq/home/user/.config\*(Aq,
187\& multiple => 1,
188\& replace_all => 1,
189\& );
190\&
191\& # make sure to reload the config files before reading if you\*(Aqve set
192\& # any variables!
193\& $c\->load;
194\&
195\& # get only the value of \*(Aqsection.name\*(Aq that matches \*(Aq2\*(Aq
196\& $c\->get( key => \*(Aqsection.name\*(Aq, filter => \*(Aq2\*(Aq );
197\& $c\->get_all( key => \*(Aqsection.name\*(Aq );
198\& # prefixing a search regexp with a ! negates it
199\& $c\->get_regexp( key => \*(Aq!na\*(Aq );
200\&
201\& $c\->rename_section(
202\& from => \*(Aqsection\*(Aq,
203\& to => \*(Aqnew\-section\*(Aq,
204\& filename => \*(Aq/home/user/.config\*(Aq
205\& );
206\&
207\& $c\->remove_section(
208\& section => \*(Aqsection\*(Aq,
209\& filename => \*(Aq/home/user/.config\*(Aq
210\& );
211\&
212\& # unsets all instances of the given key
213\& $c\->set( key => \*(Aqsection.name\*(Aq, filename => \*(Aq/home/user/.config\*(Aq );
214\&
215\& my %config_vals = $config\->dump;
216\& # string representation of config data
217\& my $str = $config\->dump;
218\& # prints rather than returning
219\& $config\->dump;
220.Ve
221.SH "DESCRIPTION"
222.IX Header "DESCRIPTION"
223This module handles interaction with configuration files of the style used
224by the version control system Git. It can both parse and modify these
225files, as well as create entirely new ones.
226.PP
227You only need to know a few things about the configuration format in order
228to use this module. First, a configuration file is made up of key/value
229pairs. Every key must be contained in a section. Sections can have
230subsections, but they don't have to. For the purposes of setting and
231getting configuration variables, we join the section name,
232subsection name, and variable name together with dots to get a key
233name that looks like \*(L"section.subsection.variable\*(R". These are the
234strings that you'll be passing in to \f(CW\*(C`key\*(C'\fR arguments.
235.PP
236Configuration files inherit from each other. By default, \f(CW\*(C`Config::GitLike\*(C'\fR
237loads data from a system-wide configuration file, a per-user
238configuration file, and a per-directory configuration file, but by
239subclassing and overriding methods you can obtain any combination of
240configuration files. By default, configuration files that don't
241exist are just skipped.
242.PP
243See
244<http://www.kernel.org/pub/software/scm/git/docs/git\-config.html#_configuration_file>
245for details on the syntax of git configuration files. We won't waste pixels
246on the nitty gritty here.
247.PP
248While the behaviour of a couple of this module's methods differ slightly
249from the \f(CW\*(C`git config\*(C'\fR equivalents, this module can read any config file
250written by git. The converse is usually true, but only if you don't take
251advantage of this module's increased permissiveness when it comes to key
252names. (See \*(L"\s-1DIFFERENCES\s0 \s-1FROM\s0 GIT-CONFIG\*(R" for details.)
253.PP
254This is an object-oriented module using Any::Moose. All
255subroutines are object method calls.
256.PP
257A few methods have parameters that are always used for the same purpose:
258.SS "Filenames"
259.IX Subsection "Filenames"
260All methods that change things in a configuration file require a filename to
261write to, via the \f(CW\*(C`filename\*(C'\fR parameter. Since a \f(CW\*(C`Config::GitLike\*(C'\fR object can
262be working with multiple config files that inherit from each other, we don't
263try to figure out which one to write to automatically and let you specify
264instead.
265.SS "Casting"
266.IX Subsection "Casting"
267All get and set methods can make sure the values they're returning or
268setting are valid values of a certain type: \f(CW\*(C`bool\*(C'\fR, \f(CW\*(C`int\*(C'\fR,
269\&\f(CW\*(C`num\*(C'\fR, or \f(CW\*(C`bool\-or\-int\*(C'\fR (or at least as close as Perl can get
270to having these types). Do this by passing one of these types
271in via the \f(CW\*(C`as\*(C'\fR parameter. The set method, if told to write
272bools, will always write \*(L"true\*(R" or \*(L"false\*(R" (not anything else that
273\&\f(CW\*(C`cast\*(C'\fR considers a valid bool).
274.PP
275Methods that are told to cast values will throw exceptions if
276the values they're trying to cast aren't valid values of the
277given type.
278.PP
279See the \*(L"cast\*(R" method documentation for more on what is considered valid
280for each type.
281.SS "Filtering"
282.IX Subsection "Filtering"
283All get and set methods can filter what values they return via their
284\&\f(CW\*(C`filter\*(C'\fR parameter, which is expected to be a string that is a valid
285regex. If you want to filter items \s-1OUT\s0 instead of \s-1IN\s0, you can
286prefix your regex with a ! and that'll do the trick.
287.PP
288Now, on the the methods!
289.SH "MAIN METHODS"
290.IX Header "MAIN METHODS"
291There are the methods you're likely to use the most.
292.SS "new( confname => 'config' )"
293.IX Subsection "new( confname => 'config' )"
294Create a new configuration object with the base config name \f(CW\*(C`confname\*(C'\fR.
295.PP
296\&\f(CW\*(C`confname\*(C'\fR is used to construct the filenames that will be loaded; by
297default, these are \f(CW\*(C`/etc/confname\*(C'\fR (global configuration file),
298\&\f(CW\*(C`~/.confname\*(C'\fR (user configuration file), and \f(CW\*(C`<Cwd\*(C'\fR/.confname> (directory
299configuration file).
300.PP
301You can override these defaults by subclassing \f(CW\*(C`Config::GitLike\*(C'\fR and
302overriding the methods \f(CW\*(C`global_file\*(C'\fR, \f(CW\*(C`user_file\*(C'\fR, and \f(CW\*(C`dir_file\*(C'\fR. (See
303\&\*(L"\s-1METHODS\s0 \s-1YOU\s0 \s-1MAY\s0 \s-1WISH\s0 \s-1TO\s0 \s-1OVERRIDE\s0\*(R" for details.)
304.PP
305If you wish to enforce only being able to read/write config files that
306git can read or write, pass in \f(CW\*(C`compatible => 1\*(C'\fR to this
307constructor. The default rules for some components of the config
308file are more permissive than git's (see \*(L"\s-1DIFFERENCES\s0 \s-1FROM\s0 GIT-CONFIG\*(R").
309.SS "confname"
310.IX Subsection "confname"
311The configuration filename that you passed in when you created
312the \f(CW\*(C`Config::GitLike\*(C'\fR object. You can change it if you want by
313passing in a new name (and then reloading via \*(L"load\*(R").
314.SS "load"
315.IX Subsection "load"
316Load the global, local, and directory configuration file with the filename
317\&\f(CW\*(C`confname\*(C'\fR(if they exist). Configuration variables loaded later
318override those loaded earlier, so variables from the directory
319configuration file have the highest precedence.
320.PP
321Pass in an optional path, and it will be passed on to \*(L"load_dirs\*(R" (which
322loads the directory configuration file(s)).
323.PP
324Returns a hash copy of all loaded configuration data stored in the module
325after the files have been loaded, or a hashref to this hash in
326scalar context.
327.SS "config_filenames"
328.IX Subsection "config_filenames"
329An array reference containing the absolute filenames of all config files
330that are currently loaded, in the order they were loaded.
331.SS "get"
332.IX Subsection "get"
333Parameters:
334.PP
335.Vb 3
336\& key => \*(Aqsect.subsect.key\*(Aq
337\& as => \*(Aqint\*(Aq
338\& filter => \*(Aq!foo
339.Ve
340.PP
341Return the config value associated with \f(CW\*(C`key\*(C'\fR cast as an \f(CW\*(C`as\*(C'\fR.
342.PP
343The \f(CW\*(C`key\*(C'\fR option is required (will return undef if unspecified); the \f(CW\*(C`as\*(C'\fR
344option is not (will return a string by default). Sections and subsections
345are specified in the key by separating them from the key name with a .
346character. Sections, subsections, and keys may all be quoted (double or
347single quotes).
348.PP
349If \f(CW\*(C`key\*(C'\fR doesn't exist in the config, undef is returned. Dies with
350the exception \*(L"Multiple values\*(R" if the given key has more than one
351value associated with it. (Use \*(L"get_all\*(R" to retrieve multiple values.)
352.PP
353Calls \*(L"load\*(R" if it hasn't been done already. Note that if you've run any
354\&\f(CW\*(C`set\*(C'\fR calls to the loaded configuration files since the last time they were
355loaded, you \s-1MUST\s0 call \*(L"load\*(R" again before getting, or the returned
356configuration data may not match the configuration variables on-disk.
357.SS "get_all"
358.IX Subsection "get_all"
359Parameters:
360.PP
361.Vb 3
362\& key => \*(Aqsection.sub\*(Aq
363\& filter => \*(Aqregex\*(Aq
364\& as => \*(Aqint\*(Aq
365.Ve
366.PP
367Like \*(L"get\*(R" but does not fail if the number of values for the key is not
368exactly one.
369.PP
370Returns a list of values (or an arrayref in scalar context).
371.SS "get_regexp"
372.IX Subsection "get_regexp"
373Parameters:
374.PP
375.Vb 3
376\& key => \*(Aqregex\*(Aq
377\& filter => \*(Aqregex\*(Aq
378\& as => \*(Aqbool\*(Aq
379.Ve
380.PP
381Similar to \*(L"get_all\*(R" but searches for values based on a key regex.
382.PP
383Returns a hash of name/value pairs (or a hashref in scalar context).
384.SS "dump"
385.IX Subsection "dump"
386In scalar context, return a string containing all configuration data, sorted in
387\&\s-1ASCII\s0 order, in the form:
388.PP
389.Vb 2
390\& section.key=value
391\& section2.key=value
392.Ve
393.PP
394If called in void context, this string is printed instead.
395.PP
396In list context, returns a hash containing all the configuration data.
397.SS "set"
398.IX Subsection "set"
399Parameters:
400.PP
401.Vb 7
402\& key => \*(Aqsection.name\*(Aq
403\& value => \*(Aqbar\*(Aq
404\& filename => File::Spec\->catfile(qw/home user/, \*(Aq.\*(Aq.$config\->confname)
405\& filter => \*(Aqregex\*(Aq
406\& as => \*(Aqbool\*(Aq
407\& multiple => 1
408\& replace_all => 1
409.Ve
410.PP
411Set the key \f(CW\*(C`foo\*(C'\fR in the configuration section \f(CW\*(C`section\*(C'\fR to the value \f(CW\*(C`bar\*(C'\fR
412in the given filename.
413.PP
414Replace \f(CW\*(C`key\*(C'\fR's value if \f(CW\*(C`key\*(C'\fR already exists.
415.PP
416To unset a key, pass in \f(CW\*(C`key\*(C'\fR but not \f(CW\*(C`value\*(C'\fR.
417.PP
418Returns true on success.
419.PP
420If you need to have a . character in your variable name, you can surround the
421name with quotes (single or double): \f(CW\*(C`key =&gt \*(Aqsection."foo.bar.com"\*(Aq\*(C'\fR
422Don't do this unless you really have to.
423.PP
424\fImultiple values\fR
425.IX Subsection "multiple values"
426.PP
427By default, set will replace the old value rather than giving a key multiple
428values. To override this, pass in \f(CW\*(C`multiple => 1\*(C'\fR. If you want to replace
429all instances of a multiple-valued key with a new value, you need to pass
430in \f(CW\*(C`replace_all => 1\*(C'\fR as well.
431.SS "group_set"
432.IX Subsection "group_set"
433Parameters:
434.PP
435.Vb 2
436\& filename => \*(Aq/home/foo/.bar\*(Aq
437\& args_ref => $ref
438.Ve
439.PP
440Same as \*(L"set\*(R", but set a group of variables at the same time without
441writing to disk separately for each.
442.PP
443\&\f(CW\*(C`args_ref\*(C'\fR is an array reference containing a list of hash references which
444are essentially hashes of arguments to \f(CW\*(C`set\*(C'\fR, excluding the \f(CW\*(C`filename\*(C'\fR
445argument since that is specified separately and the same file is used for all
446variables to be set at once.
447.SS "rename_section"
448.IX Subsection "rename_section"
449Parameters:
450.PP
451.Vb 3
452\& from => \*(Aqname.subname\*(Aq
453\& to => \*(Aqnew.subname\*(Aq
454\& filename => \*(Aq/file/to/edit\*(Aq
455.Ve
456.PP
457Rename the section existing in \f(CW\*(C`filename\*(C'\fR given by \f(CW\*(C`from\*(C'\fR to the section
458given by \f(CW\*(C`to\*(C'\fR.
459.PP
460Throws an exception \f(CW\*(C`No such section\*(C'\fR if the section in \f(CW\*(C`from\*(C'\fR doesn't exist
461in \f(CW\*(C`filename\*(C'\fR.
462.PP
463If no value is given for \f(CW\*(C`to\*(C'\fR, the section is removed instead of renamed.
464.PP
465Returns true on success, false if \f(CW\*(C`filename\*(C'\fR didn't exist and thus
466the rename did nothing.
467.SS "remove_section"
468.IX Subsection "remove_section"
469Parameters:
470.PP
471.Vb 2
472\& section => \*(Aqsection.subsection\*(Aq
473\& filename => \*(Aq/file/to/edit\*(Aq
474.Ve
475.PP
476Just a convenience wrapper around \*(L"rename_section\*(R" for readability's sake.
477Removes the given section (which you can do by renaming to nothing as well).
478.ie n .SS "cascade( $bool )"
479.el .SS "cascade( \f(CW$bool\fP )"
480.IX Subsection "cascade( $bool )"
481Gets or sets if only the \fBdeepest\fR configuration file in a directory
482tree is loaded, or if all of them are loaded, shallowest to deepest.
483Alternately, \f(CW\*(C`cascade => 1\*(C'\fR can be passed to \f(CW\*(C`new\*(C'\fR.
484.SH "METHODS YOU MAY WISH TO OVERRIDE"
485.IX Header "METHODS YOU MAY WISH TO OVERRIDE"
486If your application's configuration layout is different from the default, e.g.
487if its home directory config files are in a directory within the home
488directory (like \f(CW\*(C`~/.git/config\*(C'\fR) instead of just dot-prefixed, override these
489methods to return the right directory names. For fancier things like altering
490precedence, you'll need to override \*(L"load\*(R" as well.
491.SS "dir_file"
492.IX Subsection "dir_file"
493Return a string containing the path to a configuration file with the
494name \f(CW\*(C`confname\*(C'\fR in a directory. The directory isn't specified here.
495.SS "global_file"
496.IX Subsection "global_file"
497Return the string \f(CW\*(C`/etc/confname\*(C'\fR, the absolute name of the system-wide
498configuration file with name \f(CW\*(C`confname\*(C'\fR.
499.SS "user_file"
500.IX Subsection "user_file"
501Return a string containing the path to a configuration file
502in the current user's home directory with filename \f(CW\*(C`confname\*(C'\fR.
503.SS "load_dirs"
504.IX Subsection "load_dirs"
505Parameters:
506.PP
507.Vb 1
508\& \*(Aq/path/to/look/in/\*(Aq
509.Ve
510.PP
511Load the configuration file with the filename \*(L"dir_file\*(R" in the current
512working directory into the memory or, if there is no config matching
513\&\f(CW\*(C`dir_file\*(C'\fR in the current working directory, walk up the directory tree until
514one is found. (No error is thrown if none is found.) If an optional path
515is passed in, that directory will be used as the base directory instead
516of the working directory.
517.PP
518You'll want to use \*(L"load_file\*(R" to load config files from your overridden
519version of this subroutine.
520.PP
521Returns nothing of note.
522.SH "OTHER METHODS"
523.IX Header "OTHER METHODS"
524These are mostly used internally in other methods, but could be useful anyway.
525.SS "load_global"
526.IX Subsection "load_global"
527If a global configuration file with the absolute name given by
528\&\*(L"global_file\*(R" exists, load its configuration variables into memory.
529.PP
530Returns the current contents of all the loaded configuration variables
531after the file has been loaded, or undef if no global config file is found.
532.SS "load_user"
533.IX Subsection "load_user"
534If a configuration file with the absolute name given by
535\&\*(L"user_file\*(R" exists, load its config variables into memory.
536.PP
537Returns the current contents of all the loaded configuration variables
538after the file has been loaded, or undef if no user config file is found.
539.ie n .SS "load_file( $filename )"
540.el .SS "load_file( \f(CW$filename\fP )"
541.IX Subsection "load_file( $filename )"
542Takes a string containing the path to a file, opens it if it exists, loads its
543config variables into memory, and returns the currently loaded config
544variables (a hashref).
545.PP
546Note that you ought to only call this subroutine with an argument that you
547know exists, otherwise config files that don't exist will be recorded as
548havind been loaded.
549.SS "parse_content"
550.IX Subsection "parse_content"
551Parameters:
552.PP
553.Vb 3
554\& content => \*(Aqstr\*(Aq
555\& callback => sub {}
556\& error => sub {}
557.Ve
558.PP
559Parses the given content and runs callbacks as it finds valid information.
560.PP
561Returns undef on success and \f(CW\*(C`error($content)\*(C'\fR (the original content) on
562failure.
563.PP
564\&\f(CW\*(C`callback\*(C'\fR is called like:
565.PP
566.Vb 1
567\& callback(section => $str, offset => $num, length => $num, name => $str, value => $str)
568.Ve
569.PP
570\&\f(CW\*(C`name\*(C'\fR and \f(CW\*(C`value\*(C'\fR may be omitted if the callback is not being called on a
571key/value pair, or if it is being called on a key with no value.
572.PP
573\&\f(CW\*(C`error\*(C'\fR is called like:
574.PP
575.Vb 1
576\& error( content => $content, offset => $offset )
577.Ve
578.PP
579Where \f(CW\*(C`offset\*(C'\fR is the point in the content where the parse error occurred.
580.PP
581If you need to use this method, you might be interested in \*(L"error_callback\*(R"
582as well.
583.SS "error_callback"
584.IX Subsection "error_callback"
585Parameters:
586.PP
587.Vb 3
588\& content => \*(Aqstr\*(Aq
589\& offset => 45
590\& filename => \*(Aq/foo/bar/.baz\*(Aq
591.Ve
592.PP
593Made especially for passing to \*(L"parse_content\*(R", passed through the
594\&\f(CW\*(C`error\*(C'\fR parameter like this:
595.PP
596.Vb 3
597\& error => sub {
598\& error_callback( @_, filename => \*(Aq/file/you/were/parsing\*(Aq )
599\& }
600.Ve
601.PP
602It's used internally wherever \*(L"parse_content\*(R" is used and will throw
603an exception with a useful message detailing the line number, position on
604the line, and contents of the bad line; if you find the need to use
605\&\*(L"parse_content\*(R" elsewhere, you may find it useful as well.
606.ie n .SS "set_multiple( $name )"
607.el .SS "set_multiple( \f(CW$name\fP )"
608.IX Subsection "set_multiple( $name )"
609Mark the key string \f(CW$name\fR as containing multiple values.
610.PP
611Returns nothing.
612.ie n .SS "is_multiple( $name )"
613.el .SS "is_multiple( \f(CW$name\fP )"
614.IX Subsection "is_multiple( $name )"
615Return a true value if the key string \f(CW$name\fR contains multiple values; false
616otherwise.
617.SS "define"
618.IX Subsection "define"
619Parameters:
620.PP
621.Vb 3
622\& section => \*(Aqstr\*(Aq
623\& name => \*(Aqstr\*(Aq
624\& value => \*(Aqstr\*(Aq
625.Ve
626.PP
627Given a section, a key name, and a valueA\*^X store this information
628in memory in the config object.
629.PP
630Returns the value that was just defined on success, or undef
631if no name is given and thus the key cannot be defined.
632.SS "cast"
633.IX Subsection "cast"
634Parameters:
635.PP
636.Vb 3
637\& value => \*(Aqfoo\*(Aq
638\& as => \*(Aqint\*(Aq
639\& human => 1
640.Ve
641.PP
642Return \f(CW\*(C`value\*(C'\fR cast into the type specified by \f(CW\*(C`as\*(C'\fR.
643.PP
644Valid values for \f(CW\*(C`as\*(C'\fR are \f(CW\*(C`bool\*(C'\fR, \f(CW\*(C`int\*(C'\fR, \f(CW\*(C`num\*(C'\fR, or \f(CW\*(C`bool\-or\-num\*(C'\fR. For
645\&\f(CW\*(C`bool\*(C'\fR, \f(CW\*(C`true\*(C'\fR, \f(CW\*(C`yes\*(C'\fR, \f(CW\*(C`on\*(C'\fR, \f(CW1\fR, and undef are translated into a true
646value (for Perl); anything else is false. Specifying a true value for the
647\&\f(CW\*(C`human\*(C'\fR arg will get you a human-readable 'true' or 'false' rather than a
648value that plays along with Perl's definition of truthiness (0 or 1).
649.PP
650For \f(CW\*(C`int\*(C'\fRs and \f(CW\*(C`num\*(C'\fRs, if \f(CW\*(C`value\*(C'\fR ends in \f(CW\*(C`k\*(C'\fR, \f(CW\*(C`m\*(C'\fR, or \f(CW\*(C`g\*(C'\fR, it will be
651multiplied by 1024, 1048576, and 1073741824, respectively, before being
652returned. \f(CW\*(C`int\*(C'\fRs are truncated after being multiplied, if they have
653a decimal portion.
654.PP
655\&\f(CW\*(C`bool\-or\-int\*(C'\fR, as you might have guessed, gives you either
656a bool or an int depending on which one applies.
657.PP
658If \f(CW\*(C`as\*(C'\fR is unspecified, \f(CW\*(C`value\*(C'\fR is returned unchanged.
659.SS "format_section"
660.IX Subsection "format_section"
661Parameters:
662.PP
663.Vb 2
664\& section => \*(Aqsection.subsection\*(Aq
665\& base => 1
666.Ve
667.PP
668Return a string containing the section/subsection header, formatted
669as it should appear in a config file. If \f(CW\*(C`bare\*(C'\fR is true, the returned
670value is not followed be a newline.
671.SS "format_definition"
672.IX Subsection "format_definition"
673Parameters:
674.PP
675.Vb 3
676\& key => \*(Aqstr\*(Aq
677\& value => \*(Aqstr\*(Aq
678\& bare => 1
679.Ve
680.PP
681Return a string containing the key/value pair as they should be printed in the
682config file. If \f(CW\*(C`bare\*(C'\fR is true, the returned value is not tab-indented nor
683followed by a newline.
684.SH "DIFFERENCES FROM GIT-CONFIG"
685.IX Header "DIFFERENCES FROM GIT-CONFIG"
686This module does the following things differently from git-config:
687.PP
688We are much more permissive about valid key names and section names.
689For variables, instead of limiting variable names to alphanumeric characters
690and \-, we allow any characters except for = and newlines, including spaces as
691long as they are not leading or trailing, and . as long as the key name is
692quoted. For sections, any characters but whitespace, [], and " are allowed.
693You can enforce reading/writing only git-compatible variable names and section
694headers by passing \f(CW\*(C`compatible => 1\*(C'\fR to the constructor.
695.PP
696When replacing variable values and renaming sections, we merely use
697a substring replacement rather than writing out new lines formatted in the
698default manner for new lines. Git's replacement/renaming (as of
6991.6.3.2) is currently buggy and loses trailing comments and variables
700that are defined on the same line as a section being renamed. Our
701method preserves original formatting and surrounding information.
702.PP
703We also allow the 'num' type for casting, since in many cases we
704might want to be more lenient on numbers.
705.PP
706We truncate decimal numbers that are cast to \f(CW\*(C`int\*(C'\fRs, whereas
707Git just rejects them.
708.PP
709We don't support NUL-terminating output (the \-\-null flag to
710git-config). Who needs it?
711.SH "BUGS"
712.IX Header "BUGS"
713If you find any bugs in this module, report them at:
714.PP
715.Vb 1
716\& http://rt.cpan.org/
717.Ve
718.PP
719Include the version of the module you're using and any relevant problematic
720configuration files or code snippets.
721.SH "SEE ALSO"
722.IX Header "SEE ALSO"
723<http://www.kernel.org/pub/software/scm/git/docs/git\-config.html#_configuration_file>,
724Config::GitLike::Git, <http://syncwith.us/> (\f(CW\*(C`Config::GitLike\*(C'\fR is
725used in Prophet/SD and provides a working example)
726.SH "LICENSE"
727.IX Header "LICENSE"
728This program is free software; you may modify and/or redistribute it
729under the same terms as Perl itself.
730.SH "COPYRIGHT"
731.IX Header "COPYRIGHT"
732Copyright 2010 Best Practical Solutions, \s-1LLC\s0
733.SH "AUTHORS"
734.IX Header "AUTHORS"
735Alex Vandiver <alexmv@bestpractical.com>,
736Christine Spang <spang@bestpractical.com>