For this week, I’m turning the first of several modules I was introduced to by reading RJBS’ Advent Calendar. This module scratches a particular itch that I’ve had on several occasions, including fairly recently.
Data::Section, in simple terms, turns your
__DATA__ section into a hash-table of strings keyed by indexes you choose. It gives you a clean, programmatic way of having multiple “mini-data” sections within the main one, in a fashion similar to Inline::Files (but without the niggling caveat that it could overwrite your source files). The author notes that it was originally envisioned as a way for modules to store their own (multiple) templates, which is a task I’ve had to deal with before. But it would be useful anywhere you want to store large chunks of text data, without resorting to here-documents. It also allows for inheritance of data from a module’s super-classes that also use Data::Section, allowing a class to re-use existing data and only “declare” the extra sections it needs, or those sections that need to be different. You can learn more at the advent entry for this module.
I already have a small CGI app that will be getting the Data::Section treatment, and I hope it can be useful to you as well.Tags: CPAN, module-monday, Perl