Parse:...Control(3pm)
πΈ Parse::DebControl β the manual, but make it β¨make senseβ¨
okay bestie, sit down, hydrate, because this one is Parse:...Control(3pm) from the User Contributed Perl Documentation and it is genuinely useful, no cap. π
π NAME π
Parse::DebControl β easy OO parsing of debian control-like files. that's it, that's the vibe. π
π¦ SYNOPSIS π¦
here's the whole mood board, verbatim, don't touch a character:
use Parse::DebControl
$parser = new Parse::DebControl;
$data = $parser->parse_mem($control_data, $options);
$data = $parser->parse_file('./debian/control', $options);
$data = $parser->parse_web($url, $options);
$writer = new Parse::DebControl;
$string = $writer->write_mem($singlestanza);
$string = $writer->write_mem([$stanza1, $stanza2]);
$writer->write_file($filename, $singlestanza, $options);
$writer->write_file($filename, [$stanza1, $stanza2], $options);
$writer->write_file($handle, $singlestanza, $options);
$writer->write_file($handle, [$stanza1, $stanza2], $options);
$parser->DEBUG();
likeβ¦ she reads, she writes, she fetches from the web, she debugs. versatile queen. π
β¨ DESCRIPTION β¨
so Parse::DebControl is your easy OO way to parse debian control files and other colon separated key-value pairs. she's specifically designed to handle the format used in Debian control files, template files, and the cache files used by dpkg. π«Ά
for basic format information see: http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-controlsyntax
and listen, this module does not actually do any intelligence with the file content (because there are a lot of files in this format, and honestly? respect), but merely handles the format. it can handle simple control files, or files hundreds of lines long efficiently and easily. it's giving no thoughts, just structure. π§
π Class Methods π
new()new($debug)
returns a new Parse::DebControl object. if a true parameter $debug is passed in, it turns on debugging, similar to a call to DEBUG() (see below). cute, right? πΈ
parse_file($control_filename,$options)
takes a filename as a scalar and an optional hashref of options (see below). will parse as much as it can, warning (if DEBUGing is turned on) on parsing errors. π
returns an array of hashrefs, containing the data in the control file, split up by stanza. stanzas are deliniated by newlines, and multi-line fields are expressed as such post-parsing. single periods are treated as special extra newline deliniators, per convention. whitespace is also stripped off of lines as to make it less-easy to make mistakes with hand-written conf files).
the options hashref can take parameters as follows. setting the string to true enables the option. π
useTieIxHashβ instead of an array of regular hashrefs, usesTie::IxHash-based hashrefsdiscardCaseβ remove all case items from keys (not values)stripCommentsβ remove all commented lines in standard#commentformat. literal#'s are represented by##. for instance
Hello there #this is a comment
Hello there, I like ##CCCCCC as a grey.
the first is a comment, the second is a literal "#". π
verbMultiLineβ keep the description AS IS, and no not collapse leading spaces or dots as newlines. this also keeps whitespace from being stripped off the end of lines.tryGzipβ attempt to expand the data chunk with gzip first. if the text is already expanded (ie: plain text), parsing will continue normally. this could optionally be turned on for all items in the future, but it is off by default so we don't have to scrub over all the text for performance reasons. performance girlies, we see you.singleBlockβ only parse the first block of data and return it. this is useful when you have possible "junk" data after the metadata.strictβ tries to parse obeying the strict rules for real debian control files. this will force comment stripping fordebian/control(must start line) and for other files will check if a field may span multiple lines.allowUnknownFieldsβ in strict mode, allow unknown fields.typeβ if the strict option is chosen, then this parameter defines what format we have. available formats is:debian/controlDEBIAN/control.dsc.changes
parse_mem($control_data, $options)
similar to parse_file, except takes data as a scalar. returns the same array of hashrefs as parse_file. the options hashref is the same as parse_file as well; see above. β¨
parse_web($url, $options)
similar to the other parse_* functions, this pulls down a control file from the web and attempts to parse it. for options and return values, see parse_file, above. she's online, she's fetching, she's thriving. π
write_file($filename, $data, $options)write_file($handle, $data)write_file($filename, [$data1, $data2, $data3], $options)write_file($handle, [$data, $data2, $data3])
this function takes a filename or a handle and writes the data out. the data can be given as a single hashref or as an arrayref of hashrefs. it will then write it out in a format that it can parse. the order is dependent on your hash sorting order. if you care, use Tie::IxHash. remember for reading back in, the module doesn't care. π
the $options hashref can contain one of the following two items:
addNewlineβ at the end of the last stanza, add an additional newline.appendFileβ (default) write to the end of the fileclobberFileβ overwrite the file given.gzipβ compress the data with gzip before writing
since you determine the mode of your filehandle, passing it along with an options hashref obviously won't do anything; rather, it is ignored. π
the addNewline option solves a situation where if you are writing stanzas to a file in a loop (such as logging with this module), then the data will be streamed together, and won't parse back in correctly. it is possible that this is the behavior that you want (if you wanted to write one key at a time), so it is optional. π«Ά
this function returns the number of bytes written to the file, undef otherwise.
write_mem($data)write_mem([$data1,$data2,$data3]);
this function works similarly to the write_file method, except it returns the control structure as a scalar, instead of writing it to a file. there is no %options for this file (yet); π―οΈ manifesting
DEBUG()
turns on debugging. calling it with no parameter or a true parameter turns on verbose warn()ings. calling it with a false parameter turns it off. it is useful for nailing down any format or internal problems. the detective era π
π CHANGES π
Version 2.005 β January 13th, 2004
- More generic test suite fix for earlier versions of
Test::More - Updated copyright statement
Version 2.004 β January 12th, 2004
- More documentation formatting and typo fixes
CHANGESfile now generated automatically- Fixes for potential test suite failure in
Pod::Coveragerun - Adds the
addNewlineoption towrite_fileto solve the streaming stanza problem. - Adds tests for the
addNewlineoption
Version 2.003 β January 6th, 2004
- Added optional
Test::Podtest - Skips potential Win32 test failure in the module where it wants to write to
/tmp. - Added optional
Pod::Coveragetest
Version 2.002 β October 7th, 2003
- No code changes. Fixes to test suite
Version 2.001 β September 11th, 2003
- Cleaned up more POD errors
- Added tests for file writing
- Fixed bug where
write_fileignored thegzipparameter
Version 2.0 β September 5th, 2003
- Version increase.
- Added gzip support (with the
tryGzipoption), so that compresses control files can be parsed on the fly - Added gzip support for writing of control files
- Added
parse_webto snag files right off the web. Useful for things such as apt'sSources.gzandPackages.gz
Version 1.10b β September 2nd, 2003
- Documentation fix for
##vs#instripComments
Version 1.10 β September 2nd, 2003
- Documentation fixes, as pointed out by pudge
- Adds a feature to
stripCommentswhere##will get interpolated as a literal pound sign, as suggested by pudge.
Version 1.9 β July 24th, 2003
- Fix for warning for edge case (uninitialized value in chomp)
- Tests for CRLF
Version 1.8 β July 11th, 2003
- By default, we now strip off whitespace unless
verbMultiLineis in place. This makes sense for things like conf files where trailing whitespace has no meaning. Thanks to pudge for reporting this.
Version 1.7 β June 25th, 2003
- POD documentation error noticed again by Frank Lichtenheld
- Also by Frank, applied a patch to add a
verbMultiLineoption so that we can hand multiline fields back unparsed. - Slightly expanded test suite to cover new features
Version 1.6.1 β June 9th, 2003
- POD cleanups noticed by Frank Lichtenheld. Thank you, Frank.
Version 1.6 β June 2nd, 2003
- Cleaned up some warnings when you pass in empty hashrefs or arrayrefs
- Added
stripCommentssetting - Cleaned up POD errors
Version 1.5 β May 8th, 2003
- Added a line to quash errors with undef hashkeys and writing
- Fixed the
Makefile.PLto straighten upDebControl.pmbeing in the wrong dir
Version 1.4 β April 30th, 2003
- Removed exports as they were unnecessary. Many thanks to pudge, who pointed this out.
Version 1.3 β April 28th, 2003
- Fixed a bug where writing blank stanzas would throw a warning. Fix found and supplied by Nate Oostendorp.
Version 1.2b β April 25th, 2003
Fixed:
- A bug in the test suite where IxHash was not disabled in
40write.t. Thanks to Jeroen Latour from cpan-testers for the report.
Version 1.2 β April 24th, 2003
Fixed:
- A bug in IxHash support where multiple stanzas might be out of order
Version 1.1 β April 23rd, 2003
Added:
- Writing support
Tie::IxHashsupport- Case insensitive reading support
Version 1.0 β April 23rd, 2003
- This is the initial public release for CPAN, so everything is new. π
π BUGS π
okay so listen, bestie π this module will let you parse otherwise illegal key-value pairs and pairs with spaces. no cap. but badly formed stanzas will do things like overwrite duplicate keys, etc. so if your input is feral, that's on you, not the module, okay? π«Ά
As of 1.10, the module uses advanced regexp's to figure out about comments. If the tests fail, then stripComments won't work on your earlier perl version (should be fine on 5.6.0+, bestie β¨).
π TODO π
bestie, the glow-up plan is: change the name over to the Debian:: namespace, probably as Debian::ControlFormat. this will happen as soon as the project that uses this module reaches stability, and we can do some minor tweaks. periodt β¨
π COPYRIGHT π
Parse::DebControl is copyright 2003,2004 Jay Bonci <jaybonci@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay that's the whole page, bestie. this one was Parse:...Control(3pm), footer energy from perl v5.36.0, dated 2022-10-14. mwah ππ
π¦ where this page comes from
- ubuntu noble: libparse-debcontrol-perl 2.005-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libparse-debcontrol-perl 2.005-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libparse-debcontrol-perl 2.005-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms