Subject: | Look for packages in *.pm.PL files, and inside __DATA__ section |
PAUSE scans *.pm.PL files as possible sources of packages, but
Module::Metadata does not. Also, PAUSE looks for package declarations
inside the __DATA__ section when scanning a .pm.PL file. A good example
of this is the common::sense module, which PAUSE will index but
Module::Metadata will not.
I can't really say that PAUSE's behavior is the "right" one.
Personally, I think the burden for edge cases like this falls upon the
module author to declare the "provides" in the META.
But aside from that, PAUSE does give a more satisfactory answer in this
situation. So perhaps Module::Metadata should do the same.
A patch (with tests) is attached.
-Jeff
Subject: | Module-Metadata-1.000009.patch |
diff -Naur Module-Metadata-1.000009/lib/Module/Metadata.pm Module-Metadata-1.000009-mine/lib/Module/Metadata.pm
--- Module-Metadata-1.000009/lib/Module/Metadata.pm 2012-02-08 09:15:07.000000000 -0800
+++ Module-Metadata-1.000009-mine/lib/Module/Metadata.pm 2012-05-16 12:21:09.000000000 -0700
@@ -209,7 +209,7 @@
} else {
find( {
wanted => sub {
- push @files, $_ if -f $_ && /\.pm$/;
+ push @files, $_ if -f $_ && /\.pm(?:\.PL)?$/;
},
no_chdir => 1,
}, $dir );
@@ -459,7 +459,9 @@
$in_pod = ($line =~ /^=(?!cut)/) ? 1 : ($line =~ /^=cut/) ? 0 : $in_pod;
# Would be nice if we could also check $in_string or something too
- last if !$in_pod && $line =~ /^__(?:DATA|END)__$/;
+ # Note: *.PL files could have code after the __DATA__ as well
+ last if !$in_pod && $line =~ /^__(?:DATA|END)__$/
+ && $self->{filename} !~ /\.PL$/;
if ( $in_pod || $line =~ /^=cut/ ) {
diff -Naur Module-Metadata-1.000009/t/metadata.t Module-Metadata-1.000009-mine/t/metadata.t
--- Module-Metadata-1.000009/t/metadata.t 2012-02-08 09:15:06.000000000 -0800
+++ Module-Metadata-1.000009-mine/t/metadata.t 2012-05-16 12:46:25.000000000 -0700
@@ -203,7 +203,7 @@
);
my %modules = reverse @modules;
-plan tests => 42 + 2 * keys( %modules );
+plan tests => 43 + 2 * keys( %modules );
require_ok('Module::Metadata');
@@ -582,3 +582,41 @@
is_deeply( $got_provides, $exp_provides, "provides()" )
or diag explain $got_provides;
}
+
+#------------------------------------------------------------------------------
+
+{
+
+ # revert to pristine state
+ $dist->regen( clean => 1 );
+
+ # Create a pm.PL file with the package inside the __DATA__
+ $dist->add_file( 'Simple.pm.PL', <<'---' );
+# No code here
+__DATA__
+package Simple::InData;
+$VERSION = '1.23';
+---
+
+ $dist->regen;
+
+ my $got_pvfd = Module::Metadata->package_versions_from_directory($dist->dirname);
+ my $exp_pvfd = {
+ 'Simple' => {
+ 'file' => 'lib/Simple.pm',
+ 'version' => '0.01'
+ },
+ 'Simple::Ex' => {
+ 'file' => 'lib/Simple.pm',
+ 'version' => '0.02'
+ },
+ 'Simple::InData' => {
+ 'file' => 'Simple.pm.PL',
+ 'version' => '1.23'
+ }
+ };
+
+
+ is_deeply( $got_pvfd, $exp_pvfd, "package inside a __DATA__ section of a .PL file" )
+ or diag explain $got_pvfd;
+}