From: tokuhirom <tokuhirom@gmail.com>
Date: Tue, 30 Apr 2013 06:41:11 +0000 (+0900)
Subject: Parse POD after __END__
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Ffix%2Fpod-after-__END__;p=p5sagit%2FModule-Metadata.git

Parse POD after __END__
See https://rt.cpan.org/Ticket/Display.html?id=79656
---

diff --git a/lib/Module/Metadata.pm b/lib/Module/Metadata.pm
index 9f92dde..ee6a375 100644
--- a/lib/Module/Metadata.pm
+++ b/lib/Module/Metadata.pm
@@ -518,6 +518,7 @@ sub _parse_fh {
   my $pkg = 'main';
   my $pod_sect = '';
   my $pod_data = '';
+  my $in_end = 0;
 
   while (defined( my $line = <$fh> )) {
     my $line_num = $.;
@@ -560,11 +561,18 @@ sub _parse_fh {
 
     } else {
 
+      # Skip after __END__
+      next if $in_end;
+
       # Skip comments in code
       next if $line =~ /^\s*#/;
 
       # Would be nice if we could also check $in_string or something too
-      last if $line =~ /^__(?:DATA|END)__$/;
+      if ($line eq '__END__') {
+        $in_end++;
+        next;
+      }
+      last if $line eq '__DATA__';
 
       # parse $line to see if it's a $VERSION declaration
       my( $vers_sig, $vers_fullname, $vers_pkg ) =
diff --git a/t/endpod.t b/t/endpod.t
new file mode 100644
index 0000000..6ee0ff2
--- /dev/null
+++ b/t/endpod.t
@@ -0,0 +1,14 @@
+use strict;
+use warnings;
+use utf8;
+use Test::More;
+use Module::Metadata;
+
+# This test case tests about parsing pod after `__END__` token.
+
+my $pm_info = Module::Metadata->new_from_file('t/lib/ENDPOD.pm', collect_pod => 1,);
+is( $pm_info->name, 'ENDPOD', 'found default package' );
+is(join(',', $pm_info->pod_inside), 'NAME');
+
+done_testing;
+
diff --git a/t/lib/ENDPOD.pm b/t/lib/ENDPOD.pm
new file mode 100644
index 0000000..cb60394
--- /dev/null
+++ b/t/lib/ENDPOD.pm
@@ -0,0 +1,13 @@
+package ENDPOD;
+use strict;
+use warnings;
+use utf8;
+
+
+1;
+__END__
+
+=head1 NAME
+
+ENDPOD - End pod.
+