NAME
Data::Section::Seekable::Writer - Generate data section with multiple parts
VERSION
This document describes version 0.092 of Data::Section::Seekable::Writer (from Perl distribution Data-Section-Seekable), released on 2023-03-24.
SYNOPSIS
In your script:
use Data::Section::Seekable::Writer;
my $writer = Data::Section::Seekable::Writer->new;
$writer->add_part(part1 => "This is part1\n");
$writer->add_part(part2 => "This is part\ntwo\n", "very,important");
print "__DATA__\n", $writer;
will print:
__DATA__
Data::Section::Seekable v1
part1,0,14
part2,14,17,very,important
This is part1
This is part
two
If we add a header before printing:
$writer->header(sub { my ($writer, $name, $content, $extra) = @_; "### $name ###\n"});
print "__DATA__\n", $writer;
then the output will be:
__DATA__
Data::Section::Seekable v1
part1,14,14
part2,42,17,very,important
### part1 ###
This is part1
### part2 ###
This is part
two
DESCRIPTION
This class lets you generate data section which can contain multiple part in the format described by Data::Section::Seekable.
METHODS
new(%attrs) => obj
Constructor. Attributes:
header => str|code (default: code to list filename)
Header string (or code which should return a string) to add before each part's content. The default is to print:
### <name> ###
Code will get these arguments:
($writer, $name, $content, $extra)
$writer->add_part($name => $content)
$writer->as_string => str
Get the final data section as string. You can also use the object as a string, e.g.:
print $writer;
because this method is used for stringification overloading.
$writer->header([ $str_or_code ]) => value
Get/set header attribute.
$writer->empty
Empty content.
Why am I getting the error message "readline() on unopened filehandle DATA at ..."?
You are probably writing in the BEGIN phase, at which point the DATA filehandle is not available. Read perldata for more details.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Data-Section-Seekable.
SOURCE
Source repository is at https://github.com/perlancar/perl-Data-Section-Seekable.
SEE ALSO
Data::Section::Seekable for the description of the data format.
Data::Section::Seekable::Reader for the reader class.
AUTHOR
perlancar <perlancar@cpan.org>
CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
COPYRIGHT AND LICENSE
This software is copyright (c) 2023, 2016, 2015 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Section-Seekable
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.