Man pages sections > man3 > Config::Model::Backend::DpkgSyntax

Config::Model::Backend::DpkgSyntax - Role to read and write files with Dpkg

Config::Model::Backend::DpkgSyntax(3pm) User Contributed Perl Documentation Config::Model::Backend::DpkgSyntax(3pm)

NAME

Config::Model::Backend::DpkgSyntax - Role to read and write files with Dpkg syntax

SYNOPSIS

With a dpkg file containing:
 Name: Foo
 Version: 1.2
 
 # section comment
 Name: Bar
 # data comment
 Version: 1.3
 Files: file1,
 # inline comment
        file2
 Description: A very
  .
  long description
Parse the file with:
 package MyParser ;
 use strict;
 use warnings;
 use Log::Log4perl qw(:easy);
 Log::Log4perl->easy_init($WARN);
 # load role
 use Mouse ;
 with 'Config::Model::Backend::DpkgSyntax';
 package main ;
 use IO::File;
 use Data::Dumper;
 my $file = 'examples/dpkg-test'; # replace with any file name
 my $fh = IO::File->new();
 $fh->open("<  $file");
 my $parser = MyParser->new() ;
 my $data = $parser->parse_dpkg_file($file, $fh, 'yes', 1);
 $fh->close;
 
 print Dumper $data;
Data contains:
 [
   1,          # section 1 found in line 1
   [
     'Name',    # first parameter
       [
         'section comment',
         [
           'Foo',  # first parameter data
           1,      # also found in line 1
           ''      # currently always empty
         ]
       ],
    'Version', [ 'data comment', ['1.2', 2, '']]
   ],          # end of section 1
   4,          # section 2 found in line 4
   [
     'Name', [['Bar', 5, '']],
     'Version', [['1.3', 7, '']],
     'Files', # param with 2 lines
     [
       ['file1,', 8, ''],
       ['      file2', 10, '', 'inline comment'] # padding is kept
     ],
     'Description', # param with 3 lines
     [
       ['A very', 11, ''],
       ['', 12, ''],  # empty line, note: dot was removed
       ['long description', 13, '']
     ]
   ]                  # end of section 2
 ];                   # end of data
To write Dpkg file back:
 package MyParser ;
 
 use strict;
 use warnings;
 
 use 5.20.1;
 
 use Log::Log4perl qw(:easy);
 Log::Log4perl->easy_init($WARN);
 
 # load role
 use Mouse ;
 with 'Config::Model::Backend::DpkgSyntax';
 
 package main ;
 use IO::File;
 use Data::Dumper;
 
 # note: the structure is different compared to the one returned by
 # the parser (no line number)
 my $data = [
    [ '# section comment', qw/Name Foo/, '# data comment', qw/Version 1.2/ ],
    [
        qw/Name Bar Version 1.3/ ,
        Files => [qw/file1/, [ 'file2' , '# inline comment'] ] ,
        Description => "A very\n\nlong description"
    ]
 ];
 
 my $parser = MyParser->new() ;
 
 my $fhw = IO::File->new ;
 $fhw -> open ( 'examples/dpkg-new' ,'>',"," ) ;
 
 $parser->write_dpkg_file($fhw,$data) ;
 $fhw->close;

DESCRIPTION

This module is a Moose role to read and write dpkg control files.
Debian control file are read and transformed in a structure matching the control file. The top level list of a list of section.
Each section is mapped to a structure containing the parameter names and values, comments and line numbers. See the synopsis for an example.
Note: The description is changed into a paragraph without the Dpkg syntax idiosyncrasies. The leading white space is removed and the single dot is transformed in to a "\n". These characters are restored when the file is written back.
Last not but not least, this module could re-used outside of "Confi