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