Lintian::Deb822Parser(3) | Debian Package Checker | Lintian::Deb822Parser(3) |
Lintian::Deb822Parser - Lintian's generic Deb822 parser functions
use Lintian::Deb822Parser qw(read_dpkg_control_utf8); my (@paragraphs); eval { @paragraphs = read_dpkg_control_utf8('some/debian/ctrl/file'); }; if ($@) { # syntax error etc. die "ctrl/file: $@"; } foreach my $para (@paragraphs) { my $value = $para->{'some-field'}; if (defined $value) { # ... } }
This module contains a number of utility subs that are nice to have, but on their own did not warrant their own module.
Most subs are imported only on request.
At first glance, this module appears to contain several debian control parsers. In practise, there is only one real parser ("visit_dpkg_paragraph") - the rest are convenience functions around it.
If you have very large files (e.g. Packages_amd64), you almost certainly want "visit_dpkg_paragraph". Otherwise, one of the convenience functions are probably what you are looking for.
The following constants can be passed to the Debian control file parser functions to alter their parsing flag.
FLAGS (if given) is a bitmask of the DCTRL_* constants. Please refer to "CONSTANTS" for the list of constants and their meaning. The default value for FLAGS is 0.
If LINES is given, it should be a reference to an empty list. On return, LINES will be populated with a hashref for each paragraph (in the same order as the returned list). Each hashref will also have a special key "START-OF-PARAGRAPH" that gives the line number of the first field in that paragraph. These hashrefs will map the field name of the given paragraph to the line number where the field name appeared.
This is a convenience sub around "visit_dpkg_paragraph" and can therefore produce the same errors as it. Please see "visit_dpkg_paragraph" for the finer semantics of how the control file is parsed.
NB: parse_dpkg_control does not close the handle for the caller.
FLAGS (if given) is a bitmask of the DCTRL_* constants. Please refer to "CONSTANTS" for the list of constants and their meaning. The default value for FLAGS is 0.
If the file is empty (i.e. it contains no paragraphs), the method will contain an empty list. The deb822 contents may be inside a signed PGP message with a signature.
visit_dpkg_paragraph will require the PGP headers to be correct (if present) and require that the entire file is covered by the signature. However, it will not validate the signature (in fact, the contents of the PGP SIGNATURE part can be empty). The signature should be validated separately.
visit_dpkg_paragraph will pass paragraphs to CODE as they are completed. If CODE can process the paragraphs as they are seen, very large control files can be processed without keeping all the paragraphs in memory.
As a consequence of how the file is parsed, CODE may be passed a number of (valid) paragraphs before parsing is stopped due to a syntax error.
NB: visit_dpkg_paragraph does not close the handle for the caller.
CODE is expected to be a callable reference (e.g. a sub) and will be invoked as the following:
The return value of CODE is ignored.
If the CODE invokes die (or similar) the error is propagated to the caller.
On syntax errors, visit_dpkg_paragraph will call die with the following string:
"syntax error at line %d: %s\n"
Where %d is the line number of the issue and %s is one of:
Otherwise, this behaves like:
use autodie; open(my $fd, '<:encoding(UTF-8)', FILE); # or '<' my @p = parse_dpkg_control($fd, FLAGS, LINES); close($fd); return @p;
This goes without saying that may fail with any of the messages that "parse_dpkg_control(HANDLE[, FLAGS[, LINES]])" do. It can also emit autodie exceptions if open or close fails.
2019-05-26 | Lintian v2.15.0 |