Skip to content

Commit 2cd6d9b

Browse files
authored
Merge pull request #15 from jrha/17.3.0
Add 17.3.0 documentation
2 parents 3ac8123 + 365184a commit 2cd6d9b

File tree

129 files changed

+1971
-610
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1971
-610
lines changed

docs/CAF/Application.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Applications can extend or overwrite the default methods.
4343
- version(): string
4444

4545
Returns the version number as defined in $self->{'VERSION'}, or
46-
<unknown> if not defined.
46+
<unknown> if not defined.
4747

4848
- hostname(): string
4949

@@ -53,12 +53,30 @@ Applications can extend or overwrite the default methods.
5353

5454
Returns the name of the user.
5555

56+
- option\_exists($opt): boolean
57+
58+
Returns true if the option exists, false otherwhise. Option can be
59+
defined either in the application configuration file or on the
60+
command line (based on `AppConfig` module).
61+
5662
- option($opt): scalar|undef
5763

5864
Returns the option value coming from the command line and/or
5965
configuration file. Scalar can be a string, or a reference to a hash
6066
or an array containing the option's value. option() is a wrapper
61-
on top of AppConfig->get($opt).
67+
on top of AppConfig->get($opt).
68+
69+
If the option doesn't exist, returns `undef`, except if the `default`
70+
argument has been specified: in this case this value is returned but
71+
the option remains undefined.
72+
73+
- set\_option($opt, $val): SUCCESS
74+
75+
Defines an option and sets its value. If the option was previously
76+
defined, its value is overwritten. This is a wrapper over `AppConfig`
77+
methods to hide the internal implementation of a `CAF::Application`.
78+
79+
This method always returns SUCCESS.
6280

6381
- show\_usage(): boolean
6482

docs/CAF/FileReader.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This class should be used whenever a file is to be opened for reading,
1717
and no modifications are expected.
1818

