Skip to content

Commit

Permalink
handle no __DATA__ sections
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbs committed Jun 7, 2008
1 parent 5169032 commit 6d115eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Revision history for Data-Section

0.002 2008-06-07
improve documentation
handle valid classes with no __DATA__ section

0.001 2008-06-07
first release
8 changes: 7 additions & 1 deletion lib/Data/Section.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Data::Section provides an easy way to access multiple named chunks of
line-oriented data in your module's DATA section. It was written to allow
modules to store their own templates, but probably has other uses.
=head1 WARNING
You will need to use C<__DATA__> sections and not C<__END__> sections. Yes, it
matters. Who knew!
=head1 EXPORTS
To get the methods exported by Data::Section, you must import like this:
Expand All @@ -60,7 +65,7 @@ Optional arguments may be given to Data::Section like this:
Valid arguments are:
inherit - if true, allow packages to inherit the data of the packages
from which they inherit
from which they inherit; default: true
header_re - if given, changes the regex used to find section headers
in the data section; it should leave the section name in $1
Expand Down Expand Up @@ -141,6 +146,7 @@ sub _mk_reader_group {
my $template = $stash{ $pkg } = { };

my $dh = do { no strict 'refs'; \*{"$pkg\::DATA"} }; ## no critic Strict
return $stash{ $pkg} unless defined fileno *$dh;

my $current;
LINE: while (my $line = <$dh>) {
Expand Down
7 changes: 5 additions & 2 deletions t/basic.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use strict;
use warnings;
use lib 't/lib';
use Test::More tests => 18;
use Test::More tests => 19;

use Parent;
use Child;
Expand All @@ -11,6 +11,8 @@ use I::Parent;
use I::Child;
use I::Grandchild;

use NoData;

my @want = (
Parent => { a => \"1\n", b => \"2\n", c => \"3\n" },
Child => { b => \"22\n", c => \"33\n", d => \"44\n" },
Expand Down Expand Up @@ -47,5 +49,6 @@ is_deeply(
I::Grandchild->merged_section_data,
{ a => \"111\n", b => \"22\n", c => \"33\n", d => \q{}, },
"I::Grandchild->merged_section_data",
)
);

is_deeply(NoData->local_section_data, {}, "nothing found in NoData");

0 comments on commit 6d115eb

Please sign in to comment.