Codex

Data::Section

Section: User Contributed Perl Documentation (3pm)

Updated: 2014-03-10

Index?action=index Return to Main Contents


NAME

Data::Section - read multiple hunks of data out of your DATA section

VERSION

version 0.200006

SYNOPSIS

DESCRIPTION

Data::Section provides an easy way to access multiple named chunks of line-oriented data in your module's DATA section. It was written to allow modules to store their own templates, but probably has other uses.

WARNING

You will need to use sections and not sections. Yes, it matters. Who knew!

EXPORTS

To get the methods exported by Data::Section, you must import like this:

Optional arguments may be given to Data::Section like this:

Valid arguments are:

Three methods are exported by Data::Section:

section_data

This method returns a reference to a string containing the data from the name section, either in the invocant's section or in that of one of its ancestors. (The ancestor must also derive from the class that imported Data::Section.)

By default, named sections are delimited by lines that look like this:

You can use as many underscores as you want, and the space around the name is optional. This pattern can be configured with the option (see above). If present, a single leading is removed, so that sections can encode lines that look like section delimiters.
When a line containing only is reached, all processing of sections ends.

section_data_names

This returns a list of all the names that will be recognized by the method.

merged_section_data

This method returns a hashref containing all the data extracted from the package data for all the classes from which the invocant inherits --- as long as those classes also inherit from the package into which Data::Section was imported.

In other words, given this inheritance tree:

...if Data::Section was imported by A, then when D's is invoked, C's data section will not be considered. (This prevents the read position of C's data handle from being altered unexpectedly.)

The keys in the returned hashref are the section names, and the values are references to the strings extracted from the data sections.

merged_section_data_names

This returns a list of all the names that will be recognized by the method.

local_section_data

This method returns a hashref containing all the data extracted from the package on which the method was invoked. If called on an object, it will operate on the package into which the object was blessed.

This method needs to be used carefully, because it's weird. It returns only the data for the package on which it was invoked. If the package on which it was invoked has no data sections, it returns an empty hashref.

local_section_data_names

This returns a list of all the names that will be recognized by the method.

TIPS AND TRICKS

MooseX::Declare and namespace::autoclean

The namespace::autoclean library automatically cleans foreign routines from a class, including those imported by Data::Section.

MooseX::Declare does the same thing, and can also cause your section to appear outside your class's package.
These are easy to address. The Sub::Exporter::ForMethods library provides an installer that will cause installed methods to appear to come from the class and avoid autocleaning. Using an explicit statement will keep the data section in the correct package.

SEE ALSO

article for RJBS Advent 2009 <http://advent.rjbs.manxome.org/2009/2009-12-09.html>:
Inline::Files does something that is at first look similar,

but it works with source filters, and contains the warning:

Enough said.

:

AUTHOR

Ricardo SIGNES <[email protected]>

COPYRIGHT AND LICENSE

This software is copyright (c) 2008 by Ricardo SIGNES.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


Index

NAME

VERSION

SYNOPSIS

DESCRIPTION

WARNING

EXPORTS

section_data

section_data_names

merged_section_data

merged_section_data_names

local_section_data

local_section_data_names

TIPS AND TRICKS

MooseX::Declare and namespace::autoclean

SEE ALSO

AUTHOR

COPYRIGHT AND LICENSE