diff options
author | Dominique Dumont <dod@debian.org> | 2021-06-06 17:00:02 +0200 |
---|---|---|
committer | Dominique Dumont <dod@debian.org> | 2021-06-07 19:14:00 +0200 |
commit | 8b22bdcad605773b0431caae4a13050290f28147 (patch) | |
tree | f5b0af81b10cb5e1df2928ecac647363767b6d13 | |
parent | 3478a7bd23d7d646fc8afaea90f82a28b05b34c0 (diff) |
fix doc of Config::Model::Backend::DpkgSyntax
-rw-r--r-- | lib/Config/Model/Backend/DpkgSyntax.pm | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/lib/Config/Model/Backend/DpkgSyntax.pm b/lib/Config/Model/Backend/DpkgSyntax.pm index 2f0b8ce5..5ec1bf83 100644 --- a/lib/Config/Model/Backend/DpkgSyntax.pm +++ b/lib/Config/Model/Backend/DpkgSyntax.pm @@ -335,7 +335,7 @@ With a dpkg file containing: Name: Foo Version: 1.2 - + # section comment Name: Bar # data comment @@ -350,9 +350,13 @@ With a dpkg file containing: Parse the file with: package MyParser ; + use strict; use warnings; + use 5.20.1; + + # DpkgSyntax uses Log4perl, so we must initialise this module use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($WARN); @@ -361,18 +365,18 @@ Parse the file with: with 'Config::Model::Backend::DpkgSyntax'; package main ; - use IO::File; - use Data::Dumper; + use Path::Tiny; + use YAML::XS; - my $file = 'examples/dpkg-test'; # replace with any file name - my $fh = IO::File->new(); - $fh->open("< $file"); + # load control file + my $file = path('dpkg-test'); + # create your parser my $parser = MyParser->new() ; - my $data = $parser->parse_dpkg_file($file, $fh, 'yes', 1); - $fh->close; - - print Dumper $data; + + # convert control file data in a Perl data structure + # documented in Synopsis + my $data = $parser->parse_dpkg_file($file, 'yes', 1); Data contains: @@ -411,46 +415,44 @@ Data contains: To write Dpkg file back: package MyParser ; - + use strict; use warnings; - + use 5.20.1; - + + # DpkgSyntax uses Log4perl, so we must initialise this module 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) + use Path::Tiny; + 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" - ] + [ + '# 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; + + # print control file content + say $parser->write_dpkg_file($data) ; =head1 DESCRIPTION -This module is a Moose role to read and write dpkg control files. +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. @@ -463,9 +465,9 @@ 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 +Last not but not least, this module can be re-used outside of C<Config::Model> with some small modifications in exception -handing. Ask the author if you want this module shipped in its own +handling. Ask the author if you want this module shipped in its own distribution. =head1 @@ -477,7 +479,7 @@ Parameters: C<( file_path, file_handle, [ check, [ comment_allowed ]] )> Read a control file from C<file_handle> and returns a nested list (or a list ref) containing data from the file. -See sysnopsis for the returned structure. +See synopsis for the returned structure. C<check> is C<yes>, C<skip> or C<no> (default C<yes>). C<comment_allowed> is boolean (default 0) |