Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

rjbs (4671)

  (email not shown publicly)
AOL IM: RicardoJBSignes (Add Buddy, Send Message)
Yahoo! ID: RicardoSignes (Add User, Send Message)

I'm a Perl coder living in Bethlehem, PA and working Philadelphia. I'm a philosopher and theologan by training, but I was shocked to learn upon my graduation that these skills don't have many associated careers. Now I write code.

Journal of rjbs (4671)

Saturday June 07, 2008
12:49 PM

new distribution: data-section

[ #36614 ]

I've, uh, been writing a lot of new general-purpose modules this week. This happens sometimes when I suddenly find myself writing a new program and I want to reuse mostly generic tricks that I wrote into an old program. I split a lot of things out of Rubric, eventually, and now I'm splitting things off of this and that. I broke Config::INI::MVP::Reader out of App::Addex::Config, Mixin::Linewise out of Config::INI, and this next module out of Software::License -- although it's something I've done in other ways, before.

Basically, it lets you retrieve hunks of data from your package's DATA section, if you just delimit it properly. So, assuming a normal configuration, you can say something like:

package Letter::Rejection;
use Data::Section -setup;

sub reject {
  my ($self, $who) = @_;
  my $template = $self->data_section('rejection');

  my $letter = $$template;
  $letter =~ s/RECIPIENT/$who/g;

sub accept {
  my ($self, $who) = @_;
  my $template = $self->data_section('acceptance');

  my $letter = $$template;
  $letter =~ s/RECIPIENT/$who/g;

___[ rejection ]___

Sorry, no thanks.


___[ acceptance ]___

Fine, we'll print it.


This is sort of like Inline::Files, but that works with source filters, and contains the warning:

It is possible that this module may overwrite the source code in files that
use it. To protect yourself against this possibility, you are strongly
advised to use the -backup option described in "Safety first".


The other useful feature is that these data section data are inherited. If you request the section foo from your class, and it doesn't have that section in its DATA section, but one of the classes between it and the one that used Data::Section does, you'll get that.

This behavior can be switched off.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.