1919
Printing to this file is allowed, but changes will be discarded (in
20-
effect, the [FileWriter](../CAF/FileWriter.md) is `cancel`-ed.
20+
effect, the [FileEditor](../CAF/FileEditor.md) is `cancel`-ed.
2121

2222
- new
2323

docs/CAF/FileWriter.md

+48-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ level.
4040

4141
#### Gory details
4242

43-
This is just a wrapper class for `LC::Check::file`
43+
This is a wrapper class for `IO::String` with customised close based on
44+
`File::AtomicWrite`.
4445

4546
#### Public methods
4647

@@ -73,7 +74,7 @@ This is just a wrapper class for `LC::Check::file`
7374

7475
Path for the backup file, if this one has to be re-written.
7576

76-
- keeps\_state
77+
- `keeps_state`
7778

7879
A boolean specifying whether a file change respects the current system
7980
state or not. A file with `keeps_state` will be created/modified,
@@ -83,27 +84,42 @@ This is just a wrapper class for `LC::Check::file`
8384
By default, file changes modify the state and thus `keeps_state` is
8485
false.
8586

87+
- `sensitive`
88+
89+
A boolean specifying whether a file contains sensitive information
90+
(like passwords). When the content of the file is modified, the changes
91+
(either the diff or the whole content in case of a new file) themself
92+
are not reported and not added to the event history.
93+
8694
- open
8795

8896
Synonym for `new()`
8997

9098
- close
9199

92-
Closes the file. If it has not been saved and it has not been
93-
cancelled, it checks its contents and perhaps re-writes it, in a
94-
secure way (not following symlinks, etc).
100+
Closes the file.
101+
102+
If the file has been saved (e.g. previous `close` or `cancel`)
103+
nothing happens and undef is returned.
104+
105+
If the file has not been saved,
106+
it checks its contents and perhaps re-writes it, in a
107+
secure way (not following symlinks, etc). The (re)write only occurs
108+
if there was a change in content and this change (or not) is
109+
always determined and returned, even if `NoAction` is true
110+
(but in that case nothing is (re)written).
95111

96112
Under a verbose level, it will show in the standard output a diff of
97113
the old and the newly-generated contents for this file before actually
98-
saving to disk. This diff will **not** be stored in any logs to prevent
99-
any leakages of confidential information (f.i. when writing to
100-
`/etc/shadow`).
114+
saving to disk.
101115

102116
- cancel
103117

104118
Marks the printed contents as invalid. The existing file will not be
105119
altered.
106120

121+
Option `msg` to add custom message to verbose reporting.
122+
107123
- noAction
108124

109125
Returns the NoAction flag value (boolean)
@@ -114,7 +130,7 @@ This is just a wrapper class for `LC::Check::file`
114130
`""`, so it's now possible to do "$fh" and get the contents of the
115131
file so far.
116132

117-
- error, warn, info, verbose, debug, report, OK
133+
- error, warn, info, verbose, debug, report, log, OK
118134

119135
Convenience methods to access the log/reporter instance that might
120136
be passed during initialisation and set to `*$self-`{LOG}>.
@@ -125,6 +141,9 @@ This is just a wrapper class for `LC::Check::file`
125141
If it can't be determined from the reporter instance,
126142
use the global [Reporter](../CAF/Reporter.md) state.
127143

144+
Supports boolean option `verbose_logfile` to check if
145+
reporting to logfile is verbose.
146+
128147
- event
129148

130149
Method to track an event via LOG [History](../CAF/History.md) instance (if any).
@@ -137,6 +156,26 @@ This is just a wrapper class for `LC::Check::file`
137156

138157
#### Private methods
139158

159+
- \_read\_contents
160+
161+
Read the contents from file `filename` using `LC::File::file_contents`
162+
and return it.
163+
164+
Optional named arguments
165+
166+
- event
167+
168+
A hashref that will be updated in place if an error occured. The `error`
169+
attribute is set to the exception text.
170+
171+
- missing\_ok
172+
173+
When true and `LC::File::file_contents` fails with `ENOENT`
174+
(i.e. when `filename` is missing),
175+
the exception is ignored and no warning is reported.
176+
177+
By default, a warning is reported in case of an error and the exception is (re)thrown.
178+
140179
- DESTROY
141180

142181
Class destructor. Closes the file, perhaps saving it to disk.

docs/CAF/Object.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,21 @@ In particular, one should avoid to return the `$self` instance at the end of
7979
Returns the `env` hashref.
8080

8181
To be used as
82+
8283
# Setup local environment
8384
local %ENV = %ENV;
84-
$self->update\_env(\\%ENV);
85+
$self->update_env(\%ENV);
8586

8687
Example:
87-
# some method\_1 that prepares a shared environment
88-
sub method\_1
88+
89+
# some method_1 that prepares a shared environment
90+
sub method_1
8991
{
9092
...
9193
# Prepare enviroment modifications
9294
$self->{ENV}->{PATH} = "/some/new/path:$ENV{PATH}";
9395
...
9496
}
95-
9697
sub do_something
9798
{
9899
...

docs/CAF/ObjectText.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ a [FileWriter](../CAF/FileWriter.md) instance.
104104

105105
All [FileWriter](../CAF/FileWriter.md) initialisation options are supported
106106
and passed on. (If no `log` option is provided,
107-
the one from the current instance is passed).
107+
the one from the current instance is passed).
108108

109109
Two new options `header` and `footer` are supported
110-
to respectively prepend and append to the text.
110+
to respectively prepend and append to the text.
111111

112112
If `eol` was set during initialisation, the header and footer
113113
will also be checked for EOL.

docs/CAF/Path.md

+102-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ undef on failure and store the error message in the `fail` attribute.
2323
- SUCCESS: nothing changed (boolean true)
2424
- CHANGED: something changed (boolean true).
2525

26+
#### Functions
27+
28+
- mkcafpath
29+
30+
Returns an instance of [Object](../CAF/Object.md) and `CAF::Path`.
31+
This instance is a simple way to use `CAF::Path` when
32+
subclassing is not possible. Allowed options are
33+
`<log =` $logger>> and `<NoAction =` $noaction>>.
34+
35+
This function is not exported, to be used as e.g.
36+
use CAF::Path;
37+
...
38+
my $cafpath = CAF::Path::mkcafpath(log => $logger);
39+
if(! defined($cafpath->directory($name)) {
40+
$logger->error("Failed to make directory $name: $cafpath->{fail}");
41+
};
42+
2643
#### Methods
2744

2845
- \_get\_noaction
@@ -53,8 +70,10 @@ undef on failure and store the error message in the `fail` attribute.
5370

5471
Run function reference `funcref` with arrayref `argsref` and hashref `optsref`.
5572

56-
Return and set fail attribute with `failmsg` on die, verbose `msg` on success
57-
(resp. $@ and stringified result are appended).
73+
Return and set fail attribute with `failmsg` on die or an error (`undef` returned
74+
by `funcref`), or print (at verbose level) `msg` on success (respectively $@ and
75+
stringified result are appended). Note that `_safe_eval` doesn't work with functions
76+
that don't return a defined value when they succeed.
5877

5978
Resets previous exceptions and/or fail attribute
6079

@@ -80,7 +99,7 @@ undef on failure and store the error message in the `fail` attribute.
8099
wrapped in a method to allow unittesting.
81100

82101
If `directory` is a symlink, the symlink target
83-
is tested. If the symlink is broken (no target),
102+
is tested. If the symlink is broken (no target),
84103
`directory_exists` returns false.
85104

86105
- file\_exists
@@ -91,7 +110,7 @@ undef on failure and store the error message in the `fail` attribute.
91110
wrapped in a method to allow unittesting.
92111

93112
If `filename` is a symlink, the symlink target
94-
is tested. If the symlink is broken (no target),
113+
is tested. If the symlink is broken (no target),
95114
`file_exists` returns false.
96115

97116
- any\_exists
@@ -104,6 +123,13 @@ undef on failure and store the error message in the `fail` attribute.
104123
A broken symlink (symlink whose target doesn't
105124
exist) exists: `any_exists` returns true.
106125

126+
- is\_symlink
127+
128+
Test if `path` is a symlink.
129+
130+
Returns true as long as `path` is a symlink, including when the
131+
symlink target doesn't exist.
132+
107133
- cleanup
108134

109135
cleanup removes `dest` with backup support.
@@ -114,7 +140,7 @@ undef on failure and store the error message in the `fail` attribute.
114140
Returns CHANGED is something was cleaned-up, SUCCESS if nothing was done
115141
and undef on failure (and sets the fail attribute).
116142

117-
The &lt;backup> is a suffix for `dest`.
143+
The <backup> is a suffix for `dest`.
118144

119145
If backup is undefined, use `backup` attribute.
120146
(Pass an empty string to disable backup with `backup` attribute defined)
@@ -159,6 +185,76 @@ undef on failure and store the error message in the `fail` attribute.
159185

160186
- keeps\_state: boolean passed to `_get_noaction`.
161187

188+
- \_make\_link
189+
190+
This method is mainly a wrapper over `LC::Check::link`
191+
returning the standard `CAF::Path` return values. Every option
192+
supported by `LC::Check::link` is supported. `NoAction`
193+
flag is handled by `LC::Check::link` and `keeps_state` option
194+
is honored (overrides `NoAction` if true). One important
195+
difference is the order of the arguments: `CAF::Path:_make_link`
196+
and the methods based on it are following the Perl `symlink`
197+
(and `ln` command) argument order.
198+
199+
This is an internal method, not supposed to be called directly.
200+
Either call [symlink](../components/symlink.md) or `hardlink` public methods instead.
201+
202+
- hardlink
203+
204+
Create a hardlink `link_path` whose target is `target`.
205+
206+
On failure, returns undef and sets the fail attribute.
207+
If `link_path` exists and is a file, it is updated.
208+
`target` must exist (`check` flag available in symlink()
209+
is ignored for hardlinks) and it must reside in the same
210+
filesystem as `link_path`. If `target_path` is a
211+
relative path, it is interpreted from the current directory.
212+
`link_name` parent directory is created if it doesn't exist.
213+
214+
Returns SUCCESS on sucess if the hardlink already existed
215+
with the same target, CHANGED if the hardlink was created
216+
or updated, undef otherwise.
217+
218+
This method relies on `_make_link` method to do the real work,
219+
after enforcing the option saying that it is a hardlink.
220+
221+
- symlink
222+
223+
Create a symlink `link_path` whose target is `target`.
224+
225+
Returns undef and sets the fail attribute if `link_path`
226+
already exists and is not a symlink, except if this is a file
227+
and option `force` is defined and true. If `link_path` exists
228+
and is a symlink, it is updated. By default, the target is not
229+
required to exist. If you want to ensure that it exists,
230+
define option `check` to true. Both `link_path` and `target`
231+
can be relative paths: `link_path` is interpreted as relatif
232+
to the current directory and `target` is kept relative.
233+
`link_path` parent directory is created if it doesn't exist.
234+
235+
Returns SUCCESS on sucess if the symlink already existed
236+
with the same target, CHANGED if the symlink was created
237+
or updated, undef otherwise.
238+
239+
This method relies on `_make_link` method to do the real work,
240+
after enforcing the option saying that it is a symlink.
241+
242+
- has\_hardlinks
243+
244+
Method that returns the number of hardlinks for `file`. The number of
245+
hardlinks is the number of entries referring to the inodes minus 1. If
246+
`file` has no hardlink, the return value is 0. If `file` is not a file,
247+
the return value is `undef`.
248+
249+
- is\_hardlink
250+
251+
This method returns SUCCESS if `path1` and `path2` refer to the same file (inode).
252+
It returns 0 if `path1` and `path2` both exist but are different files or are the same path
253+
and `undef` if one of the paths doesn't exist or is not a file.
254+
255+
Note: the result returned will be identical whatever is the order of `path1` and `path2`
256+
arguments.
257+
162258
- status
163259

164260
Set the path stat options: `owner`, `group`, `mode` and/or `mtime`.
@@ -182,7 +278,7 @@ undef on failure and store the error message in the `fail` attribute.
182278
does not exist to start with, success is immediately returned,
183279
and no backup of `dest` is created).
184280

185-
The &lt;backup> is a suffix for the cleanup of `dest`
281+
The <backup> is a suffix for the cleanup of `dest`
186282
(and passed to `cleanup` method).
187283

188284
(The basedir of `dest` is created using `directory` method.)

docs/CAF/Process.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ secure.
8181
`noaction_value` is is the value to return with `NoAction`.
8282

8383
`msg` and `postmsg` are used to construct log message
84-
`<<msg` command: <COMMAND>\[ &lt;postmsg>\]>>.
84+
`<<msg` command: <COMMAND>\[ <postmsg>\]>>.
8585

8686
#### Public methods
8787

0 commit comments

Comments
 (0)