---
name: "Config::Model::Backend::Debian::DpkgSyntax"
section: "3pm"
platform: "linux"
package: "libconfig-model-perl"
version: "2.021-3+deb7u1"
release: "Debian 7 (Wheezy)"
platforms: ["linux"]
url: "https://new.carta.tech/Config::Model::Backend::Debian::DpkgSyntax"
---

# Config::Model::Backend::Debian::DpkgSyntax(3pm)

Role to read and write files with Dpkg syntax

## NAME

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

## VERSION

version 2.021

## SYNOPSIS

```
 package MyParser ;
 use Log::Log4perl qw(:easy);
 Log::Log4perl->easy_init($WARN);

 use Any::Moose ;
 with 'Config::Model::Backend::Debian::DpkgSyntax';

 package main ;
 use IO::File ;
 use Data::Dumper ;

 my $data = [ [ qw/Name Foo Version 1.2/ ],
              [ qw/Name Bar Version 1.3/ ,
                Files => [qw/file1 file2/] ,
                Description => "A very\n\nlong description"
             ]
           ] ;

 my $fhw = IO::File->new ;
 $fhw -> open ( 'dpkg_file' ,'>' ) ;
 my $parser = MyParser->new() ;

 $parser->write_dpkg_file($fhw,$data) ;
```

`"dpkg_file"` will contain:

```
 Name: Foo
 Version: 1.2
 Name: Bar
 Version: 1.3
 Files: file1,
        file2
 Description: A very
  .
  long description
```

## DESCRIPTION

This module is a Moose role to read and write dpkg control files.

Debian control file are read and transformed in a list of list matching the control file. The top level list of a list of section. Each section is mapped to a list made of keywords and values. Since this explanation is probably too abstract, here's an example of a file written with Dpkg syntax:

```
 Name: Foo
 Version: 1.1
 Name: Bar
 # boy, new version
 Version: 1.2
  Description: A very
  .
  long description
```

Once parsed, this file will be stored in the following list of list :

```
 (
   [ Name => 'Foo', Version => '1.1' ],
   [ Name => 'Bar', Version => [ '1.2' 'boy, new version' ],
     Description => "A very\n\nlong description"
   ]
 )
```

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 will be restored when the file is written back.

Last not but not least, this module can be re-used outside of `"Config::Model"` with some  small modifications in exception handing. Ask the author if you want this module shipped in its own distribution.

##

### parse\_dpkg\_file ( file\_handle, check, comment\_allowed )

Read a control file from the file\_handle and returns a nested list (or a list  ref) containing data from the file.

The returned list is of the form :

```
 [
   # section 1
   [ keyword1 => value1, # for text or simple values
     keyword2 => value2, # etc
   ],
   # section 2
   [ ... ]
   # etc ...
 ]
```

check is `"yes"`, `"skip"` or `"no"`.  `"comment_allowed"` is boolean (default 0)

When comments are provided in the dpkg files, the returned list is of the form :

```
 [
   [
     keyword1 => [ value1, 'value1 comment']
     keyword2 => value2, # no comment
   ],
   [ ... ]
 ]
```

### parse\_dpkg\_lines (lines, check, comment\_allowed )

Parse the dpkg date from lines (which is an array ref) and return a data  structure like parse\_dpkg\_file.

### write\_dpkg\_file ( io\_handle, list\_ref, list\_sep )

Munge the passed list ref into a string compatible with control files and write it in the passed file handle.

The input is a list of list in a form similar to the one generated by parse\_dpkg\_file:

```
 [ section [ keyword => value | value_list ] ]
```

Except that the value may be a SCALAR or a list ref. In case, of a list ref, the list  items will be joined with the value `"list_sep"` before being written. Values will be aligned in case of multi-line output of a list.

For instance the following code :

```
 my $ref = [ [ Foo => 'foo value' , Bar => [ qw/v1 v2/ ] ];
 write_dpkg_file ( $ioh, $ref, ', ' )
```

will yield:

```
 Foo: foo value
 Bar: v1, v2
```

## AUTHOR

Dominique Dumont, (ddumont at cpan dot org)

## SEE ALSO

Config::Model,  Config::Model::AutoRead,  Config::Model::Backend::Any,
