I've created this module for one reason and that is to be able to automatically modify Debian control files. Especially the debian/control where the package names are located together will all Build-Depends, Build-Depends-Indep, Build-Conflicts, Pre-Depends, Depends, Conflicts, Replaces, Provides, Suggests and Recommends. There is already Parse::DebControl which is ok for reading but, I really wanted to make sure that the automated change changes just the minimum that is necessary. Like if someone will just edit "by hand". Editing manually was not an option as there are ~150 places that needed I needed to prefix with "corp-" just in Perl source debian/control file. So I've created a parsing module.
The structure of control files is described in Debian Policy Manual, Chapter 5 and it's quite simple. Basicaly sections separated by empty lines. Each section with key+colon+value. Values can be on more lines, if the next line starts with white space it's part of the previous value.
So how is the Parse::Deb::Control
working? When parsing, there are 2 arrays filled in. One
the other one
@structure holds the keys+empty lines and
@content all the data. Thanks to the
@structure the line ordering
is preserver and doesn't change through the parse+modify+save cycle. Which allows to use diff
to check and see what really changed. After the control file is parsed the
->control function is called that generates back the control file string. This
one is compared with the original file and exception is thrown if they doesn't match.
After the modification and save the generated control file string is parsed again which
triggers the parsing+stringifying+comparing with original again. This mechanism makes sure
that control file can be generated equal as the original and no error was introduced that
will make the future parsing unpossible.
I've used Parse::Deb::Control to modify >300 control files so far and worked good for all of them. For example usage see deb-control-prefix-perl which modifies - Maintainer, Uploaders, Source, Package, all the dependecy places and the long package description.