IO::Infiles - Multiple handlers for multiple __END__-like tokens


IO-Infiles documentation Contained in the IO-Infiles distribution.

Index


Code Index:

NAME

Top

IO::Infiles - Multiple handlers for multiple __END__-like tokens

SYNOPSIS

Top

  use IO::Infiles;

  __END__
  end data 
  __FOO__
  foo data
  more
  __JOHN__
  john data

DESCRIPTION

Top

This module adds more token sections at the end of your code. The first token must be named __END__ ; as before, its data are available through the END handler. If there are more token sections with other names, handlers of the same name will all be pre-opened.

EXPORT

One read-only IO handler is exported for each token name.

TROUBLESHOOTING

Top

The first token should be the __END__ token. If instead you use __DATA__ as the name for the first token, you will receive the warning "Attempt to free unreferenced scalar: SV 0x82ebdf0 during global destruction." Rename your first token to __END__ if you want to silence this warning.

AUTHOR

Top

Ioannis Tambouras, <ioannis@yahoo.com>

COPYRIGHT AND LICENSE

Top

inlinefiles() An internal subroutine, the user should hold no interest. =head2 open() =cut


IO-Infiles documentation Contained in the IO-Infiles distribution.

package IO::Infiles;

use 5.008004;
use strict;
use warnings;
use Fatal qw(open);

our $VERSION = '0.04';



sub inlinefiles {
        m/ ^__([A-Z]\w+)__\s*\n
                      (.*?)
                      (?=__[A-Z]\w+__\s*\n | \Z)
                /xsmgo;
}

sub import {
        local $_ = do{ local $/; open 0; <0>};
        (my $pack)= (caller 1)[3] =~ /^(.*::)/g ;
        my %files = inlinefiles;
        no strict 'refs' ; no warnings 'once';
        open *{$pack.$_} , '<', \$files{$_}   for keys(%files);
}


1;
__END__