| 1 |
NAME |
| 2 |
Data::Section::Simple - Read data from __DATA__ |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use Data::Section::Simple qw(get_data_section); |
| 6 |
|
| 7 |
# Functional interface -- reads from caller package __DATA__ |
| 8 |
my $all = get_data_section; # All data in hash reference |
| 9 |
my $foo = get_data_section('foo.html'); |
| 10 |
|
| 11 |
# OO - allows reading from other packages |
| 12 |
my $reader = Data::Section::Simple->new($package); |
| 13 |
my $all = $reader->get_data_section; |
| 14 |
|
| 15 |
__DATA__ |
| 16 |
|
| 17 |
@@ foo.html |
| 18 |
<html> |
| 19 |
<body>Hello</body> |
| 20 |
</html> |
| 21 |
|
| 22 |
@@ bar.tt |
| 23 |
[% IF true %] |
| 24 |
Foo |
| 25 |
[% END %] |
| 26 |
|
| 27 |
DESCRIPTION |
| 28 |
Data::Section::Simple is a simple module to extract data from "__DATA__" |
| 29 |
section of the file. |
| 30 |
|
| 31 |
LIMITATIONS |
| 32 |
As the name suggests, this module is a simpler version of the excellent |
| 33 |
Data::Section. If you want more functionalities such as merging data |
| 34 |
sections or changing header patterns, use Data::Section instead. |
| 35 |
|
| 36 |
This module does not implement caching (yet) which means in every |
| 37 |
"get_data_section" or "get_data_section($name)" this module seeks and |
| 38 |
re-reads the data section. If you want to avoid doing so for the better |
| 39 |
performance, you should implement caching in your own caller code. |
| 40 |
|
| 41 |
BUGS |
| 42 |
__DATA__ appearing elsewhere |
| 43 |
If you data section has literal "__DATA__" in the data section, this |
| 44 |
module might be tricked by that. Although since its pattern match is |
| 45 |
greedy, "__DATA__" appearing *before* the actual data section (i.e. in |
| 46 |
the code) might be okay. |
| 47 |
|
| 48 |
This is by design -- in theory you can "tell" the DATA handle before |
| 49 |
reading it, but then reloading the data section of the file (handy for |
| 50 |
developing inline templates with PSGI web applications) would fail |
| 51 |
because the pos would be changed. |
| 52 |
|
| 53 |
If you don't like this design, again, use the superior Data::Section. |
| 54 |
|
| 55 |
utf8 pragma |
| 56 |
If you enable utf8 pragma in the caller's package (or the package you're |
| 57 |
inspecting with the OO interface), the data retrieved via |
| 58 |
"get_data_section" is decoded, but otherwise undecoded. There's no |
| 59 |
reliable way for this module to programmatically know whether utf8 |
| 60 |
pragma is enabled or not: it's your responsibility to handle them |
| 61 |
correctly. |
| 62 |
|
| 63 |
AUTHOR |
| 64 |
Tatsuhiko Miyagawa <[email protected]> |
| 65 |
|
| 66 |
COPYRIGHT |
| 67 |
Copyright 2010- Tatsuhiko Miyagawa |
| 68 |
|
| 69 |
The code to read DATA section is based on Mojo::Command get_all_data: |
| 70 |
Copyright 2008-2010 Sebastian Riedel |
| 71 |
|
| 72 |
LICENSE |
| 73 |
This library is free software; you can redistribute it and/or modify it |
| 74 |
under the same terms as Perl itself. |
| 75 |
|
| 76 |
SEE ALSO |
| 77 |
Data::Section Inline::Files |
| 78 |
|