The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Data::Section::Seekable::Reader - Read parts from data section

VERSION

This document describes version 0.091 of Data::Section::Seekable::Reader (from Perl distribution Data-Section-Seekable), released on 2023-01-20.

SYNOPSIS

In your script:

 use Data::Section::Seekable::Reader;

 my $reader = Data::Section::Seekable::Reader->new;

 my $p2 = $reader->read_part('part2'); # -> "This is part\ntwo\n"
 my $p1 = $reader->read_part('part1'); # -> "This is part1\n"
 my $p3 = $reader->read_part('part3'); # dies, unknown part

 my $e1 = $reader->read_extra('part1'); # -> undef
 my $e2 = $reader->read_extra('part2'); # -> "important"
 my $e3 = $reader->read_extra('part3'); # dies, unknown part

 __DATA__
 Data::Section::Seekable v1
 part1,0,14
 part2,14,17,important

 This is part1
 This is part
 two

DESCRIPTION

This class lets you read parts from __DATA__ section. Data section should contain data in the format described by Data::Section::Seekable.

METHODS

new(%attrs) => obj

Constructor. Attributes:

  • handle => filehandle (default: DATA)

    To access another package's data section, you can do:

     my $reader = Data::Section::Seekable::Reader->new(handle => \*Another::Package::DATA);

The constructor will also read the header and TOC in the data section. Will die on failure.

$reader->parts($name) => list

Return list of all known parts in the data section, sorted lexicographically.

$reader->read_part($name) => str

Read the content of a part named $name. Will die if part is unknown.

$reader->read_extra($name) => str

Read the extra information field (the fourth field of TOC line) of a part named $name. Will die if part is unknown.

FAQ

Why am I getting the error message "readline() on unopened filehandle DATA at ..."?

You are probably reading 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::Writer to generate the data section.

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.