pax_global_header00006660000000000000000000000064116354440610014516gustar00rootroot0000000000000052 comment=54d684f07781d7ad36475887f94cd82d319f8af1 perl-Data-Section-Simple-0.03/000075500000000000000000000000001163544406100161005ustar00rootroot00000000000000perl-Data-Section-Simple-0.03/.gitignore000064400000000000000000000000451163544406100200670ustar00rootroot00000000000000META.yml Makefile inc/ pm_to_blib *~ perl-Data-Section-Simple-0.03/.shipit000064400000000000000000000001651163544406100174030ustar00rootroot00000000000000steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN git.push_to = origin perl-Data-Section-Simple-0.03/Changes000064400000000000000000000007271163544406100174010ustar00rootroot00000000000000Revision history for Perl extension Data::Section::Simple 0.03 Sun Sep 18 12:35:54 PDT 2011 - Noted the use of utf8 pragma - Doc typo fixes (Util) 0.02 Thu Mar 18 15:14:44 PDT 2010 - Added a warning document about __DATA__ appearing elsewhere (rjbs) - Fixed a bug installing via cpanm often fails because fileno $d could be 0 when STDIN is closed (reported by rjbs) 0.01 Thu Mar 18 01:06:44 2010 - original version perl-Data-Section-Simple-0.03/MANIFEST000064400000000000000000000007341163544406100172350ustar00rootroot00000000000000.gitignore Changes inc/Module/Install.pm inc/Module/Install/Base.pm inc/Module/Install/Can.pm inc/Module/Install/Fetch.pm inc/Module/Install/Makefile.pm inc/Module/Install/Metadata.pm inc/Module/Install/ReadmeFromPod.pm inc/Module/Install/Repository.pm inc/Module/Install/Win32.pm inc/Module/Install/WriteAll.pm lib/Data/Section/Simple.pm Makefile.PL MANIFEST This list of files META.yml README t/00_compile.t t/basic.t t/data.t t/DataInCode.pm t/Foo.pm t/pkg_oo.t xt/pod.t perl-Data-Section-Simple-0.03/MANIFEST.SKIP000064400000000000000000000001731163544406100177770ustar00rootroot00000000000000\bRCS\b \bCVS\b \.svn/ \.git/ ^MANIFEST\. ^Makefile$ ~$ \.old$ ^blib/ ^pm_to_blib ^MakeMaker-\d \.gz$ \.cvsignore \.shipit perl-Data-Section-Simple-0.03/Makefile.PL000064400000000000000000000003201163544406100200450ustar00rootroot00000000000000use inc::Module::Install; all_from 'lib/Data/Section/Simple.pm'; readme_from('lib/Data/Section/Simple.pm'); build_requires 'Test::More', 0.88; test_requires 'Test::Requires'; auto_set_repository(); WriteAll; perl-Data-Section-Simple-0.03/README000064400000000000000000000051051163544406100167610ustar00rootroot00000000000000NAME Data::Section::Simple - Read data from __DATA__ SYNOPSIS use Data::Section::Simple qw(get_data_section); # Functional interface -- reads from caller package __DATA__ my $all = get_data_section; # All data in hash reference my $foo = get_data_section('foo.html'); # OO - allows reading from other packages my $reader = Data::Section::Simple->new($package); my $all = $reader->get_data_section; __DATA__ @@ foo.html Hello @@ bar.tt [% IF true %] Foo [% END %] DESCRIPTION Data::Section::Simple is a simple module to extract data from "__DATA__" section of the file. LIMITATIONS As the name suggests, this module is a simpler version of the excellent Data::Section. If you want more functionalities such as merging data sections or changing header patterns, use Data::Section instead. This module does not implement caching (yet) which means in every "get_data_section" or "get_data_section($name)" this module seeks and re-reads the data section. If you want to avoid doing so for the better performance, you should implement caching in your own caller code. BUGS __DATA__ appearing elsewhere If you data section has literal "__DATA__" in the data section, this module might be tricked by that. Although since its pattern match is greedy, "__DATA__" appearing *before* the actual data section (i.e. in the code) might be okay. This is by design -- in theory you can "tell" the DATA handle before reading it, but then reloading the data section of the file (handy for developing inline templates with PSGI web applications) would fail because the pos would be changed. If you don't like this design, again, use the superior Data::Section. utf8 pragma If you enable utf8 pragma in the caller's package (or the package you're inspecting with the OO interface), the data retrieved via "get_data_section" is decoded, but otherwise undecoded. There's no reliable way for this module to programmatically know whether utf8 pragma is enabled or not: it's your responsibility to handle them correctly. AUTHOR Tatsuhiko Miyagawa COPYRIGHT Copyright 2010- Tatsuhiko Miyagawa The code to read DATA section is based on Mojo::Command get_all_data: Copyright 2008-2010 Sebastian Riedel LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO Data::Section Inline::Files perl-Data-Section-Simple-0.03/lib/000075500000000000000000000000001163544406100166465ustar00rootroot00000000000000perl-Data-Section-Simple-0.03/lib/Data/000075500000000000000000000000001163544406100175175ustar00rootroot00000000000000perl-Data-Section-Simple-0.03/lib/Data/Section/000075500000000000000000000000001163544406100211235ustar00rootroot00000000000000perl-Data-Section-Simple-0.03/lib/Data/Section/Simple.pm000064400000000000000000000067621163544406100227250ustar00rootroot00000000000000package Data::Section::Simple; use strict; use 5.008_001; our $VERSION = '0.03'; use base qw(Exporter); our @EXPORT_OK = qw(get_data_section); sub new { my($class, $pkg) = @_; bless { package => $pkg || caller }, $class; } sub get_data_section { my $self = ref $_[0] ? shift : __PACKAGE__->new(scalar caller); if (@_) { return $self->get_data_section->{$_[0]}; } else { my $d = do { no strict 'refs'; \*{$self->{package}."::DATA"} }; return unless defined fileno $d; seek $d, 0, 0; my $content = join '', <$d>; $content =~ s/^.*\n__DATA__\n/\n/s; # for win32 $content =~ s/\n__END__\n.*$/\n/s; my @data = split /^@@\s+(.+?)\s*\r?\n/m, $content; shift @data; # trailing whitespaces my $all = {}; while (@data) { my ($name, $content) = splice @data, 0, 2; $all->{$name} = $content; } return $all; } } 1; __END__ =encoding utf-8 =for stopwords =head1 NAME Data::Section::Simple - Read data from __DATA__ =head1 SYNOPSIS use Data::Section::Simple qw(get_data_section); # Functional interface -- reads from caller package __DATA__ my $all = get_data_section; # All data in hash reference my $foo = get_data_section('foo.html'); # OO - allows reading from other packages my $reader = Data::Section::Simple->new($package); my $all = $reader->get_data_section; __DATA__ @@ foo.html Hello @@ bar.tt [% IF true %] Foo [% END %] =head1 DESCRIPTION Data::Section::Simple is a simple module to extract data from C<__DATA__> section of the file. =head1 LIMITATIONS As the name suggests, this module is a simpler version of the excellent L. If you want more functionalities such as merging data sections or changing header patterns, use L instead. This module does not implement caching (yet) which means in every C or C<< get_data_section($name) >> this module seeks and re-reads the data section. If you want to avoid doing so for the better performance, you should implement caching in your own caller code. =head1 BUGS =head2 __DATA__ appearing elsewhere If you data section has literal C<__DATA__> in the data section, this module might be tricked by that. Although since its pattern match is greedy, C<__DATA__> appearing I the actual data section (i.e. in the code) might be okay. This is by design -- in theory you can C the DATA handle before reading it, but then reloading the data section of the file (handy for developing inline templates with PSGI web applications) would fail because the pos would be changed. If you don't like this design, again, use the superior L. =head2 utf8 pragma If you enable L pragma in the caller's package (or the package you're inspecting with the OO interface), the data retrieved via C is decoded, but otherwise undecoded. There's no reliable way for this module to programmatically know whether utf8 pragma is enabled or not: it's your responsibility to handle them correctly. =head1 AUTHOR Tatsuhiko Miyagawa Emiyagawa@bulknews.netE =head1 COPYRIGHT Copyright 2010- Tatsuhiko Miyagawa The code to read DATA section is based on Mojo::Command get_all_data: Copyright 2008-2010 Sebastian Riedel =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L L =cut perl-Data-Section-Simple-0.03/t/000075500000000000000000000000001163544406100163435ustar00rootroot00000000000000perl-Data-Section-Simple-0.03/t/00_compile.t000064400000000000000000000001211163544406100204510ustar00rootroot00000000000000use strict; use Test::More tests => 1; BEGIN { use_ok 'Data::Section::Simple' } perl-Data-Section-Simple-0.03/t/DataInCode.pm000064400000000000000000000001421163544406100206310ustar00rootroot00000000000000package DataInCode; my $code = < Foo @@ bar.tt [% IF foo %] bar [% END %] __END__ =head1 NAME Foo =cut perl-Data-Section-Simple-0.03/t/basic.t000064400000000000000000000007071163544406100176150ustar00rootroot00000000000000use strict; use Data::Section::Simple qw(get_data_section); use Test::More; my $x = get_data_section(); is_deeply [ sort keys %$x ], [ qw(bar.tt foo.html) ]; is get_data_section('foo.html'), < Foo HTML is get_data_section('bar.tt'), < Foo @@ bar.tt [% IF foo %] bar [% END %] __END__ =head1 NAME basic.t =cut perl-Data-Section-Simple-0.03/t/data.t000064400000000000000000000003051163544406100174370ustar00rootroot00000000000000use lib "t"; use DataInCode; use Test::More; use Data::Section::Simple; my $d = Data::Section::Simple->new('DataInCode'); my $x = $d->get_data_section; is $x->{foo}, "bar\n\n"; done_testing; perl-Data-Section-Simple-0.03/t/pkg_oo.t000064400000000000000000000005761163544406100200160ustar00rootroot00000000000000use strict; use Data::Section::Simple; use lib "t"; use Foo; use Test::More; my $d = Data::Section::Simple->new('Foo'); my $x = $d->get_data_section(); is_deeply [ sort keys %$x ], [ qw(bar.tt foo.html) ]; is $d->get_data_section('foo.html'), < Foo HTML is $d->get_data_section('bar.tt'), < "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok();